@inkandswitch/patchwork-bootloader 0.5.4 → 0.6.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @inkandswitch/patchwork-bootloader
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 846cfac: Update the pinned `@automerge/*` versions to `2.6.0-subduction.47`. These are exact pins in `dependencies` and `peerDependencies`, so both packages need to ship the new version together — installing a `.46` and a `.47` package side by side loads two copies of automerge-repo, and document handles from one are not recognised by the other.
8
+ - 61a152a: Make `vite dev` work without a site hand-rolling the dev server.
9
+
10
+ The build emits the service worker, the automerge shared worker, the module-loader worker, and three wasm binaries. None of them existed in serve mode, so every one 404'd and dev only worked if a site served a previous production build's `dist/` behind vite. The plugin now serves all of them itself:
11
+
12
+ - The three worker entries are bundled on demand with esbuild and rebuilt per request, so they always reflect the source on disk. Their heavy imports resolve to the dev server's optimized-dep URLs, mirroring how the build rewrites them to `/packages/...` — import maps don't apply to `type: "module"` workers, so the URLs have to be real either way.
13
+ - `automerge.wasm`, `keyhive_wasm.wasm`, and `subduction.wasm` are served from the bootloader's own node_modules. `@inkandswitch/patchwork-bootloader/externals` gains `wasmAssets()`, which `emitWasmAssets` now uses too.
14
+ - `global.css` 404'd in dev: the generated `index.html` links it by bare specifier, which only the build resolves. Both patchwork's and the bootloader's stylesheets are now served under root-absolute paths, and the link points at them.
15
+ - `@patchwork/service-worker` called `emitFile` from `buildStart` unconditionally, which throws in serve mode — it logged "This plugin is likely not vite-compatible" three times on every dev-server start. It now skips emission when serving.
16
+ - Dep pre-bundling runs esbuild outside the plugin pipeline that applies `define`, so in dev the page fell back to the default storage prefix while the workers used the configured one — the two would have opened different IndexedDB databases. The defines are now passed to the optimizer as well.
17
+
18
+ Sites no longer need to filter `@patchwork/service-worker` out of the plugin list, serve stylesheets themselves, or keep a built `dist/` around for `vite dev`.
19
+
20
+ ## 0.6.0
21
+
22
+ ### Minor Changes
23
+
24
+ - 98be594: Namespace IndexedDB and peer ids with a new build-time `storagePrefix` option.
25
+
26
+ The tab and the shared automerge worker are separate bundles that must open the same databases. Both now read the name from one place, `@inkandswitch/patchwork-bootloader/storage`, resolved from the `__STORAGE_PREFIX__` define the vite plugin emits unconditionally.
27
+
28
+ Previously each side resolved `__SITE_NAME__` itself with a different fallback — `"patchwork.inkandswitch.com"` in the worker, `"patchwork"` in the tab — so a site that never set `siteName` had its tab and worker on two different keyhive databases, and one that passed `setup({name})` split them the same way, since a runtime option never reaches the worker.
29
+
30
+ - `storagePrefix` defaults to `"patchwork"` and is settable only in the build config. Sites sharing an origin must use distinct prefixes. It is deliberately not derived from any display name: changing it points a site at empty storage, so a rebrand must not be able to change it by accident.
31
+ - Sites that relied on `siteName` to namespace their storage must now set `storagePrefix` explicitly to that same value to keep their existing databases.
32
+ - `createRepo` in `@inkandswitch/patchwork` no longer takes a site name argument.
33
+
3
34
  ## 0.5.4
4
35
 
5
36
  ### Patch Changes
@@ -19,10 +19,8 @@ import { MessageChannelNetworkAdapter } from "@automerge/automerge-repo-network-
19
19
  import { WebSocketWorkerClientAdapter } from "@automerge/automerge-repo-network-websocket";
20
20
  import { initializeAutomergeRepoKeyhiveRustWithRepo, initKeyhiveWasm, } from "@automerge/automerge-repo-keyhive";
21
21
  import { DEFAULT_CLASSIC_SYNC_SERVER } from "./sync-config.js";
22
+ import { keyhiveStorageName, storagePrefix } from "./storage.js";
22
23
  import { HANDOFF_CHANNEL, SYNCSTATE_CHANNEL, } from "./types.js";
23
- const siteName = typeof __SITE_NAME__ !== "undefined"
24
- ? __SITE_NAME__
25
- : "patchwork.inkandswitch.com";
26
24
  const syncServer = typeof __SYNC_SERVER__ !== "undefined"
