@inkandswitch/patchwork-bootloader 0.4.2 → 0.4.4

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.
package/dist/types.d.ts CHANGED
@@ -133,7 +133,24 @@ export interface HandoffResponseMessage {
133
133
  type: "response";
134
134
  response: HandoffResponse;
135
135
  }
136
- export type HandoffReplyMessage = HandoffCachedMessage | HandoffResponseMessage;
136
+ /**
137
+ * Automerge worker → service worker: fail the request as a network error
138
+ * rather than serving any response at all.
139
+ *
140
+ * "Heads haven't arrived yet" is not a 404 — the document may well exist, so
141
+ * a status implying it doesn't is a lie any HTTP cache is entitled to store.
142
+ * A network error is the honest answer and isn't storable as a response.
143
+ *
144
+ * This does *not* help with `import()`: the ES module map memoizes failed
145
+ * fetches, network errors included, so a retry needs a distinct URL either
146
+ * way (see `importModule` in patchwork-filesystem).
147
+ */
148
+ export interface HandoffAbortMessage {
149
+ id: string;
150
+ type: "abort";
151
+ reason: string;
152
+ }
153
+ export type HandoffReplyMessage = HandoffCachedMessage | HandoffResponseMessage | HandoffAbortMessage;
137
154
  /**
138
155
  * Automerge worker → world: broadcast once on startup so the service worker
139
156
  * can re-send any handoff requests that raced the worker's boot.
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { createRequire } from "node:module";
3
+ import { fileURLToPath } from "node:url";
3
4
  const require = createRequire(import.meta.url);
4
5
  /**
5
6
  * these dependencies will be built into the outdir,
@@ -8,8 +9,28 @@ const require = createRequire(import.meta.url);
8
9
  import externals from "../externals.js";
9
10
  export const builtins = externals.reduce((builtins, name) => ((builtins[name] = `/packages/${name}.js`), builtins), {});
10
11
  /**
11
- * merge the importmap option with our builtins
12
+ * pretend the import came from inside this package, so node_modules resolution
13
+ * walks up from *our* directory and finds our copy of each external. that's why
14
+ * a consuming site never has to install them or agree with us about versions.
12
15
  */
