@inkandswitch/patchwork-bootloader 0.4.3 → 0.5.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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * these dependencies will be built into the outdir, and injected into the importmap
3
+ */
4
+ declare const externals: string[];
5
+ export default externals;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * these dependencies will be built into the outdir, and injected into the importmap
3
+ */
4
+ const externals = [
5
+ "@automerge/automerge",
6
+ "@automerge/automerge/slim",
7
+ "@automerge/automerge-repo",
8
+ "@automerge/automerge-repo/slim",
9
+ // Port-donation plumbing for WorkerWebSocketEndpoint: tabs spawn the shared
10
+ // proxy entry and donate its port to the automerge worker (Chrome can't
11
+ // spawn workers from inside a SharedWorker). See setup.ts/automerge-worker.ts.
12
+ "@automerge/automerge-repo/worker-port",
13
+ "@automerge/automerge-repo/subduction-websocket-worker-shared",
14
+ "@automerge/automerge-repo-network-messagechannel",
15
+ "@automerge/automerge-repo-network-websocket",
16
+ "@automerge/automerge-repo-storage-indexeddb",
17
+ "@automerge/automerge-repo-keyhive",
18
+ "@automerge/automerge-subduction",
19
+ "@automerge/automerge-subduction/slim",
20
+ "@keyhive/keyhive",
21
+ "@keyhive/keyhive/slim",
22
+ "@inkandswitch/patchwork-bootloader",
23
+ "@inkandswitch/patchwork-elements",
24
+ "@inkandswitch/patchwork-filesystem",
25
+ "@inkandswitch/patchwork-plugins",
26
+ "@inkandswitch/patchwork-providers",
27
+ "@inkandswitch/patchwork",
28
+ // sad
29
+ "@codemirror/state",
30
+ "@codemirror/view",
31
+ "@codemirror/language",
32
+ "@codemirror/commands",
33
+ // rip
34
+ "solid-js",
35
+ "solid-js/html",
36
+ "solid-js/web",
37
+ "solid-js/h",
38
+ "solid-js/store",
39
+ "solid-js/jsx-runtime",
40
+ ];
41
+ export default externals;
@@ -1,5 +1,16 @@
1
+ export { default } from "./externals-list.js";
1
2
  /**
2
- * these dependencies will be built into the outdir, and injected into the importmap
3
+ * Resolve one of this package's own dependencies from its node_modules
4
+ * rather than the site's, so a vite plugin bundling it never needs the site
5
+ * to install it or agree on a version. Exported so `@inkandswitch/patchwork`'s
6
+ * vite plugin (which lives in a different package) can reuse this for the
7
+ * externals bootloader actually owns, while resolving itself separately.
8
+ *
9
+ * This goes through rollup's resolver rather than import.meta.resolve or
10
+ * require.resolve because those apply node's conditions: subduction (and
11
+ * others) would hand us `dist/esm/node.js`, which imports node:path and blows
12
+ * up at bundle time. rollup applies the browser conditions vite configured.
3
13
  */
4
- declare const externals: string[];
5
- export default externals;
14
+ export declare function resolveExternal(this: import("rollup").PluginContext, name: string): Promise<string>;
15
+ /** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
16
+ export declare function emitWasmAssets(this: import("rollup").PluginContext): void;
package/dist/externals.js CHANGED
@@ -1,40 +1,52 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { fileURLToPath } from "node:url";
4
+ const require = createRequire(import.meta.url);
5
+ export { default } from "./externals-list.js";
1
6
  /**
2
- * these dependencies will be built into the outdir, and injected into the importmap
7
+ * pretend the import came from inside this package, so node_modules resolution
8
+ * walks up from *our* directory and finds our copy of each external. that's why
9
+ * a consuming site never has to install them or agree with us about versions.
3
10
  */
