Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions .github/workflows/backend-tests.yml

This file was deleted.

82 changes: 27 additions & 55 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,35 @@ on:
- main
- master

env:
PNPM_HOME: ~/.pnpm-store

jobs:
test:
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@v6
with:
repository: ether/etherpad-lite
path: etherpad-lite
-
run: mv etherpad-lite ..
-
uses: actions/checkout@v6
-
uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 10
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v5
name: Setup pnpm cache
name: Cache pnpm store
with:
path: ${{ env.STORE_PATH }}
path: ${{ env.PNPM_HOME }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- uses: pnpm/action-setup@v6
name: Install pnpm
with:
run_install: false
-
run: cd ../etherpad-lite && ./bin/installDeps.sh && pnpm link --global
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
-
run: |
pnpm config set auto-install-peers false
pnpm i
run: pnpm i
-
run: |
has_testcli_script () {
[[ $(pnpm run | grep "^ test" | wc -l) > 0 ]]
}

if has_testcli_script; then
pnpm run test
else
echo "No test script found"
fi
name: Run tests if available
run: pnpm run build
-
run: pnpm run lint

Expand All @@ -73,29 +51,23 @@ jobs:
uses: actions/checkout@v6
with:
fetch-depth: 0
-
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 10
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v5
name: Setup pnpm cache
name: Cache pnpm store
with:
path: ${{ env.STORE_PATH }}
path: ${{ env.PNPM_HOME }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Only install direct dependencies
run: pnpm config set auto-install-peers false
- uses: pnpm/action-setup@v6
name: Install pnpm
with:
run_install: false
-
uses: actions/setup-node@v6
with:
node-version: 24
cache: pnpm
registry-url: https://registry.npmjs.org/
-
name: Bump version (patch)
run: |
Expand Down
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "etherpad-cli-client",
"description": "Node Client for Etherpad",
"version": "4.0.2",
"version": "4.0.3",
"type": "module",
"packageManager": "pnpm@11.1.2",
"author": {
"name": "John McLear",
"email": "john@mclear.co.uk",
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
onlyBuiltDependencies:
- unrs-resolver
strictDepBuilds: false
28 changes: 23 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type PadClient = EventEmitter & {
type ClientVarsMessage = {
type: 'CLIENT_VARS';
data: {
userId?: string;
collab_client_vars: {
initialAttributedText: AText;
apool: JsonableAttributePool;
Expand Down Expand Up @@ -108,6 +109,7 @@ const isDisconnectMessage = (value: unknown): value is DisconnectMessage =>

export const connect = (host?: string): PadClient => {
const ee = new EventEmitter() as PadClient;
let authorId: string | null = null;
const padState: PadState = {
host: '',
path: '',
Expand Down Expand Up @@ -198,6 +200,7 @@ export const connect = (host?: string): PadClient => {
padState.atext = obj.data.collab_client_vars.initialAttributedText;
padState.apool = new AttributePool().fromJsonable(obj.data.collab_client_vars.apool);
padState.baseRev = obj.data.collab_client_vars.rev;
if (typeof obj.data.userId === 'string') authorId = obj.data.userId;
ee.emit('connected', padState);
} else if (isNewChangesMessage(obj)) {
if (obj.data.newRev <= padState.baseRev) return;
Expand Down Expand Up @@ -240,16 +243,31 @@ export const connect = (host?: string): PadClient => {
};

ee.append = (text: string) => {
const newChangeset = Changeset.makeSplice(
padState.atext.text, padState.atext.text.length, 0, text);
// Insert just before the trailing '\n' so the pad's "doc always ends
// with \n" invariant is preserved. Etherpad's server (post-2.7.x)
// rejects USER_CHANGES whose application would leave the doc without
// a trailing newline, and tags inserts with no `author` attribute as
// bad changesets — both produced silent disconnects with the previous
// append-at-text.length / no-attribs behaviour.
const insertPos = Math.max(0, padState.atext.text.length - 1);
const attribs: Array<[string, string]> | undefined =
authorId ? [['author', authorId]] : undefined;
const localChangeset = Changeset.makeSplice(
padState.atext.text, insertPos, 0, text, attribs, padState.apool);
const newRev = padState.baseRev;
padState.atext = Changeset.applyToAText(newChangeset, padState.atext, padState.apool) as AText;
padState.atext = Changeset.applyToAText(
localChangeset, padState.atext, padState.apool) as AText;
// Build a minimal wire pool containing only the attributes referenced
// by this changeset so the server can resolve our `*N` slot numbers.
const wireApool = new AttributePool();
const wireChangeset = Changeset.moveOpsToNewPool(
localChangeset, padState.apool, wireApool);
const msg: PendingMessage = {
component: 'pad',
type: 'USER_CHANGES',
baseRev: newRev,
changeset: newChangeset,
apool: new AttributePool().toJsonable(),
changeset: wireChangeset,
apool: wireApool.toJsonable(),
};
sendMessage(msg);
};
Expand Down