@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8
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/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +28 -2
- package/api/docs/_adapter.mjs +249 -10
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +132 -1
- package/api/theme/build/build.mjs +482 -157
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +44 -5
- package/api/theme/build/font-warning.mjs +118 -10
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +115 -4
- package/api/theme-edit/_adapter.mjs +997 -83
- package/api/theme-edit/_catalog.d.mts +20 -2
- package/api/theme-edit/_catalog.mjs +50 -10
- package/api/theme-edit/_check.d.mts +75 -24
- package/api/theme-edit/_check.mjs +2672 -422
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +54 -1
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +133 -15
- package/api/theme-edit/_context.d.mts +14 -3
- package/api/theme-edit/_context.mjs +225 -65
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +54 -4
- package/api/theme-edit/_edit.mjs +2966 -286
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +770 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6983 -701
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +303 -0
- package/api/theme-edit/_normal.mjs +1517 -0
- package/api/theme-edit/_palette.d.mts +12 -0
- package/api/theme-edit/_palette.mjs +37 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +28 -2
- package/api/theme-edit/_parts.mjs +267 -31
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +814 -406
- package/api/theme-edit/_preview.d.mts +116 -16
- package/api/theme-edit/_preview.mjs +649 -152
- package/api/theme-edit/_project.d.mts +22 -1
- package/api/theme-edit/_project.mjs +83 -3
- package/api/theme-edit/_settings.d.mts +467 -42
- package/api/theme-edit/_settings.mjs +3527 -468
- package/api/theme-edit/_tables.d.mts +21 -0
- package/api/theme-edit/_tables.mjs +97 -3
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +16 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +573 -119
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +718 -438
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +132 -24
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.d.mts +6 -5
- package/foundation/discovery/theming-targets.mjs +31 -47
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +38 -0
- package/foundation/fonts/font-stylesheet.mjs +141 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +517 -91
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +641 -96
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Whether only a path alias can resolve an import: its name cannot be a
|
|
6
|
+
* package's, a Node built-in's, or a package's own subpath import
|
|
7
|
+
* (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
|
|
8
|
+
* and `#utils`, which a package.json `imports` maps, can). A received file's
|
|
9
|
+
* record of alias imports counts only for these, so it can never remap a
|
|
10
|
+
* package, or the reader's own imports, for the reader.
|
|
11
|
+
* @param {string} spec
|
|
12
|
+
*/
|
|
13
|
+
export function aliasOnly(spec: string): boolean;
|
|
4
14
|
/**
|
|
5
15
|
* What a stylesheet's `@import` rules load, read with postcss so comments
|
|
6
16
|
* are ignored.
|
|
@@ -23,33 +33,49 @@ export function importSpecifiers(source: string, file: string): string[];
|
|
|
23
33
|
*/
|
|
24
34
|
export function assetRefsIn(text: string): string[];
|
|
25
35
|
/**
|
|
26
|
-
* The
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
36
|
+
* The images, fonts and media a carried file names by a relative path: in a
|
|
37
|
+
* module's strings, or in a stylesheet. A render carries each one that
|
|
38
|
+
* exists, and {@link reachableFiles} expects each one back.
|
|
39
|
+
* @param {string} source
|
|
40
|
+
* @param {string} file its path; a `.css` file is read as a stylesheet
|
|
41
|
+
* @returns {string[]}
|
|
42
|
+
*/
|
|
43
|
+
export function assetRefsOf(source: string, file: string): string[];
|
|
44
|
+
/**
|
|
45
|
+
* The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
|
|
46
|
+
* written at `file`, by its rules (see ts-paths.mjs). The file and its
|
|
47
|
+
* folders need not exist yet.
|
|
48
|
+
* @param {string} file absolute
|
|
29
49
|
* @returns {import('./ts-paths.mjs').PathPattern[]}
|
|
30
50
|
*/
|
|
31
|
-
export function receivingAliases(
|
|
51
|
+
export function receivingAliases(file: string): import("./ts-paths.mjs").PathPattern[];
|
|
32
52
|
/**
|
|
33
53
|
* @typedef {object} Reach
|
|
34
54
|
* @property {boolean} relative - Reached by a relative import (or it is the
|
|
35
55
|
* page), so it goes where the page's layout puts it.
|
|
36
56
|
* @property {Set<string>} aliased - Absolute paths a receiving-project alias
|
|
37
57
|
* import names for it, so it also goes there.
|
|
58
|
+
* @property {Set<string>} unaliased - Alias imports that name it where no
|
|
59
|
+
* receiving-project alias does: the render recorded the file each named,
|
|
60
|
+
* so it goes where the page's layout puts it, and the page needs the alias.
|
|
38
61
|
*/
|
|
39
62
|
/**
|
|
40
63
|
* The embedded files the page reaches through its imports.
|
|
41
64
|
* @param {{path: string, base64: string}[]} files the embedded files, page
|
|
42
65
|
* first; every path appears once (callers refuse duplicates first)
|
|
43
|
-
* @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options]
|
|
44
|
-
* receiving project's path aliases (see receivingAliases)
|
|
66
|
+
* @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
|
|
67
|
+
* the receiving project's path aliases (see receivingAliases), and the
|
|
68
|
+
* alias imports the render recorded (an untrusted record: only an entry
|
|
69
|
+
* that names a carried file counts)
|
|
45
70
|
* @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
|
|
46
71
|
* tree paths, and the relative imports the file does not carry
|
|
47
72
|
*/
|
|
48
73
|
export function reachableFiles(files: {
|
|
49
74
|
path: string;
|
|
50
75
|
base64: string;
|
|
51
|
-
}[], { aliases }?: {
|
|
76
|
+
}[], { aliases, recorded }?: {
|
|
52
77
|
aliases?: import("./ts-paths.mjs").PathPattern[];
|
|
78
|
+
recorded?: unknown;
|
|
53
79
|
}): {
|
|
54
80
|
reached: Map<string, Reach>;
|
|
55
81
|
missing: string[];
|
|
@@ -65,4 +91,10 @@ export type Reach = {
|
|
|
65
91
|
* import names for it, so it also goes there.
|
|
66
92
|
*/
|
|
67
93
|
aliased: Set<string>;
|
|
94
|
+
/**
|
|
95
|
+
* - Alias imports that name it where no
|
|
96
|
+
* receiving-project alias does: the render recorded the file each named,
|
|
97
|
+
* so it goes where the page's layout puts it, and the page needs the alias.
|
|
98
|
+
*/
|
|
99
|
+
unaliased: Set<string>;
|
|
68
100
|
};
|
|
@@ -13,13 +13,33 @@
|
|
|
13
13
|
* @position foundation/render — used by the render subject's adapter
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
import * as fs from 'node:fs';
|
|
17
16
|
import * as path from 'node:path';
|
|
18
17
|
import {babelParse as parse} from '../runtime/lazy-dependencies.mjs';
|
|
19
|
-
import {
|
|
18
|
+
import {MODULE_EXTENSIONS} from './embedded-files.mjs';
|
|
20
19
|
import postcss from 'postcss';
|
|
21
|
-
import {
|
|
20
|
+
import {builtinModules} from 'node:module';
|
|
21
|
+
import {matchPath, pathsFor} from './ts-paths.mjs';
|
|
22
22
|
import {isAssetPath} from './assets.mjs';
|
|
23
|
+
import {climbsOut} from '../fs/paths.mjs';
|
|
24
|
+
|
|
25
|
+
/** A name npm gives a package, scoped or not (older names may have capitals). */
|
|
26
|
+
const PACKAGE_NAME = /^(?:@[a-z0-9][\w.-]*\/)?[a-z0-9-][\w.-]*$/i;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether only a path alias can resolve an import: its name cannot be a
|
|
30
|
+
* package's, a Node built-in's, or a package's own subpath import
|
|
31
|
+
* (`@/components/Header` and `~/lib/data` cannot; `react`, `@acme/ui`, `fs`
|
|
32
|
+
* and `#utils`, which a package.json `imports` maps, can). A received file's
|
|
33
|
+
* record of alias imports counts only for these, so it can never remap a
|
|
34
|
+
* package, or the reader's own imports, for the reader.
|
|
35
|
+
* @param {string} spec
|
|
36
|
+
*/
|
|
37
|
+
export function aliasOnly(spec) {
|
|
38
|
+
if (spec.startsWith('node:') || spec.startsWith('#')) return false;
|
|
39
|
+
const segments = spec.split('/');
|
|
40
|
+
const name = spec.startsWith('@') ? segments.slice(0, 2).join('/') : segments[0];
|
|
41
|
+
return !PACKAGE_NAME.test(name) && !builtinModules.includes(name);
|
|
42
|
+
}
|
|
23
43
|
|
|
24
44
|
/**
|
|
25
45
|
* What a stylesheet's `@import` rules load, read with postcss so comments
|
|
@@ -43,7 +63,7 @@ export function cssImports(css) {
|
|
|
43
63
|
}
|
|
44
64
|
|
|
45
65
|
/** Extensions an extensionless import may stand for, in resolution order. */
|
|
46
|
-
const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.json'];
|
|
66
|
+
const RESOLVE_EXTENSIONS = ['.tsx', '.ts', '.jsx', '.js', '.mjs', '.mts', '.cts', '.cjs', '.json'];
|
|
47
67
|
|
|
48
68
|
/**
|
|
49
69
|
* The string specifiers one module imports.
|
|
@@ -71,6 +91,18 @@ export function assetRefsIn(text) {
|
|
|
71
91
|
return out;
|
|
72
92
|
}
|
|
73
93
|
|
|
94
|
+
/**
|
|
95
|
+
* The images, fonts and media a carried file names by a relative path: in a
|
|
96
|
+
* module's strings, or in a stylesheet. A render carries each one that
|
|
97
|
+
* exists, and {@link reachableFiles} expects each one back.
|
|
98
|
+
* @param {string} source
|
|
99
|
+
* @param {string} file its path; a `.css` file is read as a stylesheet
|
|
100
|
+
* @returns {string[]}
|
|
101
|
+
*/
|
|
102
|
+
export function assetRefsOf(source, file) {
|
|
103
|
+
return /\.css$/i.test(file) ? assetRefsIn(source) : scanModule(source, file).assets;
|
|
104
|
+
}
|
|
105
|
+
|
|
74
106
|
/**
|
|
75
107
|
* One module's imports, and the relative asset paths its strings name
|
|
76
108
|
* (`<img src="./logo.png">`, `url(./bg.png)` in a style).
|
|
@@ -132,22 +164,14 @@ function scanModule(source, file) {
|
|
|
132
164
|
}
|
|
133
165
|
|
|
134
166
|
/**
|
|
135
|
-
* The path aliases (`compilerOptions.paths`)
|
|
136
|
-
* `
|
|
137
|
-
*
|
|
167
|
+
* The path aliases (`compilerOptions.paths`) that TypeScript reads for a page
|
|
168
|
+
* written at `file`, by its rules (see ts-paths.mjs). The file and its
|
|
169
|
+
* folders need not exist yet.
|
|
170
|
+
* @param {string} file absolute
|
|
138
171
|
* @returns {import('./ts-paths.mjs').PathPattern[]}
|
|
139
172
|
*/
|
|
140
|
-
export function receivingAliases(
|
|
141
|
-
|
|
142
|
-
while (!fs.existsSync(d) && path.dirname(d) !== d) d = path.dirname(d);
|
|
143
|
-
for (;;) {
|
|
144
|
-
const found = readPathsIn(d);
|
|
145
|
-
if (found) return found;
|
|
146
|
-
if (fs.existsSync(path.join(d, 'package.json'))) return [];
|
|
147
|
-
const up = path.dirname(d);
|
|
148
|
-
if (up === d) return [];
|
|
149
|
-
d = up;
|
|
150
|
-
}
|
|
173
|
+
export function receivingAliases(file) {
|
|
174
|
+
return pathsFor(file);
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
/**
|
|
@@ -156,18 +180,23 @@ export function receivingAliases(dir) {
|
|
|
156
180
|
* page), so it goes where the page's layout puts it.
|
|
157
181
|
* @property {Set<string>} aliased - Absolute paths a receiving-project alias
|
|
158
182
|
* import names for it, so it also goes there.
|
|
183
|
+
* @property {Set<string>} unaliased - Alias imports that name it where no
|
|
184
|
+
* receiving-project alias does: the render recorded the file each named,
|
|
185
|
+
* so it goes where the page's layout puts it, and the page needs the alias.
|
|
159
186
|
*/
|
|
160
187
|
|
|
161
188
|
/**
|
|
162
189
|
* The embedded files the page reaches through its imports.
|
|
163
190
|
* @param {{path: string, base64: string}[]} files the embedded files, page
|
|
164
191
|
* first; every path appears once (callers refuse duplicates first)
|
|
165
|
-
* @param {{aliases?: import('./ts-paths.mjs').PathPattern[]}} [options]
|
|
166
|
-
* receiving project's path aliases (see receivingAliases)
|
|
192
|
+
* @param {{aliases?: import('./ts-paths.mjs').PathPattern[], recorded?: unknown}} [options]
|
|
193
|
+
* the receiving project's path aliases (see receivingAliases), and the
|
|
194
|
+
* alias imports the render recorded (an untrusted record: only an entry
|
|
195
|
+
* that names a carried file counts)
|
|
167
196
|
* @returns {{reached: Map<string, Reach>, missing: string[]}} the reached
|
|
168
197
|
* tree paths, and the relative imports the file does not carry
|
|
169
198
|
*/
|
|
170
|
-
export function reachableFiles(files, {aliases = []} = {}) {
|
|
199
|
+
export function reachableFiles(files, {aliases = [], recorded} = {}) {
|
|
171
200
|
const byPath = new Map(files.map(f => [f.path, f]));
|
|
172
201
|
/** @type {Map<string, Reach>} */
|
|
173
202
|
const reached = new Map();
|
|
@@ -203,7 +232,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
203
232
|
let r = reached.get(p);
|
|
204
233
|
const fresh = !r;
|
|
205
234
|
if (!r) {
|
|
206
|
-
r = {relative: false, aliased: new Set()};
|
|
235
|
+
r = {relative: false, aliased: new Set(), unaliased: new Set()};
|
|
207
236
|
reached.set(p, r);
|
|
208
237
|
}
|
|
209
238
|
return {r, fresh};
|
|
@@ -217,7 +246,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
217
246
|
while (queue.length > 0) {
|
|
218
247
|
const current = /** @type {string} */ (queue.shift());
|
|
219
248
|
const ext = path.posix.extname(current).toLowerCase();
|
|
220
|
-
const isModule =
|
|
249
|
+
const isModule = MODULE_EXTENSIONS.includes(ext);
|
|
221
250
|
if (!isModule && ext !== '.css') continue;
|
|
222
251
|
const entry = byPath.get(current);
|
|
223
252
|
if (!entry) continue;
|
|
@@ -225,7 +254,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
225
254
|
// Images and fonts a module or stylesheet names by a relative path are
|
|
226
255
|
// part of the page too.
|
|
227
256
|
const scanned = isModule
|
|
228
|
-
?
|
|
257
|
+
? {imports: importSpecifiers(source, current), assets: assetRefsOf(source, current)}
|
|
229
258
|
: {
|
|
230
259
|
// A stylesheet's own `@import`s count as imports.
|
|
231
260
|
// A stylesheet's own relative `@import`s count as imports (read
|
|
@@ -237,11 +266,11 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
237
266
|
// carries one, else a package's.
|
|
238
267
|
.filter(ref => ref.startsWith('.') || byPath.has(path.posix.normalize(path.posix.join(path.posix.dirname(current), ref))))
|
|
239
268
|
.map(ref => (ref.startsWith('.') ? ref : `./${ref}`)),
|
|
240
|
-
assets:
|
|
269
|
+
assets: assetRefsOf(source, current),
|
|
241
270
|
};
|
|
242
271
|
for (const ref of scanned.assets) {
|
|
243
272
|
const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), ref));
|
|
244
|
-
if (joined
|
|
273
|
+
if (climbsOut(joined)) continue;
|
|
245
274
|
if (!byPath.has(joined)) {
|
|
246
275
|
missing.add(joined);
|
|
247
276
|
continue;
|
|
@@ -252,7 +281,7 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
252
281
|
const bare = spec.split('?')[0];
|
|
253
282
|
if (bare.startsWith('./') || bare.startsWith('../')) {
|
|
254
283
|
const joined = path.posix.normalize(path.posix.join(path.posix.dirname(current), bare));
|
|
255
|
-
const target = joined
|
|
284
|
+
const target = climbsOut(joined) ? null : resolveIn(joined);
|
|
256
285
|
if (!target) {
|
|
257
286
|
missing.add(joined);
|
|
258
287
|
continue;
|
|
@@ -317,6 +346,16 @@ export function reachableFiles(files, {aliases = []} = {}) {
|
|
|
317
346
|
r.aliased.add(chosen.abs);
|
|
318
347
|
if (fresh) queue.push(chosen.hit.path);
|
|
319
348
|
}
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
// No alias here names it, but the render recorded the carried file it
|
|
352
|
+
// named: that file comes back in the page's own layout.
|
|
353
|
+
const sent = aliasOnly(bare) && recorded && typeof recorded === 'object' && Object.hasOwn(recorded, bare) ? /** @type {Record<string, unknown>} */ (recorded)[bare] : undefined;
|
|
354
|
+
if (typeof sent === 'string' && byPath.has(sent)) {
|
|
355
|
+
const {r, fresh} = reach(sent);
|
|
356
|
+
r.relative = true;
|
|
357
|
+
r.unaliased.add(bare);
|
|
358
|
+
if (fresh) queue.push(sent);
|
|
320
359
|
}
|
|
321
360
|
}
|
|
322
361
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {object} FileFacts
|
|
6
|
+
* @property {string | null} cli - The CLI version that rendered the file.
|
|
7
|
+
* @property {number} format - The render format of the embedded source.
|
|
8
|
+
* @property {string} file - The rendered file's name.
|
|
9
|
+
* @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
|
|
10
|
+
* @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
|
|
11
|
+
* @property {string[]} files - The embedded files, page first.
|
|
12
|
+
* @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
|
|
13
|
+
* @property {string[]} install - What a render outside a project must install first, as name@version.
|
|
14
|
+
* @property {string} [title] - The title given with --title.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The note at the top of a rendered file.
|
|
18
|
+
* @param {FileFacts} facts
|
|
19
|
+
* @returns {string} an HTML comment on lines of its own
|
|
20
|
+
*/
|
|
21
|
+
export function headerNote(facts: FileFacts): string;
|
|
22
|
+
/**
|
|
23
|
+
* The note after the embedded source.
|
|
24
|
+
* @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
|
|
25
|
+
* @returns {string} an HTML comment on one line
|
|
26
|
+
*/
|
|
27
|
+
export function endNote(facts: Pick<FileFacts, "cli" | "format" | "file">): string;
|
|
28
|
+
export function cliCommand(version: string | null): string;
|
|
29
|
+
export type FileFacts = {
|
|
30
|
+
/**
|
|
31
|
+
* - The CLI version that rendered the file.
|
|
32
|
+
*/
|
|
33
|
+
cli: string | null;
|
|
34
|
+
/**
|
|
35
|
+
* - The render format of the embedded source.
|
|
36
|
+
*/
|
|
37
|
+
format: number;
|
|
38
|
+
/**
|
|
39
|
+
* - The rendered file's name.
|
|
40
|
+
*/
|
|
41
|
+
file: string;
|
|
42
|
+
/**
|
|
43
|
+
* - The page's path from its project's root; outside a project, its path among the files it carries.
|
|
44
|
+
*/
|
|
45
|
+
page: string;
|
|
46
|
+
/**
|
|
47
|
+
* - Where --reverse writes the page by default, from the rendered file's folder.
|
|
48
|
+
*/
|
|
49
|
+
restored: string;
|
|
50
|
+
/**
|
|
51
|
+
* - The embedded files, page first.
|
|
52
|
+
*/
|
|
53
|
+
files: string[];
|
|
54
|
+
/**
|
|
55
|
+
* - The packages the page rendered with, by name: their versions.
|
|
56
|
+
*/
|
|
57
|
+
packages: Record<string, string>;
|
|
58
|
+
/**
|
|
59
|
+
* - What a render outside a project must install first, as name@version.
|
|
60
|
+
*/
|
|
61
|
+
install: string[];
|
|
62
|
+
/**
|
|
63
|
+
* - The title given with --title.
|
|
64
|
+
*/
|
|
65
|
+
title?: string | undefined;
|
|
66
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
import {shellArg} from '../text/shell-arg.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @file The plain-text notes a rendered file carries for whoever opens it
|
|
7
|
+
* next, a person or an agent with no other context: what made the file, what
|
|
8
|
+
* it carries, and the exact commands that give the page back and render it
|
|
9
|
+
* again. The note at the top sits in <head> after the charset and generator
|
|
10
|
+
* metas, so browsers and older CLIs still find both in the first bytes. The
|
|
11
|
+
* short note at the end follows the embedded source, for a reader that starts
|
|
12
|
+
* at the end of the file.
|
|
13
|
+
*
|
|
14
|
+
* The notes never spell the opening tag of the embedded block: every CLI
|
|
15
|
+
* finds the block by that tag, and the last match wins.
|
|
16
|
+
*
|
|
17
|
+
* @position foundation/render — used by render-page.mjs
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The command that runs one version of the CLI anywhere npm runs.
|
|
22
|
+
* @param {string | null} version
|
|
23
|
+
*/
|
|
24
|
+
export const cliCommand = version => `npx @astryxdesign/cli${version ? `@${version}` : ''}`;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Text that cannot end or nest an HTML comment.
|
|
29
|
+
* @param {string} text
|
|
30
|
+
*/
|
|
31
|
+
const commentSafe = text => text.replace(/--!?>/g, '- ->').replace(/<!--/g, '<!- -');
|
|
32
|
+
|
|
33
|
+
/** The most file names the note at the top lists. */
|
|
34
|
+
const MAX_LISTED = 24;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} FileFacts
|
|
38
|
+
* @property {string | null} cli - The CLI version that rendered the file.
|
|
39
|
+
* @property {number} format - The render format of the embedded source.
|
|
40
|
+
* @property {string} file - The rendered file's name.
|
|
41
|
+
* @property {string} page - The page's path from its project's root; outside a project, its path among the files it carries.
|
|
42
|
+
* @property {string} restored - Where --reverse writes the page by default, from the rendered file's folder.
|
|
43
|
+
* @property {string[]} files - The embedded files, page first.
|
|
44
|
+
* @property {Record<string, string>} packages - The packages the page rendered with, by name: their versions.
|
|
45
|
+
* @property {string[]} install - What a render outside a project must install first, as name@version.
|
|
46
|
+
* @property {string} [title] - The title given with --title.
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The note at the top of a rendered file.
|
|
51
|
+
* @param {FileFacts} facts
|
|
52
|
+
* @returns {string} an HTML comment on lines of its own
|
|
53
|
+
*/
|
|
54
|
+
export function headerNote(facts) {
|
|
55
|
+
const run = cliCommand(facts.cli);
|
|
56
|
+
const file = shellArg(facts.file);
|
|
57
|
+
const shown = facts.files.slice(0, MAX_LISTED).join(', ');
|
|
58
|
+
const more = facts.files.length > MAX_LISTED ? `, and ${facts.files.length - MAX_LISTED} more` : '';
|
|
59
|
+
const versions = Object.entries(facts.packages).map(([name, version]) => `${name} ${version}`);
|
|
60
|
+
const core = facts.packages['@astryxdesign/core'];
|
|
61
|
+
// A title with < or > stays out of the note, which other tools read as
|
|
62
|
+
// HTML; step 1 prints the command with it.
|
|
63
|
+
const quotable = facts.title !== undefined && !/[<>]/.test(facts.title);
|
|
64
|
+
const title = quotable ? ` --title ${shellArg(/** @type {string} */ (facts.title))}` : '';
|
|
65
|
+
const lines = [
|
|
66
|
+
`Rendered by Astryx: astryx experimental render, @astryxdesign/cli ${facts.cli ?? '(version unknown)'}, render format ${facts.format}.`,
|
|
67
|
+
'This is one static file. It runs no script and loads nothing from the network.',
|
|
68
|
+
'It also carries the source of the page, so the page can come back exactly.',
|
|
69
|
+
'',
|
|
70
|
+
`Page: ${facts.page}`,
|
|
71
|
+
`Carried files (${facts.files.length}): ${shown}${more}`,
|
|
72
|
+
...(versions.length > 0 ? [`Rendered with: ${versions.join(', ')}`] : []),
|
|
73
|
+
'',
|
|
74
|
+
'To change the page, change its source and render it again. Do not edit this HTML:',
|
|
75
|
+
'the carried source does not get the edits you make here.',
|
|
76
|
+
'Run these commands in the folder that holds this file:',
|
|
77
|
+
` 1. Get the source back. This writes ${facts.restored} and the files it imports`,
|
|
78
|
+
` (into ${facts.restored.split('/')[0]}-2/ and so on when that folder exists; the output names it):`,
|
|
79
|
+
` ${run} experimental render --reverse ${file}`,
|
|
80
|
+
' 2. Edit the restored files.',
|
|
81
|
+
' 3. Render again. A render replaces a file that a render wrote. Step 1 prints this',
|
|
82
|
+
' command with the folder it wrote:',
|
|
83
|
+
` ${run} experimental render ${shellArg(facts.restored)} --out ${file}${title}`,
|
|
84
|
+
...(facts.title !== undefined && !quotable ? [' The page was rendered with --title; step 1 prints the command with it.'] : []),
|
|
85
|
+
`If you have the project, edit ${facts.page} there instead, and render it in the same way.`,
|
|
86
|
+
"Inside a project, the project's own CLI answers these commands. A project CLI older than",
|
|
87
|
+
`${facts.cli ?? 'the one that rendered this file'} writes the page without this note; to keep the note, update that CLI first:`,
|
|
88
|
+
` npm install --save-dev @astryxdesign/cli@${facts.cli ?? 'latest'}`,
|
|
89
|
+
...(facts.install.length > 0
|
|
90
|
+
? [
|
|
91
|
+
'Outside a project, the CLI supplies Astryx, React and StyleX. Install the other packages first:',
|
|
92
|
+
` npm install ${facts.install.join(' ')}`,
|
|
93
|
+
]
|
|
94
|
+
: []),
|
|
95
|
+
...(core
|
|
96
|
+
? [
|
|
97
|
+
`The source was written for @astryxdesign/core ${core}. In a project on a newer Core, update the`,
|
|
98
|
+
"restored code from inside that project (the CLI hands this to the project's own CLI):",
|
|
99
|
+
` ${cliCommand(null)} upgrade --from ${core} --path ${shellArg(facts.restored.split('/')[0])} --apply`,
|
|
100
|
+
]
|
|
101
|
+
: []),
|
|
102
|
+
'Later CLI versions read this file too.',
|
|
103
|
+
'If someone edits this HTML after the render, step 1 still gives back the page as rendered,',
|
|
104
|
+
'and it lists the text that changed, so you can make the same change in the source.',
|
|
105
|
+
'The source is in the script block at the end of this file. Keep it: without it,',
|
|
106
|
+
'step 1 can rebuild only the text and the layout from the markup.',
|
|
107
|
+
];
|
|
108
|
+
return `<!--\n${lines.map(line => (line ? ` ${commentSafe(line)}` : '')).join('\n')}\n-->`.replace(/<(?=\/?script)/gi, '<');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The note after the embedded source.
|
|
113
|
+
* @param {Pick<FileFacts, 'cli' | 'format' | 'file'>} facts
|
|
114
|
+
* @returns {string} an HTML comment on one line
|
|
115
|
+
*/
|
|
116
|
+
export function endNote(facts) {
|
|
117
|
+
return `<!-- Astryx render: the block above is the source of the page (render format ${facts.format}), as JSON; each file is base64 with its SHA-256. Get it back: ${commentSafe(cliCommand(facts.cli))} experimental render --reverse ${commentSafe(shellArg(facts.file))} -->`;
|
|
118
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {{
|
|
6
|
+
* send: (message: unknown, done: (error: Error | null) => void) => unknown,
|
|
7
|
+
* exit: (code: number) => void,
|
|
8
|
+
* connected: () => boolean,
|
|
9
|
+
* record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
|
|
10
|
+
* }} io
|
|
11
|
+
* @returns {(message: unknown) => void}
|
|
12
|
+
*/
|
|
13
|
+
export function makeAnswer({ send, exit, connected, record }: {
|
|
14
|
+
send: (message: unknown, done: (error: Error | null) => void) => unknown;
|
|
15
|
+
exit: (code: number) => void;
|
|
16
|
+
connected: () => boolean;
|
|
17
|
+
record?: (phase: "no-channel" | "sending" | "sent" | "send-failed") => void;
|
|
18
|
+
}): (message: unknown) => void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The render host's one answer to the CLI. The host exits 0 only after
|
|
5
|
+
* the channel accepted the answer; a send that fails exits with its own code
|
|
6
|
+
* (HOST_EXIT.sendFailed), so a lost answer never reads as a clean exit. Each
|
|
7
|
+
* phase is recorded, so the CLI can tell "sent but not received" from "ended
|
|
8
|
+
* before it answered".
|
|
9
|
+
* @input send, exit, connected and record functions (process ones in the host)
|
|
10
|
+
* @output an answer(message) function that sends at most once
|
|
11
|
+
* @position foundation/render — used by page-host.mjs
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {HOST_EXIT} from './host-exit.mjs';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {{
|
|
18
|
+
* send: (message: unknown, done: (error: Error | null) => void) => unknown,
|
|
19
|
+
* exit: (code: number) => void,
|
|
20
|
+
* connected: () => boolean,
|
|
21
|
+
* record?: (phase: 'no-channel' | 'sending' | 'sent' | 'send-failed') => void,
|
|
22
|
+
* }} io
|
|
23
|
+
* @returns {(message: unknown) => void}
|
|
24
|
+
*/
|
|
25
|
+
export function makeAnswer({send, exit, connected, record = () => {}}) {
|
|
26
|
+
let answered = false;
|
|
27
|
+
return message => {
|
|
28
|
+
if (answered) return;
|
|
29
|
+
answered = true;
|
|
30
|
+
if (!connected()) {
|
|
31
|
+
record('no-channel');
|
|
32
|
+
exit(HOST_EXIT.noChannel);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
record('sending');
|
|
36
|
+
try {
|
|
37
|
+
send(message, error => {
|
|
38
|
+
record(error ? 'send-failed' : 'sent');
|
|
39
|
+
exit(error ? HOST_EXIT.sendFailed : 0);
|
|
40
|
+
});
|
|
41
|
+
} catch {
|
|
42
|
+
record('send-failed');
|
|
43
|
+
exit(HOST_EXIT.sendFailed);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -8,4 +8,9 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/** Exit codes for each way the host ends without sending an answer. */
|
|
11
|
-
export const HOST_EXIT = {
|
|
11
|
+
export const HOST_EXIT = {
|
|
12
|
+
disconnected: 70,
|
|
13
|
+
timeout: 71,
|
|
14
|
+
noChannel: 72,
|
|
15
|
+
sendFailed: 73,
|
|
16
|
+
};
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The tag whose name starts at `i`, read as a browser reads it: an attribute
|
|
6
|
+
* value is quoted or runs to a space or `>`, and a `/` just before `>` makes
|
|
7
|
+
* the tag self-closing.
|
|
8
|
+
* @param {string} html
|
|
9
|
+
* @param {number} i the first letter of the name
|
|
10
|
+
* @returns {{tag: string, attrs: Array<[string, string]>, selfClosing: boolean, end: number} | 'text' | 'open'}
|
|
11
|
+
* 'text' when the name is not a tag name, so the `<` is text; 'open' when
|
|
12
|
+
* no `>` ends the tag, so the rest of the document is text
|
|
13
|
+
*/
|
|
14
|
+
export function readTag(html: string, i: number): {
|
|
15
|
+
tag: string;
|
|
16
|
+
attrs: Array<[string, string]>;
|
|
17
|
+
selfClosing: boolean;
|
|
18
|
+
end: number;
|
|
19
|
+
} | "text" | "open";
|
|
20
|
+
/**
|
|
21
|
+
* Split an HTML document into its pieces, in order, as a browser does for
|
|
22
|
+
* the markup a render writes. A comment ends at the first `-->` after its
|
|
23
|
+
* `<!--` (so `<!-->` and `<!--->` are whole comments), or at the end. The
|
|
24
|
+
* content of a raw-text element up to its end tag is one `raw` piece, so a
|
|
25
|
+
* tag or a comment in a stylesheet is text. A `<` that starts no tag is
|
|
26
|
+
* text, and a tag that no `>` ends makes the rest text. Each character is
|
|
27
|
+
* read a fixed number of times, so the time grows with the document's length.
|
|
28
|
+
* @param {string} html
|
|
29
|
+
* @returns {Generator<HtmlToken>}
|
|
30
|
+
*/
|
|
31
|
+
export function scanHtml(html: string): Generator<HtmlToken>;
|
|
4
32
|
/**
|
|
5
33
|
* A small, forgiving HTML parser: enough for rendered markup.
|
|
6
34
|
* @param {string} html
|
|
@@ -12,14 +40,18 @@ export function find(n: ElementNode, tag: string): ElementNode | undefined;
|
|
|
12
40
|
/**
|
|
13
41
|
* @file A small, forgiving HTML reader for `astryx experimental render
|
|
14
42
|
* --reverse`: enough for rendered markup, plus the helpers that ask it which
|
|
15
|
-
* Astryx component an element came from.
|
|
43
|
+
* Astryx component an element came from. Its scanner also finds the parts of
|
|
44
|
+
* a rendered file that a reverse compares.
|
|
16
45
|
*
|
|
17
|
-
* @position foundation/render — used by rebuild.mjs
|
|
46
|
+
* @position foundation/render — used by rebuild.mjs, markup-edits.mjs,
|
|
47
|
+
* source-block.mjs and the render subject
|
|
18
48
|
*/
|
|
19
49
|
/** @typedef {{tag: string, attrs: Record<string, string>, children: Node[]}} ElementNode */
|
|
20
50
|
/** @typedef {ElementNode | {text: string}} Node */
|
|
21
51
|
export const VOID: Set<string>;
|
|
22
52
|
export function decode(s: string): string;
|
|
53
|
+
/** Elements whose content is raw text: a tag or a comment opener in it is text. */
|
|
54
|
+
export const RAW_TEXT: Set<string>;
|
|
23
55
|
export function isEl(n: Node): n is ElementNode;
|
|
24
56
|
/** Elements whose children React refuses or treats as a value. */
|
|
25
57
|
export const FORM_TAGS: Set<string>;
|
|
@@ -35,3 +67,24 @@ export type ElementNode = {
|
|
|
35
67
|
export type Node = ElementNode | {
|
|
36
68
|
text: string;
|
|
37
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* One piece of an HTML document, by its place in the text. `raw` is the
|
|
72
|
+
* content of a raw-text element.
|
|
73
|
+
*/
|
|
74
|
+
export type HtmlToken = {
|
|
75
|
+
kind: "text" | "raw" | "comment" | "doctype";
|
|
76
|
+
start: number;
|
|
77
|
+
end: number;
|
|
78
|
+
} | {
|
|
79
|
+
kind: "end";
|
|
80
|
+
tag: string;
|
|
81
|
+
start: number;
|
|
82
|
+
end: number;
|
|
83
|
+
} | {
|
|
84
|
+
kind: "start";
|
|
85
|
+
tag: string;
|
|
86
|
+
attrs: Array<[string, string]>;
|
|
87
|
+
selfClosing: boolean;
|
|
88
|
+
start: number;
|
|
89
|
+
end: number;
|
|
90
|
+
};
|