@flanksource/page-runtime 0.0.0-stage → 0.1.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/LICENSE +17 -0
- package/README.md +494 -2
- package/dist/build/README.md +96 -0
- package/dist/build/cjs-export-names.mjs +24 -0
- package/dist/build/dependencies.mjs +279 -0
- package/dist/build/dependencies.mjs.map +1 -0
- package/dist/build/dependency-cache-Zg-FGasE.mjs +2130 -0
- package/dist/build/dependency-cache-Zg-FGasE.mjs.map +1 -0
- package/dist/build/index.mjs +42 -0
- package/dist/build/index.mjs.map +1 -0
- package/dist/build/package.json +19 -0
- package/dist/build/types/activity-schema.d.ts +62 -0
- package/dist/build/types/build/barrels.d.ts +70 -0
- package/dist/build/types/build/base.d.ts +2 -0
- package/dist/build/types/build/browser-runtime-exports.d.ts +19 -0
- package/dist/build/types/build/check-fragment.d.ts +5 -0
- package/dist/build/types/build/commonjs-exports.d.ts +5 -0
- package/dist/build/types/build/convert-commonjs.d.ts +12 -0
- package/dist/build/types/build/dependencies.d.ts +6 -0
- package/dist/build/types/build/dependency-barrel-index.d.ts +5 -0
- package/dist/build/types/build/dependency-barrels.d.ts +7 -0
- package/dist/build/types/build/dependency-cache.d.ts +7 -0
- package/dist/build/types/build/dependency-optional.d.ts +4 -0
- package/dist/build/types/build/dependency-plugin.d.ts +8 -0
- package/dist/build/types/build/dependency-runtime.d.ts +20 -0
- package/dist/build/types/build/dependency-workers.d.ts +8 -0
- package/dist/build/types/build/errors.d.ts +9 -0
- package/dist/build/types/build/fragment.d.ts +13 -0
- package/dist/build/types/build/index.d.ts +7 -0
- package/dist/build/types/build/library-runtime.d.ts +21 -0
- package/dist/build/types/build/module-utils.d.ts +3 -0
- package/dist/build/types/build/recipe-dependencies.d.ts +2 -0
- package/dist/build/types/build/runtime-entries.d.ts +4 -0
- package/dist/build/types/build/runtime-layer.d.ts +17 -0
- package/dist/build/types/build/trace.d.ts +140 -0
- package/dist/build/types/design-schema.d.ts +98 -0
- package/dist/build/types/host/agent-source.d.ts +2 -0
- package/dist/build/types/host/agent-validation.d.ts +3 -0
- package/dist/build/types/host/design-validation.d.ts +2 -0
- package/dist/build/types/host/message-values.d.ts +8 -0
- package/dist/build/types/host/review/validation.d.ts +5 -0
- package/dist/build/types/host/validation.d.ts +6 -0
- package/dist/build/types/link/page-sources.d.ts +31 -0
- package/dist/build/types/link/types.d.ts +62 -0
- package/dist/build/types/link/validation.d.ts +9 -0
- package/dist/build/types/markers.d.ts +10 -0
- package/dist/build/types/review-schema.d.ts +60 -0
- package/dist/build/types/schema.d.ts +319 -0
- package/dist/build/types/sw/barrels.d.ts +9 -0
- package/dist/build/types/sw/compiler-plugins.d.ts +6 -0
- package/dist/build/types/sw/composition.d.ts +8 -0
- package/dist/build/types/sw/module-transform.d.ts +68 -0
- package/dist/build/types/sw/profile.d.ts +7 -0
- package/dist/build/types/sw/source-provider.d.ts +7 -0
- package/dist/build/types/sw/versions.d.ts +10 -0
- package/dist/node/catalog.mjs +1 -0
- package/dist/node/chunks/publication-RchcQvxD.mjs +229 -0
- package/dist/node/chunks/publication-RchcQvxD.mjs.map +1 -0
- package/dist/node/chunks/schema-CaRTfg2x.mjs +12 -0
- package/dist/node/chunks/schema-CaRTfg2x.mjs.map +1 -0
- package/dist/node/dev.mjs +410 -0
- package/dist/node/dev.mjs.map +1 -0
- package/dist/node/publication/cli.mjs +13 -0
- package/dist/node/publication/cli.mjs.map +1 -0
- package/dist/node/publication.mjs +1 -0
- package/dist/node/schema.mjs +1 -0
- package/dist/node/styles.mjs +49 -0
- package/dist/node/styles.mjs.map +1 -0
- package/dist/static/boot.js +40938 -0
- package/dist/static/boot.js.map +1 -0
- package/dist/static/bootstrap.html +1 -0
- package/dist/static/devtools-hook.js +118 -0
- package/dist/static/document-bundle.js +1 -0
- package/dist/static/document.js +2621 -0
- package/dist/static/editing.js +37 -0
- package/dist/static/export-compiler.js +81521 -0
- package/dist/static/export-compiler.js.map +1 -0
- package/dist/static/page-agent.js +17193 -0
- package/dist/static/page-agent.js.map +1 -0
- package/dist/static/sw.js +86112 -0
- package/dist/static/sw.js.map +1 -0
- package/package.json +110 -3
- package/scripts/build-builder.ts +27 -0
- package/scripts/build-library-runtime.ts +9 -0
- package/scripts/build-node.ts +26 -0
- package/scripts/build-static.ts +86 -0
- package/scripts/build.ts +7 -0
- package/scripts/check-fragment.ts +12 -0
- package/scripts/local-workspaces.ts +55 -0
- package/scripts/react-externals.ts +18 -0
- package/scripts/release-version.ts +47 -0
- package/scripts/run-package-build.ts +8 -0
- package/scripts/serve-packages.ts +8 -0
- package/src/activity-schema.ts +92 -0
- package/src/build/README.md +96 -0
- package/src/build/barrels.ts +306 -0
- package/src/build/base.ts +2 -0
- package/src/build/browser-runtime-exports.ts +52 -0
- package/src/build/check-fragment.ts +45 -0
- package/src/build/cjs-export-names.mjs +24 -0
- package/src/build/commonjs-exports.ts +24 -0
- package/src/build/convert-commonjs.ts +183 -0
- package/src/build/dependencies.ts +6 -0
- package/src/build/dependency-barrel-index.ts +48 -0
- package/src/build/dependency-barrels.ts +80 -0
- package/src/build/dependency-cache.ts +40 -0
- package/src/build/dependency-optional.ts +15 -0
- package/src/build/dependency-plugin.ts +58 -0
- package/src/build/dependency-runtime.ts +182 -0
- package/src/build/dependency-workers.ts +41 -0
- package/src/build/errors.ts +9 -0
- package/src/build/fragment.ts +89 -0
- package/src/build/index.ts +7 -0
- package/src/build/library-runtime.ts +101 -0
- package/src/build/module-utils.ts +11 -0
- package/src/build/recipe-dependencies.ts +14 -0
- package/src/build/runtime-entries.ts +10 -0
- package/src/build/runtime-layer.ts +99 -0
- package/src/build/trace.ts +431 -0
- package/src/design-schema.ts +25 -0
- package/src/dev/README.md +78 -0
- package/src/dev/catalog.ts +79 -0
- package/src/dev/cli.ts +25 -0
- package/src/dev/index.ts +118 -0
- package/src/dev/runtime-origin.ts +63 -0
- package/src/editing.ts +25 -0
- package/src/form/entry-source.ts +68 -0
- package/src/form/form-page.ts +63 -0
- package/src/form/index.ts +2 -0
- package/src/form/source-update.ts +17 -0
- package/src/frame/activity.browser.ts +34 -0
- package/src/frame/activity.ts +52 -0
- package/src/frame/agent/README.md +47 -0
- package/src/frame/agent/agent.browser.ts +127 -0
- package/src/frame/agent/design.ts +62 -0
- package/src/frame/agent/frame-layout.ts +54 -0
- package/src/frame/agent/index.ts +151 -0
- package/src/frame/agent/overlay.ts +104 -0
- package/src/frame/agent/owner.ts +61 -0
- package/src/frame/agent/provider.tsx +14 -0
- package/src/frame/agent/react-override.ts +55 -0
- package/src/frame/agent/review.browser.ts +65 -0
- package/src/frame/agent/review.ts +108 -0
- package/src/frame/agent/testing/callsite.tsx +5 -0
- package/src/frame/agent/testing/client.ts +99 -0
- package/src/frame/agent/testing/library.ts +3 -0
- package/src/frame/agent/testing/modal.tsx +5 -0
- package/src/frame/agent/testing/review-client.ts +43 -0
- package/src/frame/agent/testing/review-server.ts +31 -0
- package/src/frame/agent/testing/server.ts +72 -0
- package/src/frame/agent/testing/vocabulary-host.ts +20 -0
- package/src/frame/agent/testing/vocabulary.tsx +10 -0
- package/src/frame/agent/vitest.browser.config.ts +6 -0
- package/src/frame/agent/vocabulary.browser.ts +30 -0
- package/src/frame/agent/vocabulary.ts +13 -0
- package/src/frame/agent.ts +3 -0
- package/src/frame/boot-styles.ts +50 -0
- package/src/frame/boot.ts +269 -0
- package/src/frame/bridge.ts +27 -0
- package/src/frame/devtools-hook.ts +1 -0
- package/src/frame/document-assets.ts +76 -0
- package/src/frame/document-entry.ts +68 -0
- package/src/frame/document-modules.ts +113 -0
- package/src/frame/document-mount.ts +32 -0
- package/src/frame/entry.ts +4 -0
- package/src/frame/export-compiler.ts +18 -0
- package/src/frame/export-page.ts +61 -0
- package/src/frame/export.ts +89 -0
- package/src/frame/index.ts +8 -0
- package/src/frame/local-runtime.browser.ts +36 -0
- package/src/frame/mount-page.ts +36 -0
- package/src/frame/page-agent.ts +2 -0
- package/src/frame/readiness.ts +51 -0
- package/src/frame/render-job.ts +101 -0
- package/src/frame/review-integration.browser.ts +48 -0
- package/src/frame/runtime.browser.ts +90 -0
- package/src/frame/tailwind/README.md +49 -0
- package/src/frame/tailwind/boot-styles.browser.ts +18 -0
- package/src/frame/tailwind/cache.ts +20 -0
- package/src/frame/tailwind/load.ts +75 -0
- package/src/frame/tailwind/recipe.ts +76 -0
- package/src/frame/tailwind/runtime.ts +113 -0
- package/src/frame/tailwind/store.ts +55 -0
- package/src/frame/tailwind/stylesheets.ts +42 -0
- package/src/frame/tailwind/tailwind.browser.ts +71 -0
- package/src/frame/tailwind/testing/client.ts +133 -0
- package/src/frame/tailwind/testing/compare.ts +91 -0
- package/src/frame/tailwind/testing/pages.ts +14 -0
- package/src/frame/tailwind/testing/server.ts +89 -0
- package/src/frame/tailwind/vitest.browser.config.ts +7 -0
- package/src/frame/testing/boot-layout.ts +3 -0
- package/src/frame/testing/boot-page.ts +3 -0
- package/src/frame/testing/host.ts +78 -0
- package/src/frame/testing/local-host.tsx +33 -0
- package/src/frame/testing/server.ts +135 -0
- package/src/host/BuildLog.tsx +28 -0
- package/src/host/DEBUG_CONSOLE.md +13 -0
- package/src/host/PageForm.tsx +63 -0
- package/src/host/PageFrame.tsx +49 -0
- package/src/host/RuntimeActivity.tsx +77 -0
- package/src/host/RuntimeDebugPanel.tsx +18 -0
- package/src/host/activity-state.ts +69 -0
- package/src/host/agent-source.ts +14 -0
- package/src/host/agent-validation.ts +73 -0
- package/src/host/bridge.ts +56 -0
- package/src/host/build-log.ts +29 -0
- package/src/host/clear-cache.ts +66 -0
- package/src/host/debug-runtime.tsx +17 -0
- package/src/host/design-validation.ts +96 -0
- package/src/host/index.ts +12 -0
- package/src/host/link/index.ts +66 -0
- package/src/host/link/transport.ts +68 -0
- package/src/host/link/watch.ts +62 -0
- package/src/host/message-values.ts +55 -0
- package/src/host/origin.ts +7 -0
- package/src/host/review/README.md +32 -0
- package/src/host/review/index.ts +43 -0
- package/src/host/review/validation.ts +55 -0
- package/src/host/runtime-diagnostics.ts +41 -0
- package/src/host/validation.ts +148 -0
- package/src/link/README.md +115 -0
- package/src/link/barrels.ts +5 -0
- package/src/link/build-cli.ts +12 -0
- package/src/link/build.ts +99 -0
- package/src/link/commonjs.ts +39 -0
- package/src/link/examples/server.ts +18 -0
- package/src/link/index.ts +6 -0
- package/src/link/link.browser.ts +66 -0
- package/src/link/local-relay.browser.ts +22 -0
- package/src/link/overrides.ts +69 -0
- package/src/link/page-sources.ts +69 -0
- package/src/link/source.ts +25 -0
- package/src/link/storage.ts +32 -0
- package/src/link/testing/client.ts +96 -0
- package/src/link/testing/folder.ts +19 -0
- package/src/link/testing/local-client.ts +30 -0
- package/src/link/testing/local-server.ts +26 -0
- package/src/link/testing/local-worker.ts +17 -0
- package/src/link/testing/server.ts +131 -0
- package/src/link/testing/worker.ts +32 -0
- package/src/link/testing-cache.ts +20 -0
- package/src/link/testing-fixtures.ts +16 -0
- package/src/link/types.ts +27 -0
- package/src/link/validation.ts +44 -0
- package/src/link/vitest.browser.config.ts +3 -0
- package/src/markers.ts +18 -0
- package/src/publication/build.ts +27 -0
- package/src/publication/fixtures/build.mjs +2 -0
- package/src/publication/index.ts +3 -0
- package/src/publication/lock.ts +32 -0
- package/src/publication/manifest.ts +14 -0
- package/src/publication/publish.ts +80 -0
- package/src/publication/runtime.ts +28 -0
- package/src/publication/schema.ts +13 -0
- package/src/review-schema.ts +17 -0
- package/src/schema.ts +175 -0
- package/src/storage/db.ts +64 -0
- package/src/styles.ts +40 -0
- package/src/sw/activity.ts +66 -0
- package/src/sw/barrels.ts +44 -0
- package/src/sw/candidates.ts +14 -0
- package/src/sw/compile.ts +92 -0
- package/src/sw/compiler-columns.ts +44 -0
- package/src/sw/compiler-internals.d.ts +8 -0
- package/src/sw/compiler-plugins.ts +18 -0
- package/src/sw/compiler.ts +93 -0
- package/src/sw/composition.ts +86 -0
- package/src/sw/content-types.ts +28 -0
- package/src/sw/converted.browser.ts +31 -0
- package/src/sw/converted.ts +64 -0
- package/src/sw/editable-sites.ts +42 -0
- package/src/sw/errors.ts +30 -0
- package/src/sw/esm-sh-fixtures/browser-client.ts +18 -0
- package/src/sw/esm-sh-fixtures/browser-server.ts +104 -0
- package/src/sw/esm-sh-fixtures/fixtures/copy-to-clipboard-entry.headers +15 -0
- package/src/sw/esm-sh-fixtures/fixtures/copy-to-clipboard-entry.mjs.txt +3 -0
- package/src/sw/esm-sh-fixtures/fixtures/copy-to-clipboard-module.headers +13 -0
- package/src/sw/esm-sh-fixtures/fixtures/copy-to-clipboard-module.mjs.txt +142 -0
- package/src/sw/esm-sh-fixtures/fixtures/react-copy-to-clipboard-entry.headers +15 -0
- package/src/sw/esm-sh-fixtures/fixtures/react-copy-to-clipboard-entry.mjs.txt +3 -0
- package/src/sw/esm-sh-fixtures/fixtures/react-copy-to-clipboard-module.headers +11 -0
- package/src/sw/esm-sh-fixtures/fixtures/react-copy-to-clipboard-module.mjs.txt +222 -0
- package/src/sw/esm-sh-fixtures/fixtures/toggle-selection-entry.headers +14 -0
- package/src/sw/esm-sh-fixtures/fixtures/toggle-selection-entry.mjs.txt +3 -0
- package/src/sw/esm-sh-fixtures/fixtures/toggle-selection-module.headers +11 -0
- package/src/sw/esm-sh-fixtures/fixtures/toggle-selection-module.mjs.txt +76 -0
- package/src/sw/esm-sh-fixtures/fixtures.ts +54 -0
- package/src/sw/esm-sh-fixtures/redact.ts +1 -0
- package/src/sw/index.ts +7 -0
- package/src/sw/integrity.ts +10 -0
- package/src/sw/legacy-storage.ts +18 -0
- package/src/sw/link-activity.ts +21 -0
- package/src/sw/link-cache.ts +19 -0
- package/src/sw/link-compiler.ts +120 -0
- package/src/sw/link-folder.ts +29 -0
- package/src/sw/link-relay.ts +40 -0
- package/src/sw/link-route.ts +239 -0
- package/src/sw/link-source.ts +41 -0
- package/src/sw/markers.ts +128 -0
- package/src/sw/module-transform.ts +364 -0
- package/src/sw/page-clients.ts +45 -0
- package/src/sw/profile.ts +90 -0
- package/src/sw/resolver.ts +224 -0
- package/src/sw/router.ts +360 -0
- package/src/sw/runtime-exports.ts +39 -0
- package/src/sw/runtime-module.ts +13 -0
- package/src/sw/source-hash.ts +37 -0
- package/src/sw/source-provider.ts +20 -0
- package/src/sw/versions.ts +96 -0
- package/src/sw/worker.ts +91 -0
- package/static/README.md +15 -0
- package/static/profile.example.json +15 -0
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import { n as validateCatalog, t as BUILD_ID } from "./chunks/schema-CaRTfg2x.mjs";
|
|
2
|
+
import { a as readPublication, n as atomicJson, o as readManifest, r as publicationRoot } from "./chunks/publication-RchcQvxD.mjs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { readFile, realpath } from "node:fs/promises";
|
|
5
|
+
import { dirname, extname, join, resolve, sep } from "node:path";
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
import { existsSync, unwatchFile, watchFile } from "node:fs";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
// src/dev/catalog.ts
|
|
10
|
+
async function createCatalogStore(options) {
|
|
11
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
12
|
+
const retained = /* @__PURE__ */ new Map();
|
|
13
|
+
const directories = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const path of options.packages) {
|
|
15
|
+
const publication = await readPublication(path);
|
|
16
|
+
if (directories.has(publication.name)) throw new Error(`Duplicate local package: ${publication.name}`);
|
|
17
|
+
directories.set(publication.name, path);
|
|
18
|
+
}
|
|
19
|
+
let current;
|
|
20
|
+
let failure;
|
|
21
|
+
const load = async () => {
|
|
22
|
+
const entries = await Promise.all([...directories].sort(([a], [b]) => a.localeCompare(b)).map(async ([name, path]) => {
|
|
23
|
+
const publication = await readPublication(path);
|
|
24
|
+
if (publication.name !== name) throw new Error(`${path}: package identity changed; restart the local origin`);
|
|
25
|
+
return publication;
|
|
26
|
+
}));
|
|
27
|
+
const packages = Object.fromEntries(entries.map(({ name, version, build }) => [name, {
|
|
28
|
+
name,
|
|
29
|
+
version,
|
|
30
|
+
build
|
|
31
|
+
}]));
|
|
32
|
+
const revision = createHash("sha256").update(JSON.stringify(packages)).digest("hex");
|
|
33
|
+
if (current?.catalog.revision === revision) {
|
|
34
|
+
failure = void 0;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const catalog = {
|
|
38
|
+
revision,
|
|
39
|
+
packages
|
|
40
|
+
};
|
|
41
|
+
const locals = await localPackages(entries);
|
|
42
|
+
await atomicJson(resolve(options.stateDir, `${revision}.json`), catalog);
|
|
43
|
+
current = {
|
|
44
|
+
catalog,
|
|
45
|
+
locals
|
|
46
|
+
};
|
|
47
|
+
failure = void 0;
|
|
48
|
+
retained.set(revision, current);
|
|
49
|
+
listeners.forEach((listener) => listener(catalog));
|
|
50
|
+
};
|
|
51
|
+
await load();
|
|
52
|
+
let queue = Promise.resolve();
|
|
53
|
+
const refresh = () => {
|
|
54
|
+
queue = queue.then(load).catch((error) => {
|
|
55
|
+
failure = error instanceof Error ? error : new Error(String(error));
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const watchers = options.packages.map((path) => {
|
|
59
|
+
const file = resolve(publicationRoot(path), "current.json");
|
|
60
|
+
const listener = () => refresh();
|
|
61
|
+
watchFile(file, {
|
|
62
|
+
interval: 250,
|
|
63
|
+
persistent: false
|
|
64
|
+
}, listener);
|
|
65
|
+
return () => unwatchFile(file, listener);
|
|
66
|
+
});
|
|
67
|
+
refresh();
|
|
68
|
+
return {
|
|
69
|
+
current() {
|
|
70
|
+
if (failure) throw failure;
|
|
71
|
+
return current.catalog;
|
|
72
|
+
},
|
|
73
|
+
async get(revision) {
|
|
74
|
+
if (!revision) {
|
|
75
|
+
if (failure) throw failure;
|
|
76
|
+
return current;
|
|
77
|
+
}
|
|
78
|
+
if (!BUILD_ID.test(revision)) throw new Error("Invalid package catalog revision");
|
|
79
|
+
const known = retained.get(revision);
|
|
80
|
+
if (known) return known;
|
|
81
|
+
const catalog = validateCatalog(JSON.parse(await readFile(resolve(options.stateDir, `${revision}.json`), "utf8")));
|
|
82
|
+
if (catalog.revision !== revision || createHash("sha256").update(JSON.stringify(catalog.packages)).digest("hex") !== revision) throw new Error("Package catalog integrity mismatch");
|
|
83
|
+
const loaded = {
|
|
84
|
+
catalog,
|
|
85
|
+
locals: await localPackages(Object.values(catalog.packages).map((entry) => {
|
|
86
|
+
const path = directories.get(entry.name);
|
|
87
|
+
if (!path) throw new Error(`Unconfigured catalog package: ${entry.name}`);
|
|
88
|
+
return {
|
|
89
|
+
...entry,
|
|
90
|
+
directory: resolve(publicationRoot(path), "generations", entry.build, "package")
|
|
91
|
+
};
|
|
92
|
+
}))
|
|
93
|
+
};
|
|
94
|
+
retained.set(revision, loaded);
|
|
95
|
+
return loaded;
|
|
96
|
+
},
|
|
97
|
+
subscribe(listener) {
|
|
98
|
+
listeners.add(listener);
|
|
99
|
+
return () => {
|
|
100
|
+
listeners.delete(listener);
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
close() {
|
|
104
|
+
watchers.forEach((close) => close());
|
|
105
|
+
listeners.clear();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function localPackages(entries) {
|
|
110
|
+
return new Map(await Promise.all(entries.map(async (entry) => {
|
|
111
|
+
const directory = await realpath(entry.directory);
|
|
112
|
+
const manifest = await readManifest(directory);
|
|
113
|
+
if (manifest.name !== entry.name || manifest.version !== entry.version) throw new Error(`Package snapshot identity mismatch: ${entry.name}`);
|
|
114
|
+
return [entry.name, {
|
|
115
|
+
directory,
|
|
116
|
+
manifest
|
|
117
|
+
}];
|
|
118
|
+
})));
|
|
119
|
+
}
|
|
120
|
+
// src/dev/runtime-origin.ts
|
|
121
|
+
function packageAssets() {
|
|
122
|
+
for (let dir = dirname(fileURLToPath(import.meta.url)); dir !== dirname(dir); dir = dirname(dir)) if (existsSync(join(dir, "package.json")) && existsSync(join(dir, "dist/static"))) return join(dir, "dist/static");
|
|
123
|
+
throw new Error("Cannot find the built page-runtime assets; run the page-runtime build");
|
|
124
|
+
}
|
|
125
|
+
/** Serves built browser assets and local package publications on a separate loopback origin. */
|
|
126
|
+
async function serveRuntime(options) {
|
|
127
|
+
const host = new URL(options.hostOrigin);
|
|
128
|
+
if (host.origin !== options.hostOrigin || !["http:", "https:"].includes(host.protocol) || ![
|
|
129
|
+
"localhost",
|
|
130
|
+
"127.0.0.1",
|
|
131
|
+
"[::1]"
|
|
132
|
+
].includes(host.hostname)) throw new Error("Local page runtime requires an exact loopback origin");
|
|
133
|
+
const assetsDir = options.assetsDir ?? packageAssets();
|
|
134
|
+
const assets = new Map(await Promise.all([
|
|
135
|
+
"bootstrap.html",
|
|
136
|
+
"sw.js",
|
|
137
|
+
"boot.js",
|
|
138
|
+
"page-agent.js",
|
|
139
|
+
"editing.js",
|
|
140
|
+
"export-compiler.js",
|
|
141
|
+
"devtools-hook.js"
|
|
142
|
+
].map(async (file) => [file, await readFile(resolve(assetsDir, file))])));
|
|
143
|
+
const packages = await createPackageHandler(options);
|
|
144
|
+
const dependencies = () => Object.fromEntries(Object.entries(packages.current().packages).map(([name, entry]) => [name, entry.version]));
|
|
145
|
+
let origin;
|
|
146
|
+
const server = createServer((request, response) => {
|
|
147
|
+
try {
|
|
148
|
+
const path = new URL(request.url ?? "/", "http://localhost").pathname;
|
|
149
|
+
if (path.startsWith("/_generations/")) {
|
|
150
|
+
packages.handle(request, response);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (request.method !== "GET" && request.method !== "HEAD") {
|
|
154
|
+
response.writeHead(405).end();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (path === "/profile.json") {
|
|
158
|
+
const packageOrigin = `${origin}/_generations/${packages.current().revision}`;
|
|
159
|
+
const profile = {
|
|
160
|
+
runtimeDomain: new URL(origin).host,
|
|
161
|
+
embedders: [host.origin],
|
|
162
|
+
packageOrigin,
|
|
163
|
+
registry: packageOrigin,
|
|
164
|
+
managed: dependencies(),
|
|
165
|
+
policy: { dependencies: "strict" },
|
|
166
|
+
minReleaseAgeDays: 0,
|
|
167
|
+
network: { allow: ["https://fonts.googleapis.com/*", "https://fonts.gstatic.com/*"] },
|
|
168
|
+
csp: { add: {
|
|
169
|
+
"style-src": ["https://fonts.googleapis.com"],
|
|
170
|
+
"font-src": [
|
|
171
|
+
"'self'",
|
|
172
|
+
"data:",
|
|
173
|
+
"https://fonts.gstatic.com"
|
|
174
|
+
]
|
|
175
|
+
} },
|
|
176
|
+
links: "deny",
|
|
177
|
+
sources: ["host"],
|
|
178
|
+
readinessTimeoutMs: 3e4
|
|
179
|
+
};
|
|
180
|
+
response.writeHead(200, {
|
|
181
|
+
"content-type": "application/json",
|
|
182
|
+
"cache-control": "no-store"
|
|
183
|
+
}).end(request.method === "HEAD" ? void 0 : JSON.stringify(profile));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const file = path.startsWith("/frame/") ? "bootstrap.html" : path.slice(1);
|
|
187
|
+
const asset = assets.get(file);
|
|
188
|
+
if (!asset) {
|
|
189
|
+
response.writeHead(404).end("Runtime asset not found");
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
response.writeHead(200, {
|
|
193
|
+
"content-type": file.endsWith(".html") ? "text/html; charset=utf-8" : "text/javascript; charset=utf-8",
|
|
194
|
+
"cache-control": "no-store",
|
|
195
|
+
...file === "sw.js" ? { "service-worker-allowed": "/frame/" } : {}
|
|
196
|
+
});
|
|
197
|
+
response.end(request.method === "HEAD" ? void 0 : asset);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
response.writeHead(500, {
|
|
200
|
+
"content-type": "text/plain; charset=utf-8",
|
|
201
|
+
"cache-control": "no-store"
|
|
202
|
+
}).end(request.method === "HEAD" ? void 0 : error instanceof Error ? error.message : String(error));
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
try {
|
|
206
|
+
await new Promise((done, fail) => {
|
|
207
|
+
server.once("error", fail);
|
|
208
|
+
server.listen(0, "127.0.0.1", done);
|
|
209
|
+
});
|
|
210
|
+
} catch (error) {
|
|
211
|
+
packages.close();
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
origin = `http://127.0.0.1:${server.address().port}`;
|
|
215
|
+
return {
|
|
216
|
+
origin,
|
|
217
|
+
get dependencies() {
|
|
218
|
+
return dependencies();
|
|
219
|
+
},
|
|
220
|
+
close: () => new Promise((done, fail) => {
|
|
221
|
+
packages.close();
|
|
222
|
+
server.closeAllConnections();
|
|
223
|
+
server.close((error) => error ? fail(error) : done());
|
|
224
|
+
})
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
// src/dev/index.ts
|
|
228
|
+
const LOCAL_RELEASE_TIME = "2000-01-01T00:00:00.000Z";
|
|
229
|
+
const types = {
|
|
230
|
+
".js": "text/javascript",
|
|
231
|
+
".mjs": "text/javascript",
|
|
232
|
+
".cjs": "text/javascript",
|
|
233
|
+
".json": "application/json",
|
|
234
|
+
".map": "application/json",
|
|
235
|
+
".css": "text/css",
|
|
236
|
+
".html": "text/html",
|
|
237
|
+
".txt": "text/plain",
|
|
238
|
+
".md": "text/markdown",
|
|
239
|
+
".svg": "image/svg+xml",
|
|
240
|
+
".png": "image/png",
|
|
241
|
+
".jpg": "image/jpeg",
|
|
242
|
+
".jpeg": "image/jpeg",
|
|
243
|
+
".gif": "image/gif",
|
|
244
|
+
".webp": "image/webp",
|
|
245
|
+
".avif": "image/avif",
|
|
246
|
+
".ico": "image/x-icon",
|
|
247
|
+
".woff": "font/woff",
|
|
248
|
+
".woff2": "font/woff2",
|
|
249
|
+
".ttf": "font/ttf",
|
|
250
|
+
".otf": "font/otf",
|
|
251
|
+
".wasm": "application/wasm"
|
|
252
|
+
};
|
|
253
|
+
const textResponse = (status, body) => ({
|
|
254
|
+
status,
|
|
255
|
+
body,
|
|
256
|
+
type: "text/plain; charset=utf-8",
|
|
257
|
+
cache: "no-store"
|
|
258
|
+
});
|
|
259
|
+
function upstreamBase(value) {
|
|
260
|
+
const url = new URL(value);
|
|
261
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error(`upstream must be an HTTP(S) URL without credentials, query or hash: ${value}`);
|
|
262
|
+
return url.href.replace(/\/$/, "");
|
|
263
|
+
}
|
|
264
|
+
async function localFile(local, path) {
|
|
265
|
+
if (!path || path.split(/[\\/]/).some((part) => part === "..") || path.includes("\0")) return textResponse(404, "Invalid local package file path");
|
|
266
|
+
try {
|
|
267
|
+
const file = await realpath(resolve(local.directory, path));
|
|
268
|
+
if (!file.startsWith(`${local.directory}${sep}`)) return textResponse(404, "File is outside the local package directory");
|
|
269
|
+
return {
|
|
270
|
+
body: await readFile(file),
|
|
271
|
+
status: 200,
|
|
272
|
+
type: types[extname(file)] ?? "application/octet-stream",
|
|
273
|
+
cache: "no-store"
|
|
274
|
+
};
|
|
275
|
+
} catch (error) {
|
|
276
|
+
if ([
|
|
277
|
+
"ENOENT",
|
|
278
|
+
"ENOTDIR",
|
|
279
|
+
"EISDIR"
|
|
280
|
+
].includes(error.code ?? "")) return textResponse(404, `${local.manifest.name}@${local.manifest.version}: file not found: ${path}`);
|
|
281
|
+
throw error;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
async function serveRequest(options) {
|
|
285
|
+
const { url, method, locals, registry, origin } = options;
|
|
286
|
+
if (method === "OPTIONS") return textResponse(204, "");
|
|
287
|
+
if (!["GET", "HEAD"].includes(method)) return textResponse(405, "Only GET, HEAD and OPTIONS are supported");
|
|
288
|
+
let path;
|
|
289
|
+
try {
|
|
290
|
+
path = decodeURIComponent(url.split("?")[0]);
|
|
291
|
+
} catch {
|
|
292
|
+
return textResponse(400, "Invalid URL encoding");
|
|
293
|
+
}
|
|
294
|
+
if (path === "/") return {
|
|
295
|
+
status: 200,
|
|
296
|
+
body: JSON.stringify({ packages: [...locals.keys()] }),
|
|
297
|
+
type: "application/json",
|
|
298
|
+
cache: "no-store"
|
|
299
|
+
};
|
|
300
|
+
const match = path.match(/^\/((?:@[^/@]+\/)?[^/@]+)(?:@([^/]+)(?:\/(.*))?)?$/);
|
|
301
|
+
if (!match) return textResponse(404, `Invalid package path: ${path}`);
|
|
302
|
+
const [, name, version, file] = match;
|
|
303
|
+
const local = locals.get(name);
|
|
304
|
+
if (local) {
|
|
305
|
+
const manifest = local.manifest;
|
|
306
|
+
if (!version) return {
|
|
307
|
+
status: 200,
|
|
308
|
+
body: JSON.stringify({
|
|
309
|
+
name,
|
|
310
|
+
versions: { [manifest.version]: manifest },
|
|
311
|
+
time: { [manifest.version]: LOCAL_RELEASE_TIME },
|
|
312
|
+
"dist-tags": { latest: manifest.version }
|
|
313
|
+
}),
|
|
314
|
+
type: "application/json",
|
|
315
|
+
cache: options.immutable ? "public, max-age=31536000, immutable" : "no-store"
|
|
316
|
+
};
|
|
317
|
+
if (version !== manifest.version) return textResponse(404, `Requested ${name}@${version}; local package is ${name}@${manifest.version}`);
|
|
318
|
+
const served = await localFile(local, file ?? "");
|
|
319
|
+
if (options.immutable && served.status === 200) served.cache = "public, max-age=31536000, immutable";
|
|
320
|
+
return served;
|
|
321
|
+
}
|
|
322
|
+
const target = `${version ? origin : registry}${url}`;
|
|
323
|
+
try {
|
|
324
|
+
const response = await fetch(target, {
|
|
325
|
+
method,
|
|
326
|
+
signal: AbortSignal.timeout(3e4)
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
status: response.status,
|
|
330
|
+
body: new Uint8Array(await response.arrayBuffer()),
|
|
331
|
+
type: response.headers.get("content-type") ?? "application/octet-stream",
|
|
332
|
+
cache: response.headers.get("cache-control") ?? "no-store"
|
|
333
|
+
};
|
|
334
|
+
} catch (error) {
|
|
335
|
+
return textResponse(502, `Proxy ${target}: ${error instanceof Error ? error.message : String(error)}`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
async function createPackageHandler(options) {
|
|
339
|
+
const registry = upstreamBase(options.upstreamRegistry);
|
|
340
|
+
const origin = upstreamBase(options.upstreamOrigin);
|
|
341
|
+
if (!options.packages.length) throw new Error("At least one local package directory is required");
|
|
342
|
+
const store = await createCatalogStore(options);
|
|
343
|
+
const handle = async (request, response) => {
|
|
344
|
+
response.setHeader("access-control-allow-origin", "*");
|
|
345
|
+
response.setHeader("access-control-allow-methods", "GET, HEAD, OPTIONS");
|
|
346
|
+
response.setHeader("access-control-allow-headers", "*");
|
|
347
|
+
try {
|
|
348
|
+
const raw = request.url ?? "/";
|
|
349
|
+
const generation = raw.match(/^\/_generations\/([^/]+)(\/.*)$/);
|
|
350
|
+
const selected = await store.get(generation?.[1]);
|
|
351
|
+
const url = generation?.[2] ?? raw;
|
|
352
|
+
const served = ["GET", "HEAD"].includes(request.method ?? "GET") && url.split("?")[0] === "/__catalog.json" ? {
|
|
353
|
+
status: 200,
|
|
354
|
+
body: JSON.stringify(selected.catalog),
|
|
355
|
+
type: "application/json",
|
|
356
|
+
cache: generation ? "public, max-age=31536000, immutable" : "no-store"
|
|
357
|
+
} : await serveRequest({
|
|
358
|
+
url,
|
|
359
|
+
method: request.method ?? "GET",
|
|
360
|
+
locals: selected.locals,
|
|
361
|
+
registry,
|
|
362
|
+
origin,
|
|
363
|
+
immutable: Boolean(generation)
|
|
364
|
+
});
|
|
365
|
+
response.writeHead(served.status, {
|
|
366
|
+
"content-type": served.type,
|
|
367
|
+
"cache-control": served.cache,
|
|
368
|
+
...served.status === 204 || served.status === 304 ? {} : { "content-length": typeof served.body === "string" ? Buffer.byteLength(served.body) : served.body.byteLength },
|
|
369
|
+
"timing-allow-origin": "*",
|
|
370
|
+
"access-control-expose-headers": "content-length, content-encoding, server-timing"
|
|
371
|
+
});
|
|
372
|
+
response.end(request.method === "HEAD" ? void 0 : served.body);
|
|
373
|
+
} catch (error) {
|
|
374
|
+
console.error("Package request failed", error);
|
|
375
|
+
response.writeHead(error.code === "ENOENT" ? 404 : 500, {
|
|
376
|
+
"content-type": "text/plain; charset=utf-8",
|
|
377
|
+
"cache-control": "no-store"
|
|
378
|
+
});
|
|
379
|
+
response.end(error.code === "ENOENT" ? "Package not found" : "Package request failed");
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
return {
|
|
383
|
+
handle,
|
|
384
|
+
current: store.current,
|
|
385
|
+
subscribe: store.subscribe,
|
|
386
|
+
close: store.close
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
async function servePackages(options) {
|
|
390
|
+
if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535) throw new Error(`Invalid port: ${options.port}`);
|
|
391
|
+
const handler = await createPackageHandler(options);
|
|
392
|
+
const server = createServer((request, response) => {
|
|
393
|
+
handler.handle(request, response);
|
|
394
|
+
});
|
|
395
|
+
await new Promise((done, fail) => {
|
|
396
|
+
server.once("error", fail);
|
|
397
|
+
server.listen(options.port, "127.0.0.1", done);
|
|
398
|
+
});
|
|
399
|
+
return {
|
|
400
|
+
origin: `http://127.0.0.1:${server.address().port}`,
|
|
401
|
+
close: () => new Promise((done, fail) => {
|
|
402
|
+
handler.close();
|
|
403
|
+
server.closeAllConnections();
|
|
404
|
+
server.close((error) => error ? fail(error) : done());
|
|
405
|
+
})
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
export { LOCAL_RELEASE_TIME, createPackageHandler, servePackages, serveRuntime };
|
|
409
|
+
|
|
410
|
+
//# sourceMappingURL=dev.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.mjs","names":[],"sources":["../../src/dev/catalog.ts","../../src/dev/runtime-origin.ts","../../src/dev/index.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { watchFile, unwatchFile } from \"node:fs\";\nimport { readFile, realpath } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { atomicJson, publicationRoot, readPublication, type PackageCatalog, type Publication } from \"../publication/index.ts\";\nimport { readManifest, type PackageManifest } from \"../publication/manifest.ts\";\nimport { BUILD_ID, validateCatalog } from \"../publication/schema.ts\";\n\nexport type LocalPackage = { directory: string; manifest: PackageManifest };\ntype Catalog = { catalog: PackageCatalog; locals: Map<string, LocalPackage> };\nexport async function createCatalogStore(options: { packages: string[]; stateDir: string }) {\n const listeners = new Set<(catalog: PackageCatalog) => void>();\n const retained = new Map<string, Catalog>();\n const directories = new Map<string, string>();\n for (const path of options.packages) {\n const publication = await readPublication(path);\n if (directories.has(publication.name)) throw new Error(`Duplicate local package: ${publication.name}`);\n directories.set(publication.name, path);\n }\n let current: Catalog;\n let failure: Error | undefined;\n const load = async () => {\n const entries = await Promise.all([...directories].sort(([a], [b]) => a.localeCompare(b)).map(async ([name, path]) => {\n const publication = await readPublication(path);\n if (publication.name !== name) throw new Error(`${path}: package identity changed; restart the local origin`);\n return publication;\n }));\n const packages = Object.fromEntries(entries.map(({ name, version, build }) => [name, { name, version, build }]));\n const revision = createHash(\"sha256\").update(JSON.stringify(packages)).digest(\"hex\");\n if (current?.catalog.revision === revision) { failure = undefined; return; }\n const catalog = { revision, packages };\n const locals = await localPackages(entries);\n await atomicJson(resolve(options.stateDir, `${revision}.json`), catalog);\n current = { catalog, locals }; failure = undefined;\n retained.set(revision, current);\n listeners.forEach(listener => listener(catalog));\n };\n await load();\n let queue = Promise.resolve();\n const refresh = () => { queue = queue.then(load).catch(error => { failure = error instanceof Error ? error : new Error(String(error)); }); };\n const watchers = options.packages.map(path => {\n const file = resolve(publicationRoot(path), \"current.json\");\n const listener = () => refresh();\n watchFile(file, { interval: 250, persistent: false }, listener);\n return () => unwatchFile(file, listener);\n });\n // Catch a publication completed between the initial read and watcher setup.\n refresh();\n return {\n current(): PackageCatalog { if (failure) throw failure; return current.catalog; },\n async get(revision?: string): Promise<Catalog> {\n if (!revision) { if (failure) throw failure; return current; }\n if (!BUILD_ID.test(revision)) throw new Error(\"Invalid package catalog revision\");\n const known = retained.get(revision);\n if (known) return known;\n const catalog = validateCatalog(JSON.parse(await readFile(resolve(options.stateDir, `${revision}.json`), \"utf8\")));\n if (catalog.revision !== revision || createHash(\"sha256\").update(JSON.stringify(catalog.packages)).digest(\"hex\") !== revision) throw new Error(\"Package catalog integrity mismatch\");\n const entries = Object.values(catalog.packages).map(entry => {\n const path = directories.get(entry.name);\n if (!path) throw new Error(`Unconfigured catalog package: ${entry.name}`);\n return { ...entry, directory: resolve(publicationRoot(path), \"generations\", entry.build, \"package\") };\n });\n const loaded = { catalog, locals: await localPackages(entries) };\n retained.set(revision, loaded);\n return loaded;\n },\n subscribe(listener: (catalog: PackageCatalog) => void) { listeners.add(listener); return () => { listeners.delete(listener); }; },\n close() { watchers.forEach(close => close()); listeners.clear(); },\n };\n}\n\nasync function localPackages(entries: Publication[]): Promise<Map<string, LocalPackage>> {\n return new Map(await Promise.all(entries.map(async entry => {\n const directory = await realpath(entry.directory);\n const manifest = await readManifest(directory);\n if (manifest.name !== entry.name || manifest.version !== entry.version) throw new Error(`Package snapshot identity mismatch: ${entry.name}`);\n return [entry.name, { directory, manifest }] as const;\n })));\n}\n","import { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { createServer } from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { RuntimeProfile } from \"../schema.ts\";\nimport { createPackageHandler, type PackageOriginOptions } from \"./index.ts\";\n\n// This module runs from src/ in the workspace and from a bundle in dist/node/ when installed, so locate the package root.\nfunction packageAssets(): string {\n for (let dir = dirname(fileURLToPath(import.meta.url)); dir !== dirname(dir); dir = dirname(dir)) {\n if (existsSync(join(dir, \"package.json\")) && existsSync(join(dir, \"dist/static\"))) return join(dir, \"dist/static\");\n }\n throw new Error(\"Cannot find the built page-runtime assets; run the page-runtime build\");\n}\n\nexport type RuntimeOriginOptions = PackageOriginOptions & { hostOrigin: string; assetsDir?: string };\n\n/** Serves built browser assets and local package publications on a separate loopback origin. */\nexport async function serveRuntime(options: RuntimeOriginOptions): Promise<{ origin: string; dependencies: Record<string, string>; close: () => Promise<void> }> {\n const host = new URL(options.hostOrigin);\n if (host.origin !== options.hostOrigin || ![\"http:\", \"https:\"].includes(host.protocol) || ![\"localhost\", \"127.0.0.1\", \"[::1]\"].includes(host.hostname)) throw new Error(\"Local page runtime requires an exact loopback origin\");\n const assetsDir = options.assetsDir ?? packageAssets();\n const assets = new Map(await Promise.all([\"bootstrap.html\", \"sw.js\", \"boot.js\", \"page-agent.js\", \"editing.js\", \"export-compiler.js\", \"devtools-hook.js\"].map(async (file) => [file, await readFile(resolve(assetsDir, file))] as const)));\n const packages = await createPackageHandler(options);\n const dependencies = () => Object.fromEntries(Object.entries(packages.current().packages).map(([name, entry]) => [name, entry.version]));\n let origin: string;\n const server = createServer((request, response) => {\n try {\n const path = new URL(request.url ?? \"/\", \"http://localhost\").pathname;\n if (path.startsWith(\"/_generations/\")) { void packages.handle(request, response); return; }\n if (request.method !== \"GET\" && request.method !== \"HEAD\") { response.writeHead(405).end(); return; }\n if (path === \"/profile.json\") {\n const packageOrigin = `${origin}/_generations/${packages.current().revision}`;\n const profile: RuntimeProfile = {\n runtimeDomain: new URL(origin).host, embedders: [host.origin], packageOrigin, registry: packageOrigin, managed: dependencies(),\n policy: { dependencies: \"strict\" }, minReleaseAgeDays: 0,\n network: { allow: [\"https://fonts.googleapis.com/*\", \"https://fonts.gstatic.com/*\"] },\n csp: { add: { \"style-src\": [\"https://fonts.googleapis.com\"], \"font-src\": [\"'self'\", \"data:\", \"https://fonts.gstatic.com\"] } },\n links: \"deny\", sources: [\"host\"], readinessTimeoutMs: 30000,\n };\n response.writeHead(200, { \"content-type\": \"application/json\", \"cache-control\": \"no-store\" }).end(request.method === \"HEAD\" ? undefined : JSON.stringify(profile));\n return;\n }\n const file = path.startsWith(\"/frame/\") ? \"bootstrap.html\" : path.slice(1);\n const asset = assets.get(file);\n if (!asset) { response.writeHead(404).end(\"Runtime asset not found\"); return; }\n response.writeHead(200, { \"content-type\": file.endsWith(\".html\") ? \"text/html; charset=utf-8\" : \"text/javascript; charset=utf-8\", \"cache-control\": \"no-store\", ...(file === \"sw.js\" ? { \"service-worker-allowed\": \"/frame/\" } : {}) });\n response.end(request.method === \"HEAD\" ? undefined : asset);\n } catch (error) {\n response.writeHead(500, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-store\" }).end(request.method === \"HEAD\" ? undefined : error instanceof Error ? error.message : String(error));\n }\n });\n try { await new Promise<void>((done, fail) => { server.once(\"error\", fail); server.listen(0, \"127.0.0.1\", done); }); }\n catch (error) { packages.close(); throw error; }\n origin = `http://127.0.0.1:${(server.address() as AddressInfo).port}`;\n return { origin, get dependencies() { return dependencies(); }, close: () => new Promise<void>((done, fail) => {\n packages.close();\n server.closeAllConnections();\n server.close((error) => error ? fail(error) : done());\n }) };\n}\n","import { readFile, realpath } from \"node:fs/promises\";\nimport { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport type { AddressInfo } from \"node:net\";\nimport { extname, resolve, sep } from \"node:path\";\nimport { createCatalogStore, type LocalPackage } from \"./catalog.ts\";\n\nexport { serveRuntime, type RuntimeOriginOptions } from \"./runtime-origin.ts\";\n\nexport type PackageOriginOptions = { packages: string[]; upstreamRegistry: string; upstreamOrigin: string; stateDir: string };\nexport type PackageHandler = (request: IncomingMessage, response: ServerResponse) => Promise<void>;\nexport const LOCAL_RELEASE_TIME = \"2000-01-01T00:00:00.000Z\";\n\ntype Served = { body: string | Uint8Array; type: string; status: number; cache: string };\nconst types: Record<string, string> = {\n \".js\": \"text/javascript\", \".mjs\": \"text/javascript\", \".cjs\": \"text/javascript\",\n \".json\": \"application/json\", \".map\": \"application/json\", \".css\": \"text/css\",\n \".html\": \"text/html\", \".txt\": \"text/plain\", \".md\": \"text/markdown\",\n \".svg\": \"image/svg+xml\", \".png\": \"image/png\", \".jpg\": \"image/jpeg\", \".jpeg\": \"image/jpeg\",\n \".gif\": \"image/gif\", \".webp\": \"image/webp\", \".avif\": \"image/avif\", \".ico\": \"image/x-icon\",\n \".woff\": \"font/woff\", \".woff2\": \"font/woff2\", \".ttf\": \"font/ttf\", \".otf\": \"font/otf\", \".wasm\": \"application/wasm\",\n};\nconst textResponse = (status: number, body: string): Served => ({ status, body, type: \"text/plain; charset=utf-8\", cache: \"no-store\" });\n\nfunction upstreamBase(value: string): string {\n const url = new URL(value);\n if (![\"http:\", \"https:\"].includes(url.protocol) || url.username || url.password || url.search || url.hash) throw new Error(`upstream must be an HTTP(S) URL without credentials, query or hash: ${value}`);\n return url.href.replace(/\\/$/, \"\");\n}\n\nasync function localFile(local: LocalPackage, path: string): Promise<Served> {\n if (!path || path.split(/[\\\\/]/).some((part) => part === \"..\") || path.includes(\"\\0\")) return textResponse(404, \"Invalid local package file path\");\n try {\n const file = await realpath(resolve(local.directory, path));\n if (!file.startsWith(`${local.directory}${sep}`)) return textResponse(404, \"File is outside the local package directory\");\n return { body: await readFile(file), status: 200, type: types[extname(file)] ?? \"application/octet-stream\", cache: \"no-store\" };\n } catch (error) {\n if ([\"ENOENT\", \"ENOTDIR\", \"EISDIR\"].includes((error as NodeJS.ErrnoException).code ?? \"\")) return textResponse(404, `${local.manifest.name}@${local.manifest.version}: file not found: ${path}`);\n throw error;\n }\n}\n\nasync function serveRequest(options: { url: string; method: string; locals: Map<string, LocalPackage>; registry: string; origin: string; immutable: boolean }): Promise<Served> {\n const { url, method, locals, registry, origin } = options;\n if (method === \"OPTIONS\") return textResponse(204, \"\");\n if (![\"GET\", \"HEAD\"].includes(method)) return textResponse(405, \"Only GET, HEAD and OPTIONS are supported\");\n let path: string;\n try { path = decodeURIComponent(url.split(\"?\")[0]!); }\n catch { return textResponse(400, \"Invalid URL encoding\"); }\n if (path === \"/\") return { status: 200, body: JSON.stringify({ packages: [...locals.keys()] }), type: \"application/json\", cache: \"no-store\" };\n const match = path.match(/^\\/((?:@[^/@]+\\/)?[^/@]+)(?:@([^/]+)(?:\\/(.*))?)?$/);\n if (!match) return textResponse(404, `Invalid package path: ${path}`);\n const [, name, version, file] = match;\n const local = locals.get(name!);\n if (local) {\n const manifest = local.manifest;\n if (!version) return { status: 200, body: JSON.stringify({ name, versions: { [manifest.version]: manifest }, time: { [manifest.version]: LOCAL_RELEASE_TIME }, \"dist-tags\": { latest: manifest.version } }), type: \"application/json\", cache: options.immutable ? \"public, max-age=31536000, immutable\" : \"no-store\" };\n if (version !== manifest.version) return textResponse(404, `Requested ${name}@${version}; local package is ${name}@${manifest.version}`);\n const served = await localFile(local, file ?? \"\");\n if (options.immutable && served.status === 200) served.cache = \"public, max-age=31536000, immutable\";\n return served;\n }\n const target = `${version ? origin : registry}${url}`;\n try {\n const response = await fetch(target, { method, signal: AbortSignal.timeout(30_000) });\n return { status: response.status, body: new Uint8Array(await response.arrayBuffer()), type: response.headers.get(\"content-type\") ?? \"application/octet-stream\", cache: response.headers.get(\"cache-control\") ?? \"no-store\" };\n } catch (error) {\n return textResponse(502, `Proxy ${target}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\nexport async function createPackageHandler(options: PackageOriginOptions) {\n const registry = upstreamBase(options.upstreamRegistry);\n const origin = upstreamBase(options.upstreamOrigin);\n if (!options.packages.length) throw new Error(\"At least one local package directory is required\");\n const store = await createCatalogStore(options);\n const handle: PackageHandler = async (request, response) => {\n response.setHeader(\"access-control-allow-origin\", \"*\");\n response.setHeader(\"access-control-allow-methods\", \"GET, HEAD, OPTIONS\");\n response.setHeader(\"access-control-allow-headers\", \"*\");\n try {\n const raw = request.url ?? \"/\";\n const generation = raw.match(/^\\/_generations\\/([^/]+)(\\/.*)$/);\n const selected = await store.get(generation?.[1]);\n const url = generation?.[2] ?? raw;\n const served = [\"GET\", \"HEAD\"].includes(request.method ?? \"GET\") && url.split(\"?\")[0] === \"/__catalog.json\"\n ? { status: 200, body: JSON.stringify(selected.catalog), type: \"application/json\", cache: generation ? \"public, max-age=31536000, immutable\" : \"no-store\" }\n : await serveRequest({ url, method: request.method ?? \"GET\", locals: selected.locals, registry, origin, immutable: Boolean(generation) });\n response.writeHead(served.status, {\n \"content-type\": served.type,\n \"cache-control\": served.cache,\n ...(served.status === 204 || served.status === 304 ? {} : { \"content-length\": typeof served.body === \"string\" ? Buffer.byteLength(served.body) : served.body.byteLength }),\n \"timing-allow-origin\": \"*\",\n \"access-control-expose-headers\": \"content-length, content-encoding, server-timing\",\n });\n response.end(request.method === \"HEAD\" ? undefined : served.body);\n } catch (error) {\n console.error(\"Package request failed\", error);\n response.writeHead((error as NodeJS.ErrnoException).code === \"ENOENT\" ? 404 : 500, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-store\" });\n response.end((error as NodeJS.ErrnoException).code === \"ENOENT\" ? \"Package not found\" : \"Package request failed\");\n }\n };\n return { handle, current: store.current, subscribe: store.subscribe, close: store.close };\n}\n\nexport async function servePackages(options: PackageOriginOptions & { port: number }): Promise<{ origin: string; close: () => Promise<void> }> {\n if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535) throw new Error(`Invalid port: ${options.port}`);\n const handler = await createPackageHandler(options);\n const server = createServer((request, response) => { void handler.handle(request, response); });\n await new Promise<void>((done, fail) => { server.once(\"error\", fail); server.listen(options.port, \"127.0.0.1\", done); });\n return {\n origin: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,\n close: () => new Promise<void>((done, fail) => {\n handler.close();\n server.closeAllConnections();\n server.close((error) => error ? fail(error) : done());\n }),\n };\n}\n"],"mappings":";;;;;;;;;AAUA,eAAsB,mBAAmB,SAAmD;CAC1F,MAAM,4BAAY,IAAI,IAAuC;CAC7D,MAAM,2BAAW,IAAI,IAAqB;CAC1C,MAAM,8BAAc,IAAI,IAAoB;CAC5C,KAAK,MAAM,QAAQ,QAAQ,UAAU;EACnC,MAAM,cAAc,MAAM,gBAAgB,IAAI;EAC9C,IAAI,YAAY,IAAI,YAAY,IAAI,GAAG,MAAM,IAAI,MAAM,4BAA4B,YAAY,MAAM;EACrG,YAAY,IAAI,YAAY,MAAM,IAAI;CACxC;CACA,IAAI;CACJ,IAAI;CACJ,MAAM,OAAO,YAAY;EACvB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AC;GACD,SAAS,IAAI,QAAQ,WAAW,SAAS,KAAA,IAAY,OAAO,IAAI;EAClE,SAAS,OAAO;GACd,QAAQ,MAAM,0BAA0B,KAAK;GAC7C,SAAS,UAAW,MAAgC,SAAS,WAAW,MAAM,KAAK;IAAE,gBAAgB;IAA6B,iBAAiB;GAAW,CAAC;GAC/J,SAAS,IAAK,MAAgC,SAAS,WAAW,sBAAsB,wBAAwB;EAClH;CACF;CACA,OAAO;EAAE;EAAQ,SAAS,MAAM;EAAS,WAAW,MAAM;EAAW,OAAO,MAAM;CAAM;AAC1F;AAEA,eAAsB,cAAc,SAA2G;CAC7I,IAAI,CAAC,OAAO,UAAU,QAAQ,IAAI,KAAK,QAAQ,OAAO,KAAK,QAAQ,OAAO,OAAO,MAAM,IAAI,MAAM,iBAAiB,QAAQ,MAAM;CAChI,MAAM,UAAU,MAAM,qBAAqB,OAAO;CAClD,MAAM,SAAS,cAAc,SAAS,aAAa;EAAE,QAAa,OAAO,SAAS,QAAQ;CAAG,CAAC;CAC9F,MAAM,IAAI,SAAe,MAAM,SAAS;EAAE,OAAO,KAAK,SAAS,IAAI;EAAG,OAAO,OAAO,QAAQ,MAAM,aAAa,IAAI;CAAG,CAAC;CACvH,OAAO;EACL,QAAQ,oBAAqB,OAAO,QAAQ,CAAC,CAAiB;EAC9D,aAAa,IAAI,SAAe,MAAM,SAAS;GAC7C,QAAQ,MAAM;GACd,OAAO,oBAAoB;GAC3B,OAAO,OAAO,UAAU,QAAQ,KAAK,KAAK,IAAI,KAAK,CAAC;EACtD,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { i as publishPackage, t as runPackageBuild } from "../chunks/publication-RchcQvxD.mjs";
|
|
2
|
+
// scripts/run-package-build.ts
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
if (args.length > 1 || args[0] !== void 0 && args[0] !== "--publish-only") throw new Error("Usage: run-package-build.ts [--publish-only]");
|
|
5
|
+
const publication = args[0] === "--publish-only" ? await publishPackage({ libraryDir: process.cwd() }) : await runPackageBuild({
|
|
6
|
+
libraryDir: process.cwd(),
|
|
7
|
+
command: "pnpm",
|
|
8
|
+
args: ["run", "build:artifacts"]
|
|
9
|
+
});
|
|
10
|
+
process.stdout.write(`Published ${publication.name}@${publication.version} build ${publication.build}\n`);
|
|
11
|
+
export {};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=cli.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.mjs","names":[],"sources":["../../../scripts/run-package-build.ts"],"sourcesContent":["import { runPackageBuild, publishPackage } from \"../src/publication/index.ts\";\n\nconst args = process.argv.slice(2);\nif (args.length > 1 || (args[0] !== undefined && args[0] !== \"--publish-only\")) throw new Error(\"Usage: run-package-build.ts [--publish-only]\");\nconst publication = args[0] === \"--publish-only\"\n ? await publishPackage({ libraryDir: process.cwd() })\n : await runPackageBuild({ libraryDir: process.cwd(), command: \"pnpm\", args: [\"run\", \"build:artifacts\"] });\nprocess.stdout.write(`Published ${publication.name}@${publication.version} build ${publication.build}\\n`);\n"],"mappings":";;AAEA,MAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AACjC,IAAI,KAAK,SAAS,KAAM,KAAK,OAAO,KAAA,KAAa,KAAK,OAAO,kBAAmB,MAAM,IAAI,MAAM,8CAA8C;AAC9I,MAAM,cAAc,KAAK,OAAO,mBAC5B,MAAM,eAAe,EAAE,YAAY,QAAQ,IAAI,EAAE,CAAC,IAClD,MAAM,gBAAgB;CAAE,YAAY,QAAQ,IAAI;CAAG,SAAS;CAAQ,MAAM,CAAC,OAAO,iBAAiB;AAAE,CAAC;AAC1G,QAAQ,OAAO,MAAM,aAAa,YAAY,KAAK,GAAG,YAAY,QAAQ,SAAS,YAAY,MAAM,GAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as atomicJson, r as publicationRoot, i as publishPackage, a as readPublication, t as runPackageBuild } from "./chunks/publication-RchcQvxD.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// src/styles.ts
|
|
2
|
+
/** Normal declarations: dependencies first, derived libraries next, utilities last. */
|
|
3
|
+
function cascadeOrder(layers = ["components", "facet"]) {
|
|
4
|
+
const ordered = [...new Set(layers)];
|
|
5
|
+
for (const layer of ordered) if (!/^[a-zA-Z_][\w-]*$/.test(layer) || [
|
|
6
|
+
"theme",
|
|
7
|
+
"base",
|
|
8
|
+
"utilities"
|
|
9
|
+
].includes(layer)) throw new Error(`Invalid library cascade layer: ${layer}`);
|
|
10
|
+
return `@layer theme, base, ${ordered.join(", ")}, utilities;`;
|
|
11
|
+
}
|
|
12
|
+
const layerOrder = cascadeOrder();
|
|
13
|
+
function inspectStyles(document) {
|
|
14
|
+
const view = document.defaultView;
|
|
15
|
+
if (!view) throw new Error("Style inspection requires a live document");
|
|
16
|
+
const root = view.getComputedStyle(document.documentElement);
|
|
17
|
+
const body = view.getComputedStyle(document.body);
|
|
18
|
+
const documentRoot = document.querySelector("[data-facet-theme]") ?? document.body;
|
|
19
|
+
const documentStyle = view.getComputedStyle(documentRoot);
|
|
20
|
+
const heading = document.querySelector("h2");
|
|
21
|
+
const page = documentRoot.querySelector("[data-page-size]");
|
|
22
|
+
return {
|
|
23
|
+
order: [...document.querySelectorAll("style")].map((style) => style.textContent?.match(/@layer\s+[^{};]+;/)?.[0]).find(Boolean) ?? "No explicit layer order",
|
|
24
|
+
theme: documentRoot.getAttribute("data-facet-theme") ?? "facet",
|
|
25
|
+
"--text-xl": root.getPropertyValue("--text-xl").trim(),
|
|
26
|
+
"--text-sm": root.getPropertyValue("--text-sm").trim(),
|
|
27
|
+
...Object.fromEntries([.../* @__PURE__ */ new Set([...Array.from(root), ...Array.from(documentStyle)])].filter((name) => /^--(?:facet|text)-/.test(name)).map((name) => [name, (documentStyle.getPropertyValue(name) || root.getPropertyValue(name)).trim()])),
|
|
28
|
+
"body font size": body.fontSize,
|
|
29
|
+
"document font size": documentStyle.fontSize,
|
|
30
|
+
"document font family": documentStyle.fontFamily,
|
|
31
|
+
"document line height": documentStyle.lineHeight,
|
|
32
|
+
"document text color": documentStyle.color,
|
|
33
|
+
"document background": documentStyle.backgroundColor === "rgba(0, 0, 0, 0)" ? body.backgroundColor : documentStyle.backgroundColor,
|
|
34
|
+
"heading font size": heading ? view.getComputedStyle(heading).fontSize : "No h2",
|
|
35
|
+
...page ? {
|
|
36
|
+
"page size": page.getAttribute("data-page-size") ?? "",
|
|
37
|
+
...Object.fromEntries([
|
|
38
|
+
"top",
|
|
39
|
+
"right",
|
|
40
|
+
"bottom",
|
|
41
|
+
"left"
|
|
42
|
+
].map((side) => [`page margin ${side}`, page.getAttribute(`data-margin-${side}`) ?? ""]))
|
|
43
|
+
} : {},
|
|
44
|
+
stylesheets: [...document.querySelectorAll("[data-page-runtime-base]")].map((style) => style.getAttribute("data-page-runtime-base")).join("\n")
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export { cascadeOrder, inspectStyles, layerOrder };
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=styles.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.mjs","names":[],"sources":["../../src/styles.ts"],"sourcesContent":["/** Normal declarations: dependencies first, derived libraries next, utilities last. */\nexport function cascadeOrder(layers: string[] = ['components', 'facet']): string {\n const ordered = [...new Set(layers)];\n for (const layer of ordered) if (!/^[a-zA-Z_][\\w-]*$/.test(layer) || ['theme', 'base', 'utilities'].includes(layer)) throw new Error(`Invalid library cascade layer: ${layer}`);\n return `@layer theme, base, ${ordered.join(', ')}, utilities;`;\n}\n\nexport const layerOrder = cascadeOrder();\n\nexport function inspectStyles(document: Document): Record<string, string> {\n const view = document.defaultView;\n if (!view) throw new Error('Style inspection requires a live document');\n const root = view.getComputedStyle(document.documentElement);\n const body = view.getComputedStyle(document.body);\n const documentRoot = document.querySelector('[data-facet-theme]') ?? document.body;\n const documentStyle = view.getComputedStyle(documentRoot);\n const heading = document.querySelector('h2');\n const page = documentRoot.querySelector('[data-page-size]');\n return {\n order: [...document.querySelectorAll('style')].map(style => style.textContent?.match(/@layer\\s+[^{};]+;/)?.[0]).find(Boolean) ?? 'No explicit layer order',\n theme: documentRoot.getAttribute('data-facet-theme') ?? 'facet',\n '--text-xl': root.getPropertyValue('--text-xl').trim(),\n '--text-sm': root.getPropertyValue('--text-sm').trim(),\n ...Object.fromEntries([...new Set([...Array.from(root), ...Array.from(documentStyle)])]\n .filter(name => /^--(?:facet|text)-/.test(name))\n .map(name => [name, (documentStyle.getPropertyValue(name) || root.getPropertyValue(name)).trim()])),\n 'body font size': body.fontSize,\n 'document font size': documentStyle.fontSize,\n 'document font family': documentStyle.fontFamily,\n 'document line height': documentStyle.lineHeight,\n 'document text color': documentStyle.color,\n 'document background': documentStyle.backgroundColor === 'rgba(0, 0, 0, 0)' ? body.backgroundColor : documentStyle.backgroundColor,\n 'heading font size': heading ? view.getComputedStyle(heading).fontSize : 'No h2',\n ...(page ? {\n 'page size': page.getAttribute('data-page-size') ?? '',\n ...Object.fromEntries(['top', 'right', 'bottom', 'left'].map(side => [`page margin ${side}`, page.getAttribute(`data-margin-${side}`) ?? ''])),\n } : {}),\n stylesheets: [...document.querySelectorAll('[data-page-runtime-base]')].map(style => style.getAttribute('data-page-runtime-base')).join('\\n'),\n };\n}\n"],"mappings":";;AACA,SAAgB,aAAa,SAAmB,CAAC,cAAc,OAAO,GAAW;CAC/E,MAAM,UAAU,CAAC,GAAG,IAAI,IAAI,MAAM,CAAC;CACnC,KAAK,MAAM,SAAS,SAAS,IAAI,CAAC,oBAAoB,KAAK,KAAK,KAAK;EAAC;EAAS;EAAQ;CAAW,CAAC,CAAC,SAAS,KAAK,GAAG,MAAM,IAAI,MAAM,kCAAkC,OAAO;CAC9K,OAAO,uBAAuB,QAAQ,KAAK,IAAI,EAAE;AACnD;AAEA,MAAa,aAAa,aAAa;AAEv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