Skip to content
Open
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
34 changes: 21 additions & 13 deletions .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,35 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
cache-dependency-path: |
etherpad/src/package-lock.json
etherpad/src/bin/doc/package-lock.json
plugin/package-lock.json
- run: npm install [email protected] -g
name: Install legacy npm for correct dependency resolution
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
-
name: Prepare Etherpad core
run: |
cd ./etherpad/src
npm ci
npm link
pnpm i
-
name: Prepare plugin
run: |
cd ./plugin
PLUGIN_NAME=$(npx -c 'printf %s\\n "${npm_package_name}"') || exit 1
npm ci
npm link
npm link ep_etherpad-lite
pnpm i
pnpm link ep_etherpad-lite
pnpm link ep_etherpad-lite
cd ../etherpad
npm link "${PLUGIN_NAME}"
# Rename to match the glob pattern passed to mocha.
Expand All @@ -59,4 +67,4 @@ jobs:
run: rm -rf ./etherpad/src/tests/backend/specs
-
name: Run the backend tests
run: cd ./etherpad/src && npm test
run: cd ./etherpad/src && pnpm test
32 changes: 20 additions & 12 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
cache-dependency-path: |
node_modules/ep_etherpad-lite/package-lock.json
node_modules/ep_etherpad-lite/bin/doc/package-lock.json
package-lock.json
- run: npm install [email protected] -g
name: Install legacy npm for correct dependency resolution
# All of ep_etherpad-lite's devDependencies are installed because the
# plugin might do `require('ep_etherpad-lite/node_modules/${devDep}')`.
# Eventually it would be nice to create an ESLint plugin that prohibits
Expand Down Expand Up @@ -87,9 +80,24 @@ jobs:
with:
node-version: 20
registry-url: https://registry.npmjs.org/
cache: 'npm'
- run: npm install [email protected] -g
name: Install legacy npm for correct dependency resolution
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
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
-
name: Bump version (patch)
run: |
Expand All @@ -98,13 +106,13 @@ jobs:
[ "${NEW_COMMITS}" -gt 0 ] || exit 0
git config user.name 'github-actions[bot]'
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
npm ci
pnpm i
npm version patch
git push --follow-tags
# This is required if the package has a prepare script that uses something
# in dependencies or devDependencies.
-
run: npm ci
run: pnpm i
# `npm publish` must come after `git push` otherwise there is a race
# condition: If two PRs are merged back-to-back then master/main will be
# updated with the commits from the second PR before the first PR's
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto-install-peers=false
41 changes: 21 additions & 20 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ exports.connect = (host) => {
const padIdParam = '/p/';
const indexOfPadId = parsed.pathname.indexOf(padIdParam);
if (indexOfPadId >= 0) {
padState.path = parsed.pathname.substring(0, indexOfPadId)
padState.padId = parsed.pathname.substring(indexOfPadId + padIdParam.length)
padState.path = parsed.pathname.substring(0, indexOfPadId);
padState.padId = parsed.pathname.substring(indexOfPadId + padIdParam.length);
} else {
padState.path = '';
padState.padId = randomString();
Expand Down Expand Up @@ -60,11 +60,11 @@ exports.connect = (host) => {
protocolVersion: 2,
};

socket.json.send(msg);
socket.emit('message', msg);
});

socket.on('message', (obj) => {
// message emitter sends all messages should they be required
// message emitter sends all messages should they be required
ee.emit('message', obj);


Expand All @@ -76,8 +76,8 @@ exports.connect = (host) => {
ee.emit('connected', padState);
} else if (obj.type === 'COLLABROOM' && obj.data && obj.data.type === 'NEW_CHANGES') {
if (obj.data.newRev <= padState.baseRev) {
// looks like server sometimes can send the same change twice. A bug in server or socket.io?
// anyways, we're not interested in changes already happend, just ignore them
// looks like server sometimes can send the same change twice. A bug in server or socket.io?
// anyways, we're not interested in changes already happend, just ignore them
return;
}
assert((obj.data.newRev - 1) === padState.baseRev,
Expand Down Expand Up @@ -107,8 +107,8 @@ exports.connect = (host) => {
ee.emit('newContents', padState.atext);
} else if (obj.type === 'COLLABROOM' && obj.data && obj.data.type === 'ACCEPT_COMMIT') {
if (obj.data.newRev <= padState.baseRev) {
// looks like server sometimes can send the same change twice. A bug in server or socket.io?
// anyways, we're not interested in changes already happend, just ignore them
// looks like server sometimes can send the same change twice. A bug in server or socket.io?
// anyways, we're not interested in changes already happend, just ignore them
return;
}

Expand All @@ -124,14 +124,14 @@ exports.connect = (host) => {
}
sendMessage();
} else if (obj.type === 'COLLABROOM' && obj.data && obj.data.type === 'USER_NEWINFO') {
// We don't care about this for now.
// We don't care about this for now.
} else if (obj.type === 'COLLABROOM' && obj.data && obj.data.type === 'USER_LEAVE') {
// We don't care about this for now.
// We don't care about this for now.
} else if (obj.disconnect) {
ee.emit('disconnect', obj.disconnect);
// TODO close socket here
// TODO close socket here
} else { // Unhandled message
// console.log("Message from Server", obj);
// console.log("Message from Server", obj);
}
});

Expand All @@ -153,7 +153,7 @@ exports.connect = (host) => {

// Function to append contents to a pad
ee.append = (text) => {
// Create a new changeset using the makeSplice method
// Create a new changeset using the makeSplice method
const newChangeset = Changeset.makeSplice(
padState.atext.text, padState.atext.text.length, 0, text);
const newRev = padState.baseRev;
Expand Down Expand Up @@ -188,12 +188,12 @@ exports.connect = (host) => {

// sends a message to the server. Can be used without parameters to try sending outgoing message
const sendMessage = (optMsg) => {
// console.log("sending message: ", optMsg && (optMsg.changeset + '[' + optMsg.baseRev + ']'),
// '; inflight: ' + (padState.inFlight && (
// padState.inFlight.changeset + '[' + padState.inFlight.baseRev + ']')),
// '; outgoing: ' + (padState.outgoing && (
// padState.outgoing.changeset + '[' + padState.outgoing.baseRev + ']'))
// );
// console.log("sending message: ", optMsg && (optMsg.changeset + '[' + optMsg.baseRev + ']'),
// '; inflight: ' + (padState.inFlight && (
// padState.inFlight.changeset + '[' + padState.inFlight.baseRev + ']')),
// '; outgoing: ' + (padState.outgoing && (
// padState.outgoing.changeset + '[' + padState.outgoing.baseRev + ']'))
// );
if (optMsg) {
if (padState.outgoing) {
assert(optMsg.baseRev === padState.outgoing.baseRev,
Expand All @@ -209,14 +209,15 @@ exports.connect = (host) => {
if (!padState.inFlight && padState.outgoing) {
padState.inFlight = padState.outgoing;
padState.outgoing = null;
socket.json.send({
socket.emit('message', {
type: 'COLLABROOM',
component: 'pad',
data: JSON.parse(JSON.stringify(padState.inFlight)),
});
}
};
});

return ee;
};

Expand Down
Loading