Skip to content

Commit

Permalink
y-partykit: remove vendored libs (#34)
Browse files Browse the repository at this point in the history
We'd previously vendored the libs used by y-partykit (yjs, lib0, etc) to workaround a bug in edge-runtime vercel/edge-runtime#243, but it makes using other libs that include those libs difficult. So instead this patch removes the vendoring, and applies the other workaround (which is to set `minify:true`). The tradeoff for this workaround is that any "dev mode" code (i.e. code wrapped with `if (process.env.NODE_ENV !== 'production')`) will be removed. This is temporary and we'll remove it once the bug is fixed by edge-runtime.
  • Loading branch information
threepointone committed Jan 25, 2023
1 parent 37986a8 commit 0fdf7a3
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 58 deletions.
8 changes: 8 additions & 0 deletions .changeset/modern-carrots-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"y-partykit": patch
"partykit": patch
---

y-partykit: remove vendored libs

We'd previously vendored the libs used by y-partykit (yjs, lib0, etc) to workaround a bug in edge-runtime https://github.com/vercel/edge-runtime/issues/243, but it makes using other libs that include those libs difficult. So instead this patch removes the vendoring, and applies the other workaround (which is to set `minify:true`). The tradeoff for this workaround is that any "dev mode" code (i.e. code wrapped with `if (process.env.NODE_ENV !== 'production')`) will be removed. This is temporary and we'll remove it once the bug is fixed by edge-runtime.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module.exports = {
"lib",
"coverage",
".eslintrc.js",
"vendor",
"*.d.ts",
],
rules: {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions packages/partykit/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ const esbuildOptions = {
bundle: true,
write: false,
target: "esnext",
minify: true, // TODO: remove this once https://github.com/vercel/edge-runtime/issues/243 is fixed
} as const;

const CONFIG_PATH = path.join(os.homedir(), ".partykit", "config.json");
Expand Down
3 changes: 1 addition & 2 deletions packages/y-partykit/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/*.d.ts
/*.d.ts.map
vendor
/*.d.ts.map
21 changes: 8 additions & 13 deletions packages/y-partykit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,29 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rm -rf dist && rm -rf vendor && rm -rf *.d.ts*",
"build:vendor": "npx esbuild src/ylibs.ts --bundle --outfile=vendor/ylibs.js --format=cjs --minify --sourcemap & tsc --project tsconfig.vendor.json",
"clean": "rm -rf dist && rm -rf *.d.ts*",
"build:server": "npx esbuild src/index.ts src/storage.ts --outdir=dist --format=esm --sourcemap",
"build:provider": "npx esbuild src/provider.ts --outfile=dist/provider.js --format=esm --sourcemap",
"build:package-types": "tsc --project tsconfig.extract.json && mv dist/*.d.ts* .",
"build": "npm run clean && npm run build:vendor && npm run build:server && npm run build:provider && npm run build:package-types"
"build": "npm run clean && npm run build:server && npm run build:provider && npm run build:package-types"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/lodash.debounce": "^4.0.7",
"lib0": "^0.2.60",
"lodash.debounce": "^4.0.8",
"y-protocols": "^1.0.5",
"yjs": "^13.5.44"
"@types/lodash.debounce": "^4.0.7"
},
"files": [
"dist/*.js",
"dist/*.js.map",
"vendor/*.js",
"vendor/*.js.map",
"vendor/*.d.ts",
"vendor/*.d.ts.map",
"*.d.ts",
"*.d.ts.map"
],
"dependencies": {
"y-websocket": "^1.4.5"
"lib0": "^0.2.60",
"lodash.debounce": "^4.0.8",
"y-protocols": "^1.0.5",
"y-websocket": "^1.4.5",
"yjs": "^13.5.44"
}
}
17 changes: 6 additions & 11 deletions packages/y-partykit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// Our dev environment has a problem where yjs doesn't
// "work", so we use a special build
import {
Y,
syncProtocol,
awarenessProtocol,
encoding,
decoding,
map,
} from "../vendor/ylibs";

// Let's also export it all for anyone else to use
export * from "../vendor/ylibs";
import * as Y from "yjs";
import * as syncProtocol from "y-protocols/sync";
import * as awarenessProtocol from "y-protocols/awareness";
import * as encoding from "lib0/encoding";
import * as decoding from "lib0/decoding";
import * as map from "lib0/map";

import debounce from "lodash.debounce";
import type { PartyKitRoom } from "partykit/server";
Expand Down
2 changes: 1 addition & 1 deletion packages/y-partykit/src/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WebsocketProvider } from "y-websocket";
import type { Y } from "./ylibs";
import type * as Y from "yjs";

export default class YPartyKitProvider extends WebsocketProvider {
constructor(
Expand Down
4 changes: 3 additions & 1 deletion packages/y-partykit/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Y, encoding, decoding } from "../vendor/ylibs";
import * as Y from "yjs";
import * as encoding from "lib0/encoding";
import * as decoding from "lib0/decoding";

import type { PartyKitStorage } from "partykit/server";

Expand Down
12 changes: 0 additions & 12 deletions packages/y-partykit/src/ylibs.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/y-partykit/tsconfig.vendor.json

This file was deleted.

0 comments on commit 0fdf7a3

Please sign in to comment.