4
- const externals = [
5
- "@automerge/automerge",
6
- "@automerge/automerge/slim",
7
- "@automerge/automerge-repo",
8
- "@automerge/automerge-repo/slim",
9
- // Port-donation plumbing for WorkerWebSocketEndpoint: tabs spawn the shared
10
- // proxy entry and donate its port to the automerge worker (Chrome can't
11
- // spawn workers from inside a SharedWorker). See setup.ts/automerge-worker.ts.
12
- "@automerge/automerge-repo/worker-port",
13
- "@automerge/automerge-repo/subduction-websocket-worker-shared",
14
- "@automerge/automerge-repo-network-messagechannel",
15
- "@automerge/automerge-repo-network-websocket",
16
- "@automerge/automerge-repo-storage-indexeddb",
17
- "@automerge/automerge-repo-keyhive",
18
- "@automerge/automerge-subduction",
19
- "@automerge/automerge-subduction/slim",
20
- "@keyhive/keyhive",
21
- "@keyhive/keyhive/slim",
22
- "@inkandswitch/patchwork-bootloader",
23
- "@inkandswitch/patchwork-elements",
24
- "@inkandswitch/patchwork-filesystem",
25
- "@inkandswitch/patchwork-plugins",
26
- "@inkandswitch/patchwork-providers",
27
- // sad
28
- "@codemirror/state",
29
- "@codemirror/view",
30
- "@codemirror/language",
31
- "@codemirror/commands",
32
- // rip
33
- "solid-js",
34
- "solid-js/html",
35
- "solid-js/web",
36
- "solid-js/h",
37
- "solid-js/store",
38
- "solid-js/jsx-runtime",
39
- ];
40
- export default externals;
11
+ const self = fileURLToPath(import.meta.url);
12
+ /**
13
+ * Resolve one of this package's own dependencies from its node_modules
14
+ * rather than the site's, so a vite plugin bundling it never needs the site
15
+ * to install it or agree on a version. Exported so `@inkandswitch/patchwork`'s
16
+ * vite plugin (which lives in a different package) can reuse this for the
17
+ * externals bootloader actually owns, while resolving itself separately.
18
+ *
19
+ * This goes through rollup's resolver rather than import.meta.resolve or
20
+ * require.resolve because those apply node's conditions: subduction (and
21
+ * others) would hand us `dist/esm/node.js`, which imports node:path and blows
22
+ * up at bundle time. rollup applies the browser conditions vite configured.
23
+ */
24
+ export async function resolveExternal(name) {
25
+ const resolved = await this.resolve(name, self, { skipSelf: true });
26
+ if (!resolved) {
27
+ throw new Error(`@inkandswitch/patchwork-bootloader: couldn't resolve the external ` +
28
+ `"${name}". it should be one of the bootloader's own dependencies.`);
29
+ }
30
+ return resolved.id;
31
+ }
32
+ /** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
33
+ 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
+ });
52
+ }
@@ -0,0 +1,30 @@
1
+ html,
2
+ body {
3
+ overscroll-behavior: none;
4
+ font-family: system-ui, sans-serif;
5
+ font-size: 16px;
6
+ height: 100%;
7
+ height: 100vh;
8
+ height: 100dvh;
9
+
10
+ @media all and (display-mode: standalone) {
11
+ height: 100lvh;
12
+ }
13
+ }
14
+
15
+ patchwork-view {
16
+ display: block;
17
+ height: 100%;
18
+ width: 100%;
19
+ contain: layout;
20
+ }
21
+
22
+ @media (prefers-reduced-motion: reduce) {
23
+ *,
24
+ *:before,
25
+ *:after {
26
+ animation-duration: 0.001s !important;
27
+ transition-duration: 0.001s !important;
28
+ animation-iteration-count: 1 !important;
29
+ }
30
+ }
@@ -2,11 +2,6 @@ type Descriptor = Record<string, unknown> & {
2
2
  id?: string;
3
3
  type?: string;
4
4
  };
5
- /**
6
- * ModuleWatcher `importAutomergePackage` hook: discover descriptors in the
7
- * worker, then return the `{ plugins }` shape with a main-thread `load()` per
8
- * plugin that imports the package at heads and calls its real loader.
9
- */
10
5
  export declare function importAutomergePackageViaWorker(urlAtHeads: string): Promise<{
11
6
  plugins: Descriptor[];
12
7
  }>;
@@ -41,7 +41,6 @@ function getWorker() {
41
41
  });
42
42
  return worker;
43
43
  }
44
- /** Ask the worker which plugins the package at `urlAtHeads` exports. */
45
44
  function discoverDescriptors(urlAtHeads) {
46
45
  const id = nextRequestId++;
47
46
  return new Promise((resolve, reject) => {
@@ -49,11 +48,6 @@ function discoverDescriptors(urlAtHeads) {
49
48
  getWorker().postMessage({ type: "discover", id, url: urlAtHeads });
50
49
  });
51
50
  }
52
- /**
53
- * ModuleWatcher `importAutomergePackage` hook: discover descriptors in the
54
- * worker, then return the `{ plugins }` shape with a main-thread `load()` per
55
- * plugin that imports the package at heads and calls its real loader.
56
- */
57
51
  export async function importAutomergePackageViaWorker(urlAtHeads) {
58
52
  const url = urlAtHeads;
59
53
  const descriptors = await discoverDescriptors(url);