16
+ const self = fileURLToPath(import.meta.url);
17
+ /**
18
+ * resolve an external from our node_modules rather than the site's.
19
+ *
20
+ * this goes through rollup's resolver rather than import.meta.resolve or
21
+ * require.resolve because those apply node's conditions: subduction (and
22
+ * others) would hand us `dist/esm/node.js`, which imports node:path and blows
23
+ * up at bundle time. rollup applies the browser conditions vite configured.
24
+ */
25
+ async function resolveExternal(name) {
26
+ const resolved = await this.resolve(name, self, { skipSelf: true });
27
+ if (!resolved) {
28
+ throw new Error(`@patchwork/vite: couldn't resolve the external "${name}" from ` +
29
+ `@inkandswitch/patchwork-bootloader. it should be one of the ` +
30
+ `bootloader's own dependencies.`);
31
+ }
32
+ return resolved.id;
33
+ }
13
34
  function createImportMap(options) {
14
35
  const importmap = structuredClone(options?.importmap ?? { imports: {}, scopes: {} });
15
36
  importmap.imports ??= {};
@@ -26,11 +47,11 @@ export function importmap(options) {
26
47
  this.emitFile({
27
48
  type: "chunk",
28
49
  fileName: fileName.slice(1),
29
- id,
50
+ id: await resolveExternal.call(this, id),
30
51
  preserveSignature: "strict",
31
52
  });
32
53
  }
33
- // Emit automerge, keyhive, and subduction wasm so the service worker can fetch them
54
+ // Emitted so the service worker can fetch them
34
55
  const automergeWasmPath = require.resolve("@automerge/automerge/automerge.wasm");
35
56
  this.emitFile({
36
57
  type: "asset",
@@ -43,7 +64,6 @@ export function importmap(options) {
43
64
  fileName: "keyhive_wasm.wasm",
44
65
  source: readFileSync(keyhiveWasmPath),
45
66
  });
46
- // Emit subduction wasm so the service worker can fetch it
47
67
  const subdWasmPath = require.resolve("@automerge/automerge-subduction/wasm");
48
68
  this.emitFile({
49
69
  type: "asset",
@@ -51,8 +71,14 @@ export function importmap(options) {
51
71
  source: readFileSync(subdWasmPath),
52
72
  });
53
73
  },
54
- resolveId(id) {
55
- if (id in importmap.imports && !(id in builtins)) {
74
+ async resolveId(id) {
75
+ if (id in builtins) {
76
+ // point the site's own imports at the same copy we emit as a chunk,
77
+ // otherwise rollup bundles a second one out of the site's node_modules
78
+ // and you end up with two automerges racing to init the same wasm
79
+ return resolveExternal.call(this, id);
80
+ }
81
+ if (id in importmap.imports) {
56
82
  return { id: importmap.imports[id], external: true };
57
83
  }
58
84
  },
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@inkandswitch/patchwork-bootloader",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "author": "chee",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "devDependencies": {
8
- "@automerge/automerge-repo-keyhive": "0.3.0-alpha.sub.8b",
9
8
  "esbuild": "^0.23.1",
10
9
  "rollup": "^4.61.1"
11
10
  },
@@ -46,27 +45,47 @@
46
45
  "dependencies": {
47
46
  "@automerge/automerge": "3.3.2",
48
47
  "@automerge/automerge-repo": "2.6.0-subduction.46",
49
- "@automerge/automerge-repo-network-messagechannel": "2.6.0-subduction.45",
50
- "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.45",
51
- "@automerge/automerge-repo-storage-indexeddb": "2.6.0-subduction.45",
48
+ "@automerge/automerge-repo-keyhive": "0.3.0-alpha.sub.8b",
49
+ "@automerge/automerge-repo-network-messagechannel": "2.6.0-subduction.46",
50
+ "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.46",
51
+ "@automerge/automerge-repo-storage-indexeddb": "2.6.0-subduction.46",
52
52
  "@automerge/automerge-subduction": "0.16.0",
53
- "@automerge/vanillajs": "2.6.0-subduction.45",
53
+ "@automerge/vanillajs": "2.6.0-subduction.46",
54
+ "@codemirror/commands": "^6.10.4",
55
+ "@codemirror/language": "^6.12.4",
56
+ "@codemirror/state": "^6.7.1",
57
+ "@codemirror/view": "^6.43.6",
54
58
  "@keyhive/keyhive": "0.1.0-alpha.5",
55
59
  "@types/debug": "^4.1.13",
56
60
  "debug": "^4.4.3",
57
61
  "resolve.exports": "^2.0.3",
58
62
  "service-worker-types": "npm:@types/serviceworker@^0.0.153",
63
+ "solid-js": "^1.9.13",
59
64
  "tinyargs": "^0.1.4",
60
- "@inkandswitch/patchwork-elements": "^4.0.0",
61
- "@inkandswitch/patchwork-filesystem": "^0.2.0",
62
- "@inkandswitch/patchwork-plugins": "^1.0.0",
63
- "@inkandswitch/patchwork-providers": "^0.4.0"
65
+ "@inkandswitch/patchwork-elements": "^4.0.1",
66
+ "@inkandswitch/patchwork-filesystem": "^0.2.2",
67
+ "@inkandswitch/patchwork-plugins": "^1.0.1",
68
+ "@inkandswitch/patchwork-providers": "^0.4.2"
64
69
  },
65
70
  "peerDependencies": {
66
71
  "@automerge/automerge": "3.3.2",
67
72
  "@automerge/automerge-repo": "2.6.0-subduction.46",
68
73
  "@automerge/automerge-repo-keyhive": "0.3.0-alpha.sub.8b",
69
- "@automerge/vanillajs": "2.6.0-subduction.45"
74
+ "@automerge/vanillajs": "2.6.0-subduction.46"
75
+ },
76
+ "peerDependenciesMeta": {
77
+ "@automerge/automerge": {
78
+ "optional": true
79
+ },
80
+ "@automerge/automerge-repo": {
81
+ "optional": true
82
+ },
83
+ "@automerge/automerge-repo-keyhive": {
84
+ "optional": true
85
+ },
86
+ "@automerge/vanillajs": {
87
+ "optional": true
88
+ }
70
89
  },
71
90
  "scripts": {
72
91
  "build": "tsc",