@chee/patchwork-bundles 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/esbuild.d.ts +3 -0
  2. package/dist/esbuild.d.ts.map +1 -0
  3. package/{src/esbuild.ts → dist/esbuild.js} +1 -0
  4. package/dist/esbuild.js.map +1 -0
  5. package/dist/farm.d.ts +3 -0
  6. package/dist/farm.d.ts.map +1 -0
  7. package/{src/farm.ts → dist/farm.js} +1 -0
  8. package/dist/farm.js.map +1 -0
  9. package/dist/index.d.ts +5 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +98 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/rollup.d.ts +3 -0
  14. package/dist/rollup.d.ts.map +1 -0
  15. package/{src/rollup.ts → dist/rollup.js} +1 -0
  16. package/dist/rollup.js.map +1 -0
  17. package/dist/rspack.d.ts +3 -0
  18. package/dist/rspack.d.ts.map +1 -0
  19. package/{src/rspack.ts → dist/rspack.js} +1 -0
  20. package/dist/rspack.js.map +1 -0
  21. package/dist/test/integration.test.d.ts +2 -0
  22. package/dist/test/integration.test.d.ts.map +1 -0
  23. package/dist/test/integration.test.js +172 -0
  24. package/dist/test/integration.test.js.map +1 -0
  25. package/dist/types.d.ts +41 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/types.js +10 -0
  28. package/dist/types.js.map +1 -0
  29. package/dist/utils.d.ts +42 -0
  30. package/dist/utils.d.ts.map +1 -0
  31. package/dist/utils.js +141 -0
  32. package/dist/utils.js.map +1 -0
  33. package/dist/vite.d.ts +3 -0
  34. package/dist/vite.d.ts.map +1 -0
  35. package/{src/vite.ts → dist/vite.js} +1 -0
  36. package/dist/vite.js.map +1 -0
  37. package/dist/webpack.d.ts +3 -0
  38. package/dist/webpack.d.ts.map +1 -0
  39. package/{src/webpack.ts → dist/webpack.js} +1 -0
  40. package/dist/webpack.js.map +1 -0
  41. package/package.json +4 -1
  42. package/.claude/settings.local.json +0 -27
  43. package/pnpm-workspace.yaml +0 -41
  44. package/src/index.ts +0 -133
  45. package/src/types.ts +0 -52
  46. package/src/utils.ts +0 -166
  47. package/test/integration.test.ts +0 -305
  48. package/tsconfig.json +0 -40
  49. package/vitest.config.d.ts +0 -3
  50. package/vitest.config.d.ts.map +0 -1
  51. package/vitest.config.js +0 -10
  52. package/vitest.config.js.map +0 -1
  53. package/vitest.config.ts +0 -10
