@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
package/package.json
CHANGED
|
@@ -1,6 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flanksource/page-runtime",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Browser-mode page runtime for facet and clicky-ui pages: library runtime sets, the module service worker and the page frame.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/flanksource/clicky-ui.git",
|
|
10
|
+
"directory": "packages/page-runtime"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"scripts",
|
|
18
|
+
"static",
|
|
19
|
+
"dist",
|
|
20
|
+
"!**/*.test.ts",
|
|
21
|
+
"!**/*.test.tsx"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
"./styles": {
|
|
25
|
+
"types": "./src/styles.ts",
|
|
26
|
+
"default": "./dist/node/styles.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./editing": "./src/editing.ts",
|
|
29
|
+
"./build": {
|
|
30
|
+
"types": "./src/build/index.ts",
|
|
31
|
+
"default": "./dist/build/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./build/dependencies": {
|
|
34
|
+
"types": "./src/build/dependencies.ts",
|
|
35
|
+
"default": "./dist/build/dependencies.mjs"
|
|
36
|
+
},
|
|
37
|
+
"./sw": "./src/sw/index.ts",
|
|
38
|
+
"./frame": "./src/frame/index.ts",
|
|
39
|
+
"./frame/agent": "./src/frame/agent.ts",
|
|
40
|
+
"./form": "./src/form/index.ts",
|
|
41
|
+
"./host": "./src/host/index.ts",
|
|
42
|
+
"./host/link": "./src/host/link/index.ts",
|
|
43
|
+
"./dev": {
|
|
44
|
+
"types": "./src/dev/index.ts",
|
|
45
|
+
"default": "./dist/node/dev.mjs"
|
|
46
|
+
},
|
|
47
|
+
"./publication": {
|
|
48
|
+
"types": "./src/publication/index.ts",
|
|
49
|
+
"default": "./dist/node/publication.mjs"
|
|
50
|
+
},
|
|
51
|
+
"./catalog": {
|
|
52
|
+
"types": "./src/publication/schema.ts",
|
|
53
|
+
"default": "./dist/node/catalog.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./publication/cli": {
|
|
56
|
+
"types": "./scripts/run-package-build.ts",
|
|
57
|
+
"default": "./dist/node/publication/cli.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./link": "./src/link/index.ts",
|
|
60
|
+
"./link/build": "./src/link/build.ts",
|
|
61
|
+
"./schema": {
|
|
62
|
+
"types": "./src/schema.ts",
|
|
63
|
+
"default": "./dist/node/schema.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./markers": "./src/markers.ts",
|
|
66
|
+
"./static/*": "./dist/static/*"
|
|
67
|
+
},
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@mdx-js/mdx": "^3.1.1",
|
|
70
|
+
"autoprefixer": "^10.4.20",
|
|
71
|
+
"bippy": "0.6.1",
|
|
72
|
+
"es-module-lexer": "^3.0.0",
|
|
73
|
+
"postcss": "^8.4.49",
|
|
74
|
+
"rehype-raw": "^7.0.0",
|
|
75
|
+
"remark-frontmatter": "^5.0.0",
|
|
76
|
+
"remark-gfm": "^4.0.0",
|
|
77
|
+
"remark-github-blockquote-alert": "^2.1.0",
|
|
78
|
+
"rolldown": "~1.2.14",
|
|
79
|
+
"sucrase": "^3.35.1",
|
|
80
|
+
"tailwindcss": "^4.3.3"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@flanksource/clicky-ui": "^0.3.66",
|
|
84
|
+
"react": "^18.3.1 || ^19.0.0",
|
|
85
|
+
"react-dom": "^18.3.1 || ^19.0.0"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@flanksource/facet": "0.1.74",
|
|
89
|
+
"@playwright/test": "^1.49.1",
|
|
90
|
+
"@tailwindcss/node": "^4.3.3",
|
|
91
|
+
"@tailwindcss/oxide": "^4.3.3",
|
|
92
|
+
"@types/node": "^24",
|
|
93
|
+
"@types/react": "19.2.17",
|
|
94
|
+
"@types/react-dom": "19.2.3",
|
|
95
|
+
"fake-indexeddb": "^6.0.1",
|
|
96
|
+
"react": "^18.3.1",
|
|
97
|
+
"react-dom": "^18.3.1",
|
|
98
|
+
"tsx": "^4.7.0",
|
|
99
|
+
"typescript": "^5.7.2",
|
|
100
|
+
"vitest": "^5.0.5",
|
|
101
|
+
"@flanksource/clicky-ui": "0.3.73"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"build": "tsx scripts/build.ts",
|
|
105
|
+
"build:builder": "tsx scripts/build-builder.ts",
|
|
106
|
+
"serve-packages": "tsx scripts/serve-packages.ts",
|
|
107
|
+
"check-fragment": "tsx scripts/check-fragment.ts",
|
|
108
|
+
"test": "vitest run",
|
|
109
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
110
|
+
"lint": "oxlint src scripts --deny-warnings",
|
|
111
|
+
"check": "tsc -p tsconfig.json --noEmit && pnpm run lint"
|
|
112
|
+
}
|
|
6
113
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { build } from "rolldown";
|
|
5
|
+
import ts from "typescript";
|
|
6
|
+
|
|
7
|
+
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
8
|
+
const manifest = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")) as { dependencies: Record<string, string>; peerDependencies: Record<string, string> };
|
|
9
|
+
const packages = Object.keys({ ...manifest.dependencies, ...manifest.peerDependencies });
|
|
10
|
+
await rm(resolve(root, "dist/build"), { recursive: true, force: true });
|
|
11
|
+
await mkdir(resolve(root, "dist/build"), { recursive: true });
|
|
12
|
+
await build({
|
|
13
|
+
input: { index: resolve(root, "src/build/index.ts"), dependencies: resolve(root, "src/build/dependencies.ts") },
|
|
14
|
+
platform: "node",
|
|
15
|
+
external: source => source.startsWith("node:") || packages.some(name => source === name || source.startsWith(`${name}/`)),
|
|
16
|
+
output: { dir: resolve(root, "dist/build"), format: "esm", entryFileNames: "[name].mjs", chunkFileNames: "[name]-[hash].mjs", sourcemap: true },
|
|
17
|
+
});
|
|
18
|
+
await cp(resolve(root, "src/build/cjs-export-names.mjs"), resolve(root, "dist/build/cjs-export-names.mjs"));
|
|
19
|
+
await cp(resolve(root, "src/build/README.md"), resolve(root, "dist/build/README.md"));
|
|
20
|
+
const declarations = ts.createProgram([resolve(root, "src/build/index.ts"), resolve(root, "src/build/dependencies.ts")], {
|
|
21
|
+
declaration: true, emitDeclarationOnly: true, allowImportingTsExtensions: true, outDir: resolve(root, "dist/build/types"), rootDir: resolve(root, "src"),
|
|
22
|
+
target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, skipLibCheck: true, esModuleInterop: true, strict: true,
|
|
23
|
+
});
|
|
24
|
+
const diagnostics = ts.getPreEmitDiagnostics(declarations);
|
|
25
|
+
if (diagnostics.length) throw new Error(ts.formatDiagnosticsWithColorAndContext(diagnostics, { getCurrentDirectory: () => root, getCanonicalFileName: path => path, getNewLine: () => "\n" }));
|
|
26
|
+
declarations.emit();
|
|
27
|
+
await writeFile(resolve(root, "dist/build/package.json"), await readFile(resolve(root, "builder-package.json"), "utf8"));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { buildLibraryRuntime, type Fragment } from "../src/build/index.ts";
|
|
4
|
+
|
|
5
|
+
const [libraryDir, basePath, ...extra] = process.argv.slice(2);
|
|
6
|
+
if (!libraryDir || extra.length) throw new Error("usage: build-library-runtime.ts <libraryDir> [base-fragment.json]");
|
|
7
|
+
const base = basePath ? JSON.parse(await readFile(resolve(basePath), "utf8")) as Fragment : undefined;
|
|
8
|
+
const result = await buildLibraryRuntime({ libraryDir: resolve(libraryDir), outDir: resolve(libraryDir, "dist/runtime"), ...(base ? { base } : {}) });
|
|
9
|
+
console.log(`${result.fragment.name}: runtime built (${Object.keys(result.fragment.integrity).length} files)`);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readFile, rm } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { build } from "rolldown";
|
|
5
|
+
|
|
6
|
+
// Node refuses to strip TypeScript under node_modules, so the published package (publishConfig.exports) points
|
|
7
|
+
// these Node-side entries at compiled modules; the workspace keeps importing the sources.
|
|
8
|
+
export const NODE_ENTRIES = {
|
|
9
|
+
styles: "src/styles.ts",
|
|
10
|
+
schema: "src/schema.ts",
|
|
11
|
+
catalog: "src/publication/schema.ts",
|
|
12
|
+
publication: "src/publication/index.ts",
|
|
13
|
+
"publication/cli": "scripts/run-package-build.ts",
|
|
14
|
+
dev: "src/dev/index.ts",
|
|
15
|
+
} as const;
|
|
16
|
+
|
|
17
|
+
const root = fileURLToPath(new URL("../", import.meta.url));
|
|
18
|
+
const manifest = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")) as { dependencies: Record<string, string>; peerDependencies: Record<string, string> };
|
|
19
|
+
const packages = Object.keys({ ...manifest.dependencies, ...manifest.peerDependencies });
|
|
20
|
+
await rm(resolve(root, "dist/node"), { recursive: true, force: true });
|
|
21
|
+
await build({
|
|
22
|
+
input: Object.fromEntries(Object.entries(NODE_ENTRIES).map(([name, path]) => [name, resolve(root, path)])),
|
|
23
|
+
platform: "node",
|
|
24
|
+
external: source => source.startsWith("node:") || packages.some(name => source === name || source.startsWith(`${name}/`)),
|
|
25
|
+
output: { dir: resolve(root, "dist/node"), format: "esm", entryFileNames: "[name].mjs", chunkFileNames: "chunks/[name]-[hash].mjs", sourcemap: true },
|
|
26
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { build, type Plugin } from "rolldown";
|
|
5
|
+
import { frameDocument } from "../src/sw/router.ts";
|
|
6
|
+
import { EXPORT_COMPILER_URL } from "../src/sw/runtime-module.ts";
|
|
7
|
+
import { findLocalWorkspaces, localWorkspacesPlugin } from "./local-workspaces.ts";
|
|
8
|
+
import { reactExternals } from "./react-externals.ts";
|
|
9
|
+
|
|
10
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
11
|
+
const workspaceRoot = resolve(root, "../..");
|
|
12
|
+
/** `dev`: bundle `@flanksource/*` dependencies from sibling checkouts of this workspace instead of the installed releases. */
|
|
13
|
+
export type BuildStaticOptions = { outDir?: string; version?: string; dev?: boolean };
|
|
14
|
+
/** Rolldown only warns on an unresolved import and leaves a guessed global behind; a runtime bundle must fail instead. */
|
|
15
|
+
const failOnUnresolved = { onLog(level: "info" | "debug" | "warn", log: { code?: string; message: string }, handler: (level: "info" | "debug" | "warn" | "error", log: { code?: string; message: string }) => void) { if (log.code === "UNRESOLVED_IMPORT") throw new Error(`build-static: ${log.message}; publish the missing export or build with --dev against a local checkout`); handler(level, log); } };
|
|
16
|
+
type Manifest = { version: string; dependencies?: Record<string, string>; devDependencies?: Record<string, string> };
|
|
17
|
+
|
|
18
|
+
/** The local checkouts `--dev` uses: every `@flanksource/*` dependency not already provided by this workspace. */
|
|
19
|
+
async function devPlugins(pkg: Manifest): Promise<Plugin[]> {
|
|
20
|
+
const external = Object.entries({ ...pkg.dependencies, ...pkg.devDependencies }).filter(([name, range]) => name.startsWith("@flanksource/") && !range.startsWith("workspace:")).map(([name]) => name);
|
|
21
|
+
const workspaces = findLocalWorkspaces({ workspaceRoot, names: external });
|
|
22
|
+
for (const name of external) console.log(workspaces.has(name) ? `--dev: ${name} → ${workspaces.get(name)}` : `--dev: ${name} has no local checkout; using the installed release`);
|
|
23
|
+
return [localWorkspacesPlugin(workspaces)];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function buildStatic(options: BuildStaticOptions = {}): Promise<void> {
|
|
27
|
+
const outDir = options.outDir ?? resolve(root, "dist/static");
|
|
28
|
+
const pkg = JSON.parse(await readFile(resolve(root, "package.json"), "utf8")) as Manifest;
|
|
29
|
+
const plugins = options.dev ? await devPlugins(pkg) : [];
|
|
30
|
+
await mkdir(outDir, { recursive: true });
|
|
31
|
+
await build({
|
|
32
|
+
...failOnUnresolved,
|
|
33
|
+
input: resolve(root, "src/sw/worker.ts"),
|
|
34
|
+
plugins,
|
|
35
|
+
resolve: { conditionNames: ["worker", "browser", "import", "default"] },
|
|
36
|
+
platform: "browser",
|
|
37
|
+
transform: { define: { __RUNTIME_VERSION__: JSON.stringify(options.version ?? pkg.version), "process.env.NODE_ENV": JSON.stringify("development"), "process.env": "{}" } },
|
|
38
|
+
output: { file: resolve(outDir, "sw.js"), format: "iife", sourcemap: true, codeSplitting: false },
|
|
39
|
+
});
|
|
40
|
+
await build({
|
|
41
|
+
...failOnUnresolved,
|
|
42
|
+
input: resolve(root, "src/frame/entry.ts"),
|
|
43
|
+
plugins: [...plugins, reactExternals()],
|
|
44
|
+
external: ["./page-agent.js", EXPORT_COMPILER_URL],
|
|
45
|
+
platform: "browser",
|
|
46
|
+
transform: { define: { "process.env.NODE_ENV": JSON.stringify("development") } },
|
|
47
|
+
output: { file: resolve(outDir, "boot.js"), format: "es", sourcemap: true, codeSplitting: false },
|
|
48
|
+
});
|
|
49
|
+
await build({
|
|
50
|
+
...failOnUnresolved,
|
|
51
|
+
input: resolve(root, "src/frame/page-agent.ts"),
|
|
52
|
+
plugins: [...plugins, reactExternals()],
|
|
53
|
+
external: ["/__runtime/editing.js", "@flanksource/clicky-ui/comments"],
|
|
54
|
+
platform: "browser",
|
|
55
|
+
transform: { jsx: { runtime: "automatic", development: true }, define: { "process.env.NODE_ENV": JSON.stringify("development") } },
|
|
56
|
+
output: { file: resolve(outDir, "page-agent.js"), format: "es", sourcemap: true, codeSplitting: false },
|
|
57
|
+
});
|
|
58
|
+
await build({
|
|
59
|
+
...failOnUnresolved,
|
|
60
|
+
input: resolve(root, "src/frame/export-compiler.ts"),
|
|
61
|
+
// The frame's CSP has no 'wasm-unsafe-eval', so the export compiler uses the lexer's asm.js build; the worker keeps WASM.
|
|
62
|
+
plugins: [...plugins, { name: "es-module-lexer-asm", resolveId(id, importer, extra) { return id === "es-module-lexer" ? this.resolve("es-module-lexer/js", importer, { ...extra, skipSelf: true }) : null; } }],
|
|
63
|
+
platform: "browser",
|
|
64
|
+
transform: { define: { "process.env.NODE_ENV": JSON.stringify("development"), "process.env": "{}" } },
|
|
65
|
+
output: { file: resolve(outDir, "export-compiler.js"), format: "es", sourcemap: true, codeSplitting: false },
|
|
66
|
+
});
|
|
67
|
+
await build({ ...failOnUnresolved, input: resolve(root, "src/frame/devtools-hook.ts"), plugins, platform: "browser", transform: { define: { "process.env.NODE_ENV": JSON.stringify("development") } }, output: { file: resolve(outDir, "devtools-hook.js"), format: "iife" } });
|
|
68
|
+
await writeFile(resolve(outDir, "bootstrap.html"), frameDocument().html);
|
|
69
|
+
await build({
|
|
70
|
+
...failOnUnresolved,
|
|
71
|
+
input: resolve(root, "src/frame/document-entry.ts"),
|
|
72
|
+
plugins,
|
|
73
|
+
platform: "browser",
|
|
74
|
+
transform: { define: { "process.env.NODE_ENV": JSON.stringify("development"), "process.env": "{}" } },
|
|
75
|
+
output: { file: resolve(outDir, "document.js"), name: "FacetDocumentRuntime", format: "iife", minify: true },
|
|
76
|
+
});
|
|
77
|
+
await build({ ...failOnUnresolved, input: resolve(root, "src/frame/document-mount.ts"), platform: "browser",
|
|
78
|
+
output: { file: resolve(outDir, "document-bundle.js"), name: "FacetDocumentRuntime", format: "iife", minify: true } });
|
|
79
|
+
await build({ input: resolve(root, "src/editing.ts"), external: ["react"], platform: "browser", output: { file: resolve(outDir, "editing.js"), format: "es" } });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
83
|
+
const unknown = process.argv.slice(2).filter(arg => arg !== "--dev");
|
|
84
|
+
if (unknown.length) throw new Error(`build-static: unknown arguments ${unknown.join(" ")}; the only flag is --dev`);
|
|
85
|
+
await buildStatic({ dev: process.argv.includes("--dev") });
|
|
86
|
+
}
|
package/scripts/build.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import "./build-builder.ts";
|
|
2
|
+
import "./build-node.ts";
|
|
3
|
+
import { buildStatic } from "./build-static.ts";
|
|
4
|
+
|
|
5
|
+
const unknown = process.argv.slice(2).filter(arg => arg !== "--dev");
|
|
6
|
+
if (unknown.length) throw new Error(`Unknown build arguments ${unknown.join(" ")}; the only flag is --dev`);
|
|
7
|
+
await buildStatic({ dev: process.argv.includes("--dev") });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { checkFragment, type Fragment } from "../src/build/index.ts";
|
|
4
|
+
|
|
5
|
+
const [libraryDir, basePath, ...extra] = process.argv.slice(2);
|
|
6
|
+
if (!libraryDir || extra.length) throw new Error("usage: check-fragment.ts <libraryDir> [base-fragment.json]");
|
|
7
|
+
const base = basePath ? JSON.parse(await readFile(resolve(basePath), "utf8")) as Fragment : undefined;
|
|
8
|
+
const failures = await checkFragment({ libraryDir: resolve(libraryDir), ...(base ? { base } : {}) });
|
|
9
|
+
if (failures.length) {
|
|
10
|
+
console.error(failures.join("\n"));
|
|
11
|
+
process.exitCode = 1;
|
|
12
|
+
} else console.log(`${libraryDir}: fragment checks passed`);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
import type { Plugin } from "rolldown";
|
|
4
|
+
|
|
5
|
+
const packageName = (specifier: string) => specifier.startsWith("@") ? specifier.split("/").slice(0, 2).join("/") : specifier.split("/")[0]!;
|
|
6
|
+
|
|
7
|
+
function manifestName(dir: string): string | undefined {
|
|
8
|
+
const file = join(dir, "package.json");
|
|
9
|
+
if (!existsSync(file)) return undefined;
|
|
10
|
+
return (JSON.parse(readFileSync(file, "utf8")) as { name?: string }).name;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function workspaceDirs(checkout: string): string[] {
|
|
14
|
+
const packages = join(checkout, "packages");
|
|
15
|
+
const nested = existsSync(packages) && statSync(packages).isDirectory() ? readdirSync(packages).map(name => join(packages, name)) : [];
|
|
16
|
+
return [checkout, ...nested];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Finds sibling checkouts of `workspaceRoot` (and their `packages/*`) that declare one of `names`. When several
|
|
21
|
+
* checkouts declare a package (worktrees), the directory named after the package wins; otherwise it fails loudly.
|
|
22
|
+
*/
|
|
23
|
+
export function findLocalWorkspaces(options: { workspaceRoot: string; names: string[] }): Map<string, string> {
|
|
24
|
+
const wanted = new Set(options.names);
|
|
25
|
+
const found = new Map<string, string[]>();
|
|
26
|
+
for (const entry of readdirSync(dirname(options.workspaceRoot))) {
|
|
27
|
+
const checkout = join(dirname(options.workspaceRoot), entry);
|
|
28
|
+
// existsSync is false for a dangling symlink, which is not a checkout.
|
|
29
|
+
if (checkout === options.workspaceRoot || !existsSync(checkout) || !statSync(checkout).isDirectory()) continue;
|
|
30
|
+
for (const dir of workspaceDirs(checkout)) {
|
|
31
|
+
const name = manifestName(dir);
|
|
32
|
+
if (name && wanted.has(name)) found.set(name, [...(found.get(name) ?? []), dir]);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new Map([...found].map(([name, dirs]) => {
|
|
36
|
+
if (dirs.length === 1) return [name, dirs[0]!];
|
|
37
|
+
const canonical = dirs.filter(dir => basename(dir) === name.split("/").at(-1));
|
|
38
|
+
if (canonical.length !== 1) throw new Error(`${name}: several local checkouts declare it (${dirs.join(", ")}); keep one named ${name.split("/").at(-1)}`);
|
|
39
|
+
return [name, canonical[0]!];
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Resolves imports of each local package from its checkout, through the checkout's own package.json exports. */
|
|
44
|
+
export function localWorkspacesPlugin(workspaces: Map<string, string>): Plugin {
|
|
45
|
+
return {
|
|
46
|
+
name: "page-runtime-local-workspaces",
|
|
47
|
+
async resolveId(id, _importer, extra) {
|
|
48
|
+
const dir = id.startsWith(".") || id.startsWith("/") ? undefined : workspaces.get(packageName(id));
|
|
49
|
+
if (!dir) return null;
|
|
50
|
+
const resolved = await this.resolve(id, join(dir, "package.json"), { ...extra, skipSelf: true });
|
|
51
|
+
if (!resolved) throw new Error(`${id}: not exported by the local checkout ${dir}`);
|
|
52
|
+
return resolved;
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from "rolldown";
|
|
2
|
+
|
|
3
|
+
export function reactExternals(): Plugin {
|
|
4
|
+
const prefix = "\0page-runtime-react:";
|
|
5
|
+
return {
|
|
6
|
+
name: "page-runtime-react-externals",
|
|
7
|
+
resolveId(source, importer, { kind }) {
|
|
8
|
+
if (source.startsWith(prefix)) return source;
|
|
9
|
+
if (!/^react(?:-dom)?(?:\/|$)/.test(source)) return null;
|
|
10
|
+
if (kind === "require-call" && !importer?.startsWith(prefix)) return prefix + source;
|
|
11
|
+
return { id: source, external: true };
|
|
12
|
+
},
|
|
13
|
+
load(id) {
|
|
14
|
+
if (!id.startsWith(prefix)) return null;
|
|
15
|
+
return `import value from ${JSON.stringify(id.slice(prefix.length))}; module.exports = value;`;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { appendFileSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import { compareVersions } from "../src/sw/versions.ts";
|
|
6
|
+
|
|
7
|
+
export function nextReleaseVersion({ current, published }: { current: string; published: string[] }): string {
|
|
8
|
+
if (!/^\d+\.\d+\.\d+$/.test(current)) throw new Error(`Invalid stable release version ${current}`);
|
|
9
|
+
for (const version of [current, ...published]) compareVersions(version, version);
|
|
10
|
+
const latest = published.filter(version => /^\d+\.\d+\.\d+$/.test(version)).sort(compareVersions).at(-1);
|
|
11
|
+
// A manifest ahead of the registry (a deliberate minor/major bump) wins over a patch increment.
|
|
12
|
+
if (!latest || compareVersions(current, latest) > 0) return current;
|
|
13
|
+
const [major, minor, patch] = latest.split(".").map(Number);
|
|
14
|
+
return `${major}.${minor}.${patch! + 1}`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readPublishedVersions(result: { status: number | null; stdout: string; stderr: string }): string[] {
|
|
18
|
+
const response = JSON.parse(result.stdout) as string | string[] | { error?: { code?: string } };
|
|
19
|
+
if (result.status !== 0) {
|
|
20
|
+
if (typeof response === "object" && !Array.isArray(response) && response?.error?.code === "E404") return [];
|
|
21
|
+
throw new Error(`npm version lookup failed (${result.status}): ${result.stderr}`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof response === "string") return [response];
|
|
24
|
+
if (Array.isArray(response) && response.every(version => typeof version === "string")) return response;
|
|
25
|
+
throw new Error("npm version lookup must return a version or an array of versions");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function prepareRelease(options: { manifestPath: string; tagPrefix: string; published: string[] }): { version: string; tag: string } {
|
|
29
|
+
if (!/^[a-z0-9][a-z0-9._-]*$/.test(options.tagPrefix)) throw new Error(`Invalid release tag prefix ${options.tagPrefix}`);
|
|
30
|
+
const manifest = JSON.parse(readFileSync(options.manifestPath, "utf8")) as { name: string; version: string };
|
|
31
|
+
if (!manifest.name) throw new Error(`${options.manifestPath} must declare a package name`);
|
|
32
|
+
const version = nextReleaseVersion({ current: manifest.version, published: options.published });
|
|
33
|
+
writeFileSync(options.manifestPath, `${JSON.stringify({ ...manifest, version }, null, 2)}\n`);
|
|
34
|
+
return { version, tag: `${options.tagPrefix}@${version}` };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (process.argv[1] && pathToFileURL(resolve(process.argv[1])).href === import.meta.url) {
|
|
38
|
+
const [manifestPath, tagPrefix] = process.argv.slice(2);
|
|
39
|
+
const output = process.env.GITHUB_OUTPUT;
|
|
40
|
+
if (!manifestPath || !tagPrefix || !output) throw new Error("Usage: release-version.ts <manifest> <tag-prefix>, with GITHUB_OUTPUT set by CI");
|
|
41
|
+
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as { name: string };
|
|
42
|
+
if (!manifest.name) throw new Error(`${manifestPath} must declare a package name`);
|
|
43
|
+
const lookup = spawnSync("npm", ["view", manifest.name, "versions", "--json"], { encoding: "utf8" });
|
|
44
|
+
if (lookup.error) throw lookup.error;
|
|
45
|
+
const release = prepareRelease({ manifestPath, tagPrefix, published: readPublishedVersions(lookup) });
|
|
46
|
+
appendFileSync(output, `version=${release.version}\ntag=${release.tag}\n`);
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { runPackageBuild, publishPackage } from "../src/publication/index.ts";
|
|
2
|
+
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
if (args.length > 1 || (args[0] !== undefined && args[0] !== "--publish-only")) throw new Error("Usage: run-package-build.ts [--publish-only]");
|
|
5
|
+
const publication = args[0] === "--publish-only"
|
|
6
|
+
? await publishPackage({ libraryDir: process.cwd() })
|
|
7
|
+
: await runPackageBuild({ libraryDir: process.cwd(), command: "pnpm", args: ["run", "build:artifacts"] });
|
|
8
|
+
process.stdout.write(`Published ${publication.name}@${publication.version} build ${publication.build}\n`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { parsePackageArguments } from "../src/dev/cli.ts";
|
|
2
|
+
import { servePackages } from "../src/dev/index.ts";
|
|
3
|
+
|
|
4
|
+
const local = await servePackages(parsePackageArguments(process.argv.slice(2)));
|
|
5
|
+
process.stdout.write(`Local package registry and origin: ${local.origin}\n`);
|
|
6
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => {
|
|
7
|
+
void local.close().catch((error: unknown) => { process.stderr.write(`${String(error)}\n`); process.exitCode = 1; });
|
|
8
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { RuntimePhase } from "./schema.ts";
|
|
2
|
+
import { keys, record } from "./sw/profile.ts";
|
|
3
|
+
|
|
4
|
+
export type WorkerActivity = {
|
|
5
|
+
id: string; kind: "frame" | "src" | "npm" | "link" | "static"; url: string;
|
|
6
|
+
package: { name: string; version: string; path: string } | null;
|
|
7
|
+
source: "cache" | "network" | "compiled" | "generated";
|
|
8
|
+
cache: "storage" | "memory" | "miss"; origin: string | null; generated: string | null;
|
|
9
|
+
transferredBytes: number | null; decodedBytes: number | null; outputBytes: number | null;
|
|
10
|
+
startedAt: number; fetchMs: number; integrityMs: number; compileMs: number; rewriteMs: number; totalMs: number;
|
|
11
|
+
status: number; contentType: string; headers: Record<string, string>;
|
|
12
|
+
unavailable: Array<"fetch" | "integrity" | "compile" | "rewrite" | "cache-layer">;
|
|
13
|
+
error: { phase: RuntimePhase; message: string } | null;
|
|
14
|
+
};
|
|
15
|
+
export type TailwindActivity = { kind: "libraries" | "candidates"; startMs: number; durationMs: number; candidates: number; cssBytes: number; cacheHit: boolean };
|
|
16
|
+
export type RuntimeResolution = { versions: Record<string, string>; base: Record<string, string>; managed: string[]; importMapBytes: number; scopes: number };
|
|
17
|
+
export type ActivityMessage = { type: "activity"; load: string; navigationStart: number; records: WorkerActivity[]; timeline: Array<{ phase: string; atMs: number }>; tailwind: TailwindActivity[]; runtime?: RuntimeResolution; styles?: Record<string, string> };
|
|
18
|
+
|
|
19
|
+
export function validateActivity(value: unknown): ActivityMessage {
|
|
20
|
+
const m = record(value, "activity");
|
|
21
|
+
keys(m, ["type", "load", "navigationStart", "records", "timeline", "tailwind", "runtime", "styles"], "activity");
|
|
22
|
+
if (m.styles !== undefined) for (const [name, value] of Object.entries(record(m.styles, 'styles'))) { string(name, 128); string(value, 65536, true); }
|
|
23
|
+
if (m.type !== "activity") throw new Error("activity.type: expected activity");
|
|
24
|
+
string(m.load, 256); number(m.navigationStart);
|
|
25
|
+
for (const item of array(m.records, 32)) validateRequest(item);
|
|
26
|
+
for (const item of array(m.timeline, 64)) {
|
|
27
|
+
const mark = record(item, "timeline"); keys(mark, ["phase", "atMs"], "timeline");
|
|
28
|
+
string(mark.phase, 64); number(mark.atMs);
|
|
29
|
+
}
|
|
30
|
+
for (const item of array(m.tailwind, 32)) {
|
|
31
|
+
const build = record(item, "tailwind"); keys(build, ["kind", "startMs", "durationMs", "candidates", "cssBytes", "cacheHit"], "tailwind");
|
|
32
|
+
choice(build.kind, ["libraries", "candidates"]); number(build.startMs); number(build.durationMs);
|
|
33
|
+
number(build.candidates, true); number(build.cssBytes, true);
|
|
34
|
+
if (typeof build.cacheHit !== "boolean") throw new Error("tailwind.cacheHit: expected boolean");
|
|
35
|
+
}
|
|
36
|
+
if (m.runtime !== undefined) validateResolution(m.runtime);
|
|
37
|
+
return m as ActivityMessage;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const ACTIVITY_HEADERS = ["content-type", "content-length", "content-encoding", "cache-control", "etag", "last-modified", "age", "expires", "vary", "server-timing", "x-page-integrity", "x-page-runtime-error", "x-link-compiled", "x-link-cache"];
|
|
41
|
+
|
|
42
|
+
function validateRequest(value: unknown): void {
|
|
43
|
+
const r = record(value, "request");
|
|
44
|
+
keys(r, ["id", "kind", "url", "package", "source", "cache", "origin", "generated", "transferredBytes", "decodedBytes", "outputBytes", "startedAt", "fetchMs", "integrityMs", "compileMs", "rewriteMs", "totalMs", "status", "contentType", "headers", "unavailable", "error"], "request");
|
|
45
|
+
string(r.id, 256); url(r.url); choice(r.kind, ["frame", "src", "npm", "link", "static"]);
|
|
46
|
+
choice(r.source, ["cache", "network", "compiled", "generated"]); choice(r.cache, ["storage", "memory", "miss"]);
|
|
47
|
+
if (r.origin !== null) url(r.origin);
|
|
48
|
+
if (r.generated !== null) string(r.generated, 64);
|
|
49
|
+
for (const field of ["transferredBytes", "decodedBytes", "outputBytes"]) if (r[field] !== null) number(r[field], true);
|
|
50
|
+
for (const field of ["startedAt", "fetchMs", "integrityMs", "compileMs", "rewriteMs", "totalMs"]) number(r[field]);
|
|
51
|
+
number(r.status, true); if (Number(r.status) > 599) throw new Error("request.status: invalid HTTP status");
|
|
52
|
+
string(r.contentType, 256, true);
|
|
53
|
+
const headers = record(r.headers, "headers"); keys(headers, ACTIVITY_HEADERS, "headers");
|
|
54
|
+
for (const field of array(r.unavailable, 5)) choice(field, ["fetch", "integrity", "compile", "rewrite", "cache-layer"]);
|
|
55
|
+
for (const header of Object.values(headers)) string(header, 2048, true);
|
|
56
|
+
if (r.package !== null) {
|
|
57
|
+
const pkg = record(r.package, "package"); keys(pkg, ["name", "version", "path"], "package");
|
|
58
|
+
string(pkg.name, 256); string(pkg.version, 128); string(pkg.path, 4096);
|
|
59
|
+
}
|
|
60
|
+
if (r.kind === "npm" && r.package === null && r.error === null) throw new Error("npm request requires package identity");
|
|
61
|
+
if (r.error !== null) {
|
|
62
|
+
const error = record(r.error, "error"); keys(error, ["phase", "message"], "error");
|
|
63
|
+
choice(error.phase, ["resolve", "fetch", "compile", "link", "render", "readiness"]); string(error.message, 4096);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function validateResolution(value: unknown): void {
|
|
68
|
+
const r = record(value, "runtime"); keys(r, ["versions", "base", "managed", "importMapBytes", "scopes"], "runtime");
|
|
69
|
+
for (const field of ["versions", "base"]) {
|
|
70
|
+
const table = record(r[field], field);
|
|
71
|
+
if (Object.keys(table).length > 512) throw new Error(`${field}: too many entries`);
|
|
72
|
+
for (const [key, target] of Object.entries(table)) { string(key, 256); string(target, 4096); }
|
|
73
|
+
}
|
|
74
|
+
for (const name of array(r.managed, 32)) string(name, 256);
|
|
75
|
+
number(r.importMapBytes, true); number(r.scopes, true);
|
|
76
|
+
}
|
|
77
|
+
function string(value: unknown, max: number, empty = false): asserts value is string {
|
|
78
|
+
if (typeof value !== "string" || (!empty && !value) || value.length > max) throw new Error("activity: invalid or oversized string");
|
|
79
|
+
}
|
|
80
|
+
function number(value: unknown, integer = false): void {
|
|
81
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > Number.MAX_SAFE_INTEGER || (integer && !Number.isInteger(value))) throw new Error("activity: invalid number");
|
|
82
|
+
}
|
|
83
|
+
function choice(value: unknown, allowed: string[]): void {
|
|
84
|
+
if (typeof value !== "string" || !allowed.includes(value)) throw new Error("activity: invalid enum value");
|
|
85
|
+
}
|
|
86
|
+
function array(value: unknown, max: number): unknown[] {
|
|
87
|
+
if (!Array.isArray(value) || value.length > max) throw new Error("activity: invalid or oversized array");
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
function url(value: unknown): void {
|
|
91
|
+
string(value, 8192); if (!["https:", "http:"].includes(new URL(value).protocol)) throw new Error("activity: invalid URL protocol");
|
|
92
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Library runtime build
|
|
2
|
+
|
|
3
|
+
The shared builder ships compiled JavaScript and declarations as `@flanksource/page-runtime-build`. Build its distribution from the clicky-ui workspace before packing it:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm --dir packages/page-runtime run build:builder
|
|
7
|
+
mkdir -p .tmp
|
|
8
|
+
pnpm --dir packages/page-runtime/dist/build --config.ignoreScripts=true pack --out ../../../../.tmp/page-runtime-build.tgz
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package is assembled from `builder-package.json`; it excludes browser host dependencies. The parent clicky-ui repository publishes it through `.github/workflows/release.yml` on pushes to `main`, alongside the Clicky UI release matrix. The workflow selects the next stable patch from registry history, updates `builder-package.json`, builds and tests the compiler, publishes `dist/build` with provenance, then commits the version and creates a `page-runtime-build@<version>` tag. First publication uses the version already declared in the manifest. Registry authentication and network failures stop the release.
|
|
12
|
+
|
|
13
|
+
The parent CI workflow's `runtime-builder` job builds and tests the same package on pull requests and uploads `page-runtime-build.tgz` for inspection. Downstream dependency and lockfile updates follow a successful CI publication. The workspace's `@flanksource/page-runtime/build` export uses the same compiled implementation.
|
|
14
|
+
|
|
15
|
+
Configure the npm trusted publisher for `@flanksource/page-runtime-build` with organization `flanksource`, repository `clicky-ui`, and workflow filename `release.yml`. The package's repository metadata matches that parent repository for provenance. See [npm trusted publishing](https://docs.npmjs.com/trusted-publishers/).
|
|
16
|
+
|
|
17
|
+
## Installed dependency runtimes
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { buildDependencyRuntime, runtimeEntries } from "@flanksource/page-runtime-build/dependencies";
|
|
21
|
+
|
|
22
|
+
const root = "/workspace/render-environment";
|
|
23
|
+
await buildDependencyRuntime({
|
|
24
|
+
root,
|
|
25
|
+
outDir: `${root}/page-runtime/browser`,
|
|
26
|
+
entries: runtimeEntries({ root, libraries: ["@flanksource/facet"] }),
|
|
27
|
+
target: "browser",
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`root` contains the installed dependency environment and its lockfile. `entries` contains package specifiers and subpaths; `runtimeEntries` combines the React base set with a library's published fragment. `target` selects Node or browser resolution conditions. `outDir` receives relocatable ESM chunks, styles, assets and `runtime.json` with entry mappings, integrity and input hashes. CommonJS entry facades expose both named exports and the original default value. `external` maps shared base entries to precompiled modules, preserving React identity across additional dependency closures. `exports` optionally limits an entry to requested bindings; barrel indexes keep unrelated optional features outside that closure. The compiler uses published indexes where available and derives them from package source otherwise, honoring the package's side-effect declarations.
|
|
32
|
+
|
|
33
|
+
Absent dependencies declared through `optionalDependencies` or optional peer metadata remain external only for dynamic `import()` calls. The import rejects at runtime if called, so the library retains control of its optional feature. Missing static imports and undeclared dynamic dependencies fail compilation.
|
|
34
|
+
|
|
35
|
+
`ensureDependencyRuntime` takes the same options with `cacheDir` in place of `outDir`. It serializes competing processes, keys compilation by the lockfile, compiler, ABI, target and entry selection, validates library input hashes on reuse, and publishes immutable generations. Older generations remain available to active readers. Compilation failures leave the previous pointer intact.
|
|
36
|
+
|
|
37
|
+
`dependencyRuntimePlugin({ root, cacheDir, base })` connects a prepared runtime to Vite or Rolldown. The base includes its manifest plus `root`. Node builds import its modules externally; browser development serves its ESM modules directly. Additional package imports compile into the shared cache and reuse the base's React family. CSS imports are passed to the host's stylesheet pipeline.
|
|
38
|
+
|
|
39
|
+
## Library fragments
|
|
40
|
+
|
|
41
|
+
Build the library's normal ESM dist first, then call `buildLibraryRuntime` from `@flanksource/page-runtime-build`. It traces the installed dependency closure, preserving installed versions and nested dependency scopes. Converted CommonJS packages import other packages through the fragment, so the React family stays shared. Browser files under dist are checked even when an entry barrel does not reach them.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { buildLibraryRuntime } from "@flanksource/page-runtime-build";
|
|
45
|
+
|
|
46
|
+
const { fragment, barrels } = await buildLibraryRuntime({
|
|
47
|
+
libraryDir: "/workspace/my-library",
|
|
48
|
+
outDir: "/workspace/my-library/dist/runtime",
|
|
49
|
+
base: clickyUiFragment,
|
|
50
|
+
aliases: { "@example": "my-library" },
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`libraryDir` contains package.json, the built dist and the installed dependencies selected by the library's lockfile. `outDir` receives importmap.json, barrels.json and development modules. Publish that directory as dist/runtime; fragment URLs name the actual published dist/runtime paths. `base` is the optional fragment whose top-level packages this library inherits. A dependent library cannot replace those packages. `aliases` declares optional page-facing aliases for this library's own specifier prefixes.
|
|
55
|
+
|
|
56
|
+
The clicky-ui package defines the base set: React, its JSX runtimes, React DOM and its client entry, scheduler, React Query and jotai. Normal npm exports and React peers keep their existing behavior. Barrel shortcuts require the containing package's sideEffects declaration to permit skipping the forwarding module; a direct side-effect import keeps that module intact.
|
|
57
|
+
|
|
58
|
+
The runtime always builds React and its dependency closure with `NODE_ENV=development`, including published runtime sets and frames embedded in deployed applications. Runtime modules live directly under `dist/runtime/`, without environment subdirectories or URL placeholders. Owner metadata, source locations and warnings remain available in every frame.
|
|
59
|
+
|
|
60
|
+
Run from packages/page-runtime:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
pnpm exec tsx scripts/build-library-runtime.ts ../ui
|
|
64
|
+
pnpm run check-fragment ../ui
|
|
65
|
+
gavel test --work-dir . --framework vitest --recursive=false -- src/build
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A library inheriting clicky-ui can pass its fragment to either CLI:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
pnpm exec tsx scripts/build-library-runtime.ts /workspace/my-library ../ui/dist/runtime/importmap.json
|
|
72
|
+
pnpm run check-fragment /workspace/my-library ../ui/dist/runtime/importmap.json
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The checker validates the written fragment against a fresh dist trace and checks converted files' integrity and imports. Without a base argument, declared inherited specifiers count as mapped; with a base it also verifies that the base provides them. Missing mappings, Node built-ins and unconverted CommonJS fail the check. Build failures use NodeBuiltinError, CommonJsConversionError and BaseSetRemapError for those named failure classes.
|
|
76
|
+
|
|
77
|
+
## Export compiler plugins
|
|
78
|
+
|
|
79
|
+
A library can contribute remark plugins that run when a Markdown or MDX page is exported to HTML or PDF. Live previews never run them. Declare them in package.json under `pageRuntime.compiler`. Each `module` must be one of the library's own `exports`, and its default export is the plugin. `options` is the JSON value the plugin is applied with:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"exports": { "./remark/facet-redact": "./remark/facet-redact.mjs" },
|
|
84
|
+
"pageRuntime": {
|
|
85
|
+
"compiler": {
|
|
86
|
+
"remark": [{ "module": "@flanksource/facet/remark/facet-redact", "options": { "allow": {} } }]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The build traces each plugin module, even outside dist, and writes the declaration to the fragment's `compiler` field. A page's lock collects every library's declaration in library order. A local checkout link replaces its library's entry. On export, the frame loads the export compiler and each plugin through the page's import map, with integrity checks. It compiles the page with the base plugins followed by the declared ones, and renders that result in place of the live page for the snapshot or print. Exporting a page that imports other Markdown fails, because the worker compiles imported Markdown without these plugins. An undeclared module, an empty list, or another package's module fails the build.
|
|
93
|
+
|
|
94
|
+
A library exporting `./page-styles` declares `runtimeDependencies: string[]` on its default or named `pageStyles` recipe. List the package specifiers and recipe-relative files its CSS compiler fetches, including stylesheets, Tailwind plugins and presets. The build imports the recipe from dist and traces these dependencies from that module, including transitive CSS imports and assets, scoped mappings and integrity. The checker reads the same declaration. The recipe's `base` stylesheets are linked on every page and its `entry` holds only compiler inputs; see `src/frame/tailwind/README.md`. Browser field mappings apply before built-in rejection: `false` maps to a generated empty module, while a string resolves to its browser target.
|
|
95
|
+
|
|
96
|
+
Clicky UI's build appends the runtime step after both Vite passes and stylesheet generation, because the ESM Vite pass empties dist. `pnpm --filter @flanksource/clicky-ui test:runtime-set` runs only its Chromium probe through Gavel. It tests hooks and Clicky UI theme context, counts one React and one renderer in the development build, and checks that a deliberately duplicated React fails.
|