27
25
  ? __SYNC_SERVER__
28
26
  : { url: "wss://subduction.sync.inkandswitch.com" };
@@ -210,8 +208,8 @@ async function buildKeyhiveRepo(keyhiveSyncServer) {
210
208
  initKeyhiveWasm();
211
209
  const { hive, repo } = await initializeAutomergeRepoKeyhiveRustWithRepo({
212
210
  createRepo: (config) => new Repo(config),
213
- storage: new IndexedDBWorkerStorageAdapter(`${siteName}-keyhive`),
214
- peerIdSuffix: `${siteName}-worker` + Math.random().toString(36).slice(2),
211
+ storage: new IndexedDBWorkerStorageAdapter(keyhiveStorageName),
212
+ peerIdSuffix: `${storagePrefix}-worker` + Math.random().toString(36).slice(2),
215
213
  automaticArchiveIngestion: true,
216
214
  cachingMode: "periodic",
217
215
  // ARK selects the relay via `syncServer`, which pairs the contact card with
@@ -12,5 +12,14 @@ export { default } from "./externals-list.js";
12
12
  * up at bundle time. rollup applies the browser conditions vite configured.
13
13
  */
14
14
  export declare function resolveExternal(this: import("rollup").PluginContext, name: string): Promise<string>;
15
+ /**
16
+ * automerge/keyhive/subduction's wasm binaries, by the file name the service
17
+ * worker fetches them under. Resolved from this package's node_modules for the
18
+ * same reason as {@link resolveExternal}.
19
+ */
20
+ export declare function wasmAssets(): {
21
+ fileName: string;
22
+ path: string;
23
+ }[];
15
24
  /** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
16
25
  export declare function emitWasmAssets(this: import("rollup").PluginContext): void;
package/dist/externals.js CHANGED
@@ -29,24 +29,34 @@ export async function resolveExternal(name) {
29
29
  }
30
30
  return resolved.id;
31
31
  }
32
+ /**
33
+ * automerge/keyhive/subduction's wasm binaries, by the file name the service
34
+ * worker fetches them under. Resolved from this package's node_modules for the
35
+ * same reason as {@link resolveExternal}.
36
+ */
37
+ export function wasmAssets() {
38
+ return [
39
+ {
40
+ fileName: "automerge.wasm",
41
+ path: require.resolve("@automerge/automerge/automerge.wasm"),
42
+ },
43
+ {
44
+ fileName: "keyhive_wasm.wasm",
45
+ path: require.resolve("@keyhive/keyhive/keyhive_wasm.wasm"),
46
+ },
47
+ {
48
+ fileName: "subduction.wasm",
49
+ path: require.resolve("@automerge/automerge-subduction/wasm"),
50
+ },
51
+ ];
52
+ }
32
53
  /** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
33
54
  export function emitWasmAssets() {
34
- const automergeWasmPath = require.resolve("@automerge/automerge/automerge.wasm");
35
- this.emitFile({
36
- type: "asset",
37
- fileName: "automerge.wasm",
38
- source: readFileSync(automergeWasmPath),
39
- });
40
- const keyhiveWasmPath = require.resolve("@keyhive/keyhive/keyhive_wasm.wasm");
41
- this.emitFile({
42
- type: "asset",
43
- fileName: "keyhive_wasm.wasm",
44
- source: readFileSync(keyhiveWasmPath),
45
- });
46
- const subdWasmPath = require.resolve("@automerge/automerge-subduction/wasm");
47
- this.emitFile({
48
- type: "asset",
49
- fileName: "subduction.wasm",
50
- source: readFileSync(subdWasmPath),
51
- });
55
+ for (const { fileName, path } of wasmAssets()) {
56
+ this.emitFile({
57
+ type: "asset",
58
+ fileName,
59
+ source: readFileSync(path),
60
+ });
61
+ }
52
62
  }
@@ -0,0 +1,8 @@
1
+ export declare const DEFAULT_STORAGE_PREFIX = "patchwork";
2
+ /**
3
+ * Namespace for this site's IndexedDB databases and peer ids. The tab and the
4
+ * shared automerge worker are separate bundles that must open the same
5
+ * databases, and this module is the single place either of them gets the name.
6
+ */
7
+ export declare const storagePrefix: string;
8
+ export declare const keyhiveStorageName: string;
@@ -0,0 +1,10 @@
1
+ export const DEFAULT_STORAGE_PREFIX = "patchwork";
2
+ /**
3
+ * Namespace for this site's IndexedDB databases and peer ids. The tab and the
4
+ * shared automerge worker are separate bundles that must open the same
5
+ * databases, and this module is the single place either of them gets the name.
6
+ */
7
+ export const storagePrefix = typeof __STORAGE_PREFIX__ !== "undefined"
8
+ ? __STORAGE_PREFIX__
9
+ : DEFAULT_STORAGE_PREFIX;
10
+ export const keyhiveStorageName = `${storagePrefix}-keyhive`;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "url": "git+https://github.com/inkandswitch/patchwork-system.git",
6
6
  "directory": "core/bootloader"
7
7
  },
8
- "version": "0.5.4",
8
+ "version": "0.6.1",
9
9
  "author": "chee",
10
10
  "type": "module",
11
11
  "license": "MIT",
@@ -26,6 +26,10 @@
26
26
  "import": "./dist/externals-list.js",
27
27
  "types": "./dist/externals-list.d.ts"
28
28
  },
29
+ "./storage": {
30
+ "import": "./dist/storage.js",
31
+ "types": "./dist/storage.d.ts"
32
+ },
29
33
  "./service-worker": {
30
34
  "import": "./dist/service-worker.js",
31
35
  "types": "./dist/service-worker.d.ts"
@@ -50,13 +54,13 @@
50
54
  },
51
55
  "dependencies": {
52
56
  "@automerge/automerge": "3.3.2",
53
- "@automerge/automerge-repo": "2.6.0-subduction.46",
57
+ "@automerge/automerge-repo": "2.6.0-subduction.47",
54
58
  "@automerge/automerge-repo-keyhive": "0.3.0-alpha.sub.8b",
55
- "@automerge/automerge-repo-network-messagechannel": "2.6.0-subduction.46",
56
- "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.46",
57
- "@automerge/automerge-repo-storage-indexeddb": "2.6.0-subduction.46",
59
+ "@automerge/automerge-repo-network-messagechannel": "2.6.0-subduction.47",
60
+ "@automerge/automerge-repo-network-websocket": "2.6.0-subduction.47",
61
+ "@automerge/automerge-repo-storage-indexeddb": "2.6.0-subduction.47",
58
62
  "@automerge/automerge-subduction": "0.16.0",
59
- "@automerge/vanillajs": "2.6.0-subduction.46",
63
+ "@automerge/vanillajs": "2.6.0-subduction.47",
60
64
  "@codemirror/commands": "^6.10.4",
61
65
  "@codemirror/language": "^6.12.4",
62
66
  "@codemirror/state": "^6.7.1",
@@ -70,14 +74,14 @@
70
74
  "tinyargs": "^0.1.4",
71
75
  "@inkandswitch/patchwork-elements": "^6.0.0",
72
76
  "@inkandswitch/patchwork-filesystem": "^0.2.5",
73
- "@inkandswitch/patchwork-plugins": "^1.1.0",
77
+ "@inkandswitch/patchwork-plugins": "^1.2.0",
74
78
  "@inkandswitch/patchwork-providers": "^0.5.0"
75
79
  },
76
80
  "peerDependencies": {
77
81
  "@automerge/automerge": "3.3.2",
78
- "@automerge/automerge-repo": "2.6.0-subduction.46",
82
+ "@automerge/automerge-repo": "2.6.0-subduction.47",
79
83
  "@automerge/automerge-repo-keyhive": "0.3.0-alpha.sub.8b",
80
- "@automerge/vanillajs": "2.6.0-subduction.46"
84
+ "@automerge/vanillajs": "2.6.0-subduction.47"
81
85
  },
82
86
  "peerDependenciesMeta": {
83
87
  "@automerge/automerge": {
@@ -38,6 +38,7 @@ import {
38
38
  } from "@automerge/automerge-repo-keyhive";
39
39
 
40
40
  import { DEFAULT_CLASSIC_SYNC_SERVER } from "./sync-config.js";
41
+ import { keyhiveStorageName, storagePrefix } from "./storage.js";
41
42
  import {
42
43
  HANDOFF_CHANNEL,
43
44
  SYNCSTATE_CHANNEL,
@@ -52,16 +53,11 @@ import {
52
53
  type SyncStateRequestMessage,
53
54
  } from "./types.js";
54
55
 
55
- declare const __SITE_NAME__: string;
56
56
  declare const __SYNC_SERVER__: {
57
57
  url: string;
58
58
  keyhive?: SyncServerSelection;
59
59
  };
60
60
 
61
- const siteName =
62
- typeof __SITE_NAME__ !== "undefined"
63
- ? __SITE_NAME__
64
- : "patchwork.inkandswitch.com";
65
61
  const syncServer =
66
62
  typeof __SYNC_SERVER__ !== "undefined"
67
63
  ? __SYNC_SERVER__
@@ -288,8 +284,9 @@ async function buildKeyhiveRepo(
288
284
  initKeyhiveWasm();
289
285
  const { hive, repo } = await initializeAutomergeRepoKeyhiveRustWithRepo({
290
286
  createRepo: (config) => new Repo(config),
291
- storage: new IndexedDBWorkerStorageAdapter(`${siteName}-keyhive`),
292
- peerIdSuffix: `${siteName}-worker` + Math.random().toString(36).slice(2),
287
+ storage: new IndexedDBWorkerStorageAdapter(keyhiveStorageName),
288
+ peerIdSuffix:
289
+ `${storagePrefix}-worker` + Math.random().toString(36).slice(2),
293
290
  automaticArchiveIngestion: true,
294
291
  cachingMode: "periodic",
295
292
  // ARK selects the relay via `syncServer`, which pairs the contact card with
package/src/externals.ts CHANGED
@@ -39,30 +39,35 @@ export async function resolveExternal(
39
39
  return resolved.id;
40
40
  }
41
41
 
42
+ /**
43
+ * automerge/keyhive/subduction's wasm binaries, by the file name the service
44
+ * worker fetches them under. Resolved from this package's node_modules for the
45
+ * same reason as {@link resolveExternal}.
46
+ */
47
+ export function wasmAssets(): { fileName: string; path: string }[] {
48
+ return [
49
+ {
50
+ fileName: "automerge.wasm",
51
+ path: require.resolve("@automerge/automerge/automerge.wasm"),
52
+ },
53
+ {
54
+ fileName: "keyhive_wasm.wasm",
55
+ path: require.resolve("@keyhive/keyhive/keyhive_wasm.wasm"),
56
+ },
57
+ {
58
+ fileName: "subduction.wasm",
59
+ path: require.resolve("@automerge/automerge-subduction/wasm"),
60
+ },
61
+ ];
62
+ }
63
+
42
64
  /** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
43
65
  export function emitWasmAssets(this: import("rollup").PluginContext): void {
44
- const automergeWasmPath = require.resolve(
45
- "@automerge/automerge/automerge.wasm"
46
- );
47
- this.emitFile({
48
- type: "asset",
49
- fileName: "automerge.wasm",
50
- source: readFileSync(automergeWasmPath),
51
- });
52
-
53
- const keyhiveWasmPath = require.resolve(
54
- "@keyhive/keyhive/keyhive_wasm.wasm"
55
- );
56
- this.emitFile({
57
- type: "asset",
58
- fileName: "keyhive_wasm.wasm",
59
- source: readFileSync(keyhiveWasmPath),
60
- });
61
-
62
- const subdWasmPath = require.resolve("@automerge/automerge-subduction/wasm");
63
- this.emitFile({
64
- type: "asset",
65
- fileName: "subduction.wasm",
66
- source: readFileSync(subdWasmPath),
67
- });
66
+ for (const { fileName, path } of wasmAssets()) {
67
+ this.emitFile({
68
+ type: "asset",
69
+ fileName,
70
+ source: readFileSync(path),
71
+ });
72
+ }
68
73
  }
package/src/storage.ts ADDED
@@ -0,0 +1,15 @@
1
+ declare const __STORAGE_PREFIX__: string;
2
+
3
+ export const DEFAULT_STORAGE_PREFIX = "patchwork";
4
+
5
+ /**
6
+ * Namespace for this site's IndexedDB databases and peer ids. The tab and the
7
+ * shared automerge worker are separate bundles that must open the same
8
+ * databases, and this module is the single place either of them gets the name.
9
+ */
10
+ export const storagePrefix =
11
+ typeof __STORAGE_PREFIX__ !== "undefined"
12
+ ? __STORAGE_PREFIX__
13
+ : DEFAULT_STORAGE_PREFIX;
14
+
15
+ export const keyhiveStorageName = `${storagePrefix}-keyhive`;