@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.
- package/CHANGELOG.md +29 -0
- package/dist/automerge-worker.js +533 -771
- package/dist/externals-list.d.ts +5 -0
- package/dist/externals-list.js +41 -0
- package/dist/externals.d.ts +14 -3
- package/dist/externals.js +50 -38
- package/dist/global.css +30 -0
- package/dist/module-loader.d.ts +0 -5
- package/dist/module-loader.js +0 -6
- package/dist/service-worker.js +178 -205
- package/dist/setup.d.ts +2 -1
- package/dist/setup.js +251 -375
- package/dist/sync-config.d.ts +1 -1
- package/dist/sync-config.js +3 -1
- package/package.json +15 -14
- package/src/automerge-worker.ts +634 -839
- package/src/externals-list.ts +43 -0
- package/src/externals.ts +64 -38
- package/src/global.css +30 -0
- package/src/module-loader.ts +0 -6
- package/src/service-worker.ts +224 -238
- package/src/setup.ts +287 -401
- package/src/sync-config.ts +6 -1
- package/dist/site.d.ts +0 -111
- package/dist/site.js +0 -602
- package/dist/vite/importmap-plugin.d.ts +0 -4
- package/dist/vite/importmap-plugin.js +0 -105
- package/dist/vite/patchwork-plugin.d.ts +0 -14
- package/dist/vite/patchwork-plugin.js +0 -8
- package/dist/vite/service-worker-plugin.d.ts +0 -2
- package/dist/vite/service-worker-plugin.js +0 -42
- package/src/site.ts +0 -859
- package/src/vite/importmap-plugin.ts +0 -133
- package/src/vite/patchwork-plugin.ts +0 -20
- package/src/vite/service-worker-plugin.ts +0 -46
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
29
|
+
// sad
|
|
30
|
+
"@codemirror/state",
|
|
31
|
+
"@codemirror/view",
|
|
32
|
+
"@codemirror/language",
|
|
33
|
+
"@codemirror/commands",
|
|
34
|
+
|
|
35
|
+
// rip
|
|
36
|
+
"solid-js",
|
|
37
|
+
"solid-js/html",
|
|
38
|
+
"solid-js/web",
|
|
39
|
+
"solid-js/h",
|
|
40
|
+
"solid-js/store",
|
|
41
|
+
"solid-js/jsx-runtime",
|
|
42
|
+
];
|
|
43
|
+
export default externals;
|
package/src/externals.ts
CHANGED
|
@@ -1,42 +1,68 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
|
+
|
|
7
|
+
export { default } from "./externals-list.js";
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
|
-
*
|
|
10
|
+
* pretend the import came from inside this package, so node_modules resolution
|
|
11
|
+
* walks up from *our* directory and finds our copy of each external. that's why
|
|
12
|
+
* a consuming site never has to install them or agree with us about versions.
|
|
3
13
|
*/
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
const self = fileURLToPath(import.meta.url);
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Resolve one of this package's own dependencies from its node_modules
|
|
18
|
+
* rather than the site's, so a vite plugin bundling it never needs the site
|
|
19
|
+
* to install it or agree on a version. Exported so `@inkandswitch/patchwork`'s
|
|
20
|
+
* vite plugin (which lives in a different package) can reuse this for the
|
|
21
|
+
* externals bootloader actually owns, while resolving itself separately.
|
|
22
|
+
*
|
|
23
|
+
* This goes through rollup's resolver rather than import.meta.resolve or
|
|
24
|
+
* require.resolve because those apply node's conditions: subduction (and
|
|
25
|
+
* others) would hand us `dist/esm/node.js`, which imports node:path and blows
|
|
26
|
+
* up at bundle time. rollup applies the browser conditions vite configured.
|
|
27
|
+
*/
|
|
28
|
+
export async function resolveExternal(
|
|
29
|
+
this: import("rollup").PluginContext,
|
|
30
|
+
name: string
|
|
31
|
+
): Promise<string> {
|
|
32
|
+
const resolved = await this.resolve(name, self, { skipSelf: true });
|
|
33
|
+
if (!resolved) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
`@inkandswitch/patchwork-bootloader: couldn't resolve the external ` +
|
|
36
|
+
`"${name}". it should be one of the bootloader's own dependencies.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return resolved.id;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Emits automerge/keyhive/subduction's wasm binaries as build assets, so the service worker can fetch them. */
|
|
43
|
+
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
|
+
});
|
|
27
52
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
});
|
|
33
61
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
];
|
|
42
|
-
export default externals;
|
|
62
|
+
const subdWasmPath = require.resolve("@automerge/automerge-subduction/wasm");
|
|
63
|
+
this.emitFile({
|
|
64
|
+
type: "asset",
|
|
65
|
+
fileName: "subduction.wasm",
|
|
66
|
+
source: readFileSync(subdWasmPath),
|
|
67
|
+
});
|
|
68
|
+
}
|
package/src/global.css
ADDED
|
@@ -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
|
+
}
|
package/src/module-loader.ts
CHANGED
|
@@ -52,7 +52,6 @@ function getWorker(): Worker {
|
|
|
52
52
|
return worker;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/** Ask the worker which plugins the package at `urlAtHeads` exports. */
|
|
56
55
|
function discoverDescriptors(urlAtHeads: AutomergeUrl): Promise<Descriptor[]> {
|
|
57
56
|
const id = nextRequestId++;
|
|
58
57
|
return new Promise<Descriptor[]>((resolve, reject) => {
|
|
@@ -61,11 +60,6 @@ function discoverDescriptors(urlAtHeads: AutomergeUrl): Promise<Descriptor[]> {
|
|
|
61
60
|
});
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
/**
|
|
65
|
-
* ModuleWatcher `importAutomergePackage` hook: discover descriptors in the
|
|
66
|
-
* worker, then return the `{ plugins }` shape with a main-thread `load()` per
|
|
67
|
-
* plugin that imports the package at heads and calls its real loader.
|
|
68
|
-
*/
|
|
69
63
|
export async function importAutomergePackageViaWorker(
|
|
70
64
|
urlAtHeads: string
|
|
71
65
|
): Promise<{ plugins: Descriptor[] }> {
|