@@ -1,305 +0,0 @@
1
- import { describe, it, expect, beforeAll, afterAll } from "vitest";
2
- import * as fs from "node:fs/promises";
3
- import * as os from "node:os";
4
- import * as path from "node:path";
5
- import { execSync } from "node:child_process";
6
- import { build as viteBuild } from "vite";
7
- import * as esbuild from "esbuild";
8
-
9
- const AUTOMERGE_URL = "automerge:6iXwddwF9cwrjmM5yqp2xUENxUY";
10
- const ENCODED_URL = encodeURIComponent(AUTOMERGE_URL);
11
-
12
- describe("patchwork-bundles integration", () => {
13
- let tmpDir: string;
14
- let originalCwd: string;
15
-
16
- beforeAll(async () => {
17
- originalCwd = process.cwd();
18
- tmpDir = await fs.mkdtemp(
19
- path.join(os.tmpdir(), "patchwork-bundles-test-")
20
- );
21
-
22
- // Phase 1: set up project with pnpm-plugin-patchwork as a configDependency
23
- await fs.writeFile(
24
- path.join(tmpDir, "package.json"),
25
- JSON.stringify(
26
- {
27
- name: "test-patchwork-bundles",
28
- version: "0.0.0",
29
- type: "module",
30
- dependencies: {
31
- "my-sideboard-tool": AUTOMERGE_URL,
32
- "solid-js": "^1.9.9",
33
- },
34
- },
35
- null,
36
- 2
37
- )
38
- );
39
-
40
- // stub workspace packages that the automerge doc depends on via workspace:^
41
- const bootloaderDir = path.join(tmpDir, "packages/patchwork-bootloader");
42
- await fs.mkdir(bootloaderDir, { recursive: true });
43
- await fs.writeFile(
44
- path.join(bootloaderDir, "package.json"),
45
- JSON.stringify({
46
- name: "@inkandswitch/patchwork-bootloader",
47
- version: "0.0.1",
48
- type: "module",
49
- exports: { "./externals": { import: "./externals.js" } },
50
- })
51
- );
52
- await fs.writeFile(
53
- path.join(bootloaderDir, "externals.js"),
54
- `const externals = [\n "solid-js",\n "solid-js/web",\n "solid-js/html",\n "solid-js/store",\n "solid-js/jsx-runtime",\n "solid-js/h"\n];\nexport default externals;\n`
55
- );
56
-
57
- const elementsDir = path.join(tmpDir, "packages/patchwork-elements");
58
- await fs.mkdir(elementsDir, { recursive: true });
59
- await fs.writeFile(
60
- path.join(elementsDir, "package.json"),
61
- JSON.stringify({
62
- name: "@inkandswitch/patchwork-elements",
63
- version: "0.0.1",
64
- type: "module",
65
- })
66
- );
67
-
68
- await fs.writeFile(
69
- path.join(tmpDir, "pnpm-workspace.yaml"),
70
- [
71
- "packages:",
72
- ' - "packages/*"',
73
- "configDependencies:",
74
- ' pnpm-plugin-patchwork: "0.4.0"',
75
- "",
76
- ].join("\n")
77
- );
78
-
79
- // .npmrc — avoid strict peer deps issues
80
- await fs.writeFile(
81
- path.join(tmpDir, ".npmrc"),
82
- "strict-peer-dependencies=false\nauto-install-peers=true\n"
83
- );
84
-
85
- // install — plugin resolves automerge: deps automatically
86
- // filter out parent pnpm's npm_config_* env vars to avoid contamination
87
- const cleanEnv = Object.fromEntries(
88
- Object.entries(process.env).filter(
89
- ([k]) => !k.startsWith("npm_")
90
- )
91
- );
92
- // strictDepBuilds=false: the automerge stack pulls in cbor-extract, whose
93
- // native build script is ignored. Without this, pnpm 11 exits non-zero
94
- // (ERR_PNPM_IGNORED_BUILDS) even though the install otherwise succeeds.
95
- execSync(
96
- "npx pnpm@11 install --no-frozen-lockfile --config.strictDepBuilds=false",
97
- {
98
- cwd: tmpDir,
99
- stdio: "pipe",
100
- timeout: 120_000,
101
- env: {
102
- ...cleanEnv,
103
- PATCHWORK_SYNC_SERVER: "wss://subduction.sync.inkandswitch.com",
104
- },
105
- }
106
- );
107
-
108
- // Phase 2: write source file
109
- const srcDir = path.join(tmpDir, "src");
110
- await fs.mkdir(srcDir, { recursive: true });
111
- await fs.writeFile(
112
- path.join(srcDir, "index.ts"),
113
- [
114
- `import { createSignal } from "solid-js";`,
115
- `import * as sideboard from "my-sideboard-tool";`,
116
- `console.log(createSignal, sideboard);`,
117
- "",
118
- ].join("\n")
119
- );
120
-
121
- process.chdir(tmpDir);
122
- }, 180_000);
123
-
124
- afterAll(async () => {
125
- process.chdir(originalCwd);
126
- await fs.rm(tmpDir, { recursive: true, force: true });
127
- });
128
-
129
- describe("pnpm plugin installed my-sideboard-tool from automerge", () => {
130
- it("has a package.json with the sideboard package name", async () => {
131
- const pkgPath = path.join(
132
- tmpDir,
133
- "node_modules/my-sideboard-tool/package.json"
134
- );
135
- const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
136
- expect(pkg.name).toBe("@patchwork/chat");
137
- });
138
-
139
- it("has an exports field with a resolvable root entry", async () => {
140
- const pkgPath = path.join(
141
- tmpDir,
142
- "node_modules/my-sideboard-tool/package.json"
143
- );
144
- const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
145
- expect(pkg.exports).toBeDefined();
146
- expect(pkg.exports["."]).toBeDefined();
147
- });
148
-
149
- it("contains actual dist files from the automerge document", async () => {
150
- const distDir = path.join(tmpDir, "node_modules/my-sideboard-tool/dist");
151
- const files = await fs.readdir(distDir);
152
- expect(files.length).toBeGreaterThan(0);
153
- // should have js output
154
- expect(files.some((f) => f.endsWith(".js"))).toBe(true);
155
- });
156
- });
157
-
158
- describe("vite build", () => {
159
- let output: string;
160
-
161
- beforeAll(async () => {
162
- // Determine what entry point the plugin will resolve to
163
- const pluginPath = path.resolve(originalCwd, "dist/vite.js");
164
- const { default: vitePlugin } = await import(pluginPath);
165
-
166
- const result = await viteBuild({
167
- root: tmpDir,
168
- logLevel: "silent",
169
- build: {
170
- lib: {
171
- entry: path.join(tmpDir, "src/index.ts"),
172
- formats: ["es"],
173
- fileName: "index",
174
- },
175
- outDir: path.join(tmpDir, "dist-vite"),
176
- write: true,
177
- minify: false,
178
- },
179
- plugins: [vitePlugin()],
180
- });
181
-
182
- // vite 7 outputs .js, older versions output .mjs
183
- const mjs = path.join(tmpDir, "dist-vite/index.mjs");
184
- const js = path.join(tmpDir, "dist-vite/index.js");
185
- output = await fs.readFile(
186
- await fs.access(mjs).then(() => mjs, () => js),
187
- "utf-8"
188
- );
189
- }, 60_000);
190
-
191
- it("rewrites automerge dep to service-worker URL", () => {
192
- expect(output).toContain(ENCODED_URL);
193
- // Should be an import from /<encoded-url>/...
194
- expect(output).toMatch(new RegExp(`from ["']/${ENCODED_URL}/`));
195
- });
196
-
197
- it("externalizes solid-js", () => {
198
- expect(output).toMatch(/from ["']solid-js["']/);
199
- // if solid-js were inlined, the output would be thousands of lines
200
- const lines = output.split("\n").length;
201
- expect(lines).toBeLessThan(20);
202
- });
203
-
204
- it("does not contain bundled automerge dep code", () => {
205
- // The automerge dep should be external, not inlined
206
- expect(output).not.toContain("my-sideboard-tool");
207
- });
208
- });
209
-
210
- describe("esbuild build", () => {
211
- let output: string;
212
-
213
- beforeAll(async () => {
214
- const pluginPath = path.resolve(originalCwd, "dist/esbuild.js");
215
- const { default: esbuildPlugin } = await import(pluginPath);
216
-
217
- await esbuild.build({
218
- entryPoints: [path.join(tmpDir, "src/index.ts")],
219
- bundle: true,
220
- format: "esm",
221
- outfile: path.join(tmpDir, "dist-esbuild/index.js"),
222
- plugins: [esbuildPlugin()],
223
- logLevel: "silent",
224
- });
225
-
226
- output = await fs.readFile(
227
- path.join(tmpDir, "dist-esbuild/index.js"),
228
- "utf-8"
229
- );
230
- }, 60_000);
231
-
232
- it("rewrites automerge dep to service-worker URL", () => {
233
- expect(output).toContain(ENCODED_URL);
234
- expect(output).toMatch(new RegExp(`from ["']/${ENCODED_URL}/`));
235
- });
236
-
237
- it("externalizes solid-js", () => {
238
- expect(output).toMatch(/from ["']solid-js["']/);
239
- // if solid-js were inlined, the output would be thousands of lines
240
- const lines = output.split("\n").length;
241
- expect(lines).toBeLessThan(20);
242
- });
243
-
244
- it("does not contain bundled automerge dep code", () => {
245
- expect(output).not.toContain("my-sideboard-tool");
246
- });
247
- });
248
-
249
- describe("vite build — patchwork:cross-origin mode", () => {
250
- let output: string;
251
-
252
- beforeAll(async () => {
253
- const pluginPath = path.resolve(originalCwd, "dist/vite.js");
254
- const { default: vitePlugin } = await import(pluginPath);
255
-
256
- await viteBuild({
257
- root: tmpDir,
258
- logLevel: "silent",
259
- build: {
260
- lib: {
261
- entry: path.join(tmpDir, "src/index.ts"),
262
- formats: ["es"],
263
- fileName: "index",
264
- },
265
- outDir: path.join(tmpDir, "dist-vite-xorigin"),
266
- write: true,
267
- minify: false,
268
- // top-level await in the generated virtual module
269
- target: "esnext",
270
- },
271
- plugins: [vitePlugin({ rewrite: { automerge: "patchwork:cross-origin" } })],
272
- });
273
-
274
- const mjs = path.join(tmpDir, "dist-vite-xorigin/index.mjs");
275
- const js = path.join(tmpDir, "dist-vite-xorigin/index.js");
276
- output = await fs.readFile(
277
- await fs.access(mjs).then(() => mjs, () => js),
278
- "utf-8"
279
- );
280
- }, 60_000);
281
-
282
- it("resolves the service-worker URL at runtime, not at build time", () => {
283
- // The automerge URL is passed to the resolver as a literal string arg…
284
- expect(output).toContain(AUTOMERGE_URL);
285
- expect(output).toContain("getImportableUrlFromAutomergeUrl");
286
- expect(output).toMatch(/await import\(/);
287
- // …and is NOT baked as a root-relative `from "/<encoded>/…"` import.
288
- expect(output).not.toMatch(new RegExp(`from ["']/${ENCODED_URL}/`));
289
- });
290
-
291
- it("imports the runtime resolver from patchwork-filesystem (external)", () => {
292
- expect(output).toMatch(
293
- /from ["']@inkandswitch\/patchwork-filesystem["']/
294
- );
295
- });
296
-
297
- it("still externalizes solid-js", () => {
298
- expect(output).toMatch(/from ["']solid-js["']/);
299
- });
300
-
301
- it("does not contain bundled automerge dep code", () => {
302
- expect(output).not.toContain("my-sideboard-tool");
303
- });
304
- });
305
- });
package/tsconfig.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- // Visit https://aka.ms/tsconfig to read more about this file
3
- "compilerOptions": {
4
- // File Layout
5
- "rootDir": "./src",
6
- "outDir": "./dist",
7
-
8
- // Environment Settings
9
- // See also https://aka.ms/tsconfig/module
10
- "module": "esnext",
11
- "target": "esnext",
12
- "types": [],
13
-
14
- // Other Outputs
15
- "sourceMap": true,
16
- "declaration": true,
17
- "declarationMap": true,
18
-
19
- // Stricter Typechecking Options
20
- "noUncheckedIndexedAccess": true,
21
- "exactOptionalPropertyTypes": true,
22
-
23
- // Style Options
24
- // "noImplicitReturns": true,
25
- // "noImplicitOverride": true,
26
- // "noUnusedLocals": true,
27
- // "noUnusedParameters": true,
28
- // "noFallthroughCasesInSwitch": true,
29
- // "noPropertyAccessFromIndexSignature": true,
30
-
31
- // Recommended Options
32
- "strict": true,
33
- "verbatimModuleSyntax": true,
34
- "isolatedModules": true,
35
- "noUncheckedSideEffectImports": true,
36
- "moduleDetection": "force",
37
- "skipLibCheck": true,
38
- },
39
- "include": ["src"]
40
- }
@@ -1,3 +0,0 @@
1
- declare const _default: import("vite").UserConfig;
2
- export default _default;
3
- //# sourceMappingURL=vitest.config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest.config.d.ts","sourceRoot":"","sources":["vitest.config.ts"],"names":[],"mappings":";AAEA,wBAOG"}
package/vitest.config.js DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
- export default defineConfig({
3
- test: {
4
- globals: true,
5
- environment: "node",
6
- include: ["test/**/*.{test,spec}.ts"],
7
- testTimeout: 180_000,
8
- },
9
- });
10
- //# sourceMappingURL=vitest.config.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"vitest.config.js","sourceRoot":"","sources":["vitest.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAe,YAAY,CAAC;IAC1B,IAAI,EAAE;QACJ,OAAO,EAAE,IAAI;QACb,WAAW,EAAE,MAAM;QACnB,OAAO,EAAE,CAAC,0BAA0B,CAAC;QACrC,WAAW,EAAE,OAAO;KACrB;CACF,CAAC,CAAC"}
package/vitest.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: "node",
7
- include: ["test/**/*.{test,spec}.ts"],
8
- testTimeout: 180_000,
9
- },
10
- });