@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74
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 +17 -0
- package/api/build/_adapter.mjs +53 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/blocks/blocks.weights.json +1 -1
- 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 +6 -4
- package/api/build/kit/rank.mjs +132 -28
- package/api/build/kit/signals.d.mts +7 -1
- package/api/build/kit/signals.mjs +21 -10
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +14 -9
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +351 -46
- 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 +86 -0
- package/api/build/kit/words.mjs +241 -1
- package/api/build/tree.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/component/_adapter.d.mts +26 -2
- package/api/component/_adapter.mjs +135 -8
- package/api/component/component.mjs +14 -1
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +11 -1
- package/api/discover/_adapter.mjs +95 -1
- package/api/discover/detail/item/item.mjs +5 -0
- package/api/discover/discover.mjs +12 -3
- package/api/discover/discover.type.d.mts +16 -3
- package/api/discover/discover.type.mjs +13 -3
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +57 -2
- package/api/docs/_adapter.mjs +266 -33
- package/api/docs/_entry-names-lazily.d.mts +22 -0
- package/api/docs/_entry-names-lazily.mjs +25 -0
- package/api/docs/_entry-names.d.mts +23 -0
- package/api/docs/_entry-names.mjs +105 -0
- 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 +54 -5
- package/api/doctor/_adapter.mjs +162 -11
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +15 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +31 -7
- package/api/doctor/theme-checks.d.mts +35 -3
- package/api/doctor/theme-checks.mjs +377 -29
- package/api/hook/_adapter.d.mts +10 -4
- package/api/hook/_adapter.mjs +41 -5
- package/api/hook/detail/detail.mjs +5 -2
- package/api/hook/detail/params/params.mjs +10 -3
- 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/add-helpers.mjs +10 -0
- package/api/integration/authoring-checks.mjs +11 -8
- 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/pack-check.mjs +16 -1
- package/api/integration/validate-integration.d.mts +18 -6
- package/api/integration/validate-integration.mjs +129 -15
- package/api/integration/validate-integration.type.d.mts +22 -0
- package/api/integration/validate-integration.type.mjs +2 -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 +53 -1
- package/api/render/render.type.mjs +32 -2
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.d.mts +9 -4
- package/api/search/_candidate-score.mjs +133 -46
- 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 +14 -0
- package/api/search/_lexical.mjs +93 -11
- 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/template/_adapter.d.mts +16 -0
- package/api/template/_adapter.mjs +39 -2
- package/api/template/cdn/cdn.mjs +37 -8
- package/api/template/copy/copy.d.mts +6 -3
- package/api/template/copy/copy.mjs +40 -8
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +63 -11
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/_adapter.d.mts +12 -1
- package/api/theme/_adapter.mjs +132 -13
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.d.mts +142 -1
- package/api/theme/build/build.mjs +692 -284
- 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 +80 -5
- package/api/theme/build/font-warning.mjs +323 -55
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/build/null-values.d.mts +28 -0
- package/api/theme/build/null-values.mjs +191 -0
- package/api/theme/list/list.mjs +17 -1
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +7 -3
- package/api/theme/theme.type.d.mts +78 -1
- package/api/theme/theme.type.mjs +38 -2
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +116 -4
- package/api/theme-edit/_adapter.mjs +1058 -93
- package/api/theme-edit/_catalog.d.mts +46 -2
- package/api/theme-edit/_catalog.mjs +115 -14
- package/api/theme-edit/_check.d.mts +133 -24
- package/api/theme-edit/_check.mjs +3392 -531
- package/api/theme-edit/_color.d.mts +26 -0
- package/api/theme-edit/_color.mjs +92 -2
- package/api/theme-edit/_compiler.d.mts +5 -1
- package/api/theme-edit/_compiler.mjs +141 -17
- package/api/theme-edit/_context.d.mts +74 -6
- package/api/theme-edit/_context.mjs +468 -76
- package/api/theme-edit/_css.d.mts +21 -0
- package/api/theme-edit/_css.mjs +87 -14
- package/api/theme-edit/_edit.d.mts +74 -7
- package/api/theme-edit/_edit.mjs +4426 -319
- package/api/theme-edit/_how-commands.d.mts +76 -1
- package/api/theme-edit/_how-commands.mjs +793 -9
- package/api/theme-edit/_how-question.d.mts +97 -6
- package/api/theme-edit/_how-question.mjs +9184 -747
- package/api/theme-edit/_how.d.mts +5 -2
- package/api/theme-edit/_how.mjs +255 -46
- 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 +322 -0
- package/api/theme-edit/_normal.mjs +1630 -0
- package/api/theme-edit/_palette.d.mts +49 -0
- package/api/theme-edit/_palette.mjs +180 -38
- package/api/theme-edit/_part-words.d.mts +39 -0
- package/api/theme-edit/_part-words.mjs +152 -0
- package/api/theme-edit/_parts.d.mts +55 -3
- package/api/theme-edit/_parts.mjs +421 -36
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +1108 -599
- package/api/theme-edit/_preview.d.mts +156 -19
- package/api/theme-edit/_preview.mjs +809 -180
- package/api/theme-edit/_project.d.mts +61 -1
- package/api/theme-edit/_project.mjs +177 -6
- package/api/theme-edit/_settings.d.mts +619 -48
- package/api/theme-edit/_settings.mjs +4910 -617
- package/api/theme-edit/_tables.d.mts +41 -0
- package/api/theme-edit/_tables.mjs +261 -41
- 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 +34 -2
- package/api/theme-edit/theme-edit.type.mjs +18 -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/api/upgrade/upgrade.mjs +16 -1
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +151 -18
- package/assets/codemods/runner.mjs +1 -4
- 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 +2 -0
- package/assets/docs/theme.doc.dense.mjs +76 -7
- package/assets/docs/theme.doc.mjs +66 -2
- package/assets/docs/theme.doc.zh.mjs +51 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +46 -5
- 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/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs-routes.generated.json +1 -0
- 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/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -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/page.tsx +31 -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/page.tsx +1 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/page.tsx +60 -7
- 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/page.tsx +13 -13
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- 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/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +33 -2
- package/assets/templates/pages/kanban-board/page.tsx +12 -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/page.tsx +16 -0
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/page.tsx +19 -6
- 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/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- 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/page.tsx +162 -12
- 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/page.tsx +11 -3
- 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/page.tsx +9 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/page.tsx +14 -1
- 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/page.tsx +47 -7
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +9 -2
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +9 -9
- 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/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +24 -1
- package/authoring/integration/schema.mjs +126 -4
- package/authoring/integration/type.ts +14 -0
- 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/discover.mjs +70 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +44 -6
- package/clients/cli/commands/doctor.mjs +84 -16
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +1032 -134
- 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 +2 -2
- 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 +2 -2
- 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-remove.doc.mjs +4 -4
- 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.doc.mjs +1 -1
- package/clients/cli/commands/template.mjs +15 -2
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +849 -441
- package/clients/cli/commands/upgrade.mjs +46 -8
- package/clients/cli/index.mjs +9 -19
- 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 +265 -29
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/lib/stray-option.mjs +478 -0
- package/clients/cli/lib/unknown-command.mjs +353 -0
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +26 -29
- package/foundation/config/theme-state.d.mts +31 -2
- package/foundation/config/theme-state.mjs +140 -8
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
- package/foundation/discovery/cli-self-doc-names.mjs +51 -0
- package/foundation/discovery/cli-self-docs.d.mts +0 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -15
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +59 -10
- 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/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/docs-discovery.d.mts +66 -9
- package/foundation/discovery/docs-discovery.mjs +126 -60
- package/foundation/discovery/entry-name-files.d.mts +106 -0
- package/foundation/discovery/entry-name-files.mjs +354 -0
- package/foundation/discovery/hook-discovery.d.mts +18 -2
- package/foundation/discovery/hook-discovery.mjs +93 -42
- 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-component-views.d.mts +15 -0
- package/foundation/discovery/integration-component-views.mjs +91 -0
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/module-exports.d.mts +26 -1
- package/foundation/discovery/module-exports.mjs +114 -40
- package/foundation/discovery/name-roots.d.mts +38 -0
- package/foundation/discovery/name-roots.mjs +108 -0
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- 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 +40 -18
- package/foundation/discovery/template-adapter.d.mts +49 -29
- package/foundation/discovery/template-adapter.mjs +89 -99
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/template-ids.d.mts +69 -0
- package/foundation/discovery/template-ids.mjs +199 -0
- package/foundation/discovery/theme-discovery.d.mts +12 -0
- package/foundation/discovery/theme-discovery.mjs +34 -4
- package/foundation/discovery/theme-imports.d.mts +24 -0
- package/foundation/discovery/theme-imports.mjs +61 -4
- package/foundation/discovery/theming-targets.d.mts +13 -5
- package/foundation/discovery/theming-targets.mjs +41 -47
- package/foundation/doc-compiler/generated-levels.d.mts +43 -0
- package/foundation/doc-compiler/generated-levels.mjs +72 -0
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/literal-doc.d.mts +12 -0
- package/foundation/doc-compiler/literal-doc.mjs +322 -0
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +29 -0
- package/foundation/doc-compiler/stored-docs.mjs +63 -1
- package/foundation/doc-compiler/tree.d.mts +4 -84
- package/foundation/doc-compiler/tree.mjs +4 -62
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +46 -0
- package/foundation/fonts/font-stylesheet.mjs +173 -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 +16 -5
- package/foundation/fs/gather-cache.d.mts +94 -4
- package/foundation/fs/gather-cache.mjs +671 -106
- package/foundation/fs/glob.d.mts +16 -0
- package/foundation/fs/glob.mjs +105 -0
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +80 -0
- package/foundation/fs/kept-tree.mjs +240 -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/path-safety.d.mts +11 -2
- package/foundation/fs/path-safety.mjs +108 -18
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +56 -7
- package/foundation/fs/read-record.mjs +280 -56
- package/foundation/fs/regular-file.d.mts +29 -0
- package/foundation/fs/regular-file.mjs +77 -0
- 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/integrations.d.mts +23 -1
- package/foundation/integrations/integrations.mjs +18 -1
- package/foundation/integrations/pack-state.d.mts +75 -0
- package/foundation/integrations/pack-state.mjs +314 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/shipped-imports.d.mts +122 -0
- package/foundation/integrations/shipped-imports.mjs +497 -0
- package/foundation/integrations/validate-contributions.d.mts +0 -17
- package/foundation/integrations/validate-contributions.mjs +59 -333
- package/foundation/render/assets.mjs +52 -7
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +70 -7
- package/foundation/render/embedded-imports.mjs +132 -41
- 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/layers.d.mts +30 -0
- package/foundation/render/layers.mjs +158 -0
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/offline.d.mts +32 -0
- package/foundation/render/offline.mjs +56 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +354 -21
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +192 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +46 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +79 -5
- package/foundation/render/render-page.mjs +735 -109
- 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 +6 -6
- package/foundation/suggest/name-index.d.mts +148 -0
- package/foundation/suggest/name-index.mjs +317 -0
- package/foundation/suggest/other-command.d.mts +140 -0
- package/foundation/suggest/other-command.mjs +756 -0
- 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/entry-names.d.mts +14 -0
- package/foundation/text/entry-names.mjs +14 -0
- package/foundation/text/string-utils.d.mts +46 -6
- package/foundation/text/string-utils.mjs +118 -20
- package/foundation/text/suggest-order.d.mts +47 -4
- package/foundation/text/suggest-order.mjs +174 -5
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -17,26 +17,40 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import * as fs from 'node:fs';
|
|
20
|
+
import * as os from 'node:os';
|
|
20
21
|
import * as path from 'node:path';
|
|
21
22
|
import {fork, spawnSync} from 'node:child_process';
|
|
23
|
+
import {builtinModules} from 'node:module';
|
|
22
24
|
import {fileURLToPath} from 'node:url';
|
|
23
25
|
import postcss from 'postcss';
|
|
24
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
assetDataUri,
|
|
28
|
+
isAssetBytes,
|
|
29
|
+
isAssetPath,
|
|
30
|
+
MAX_ASSET_BYTES,
|
|
31
|
+
RenderAssetError,
|
|
32
|
+
} from './assets.mjs';
|
|
25
33
|
import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
|
|
26
|
-
import {sourceBlock} from './source-block.mjs';
|
|
34
|
+
import {asParsed, formatFor, sha256, sourceBlock} from './source-block.mjs';
|
|
27
35
|
import {embeddedPathProblem} from './embedded-files.mjs';
|
|
28
|
-
import {
|
|
36
|
+
import {scanHtml} from './html-reader.mjs';
|
|
37
|
+
import {removeOnStop} from '../fs/stop-cleanup.mjs';
|
|
38
|
+
import {aliasOnly, assetRefsOf} from './embedded-imports.mjs';
|
|
39
|
+
import {isServedPackage, resolveServed} from './served-packages.mjs';
|
|
29
40
|
import {CHART_CSS} from './charts.mjs';
|
|
30
41
|
import {HOST_EXIT} from './host-exit.mjs';
|
|
42
|
+
import {endNote, headerNote} from './file-header.mjs';
|
|
43
|
+
import {textRuns} from './markup-edits.mjs';
|
|
44
|
+
import {findNodeModulesPackage, isInside} from '../fs/paths.mjs';
|
|
31
45
|
|
|
32
46
|
/** How long one page may take to render before it is stopped. */
|
|
33
47
|
export const RENDER_TIMEOUT_MS = 60_000;
|
|
34
48
|
|
|
35
|
-
export {PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
49
|
+
export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
36
50
|
|
|
37
51
|
/**
|
|
38
52
|
* @typedef {object} RenderWarning
|
|
39
|
-
* @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'not-embedded' | 'node-crash'} code - What kind of problem.
|
|
53
|
+
* @property {'dropped-children' | 'remote-asset' | 'missing-asset' | 'page-output' | 'page-script' | 'no-astryx-styles' | 'chart-size' | 'screen-query' | 'not-embedded' | 'node-crash'} code - What kind of problem.
|
|
40
54
|
* @property {string} message - What happened and what to do, in one sentence.
|
|
41
55
|
*/
|
|
42
56
|
|
|
@@ -68,23 +82,88 @@ export class RenderError extends Error {
|
|
|
68
82
|
}
|
|
69
83
|
|
|
70
84
|
/**
|
|
71
|
-
* The nearest folder at or above `dir` with a package.json,
|
|
85
|
+
* The nearest folder at or above `dir` with a package.json, or null outside
|
|
86
|
+
* a project.
|
|
72
87
|
* @param {string} dir
|
|
88
|
+
* @returns {string | null}
|
|
73
89
|
*/
|
|
74
|
-
function
|
|
75
|
-
let d = dir;
|
|
76
|
-
for (;;) {
|
|
90
|
+
function projectOf(dir) {
|
|
91
|
+
for (let d = dir; ; d = path.dirname(d)) {
|
|
77
92
|
if (fs.existsSync(path.join(d, 'package.json'))) return d;
|
|
78
|
-
|
|
79
|
-
if (up === d) return dir;
|
|
80
|
-
d = up;
|
|
93
|
+
if (path.dirname(d) === d) return null;
|
|
81
94
|
}
|
|
82
95
|
}
|
|
83
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Whether a path names a file. A name the system cannot look up (a segment
|
|
99
|
+
* too long, a folder it may not read) names none.
|
|
100
|
+
* @param {string} file
|
|
101
|
+
*/
|
|
102
|
+
function isFileAt(file) {
|
|
103
|
+
try {
|
|
104
|
+
return fs.statSync(file).isFile();
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The first bytes of a file, enough to tell its format.
|
|
112
|
+
* @param {string} file
|
|
113
|
+
*/
|
|
114
|
+
function headOf(file) {
|
|
115
|
+
const fd = fs.openSync(file, 'r');
|
|
116
|
+
try {
|
|
117
|
+
const head = Buffer.alloc(4096);
|
|
118
|
+
return head.subarray(0, fs.readSync(fd, head, 0, head.length, 0));
|
|
119
|
+
} finally {
|
|
120
|
+
fs.closeSync(fd);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The folder whose modules the page carries: its project's. Outside a
|
|
126
|
+
* project, the current folder when it holds the page, so a page with
|
|
127
|
+
* neighbours above its own folder (as a restore lays them out) carries them;
|
|
128
|
+
* else the page's folder.
|
|
129
|
+
* @param {string} dir
|
|
130
|
+
* @param {string} [cwd]
|
|
131
|
+
*/
|
|
132
|
+
function carryScopeOf(dir, cwd) {
|
|
133
|
+
const project = projectOf(dir);
|
|
134
|
+
if (project) return project;
|
|
135
|
+
return cwd && (dir === cwd || isInside(dir, cwd)) ? cwd : dir;
|
|
136
|
+
}
|
|
137
|
+
|
|
84
138
|
/** @param {string} s */
|
|
85
139
|
const escapeHtml = s =>
|
|
86
140
|
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
87
141
|
|
|
142
|
+
/**
|
|
143
|
+
* The attributes a page's root Theme puts on `<html>` in a browser, for the
|
|
144
|
+
* static page: Core's root provider sets `data-astryx-theme` (and
|
|
145
|
+
* `data-theme` for a one-mode page) on the document element once it runs,
|
|
146
|
+
* so root-scoped tokens (the focus ring's color) resolve against the theme.
|
|
147
|
+
* A page runs no script, so they are written here: from the outermost
|
|
148
|
+
* element the theme marks, the root Theme's own.
|
|
149
|
+
* @param {string} markup
|
|
150
|
+
*/
|
|
151
|
+
function rootThemeAttrs(markup) {
|
|
152
|
+
for (const t of scanHtml(markup)) {
|
|
153
|
+
if (t.kind !== 'start') continue;
|
|
154
|
+
const attrs = new Map(t.attrs);
|
|
155
|
+
if (!attrs.has('data-astryx-theme')) continue;
|
|
156
|
+
return ['data-astryx-theme', 'data-theme']
|
|
157
|
+
.filter(a => attrs.has(a))
|
|
158
|
+
.map(
|
|
159
|
+
a =>
|
|
160
|
+
` ${a}="${escapeHtml(String(attrs.get(a))).replace(/"/g, '"')}"`,
|
|
161
|
+
)
|
|
162
|
+
.join('');
|
|
163
|
+
}
|
|
164
|
+
return '';
|
|
165
|
+
}
|
|
166
|
+
|
|
88
167
|
/** @param {string} s */
|
|
89
168
|
const decodeAttr = s =>
|
|
90
169
|
s
|
|
@@ -101,7 +180,10 @@ const decodeAttr = s =>
|
|
|
101
180
|
* @returns {{url: string, layer: string | null, supports: string | null, media: string} | null}
|
|
102
181
|
*/
|
|
103
182
|
function importParams(params) {
|
|
104
|
-
const m =
|
|
183
|
+
const m =
|
|
184
|
+
/^\s*(?:url\(\s*(['"]?)([\s\S]*?)\1\s*\)|(['"])([\s\S]*?)\3)\s*([\s\S]*)$/.exec(
|
|
185
|
+
params,
|
|
186
|
+
);
|
|
105
187
|
if (!m) return null;
|
|
106
188
|
let rest = m[5];
|
|
107
189
|
/** @type {string | null} */
|
|
@@ -113,7 +195,9 @@ function importParams(params) {
|
|
|
113
195
|
}
|
|
114
196
|
/** @type {string | null} */
|
|
115
197
|
let supports = null;
|
|
116
|
-
const sup = /^supports\(((?:[^()]|\((?:[^()]|\([^()]*\))*\))*)\)\s*/i.exec(
|
|
198
|
+
const sup = /^supports\(((?:[^()]|\((?:[^()]|\([^()]*\))*\))*)\)\s*/i.exec(
|
|
199
|
+
rest,
|
|
200
|
+
);
|
|
117
201
|
if (sup) {
|
|
118
202
|
supports = sup[1];
|
|
119
203
|
rest = rest.slice(sup[0].length);
|
|
@@ -194,7 +278,10 @@ function expandImports(file, css, ctx) {
|
|
|
194
278
|
if (fromPackage) ctx.packageSheets.push(url.replace(/^~/, ''));
|
|
195
279
|
else ctx.carried.add(target);
|
|
196
280
|
const from = target;
|
|
197
|
-
let inner = expandImports(from, fs.readFileSync(from, 'utf8'), {
|
|
281
|
+
let inner = expandImports(from, fs.readFileSync(from, 'utf8'), {
|
|
282
|
+
...ctx,
|
|
283
|
+
seen,
|
|
284
|
+
});
|
|
198
285
|
// Keep the imported sheet's relative url()s pointing at the same files.
|
|
199
286
|
inner = inner.replace(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g, (u, q, r) => {
|
|
200
287
|
if (/^(data:|blob:|#|\/|[a-z]+:)/i.test(r)) return u;
|
|
@@ -205,13 +292,17 @@ function expandImports(file, css, ctx) {
|
|
|
205
292
|
return `url(${q}${rebased.startsWith('.') ? rebased : `./${rebased}`}${q})`;
|
|
206
293
|
});
|
|
207
294
|
// The import's conditions still scope what it brings in.
|
|
208
|
-
if (parsed.supports)
|
|
295
|
+
if (parsed.supports)
|
|
296
|
+
inner = `@supports (${parsed.supports.replace(/^\((.*)\)$/s, '$1')}){${inner}}`;
|
|
209
297
|
if (parsed.media) inner = `@media ${parsed.media}{${inner}}`;
|
|
210
|
-
if (parsed.layer !== null)
|
|
298
|
+
if (parsed.layer !== null)
|
|
299
|
+
inner = `@layer${parsed.layer ? ` ${parsed.layer}` : ''}{${inner}}`;
|
|
211
300
|
try {
|
|
212
301
|
rule.replaceWith(postcss.parse(inner, {from}).nodes);
|
|
213
302
|
} catch (e) {
|
|
214
|
-
const reason =
|
|
303
|
+
const reason =
|
|
304
|
+
/** @type {any} */ (e)?.reason ??
|
|
305
|
+
(e instanceof Error ? e.message : String(e));
|
|
215
306
|
throw new RenderError(
|
|
216
307
|
'ERR_RENDER_COMPILE',
|
|
217
308
|
`${path.basename(from)}, imported by ${path.basename(file)}, is not valid CSS: ${reason}`,
|
|
@@ -224,7 +315,14 @@ function expandImports(file, css, ctx) {
|
|
|
224
315
|
/** @typedef {{dir: string, integrations: readonly string[]}} ServedSet */
|
|
225
316
|
|
|
226
317
|
/** Signals that Node itself or a native module raises when it fails. */
|
|
227
|
-
const CRASH_SIGNALS = new Set([
|
|
318
|
+
const CRASH_SIGNALS = new Set([
|
|
319
|
+
'SIGSEGV',
|
|
320
|
+
'SIGBUS',
|
|
321
|
+
'SIGILL',
|
|
322
|
+
'SIGFPE',
|
|
323
|
+
'SIGABRT',
|
|
324
|
+
'SIGTRAP',
|
|
325
|
+
]);
|
|
228
326
|
|
|
229
327
|
/**
|
|
230
328
|
* How a native crash ended a process, or null when it was not one. On
|
|
@@ -235,7 +333,8 @@ const CRASH_SIGNALS = new Set(['SIGSEGV', 'SIGBUS', 'SIGILL', 'SIGFPE', 'SIGABRT
|
|
|
235
333
|
*/
|
|
236
334
|
function crashOf(code, signal) {
|
|
237
335
|
if (signal) return CRASH_SIGNALS.has(signal) ? signal : null;
|
|
238
|
-
if (code !== null && code >>> 0 >= 0xc0000000)
|
|
336
|
+
if (code !== null && code >>> 0 >= 0xc0000000)
|
|
337
|
+
return `0x${(code >>> 0).toString(16).toUpperCase()}`;
|
|
239
338
|
return null;
|
|
240
339
|
}
|
|
241
340
|
|
|
@@ -246,7 +345,10 @@ function crashOf(code, signal) {
|
|
|
246
345
|
function segmenterCrashes() {
|
|
247
346
|
const probe = spawnSync(
|
|
248
347
|
process.execPath,
|
|
249
|
-
[
|
|
348
|
+
[
|
|
349
|
+
'-e',
|
|
350
|
+
"[...new Intl.Segmenter('en', {granularity: 'grapheme'}).segment('a b')]",
|
|
351
|
+
],
|
|
250
352
|
{stdio: 'ignore', timeout: 10_000},
|
|
251
353
|
);
|
|
252
354
|
return crashOf(probe.status, probe.signal) !== null;
|
|
@@ -261,12 +363,25 @@ function segmenterCrashes() {
|
|
|
261
363
|
*/
|
|
262
364
|
function crashError(how, {crashed, withoutSegmenter}) {
|
|
263
365
|
const node = `Node ${process.version} (${process.execPath})`;
|
|
264
|
-
const detail = {
|
|
366
|
+
const detail = {
|
|
367
|
+
signal: how,
|
|
368
|
+
node: process.version,
|
|
369
|
+
nodePath: process.execPath,
|
|
370
|
+
};
|
|
265
371
|
if (!crashed) {
|
|
266
|
-
const memory =
|
|
267
|
-
|
|
372
|
+
const memory =
|
|
373
|
+
how === 'SIGKILL'
|
|
374
|
+
? ' The system stops a process this way when the machine runs out of memory.'
|
|
375
|
+
: '';
|
|
376
|
+
return new RenderError(
|
|
377
|
+
'ERR_RENDER_FAILED',
|
|
378
|
+
`${node} was stopped by a signal (${how}) while it rendered the page.${memory}`,
|
|
379
|
+
detail,
|
|
380
|
+
);
|
|
268
381
|
}
|
|
269
|
-
const cause = withoutSegmenter
|
|
382
|
+
const cause = withoutSegmenter
|
|
383
|
+
? ' It crashed again with Intl.Segmenter removed, so the fault is elsewhere in this Node or in a native module.'
|
|
384
|
+
: '';
|
|
270
385
|
return new RenderError(
|
|
271
386
|
'ERR_RENDER_FAILED',
|
|
272
387
|
`${node} crashed (${how}) while it rendered the page. A fault in Node or in a native module causes this, not the page's code.${cause} Render with an official Node.js build of another version.`,
|
|
@@ -279,14 +394,36 @@ function crashError(how, {crashed, withoutSegmenter}) {
|
|
|
279
394
|
* reported last, how long it ran, the memory left, and its last stderr line.
|
|
280
395
|
* @param {any} message the host's {hostExit, reason, stage, elapsedMs, rssMb, freeMb, stderrTail}
|
|
281
396
|
*/
|
|
282
|
-
function noAnswerError({
|
|
283
|
-
|
|
397
|
+
function noAnswerError({
|
|
398
|
+
hostExit,
|
|
399
|
+
reason,
|
|
400
|
+
stage,
|
|
401
|
+
elapsedMs,
|
|
402
|
+
rssMb,
|
|
403
|
+
freeMb,
|
|
404
|
+
stderrTail,
|
|
405
|
+
}) {
|
|
406
|
+
const detail = {
|
|
407
|
+
reason,
|
|
408
|
+
exit: hostExit,
|
|
409
|
+
stage,
|
|
410
|
+
elapsedMs,
|
|
411
|
+
rssMb,
|
|
412
|
+
freeMb,
|
|
413
|
+
...(stderrTail ? {stderrTail} : {}),
|
|
414
|
+
};
|
|
284
415
|
const where = stage ? ` while ${stage}` : '';
|
|
285
416
|
const seconds = Math.round((elapsedMs ?? 0) / 1000);
|
|
286
417
|
if (reason === 'host-timeout') {
|
|
287
|
-
return new RenderError(
|
|
418
|
+
return new RenderError(
|
|
419
|
+
'ERR_RENDER_TIMEOUT',
|
|
420
|
+
`The page's process stopped at its own time limit${where}, after ${seconds} seconds, before this process read an answer.`,
|
|
421
|
+
detail,
|
|
422
|
+
);
|
|
288
423
|
}
|
|
289
|
-
const last = stderrTail
|
|
424
|
+
const last = stderrTail
|
|
425
|
+
? ` Its last output: ${String(stderrTail).split('\n').at(-1)}`
|
|
426
|
+
: '';
|
|
290
427
|
return new RenderError(
|
|
291
428
|
'ERR_RENDER_FAILED',
|
|
292
429
|
`The page stopped rendering without an answer (exit ${hostExit})${where}, after ${seconds} seconds, with ${freeMb} MB of memory free.${last}`,
|
|
@@ -297,39 +434,173 @@ function noAnswerError({hostExit, reason, stage, elapsedMs, rssMb, freeMb, stder
|
|
|
297
434
|
/** The error for a host process that ended, without a signal, before it answered. */
|
|
298
435
|
function hostEndError(/** @type {number | null} */ code) {
|
|
299
436
|
if (code === HOST_EXIT.disconnected) {
|
|
300
|
-
return new RenderError(
|
|
437
|
+
return new RenderError(
|
|
438
|
+
'ERR_RENDER_FAILED',
|
|
439
|
+
"The page's process lost its channel to this process and stopped without an answer.",
|
|
440
|
+
{reason: 'disconnected', exit: code},
|
|
441
|
+
);
|
|
301
442
|
}
|
|
302
443
|
if (code === HOST_EXIT.noChannel) {
|
|
303
|
-
return new RenderError(
|
|
444
|
+
return new RenderError(
|
|
445
|
+
'ERR_RENDER_FAILED',
|
|
446
|
+
"The page's process had no channel left to send its answer on.",
|
|
447
|
+
{reason: 'no-channel', exit: code},
|
|
448
|
+
);
|
|
304
449
|
}
|
|
305
450
|
if (code === HOST_EXIT.timeout) {
|
|
306
|
-
return new RenderError(
|
|
451
|
+
return new RenderError(
|
|
452
|
+
'ERR_RENDER_TIMEOUT',
|
|
453
|
+
"The page's process stopped at its own time limit before this process read an answer.",
|
|
454
|
+
{reason: 'host-timeout', exit: code},
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
if (code === HOST_EXIT.sendFailed) {
|
|
458
|
+
return new RenderError(
|
|
459
|
+
'ERR_RENDER_FAILED',
|
|
460
|
+
"The page's process could not send its answer to this process.",
|
|
461
|
+
{reason: 'send-failed', exit: code},
|
|
462
|
+
);
|
|
307
463
|
}
|
|
308
|
-
return new RenderError(
|
|
464
|
+
return new RenderError(
|
|
465
|
+
'ERR_RENDER_FAILED',
|
|
466
|
+
`The page's process ended without an answer (exit ${code}).`,
|
|
467
|
+
{reason: 'host-ended', exit: code},
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* The error for a host that ended with no answer reaching this process, from
|
|
473
|
+
* the state it left in its per-run file: an answer it sent that never
|
|
474
|
+
* arrived, or the stage it ended in.
|
|
475
|
+
* @param {number | null} code
|
|
476
|
+
* @param {string | undefined} stateFile
|
|
477
|
+
*/
|
|
478
|
+
function noMessageError(code, stateFile) {
|
|
479
|
+
if (code !== 0 && code !== null && Object.values(HOST_EXIT).includes(code))
|
|
480
|
+
return hostEndError(code);
|
|
481
|
+
/** @type {any} */
|
|
482
|
+
let saved = null;
|
|
483
|
+
try {
|
|
484
|
+
saved = stateFile ? JSON.parse(fs.readFileSync(stateFile, 'utf8')) : null;
|
|
485
|
+
} catch {
|
|
486
|
+
// No readable state: fall back to the bare message below.
|
|
487
|
+
}
|
|
488
|
+
if (!saved) return hostEndError(code);
|
|
489
|
+
const detail = {
|
|
490
|
+
exit: code,
|
|
491
|
+
stage: saved.stage,
|
|
492
|
+
elapsedMs: saved.elapsedMs,
|
|
493
|
+
rssMb: saved.rssMb,
|
|
494
|
+
freeMb: saved.freeMb,
|
|
495
|
+
...(saved.stderrTail ? {stderrTail: saved.stderrTail} : {}),
|
|
496
|
+
};
|
|
497
|
+
if (saved.answered === 'sent') {
|
|
498
|
+
return new RenderError(
|
|
499
|
+
'ERR_RENDER_FAILED',
|
|
500
|
+
`The page's process sent its answer, but this process did not receive it (exit ${code}).`,
|
|
501
|
+
{reason: 'answer-lost', ...detail},
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
if (saved.answered === 'sending') {
|
|
505
|
+
return new RenderError(
|
|
506
|
+
'ERR_RENDER_FAILED',
|
|
507
|
+
`The page's process ended while it sent its answer (exit ${code}).`,
|
|
508
|
+
{reason: 'ended-while-sending', ...detail},
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
const seconds = Math.round((saved.elapsedMs ?? 0) / 1000);
|
|
512
|
+
const last = saved.stderrTail
|
|
513
|
+
? ` Its last output: ${String(saved.stderrTail).split('\n').at(-1)}`
|
|
514
|
+
: '';
|
|
515
|
+
return new RenderError(
|
|
516
|
+
'ERR_RENDER_FAILED',
|
|
517
|
+
`The page's process ended without an answer (exit ${code}) while ${saved.stage}, after ${seconds} seconds, with ${saved.freeMb} MB of memory free.${last}`,
|
|
518
|
+
{reason: 'host-ended', ...detail},
|
|
519
|
+
);
|
|
309
520
|
}
|
|
310
521
|
|
|
311
522
|
/**
|
|
312
523
|
* Run the page in a host process (page-host.mjs), stopping it after
|
|
313
524
|
* `timeoutMs`. The host runs the page in a worker thread, and it exits when
|
|
314
525
|
* this process goes away.
|
|
315
|
-
* @param {{entry: string, root: string, served: ServedSet | null, withoutSegmenter: boolean}} input
|
|
526
|
+
* @param {{entry: string, root: string, scope: string, served: ServedSet | null, withoutSegmenter: boolean}} input
|
|
316
527
|
* @param {number} timeoutMs
|
|
317
528
|
* @returns {Promise<any>} the page's answer, or `{crashed: how}` when a
|
|
318
529
|
* native crash ended the host
|
|
319
530
|
*/
|
|
320
531
|
function runWorker(input, timeoutMs) {
|
|
321
|
-
return
|
|
532
|
+
return withHostStateFile(stateFile => {
|
|
322
533
|
const data = {
|
|
323
534
|
...input,
|
|
324
|
-
served: input.served
|
|
535
|
+
served: input.served
|
|
536
|
+
? {dir: input.served.dir, integrations: [...input.served.integrations]}
|
|
537
|
+
: null,
|
|
325
538
|
timeoutMs,
|
|
539
|
+
stateFile,
|
|
326
540
|
};
|
|
327
|
-
const host = fork(
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
541
|
+
const host = fork(
|
|
542
|
+
fileURLToPath(new URL('./page-host.mjs', import.meta.url)),
|
|
543
|
+
[JSON.stringify(data)],
|
|
544
|
+
{
|
|
545
|
+
// Never the CLI's own flags (such as --input-type).
|
|
546
|
+
execArgv: [],
|
|
547
|
+
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
548
|
+
serialization: 'advanced',
|
|
549
|
+
},
|
|
550
|
+
);
|
|
551
|
+
return awaitHost(host, {
|
|
552
|
+
timeoutMs,
|
|
553
|
+
withoutSegmenter: input.withoutSegmenter,
|
|
554
|
+
stateFile,
|
|
332
555
|
});
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Run `use` with a state file for one host in a new folder under the system's
|
|
561
|
+
* temporary folder, never in the project, and remove the folder after. The
|
|
562
|
+
* state file only explains a failure: without a temporary folder, `use` gets
|
|
563
|
+
* none and the render runs without it.
|
|
564
|
+
* @template T
|
|
565
|
+
* @param {(stateFile: string | undefined) => Promise<T>} use
|
|
566
|
+
* @param {{makeTempDir?: (prefix: string) => string}} [options]
|
|
567
|
+
* @returns {Promise<T>}
|
|
568
|
+
*/
|
|
569
|
+
export async function withHostStateFile(
|
|
570
|
+
use,
|
|
571
|
+
{makeTempDir = prefix => fs.mkdtempSync(prefix)} = {},
|
|
572
|
+
) {
|
|
573
|
+
/** @type {string} */
|
|
574
|
+
let dir;
|
|
575
|
+
try {
|
|
576
|
+
dir = makeTempDir(path.join(os.tmpdir(), 'astryx-render-'));
|
|
577
|
+
} catch {
|
|
578
|
+
// No temporary folder (missing or read-only): render without the state file.
|
|
579
|
+
return use(undefined);
|
|
580
|
+
}
|
|
581
|
+
// A stop while the page renders removes the folder too.
|
|
582
|
+
const untrack = removeOnStop(dir);
|
|
583
|
+
try {
|
|
584
|
+
return await use(path.join(dir, 'host-state.json'));
|
|
585
|
+
} finally {
|
|
586
|
+
untrack();
|
|
587
|
+
try {
|
|
588
|
+
fs.rmSync(dir, {recursive: true, force: true, maxRetries: 3});
|
|
589
|
+
} catch {
|
|
590
|
+
// Best effort: a removal that fails (a file still held open) never
|
|
591
|
+
// replaces the render's own result.
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* The page's answer from its host process, or the reason it has none.
|
|
598
|
+
* @param {import('node:child_process').ChildProcess} host
|
|
599
|
+
* @param {{timeoutMs: number, withoutSegmenter: boolean, stateFile?: string}} options
|
|
600
|
+
* @returns {Promise<any>}
|
|
601
|
+
*/
|
|
602
|
+
export function awaitHost(host, {timeoutMs, withoutSegmenter, stateFile}) {
|
|
603
|
+
return new Promise((resolve, reject) => {
|
|
333
604
|
let settled = false;
|
|
334
605
|
/** @param {() => void} settle */
|
|
335
606
|
const finish = settle => {
|
|
@@ -356,8 +627,14 @@ function runWorker(input, timeoutMs) {
|
|
|
356
627
|
const text = String(message.hostError);
|
|
357
628
|
reject(
|
|
358
629
|
/ERR_WORKER_OUT_OF_MEMORY|heap out of memory/.test(text)
|
|
359
|
-
? new RenderError(
|
|
360
|
-
|
|
630
|
+
? new RenderError(
|
|
631
|
+
'ERR_RENDER_FAILED',
|
|
632
|
+
'The page ran out of memory while rendering.',
|
|
633
|
+
)
|
|
634
|
+
: new RenderError(
|
|
635
|
+
'ERR_RENDER_FAILED',
|
|
636
|
+
`The page could not be rendered: ${text.split('\n')[0]}`,
|
|
637
|
+
),
|
|
361
638
|
);
|
|
362
639
|
} else if (message?.hostExit !== undefined) {
|
|
363
640
|
reject(noAnswerError(message));
|
|
@@ -367,14 +644,24 @@ function runWorker(input, timeoutMs) {
|
|
|
367
644
|
});
|
|
368
645
|
});
|
|
369
646
|
host.once('error', error => {
|
|
370
|
-
finish(() =>
|
|
647
|
+
finish(() =>
|
|
648
|
+
reject(
|
|
649
|
+
new RenderError(
|
|
650
|
+
'ERR_RENDER_FAILED',
|
|
651
|
+
`The page could not be rendered: ${String(error?.message ?? error).split('\n')[0]}`,
|
|
652
|
+
),
|
|
653
|
+
),
|
|
654
|
+
);
|
|
371
655
|
});
|
|
372
|
-
|
|
656
|
+
// 'close' comes after the IPC channel drains, so an answer the host sent
|
|
657
|
+
// just before it exited still wins; 'exit' can come first under load.
|
|
658
|
+
host.once('close', (code, signal) => {
|
|
373
659
|
finish(() => {
|
|
374
660
|
const crash = crashOf(code, signal);
|
|
375
661
|
if (crash) resolve({crashed: crash});
|
|
376
|
-
else if (signal)
|
|
377
|
-
|
|
662
|
+
else if (signal)
|
|
663
|
+
reject(crashError(signal, {crashed: false, withoutSegmenter}));
|
|
664
|
+
else reject(noMessageError(code, stateFile));
|
|
378
665
|
});
|
|
379
666
|
});
|
|
380
667
|
});
|
|
@@ -383,7 +670,7 @@ function runWorker(input, timeoutMs) {
|
|
|
383
670
|
/**
|
|
384
671
|
* Run the page. When this Node crashes in Intl.Segmenter, run it once more
|
|
385
672
|
* without Intl.Segmenter and say so in a warning.
|
|
386
|
-
* @param {{entry: string, root: string, served: ServedSet | null}} input
|
|
673
|
+
* @param {{entry: string, root: string, scope: string, served: ServedSet | null, openLayers?: boolean}} input
|
|
387
674
|
* @param {number} timeoutMs
|
|
388
675
|
* @param {RenderWarning[]} warnings
|
|
389
676
|
*/
|
|
@@ -391,9 +678,14 @@ async function runPage(input, timeoutMs, warnings) {
|
|
|
391
678
|
const started = Date.now();
|
|
392
679
|
const first = await runWorker({...input, withoutSegmenter: false}, timeoutMs);
|
|
393
680
|
if (!first.crashed) return first;
|
|
394
|
-
if (!segmenterCrashes())
|
|
395
|
-
|
|
396
|
-
|
|
681
|
+
if (!segmenterCrashes())
|
|
682
|
+
throw crashError(first.crashed, {crashed: true, withoutSegmenter: false});
|
|
683
|
+
const again = await runWorker(
|
|
684
|
+
{...input, withoutSegmenter: true},
|
|
685
|
+
Math.max(1000, timeoutMs - (Date.now() - started)),
|
|
686
|
+
);
|
|
687
|
+
if (again.crashed)
|
|
688
|
+
throw crashError(again.crashed, {crashed: true, withoutSegmenter: true});
|
|
397
689
|
warnings.push(segmenterWarning());
|
|
398
690
|
return again;
|
|
399
691
|
}
|
|
@@ -409,6 +701,73 @@ export function segmenterWarning() {
|
|
|
409
701
|
};
|
|
410
702
|
}
|
|
411
703
|
|
|
704
|
+
/**
|
|
705
|
+
* A CSS `url()` as CSS reads it: a quoted reference may hold parentheses
|
|
706
|
+
* and the other quote (`url("./a(1).png")`); an unquoted one holds neither.
|
|
707
|
+
* Read its reference with {@link cssUrlRef}.
|
|
708
|
+
*/
|
|
709
|
+
export const CSS_URL =
|
|
710
|
+
/url\(\s*(?:"(?<dq>[^"]*)"|'(?<sq>[^']*)'|(?<bare>[^'"()\s]+))\s*\)/;
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* The reference a {@link CSS_URL} match names.
|
|
714
|
+
* @param {RegExpMatchArray} m
|
|
715
|
+
* @returns {string}
|
|
716
|
+
*/
|
|
717
|
+
export function cssUrlRef(m) {
|
|
718
|
+
return m.groups?.dq ?? m.groups?.sq ?? m.groups?.bare ?? '';
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* What a local file reference of a page or stylesheet names: nothing to
|
|
723
|
+
* inline (inline data, a fragment, a non-asset path), a remote file, a file
|
|
724
|
+
* that is not there, one that is not a regular file (a pipe, a device or a
|
|
725
|
+
* folder: never read), or the file to inline. One reader for the renderer
|
|
726
|
+
* and for callers that say what a page will not show.
|
|
727
|
+
* @param {string} ref as written in src, poster or url()
|
|
728
|
+
* @param {{dir: string, root: string}} at the folder it is relative to,
|
|
729
|
+
* and the project root (for `/` paths, `public/` first)
|
|
730
|
+
* A reference is URL text: it names the file its percent-escapes decode to
|
|
731
|
+
* (`a%20b.png` is "a b.png"), as a browser and the app's bundler read it.
|
|
732
|
+
* A file that cannot be read (no permission) is `unreadable`.
|
|
733
|
+
* @returns {null | {kind: 'remote', ref: string} | {kind: 'missing', ref: string} | {kind: 'not-file' | 'unreadable' | 'file', ref: string, file: string}}
|
|
734
|
+
*/
|
|
735
|
+
export function assetRef(ref, at) {
|
|
736
|
+
const clean = decodeAttr(ref).trim().split(/[?#]/)[0];
|
|
737
|
+
if (!clean) return null;
|
|
738
|
+
if (/^(data:|blob:|#|about:|mailto:|tel:|javascript:)/i.test(clean))
|
|
739
|
+
return null;
|
|
740
|
+
if (/^(https?:)?\/\//i.test(clean)) return {kind: 'remote', ref: clean};
|
|
741
|
+
/** @type {string} */
|
|
742
|
+
let named;
|
|
743
|
+
try {
|
|
744
|
+
named = decodeURIComponent(clean);
|
|
745
|
+
} catch {
|
|
746
|
+
// A % that starts no escape is the character itself.
|
|
747
|
+
named = clean;
|
|
748
|
+
}
|
|
749
|
+
if (!isAssetPath(named)) return null;
|
|
750
|
+
const candidates = named.startsWith('/')
|
|
751
|
+
? [path.join(at.root, 'public', named), path.join(at.root, named)]
|
|
752
|
+
: [path.resolve(at.dir, named)];
|
|
753
|
+
const found = candidates.find(c => fs.existsSync(c));
|
|
754
|
+
if (!found) return {kind: 'missing', ref: clean};
|
|
755
|
+
/** @type {fs.Stats | undefined} */
|
|
756
|
+
let st;
|
|
757
|
+
try {
|
|
758
|
+
st = fs.statSync(found);
|
|
759
|
+
} catch {
|
|
760
|
+
return {kind: 'missing', ref: clean};
|
|
761
|
+
}
|
|
762
|
+
if (!st.isFile()) return {kind: 'not-file', ref: clean, file: found};
|
|
763
|
+
try {
|
|
764
|
+
fs.accessSync(found, fs.constants.R_OK);
|
|
765
|
+
} catch {
|
|
766
|
+
return {kind: 'unreadable', ref: clean, file: found};
|
|
767
|
+
}
|
|
768
|
+
return {kind: 'file', ref: clean, file: found};
|
|
769
|
+
}
|
|
770
|
+
|
|
412
771
|
/**
|
|
413
772
|
* Inline local images (src, srcset, poster and CSS url()) as data: URIs. A
|
|
414
773
|
* link (`href`) loads nothing, so it is left alone.
|
|
@@ -419,10 +778,10 @@ export function segmenterWarning() {
|
|
|
419
778
|
function inlineAssets(text, kind, ctx) {
|
|
420
779
|
/** @param {string} ref */
|
|
421
780
|
const resolveRef = ref => {
|
|
422
|
-
const
|
|
423
|
-
if (!
|
|
424
|
-
|
|
425
|
-
if (
|
|
781
|
+
const named = assetRef(ref, ctx);
|
|
782
|
+
if (!named) return null;
|
|
783
|
+
const clean = named.ref;
|
|
784
|
+
if (named.kind === 'remote') {
|
|
426
785
|
const key = `remote:${clean}`;
|
|
427
786
|
if (!ctx.counted.has(key)) {
|
|
428
787
|
ctx.counted.add(key);
|
|
@@ -433,22 +792,23 @@ function inlineAssets(text, kind, ctx) {
|
|
|
433
792
|
}
|
|
434
793
|
return null;
|
|
435
794
|
}
|
|
436
|
-
if (
|
|
437
|
-
const candidates = clean.startsWith('/')
|
|
438
|
-
? [path.join(ctx.root, 'public', clean), path.join(ctx.root, clean)]
|
|
439
|
-
: [path.resolve(ctx.dir, clean)];
|
|
440
|
-
const found = candidates.find(c => fs.existsSync(c));
|
|
441
|
-
if (!found) {
|
|
795
|
+
if (named.kind !== 'file') {
|
|
442
796
|
const key = `missing:${clean}`;
|
|
443
797
|
if (!ctx.counted.has(key)) {
|
|
444
798
|
ctx.counted.add(key);
|
|
445
799
|
ctx.warnings.push({
|
|
446
800
|
code: 'missing-asset',
|
|
447
|
-
message:
|
|
801
|
+
message:
|
|
802
|
+
named.kind === 'missing'
|
|
803
|
+
? `${clean} was not found next to the page, so it is left as is and will not show.`
|
|
804
|
+
: named.kind === 'unreadable'
|
|
805
|
+
? `${clean} cannot be read (no permission), so it is left as is and will not show.`
|
|
806
|
+
: `${clean} is not a regular file (a pipe, a device or a folder), so it is not read and will not show.`,
|
|
448
807
|
});
|
|
449
808
|
}
|
|
450
809
|
return null;
|
|
451
810
|
}
|
|
811
|
+
const found = named.file;
|
|
452
812
|
ctx.counted.add(`file:${found}`);
|
|
453
813
|
// A relative path names a file that is part of the page: carry it.
|
|
454
814
|
if (!clean.startsWith('/')) ctx.localAssets.add(found);
|
|
@@ -456,8 +816,10 @@ function inlineAssets(text, kind, ctx) {
|
|
|
456
816
|
};
|
|
457
817
|
/** @param {string} value */
|
|
458
818
|
const urls = value =>
|
|
459
|
-
value.replace(
|
|
460
|
-
const uri = resolveRef(
|
|
819
|
+
value.replace(new RegExp(CSS_URL.source, 'g'), (whole, ...rest) => {
|
|
820
|
+
const uri = resolveRef(
|
|
821
|
+
cssUrlRef(/** @type {any} */ ({groups: rest.at(-1)})),
|
|
822
|
+
);
|
|
461
823
|
return uri ? `url("${uri}")` : whole;
|
|
462
824
|
});
|
|
463
825
|
if (kind === 'css') return urls(text);
|
|
@@ -484,6 +846,31 @@ function inlineAssets(text, kind, ctx) {
|
|
|
484
846
|
});
|
|
485
847
|
}
|
|
486
848
|
|
|
849
|
+
/**
|
|
850
|
+
* The version of a package the page rendered with: the package set's copy
|
|
851
|
+
* when the page took it from there, else the copy Node's resolver finds from
|
|
852
|
+
* the page's folder.
|
|
853
|
+
* @param {string} name
|
|
854
|
+
* @param {string} dir the page's folder
|
|
855
|
+
* @param {Map<string, string>} setDirs the packages the page took from the package set: their folders
|
|
856
|
+
* @returns {string | null}
|
|
857
|
+
*/
|
|
858
|
+
function installedVersion(name, dir, setDirs) {
|
|
859
|
+
const packageDir =
|
|
860
|
+
setDirs.get(name) ?? findNodeModulesPackage(dir, name)?.packageDir;
|
|
861
|
+
if (!packageDir) return null;
|
|
862
|
+
try {
|
|
863
|
+
const pkg = JSON.parse(
|
|
864
|
+
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'),
|
|
865
|
+
);
|
|
866
|
+
return pkg?.name === name && typeof pkg.version === 'string'
|
|
867
|
+
? pkg.version
|
|
868
|
+
: null;
|
|
869
|
+
} catch {
|
|
870
|
+
return null;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
487
874
|
/** The light and dark switch every rendered page carries. */
|
|
488
875
|
const SCHEME_CSS =
|
|
489
876
|
':root{color-scheme:light dark}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}';
|
|
@@ -491,20 +878,38 @@ const SCHEME_CSS =
|
|
|
491
878
|
/**
|
|
492
879
|
* Render a page module to one self-contained HTML file.
|
|
493
880
|
* @param {string} entry absolute path of the page module
|
|
494
|
-
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null}} [options]
|
|
881
|
+
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string, openLayers?: boolean}} [options]
|
|
495
882
|
* `served`: the Core of the package set the CLI runs from, for the packages
|
|
496
|
-
* the page's folder has no copy of
|
|
883
|
+
* the page's folder has no copy of; `output`: the file the HTML goes to;
|
|
884
|
+
* `cwd`: the current folder, whose files are the page's own outside a
|
|
885
|
+
* project; `openLayers`: the overlays the page shows or opens are drawn
|
|
886
|
+
* and added after its markup (layers.mjs), for reading what they paint.
|
|
887
|
+
* With `output`, the file describes itself: notes at its top and end name
|
|
888
|
+
* what made it and the commands that give the page back and render it
|
|
889
|
+
* again, and its embedded source records the CLI version, the packages
|
|
890
|
+
* the page rendered with, and the markup as rendered.
|
|
497
891
|
* @returns {Promise<RenderedPage>}
|
|
498
892
|
*/
|
|
499
893
|
export async function renderPage(entry, options = {}) {
|
|
500
894
|
const dir = path.dirname(entry);
|
|
501
|
-
|
|
895
|
+
// The project's folder, else the page's: where its tsconfig.json and
|
|
896
|
+
// public/ images are read.
|
|
897
|
+
const root = projectOf(dir) ?? dir;
|
|
898
|
+
const scope = carryScopeOf(dir, options.cwd);
|
|
502
899
|
const served = options.served ?? null;
|
|
503
900
|
/** @type {RenderWarning[]} */
|
|
504
901
|
const warnings = [];
|
|
505
|
-
const message = await runPage(
|
|
902
|
+
const message = await runPage(
|
|
903
|
+
{entry, root, scope, served, openLayers: options.openLayers === true},
|
|
904
|
+
options.timeoutMs ?? RENDER_TIMEOUT_MS,
|
|
905
|
+
warnings,
|
|
906
|
+
);
|
|
506
907
|
if (!message.ok) {
|
|
507
|
-
throw new RenderError(
|
|
908
|
+
throw new RenderError(
|
|
909
|
+
message.error.code,
|
|
910
|
+
message.error.message,
|
|
911
|
+
message.error.detail,
|
|
912
|
+
);
|
|
508
913
|
}
|
|
509
914
|
/** @type {string} */
|
|
510
915
|
let markup = message.markup;
|
|
@@ -533,7 +938,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
533
938
|
const hasCore = addSheet('@astryxdesign/core/reset.css');
|
|
534
939
|
if (hasCore) addSheet('@astryxdesign/core/astryx.css');
|
|
535
940
|
// Package stylesheets the page imports itself, such as a theme's.
|
|
536
|
-
for (const {spec, from} of /** @type {{spec: string, from: string}[]} */ (
|
|
941
|
+
for (const {spec, from} of /** @type {{spec: string, from: string}[]} */ (
|
|
942
|
+
message.packageCss ?? []
|
|
943
|
+
)) {
|
|
537
944
|
if (sheets.includes(spec)) continue;
|
|
538
945
|
const file = resolveServed(spec, from, served);
|
|
539
946
|
try {
|
|
@@ -563,7 +970,13 @@ export async function renderPage(entry, options = {}) {
|
|
|
563
970
|
});
|
|
564
971
|
}
|
|
565
972
|
|
|
566
|
-
const ctx = {
|
|
973
|
+
const ctx = {
|
|
974
|
+
dir,
|
|
975
|
+
root,
|
|
976
|
+
warnings,
|
|
977
|
+
counted: new Set(),
|
|
978
|
+
localAssets: /** @type {Set<string>} */ (new Set()),
|
|
979
|
+
};
|
|
567
980
|
/** Stylesheets pulled in by another's `@import`. @type {Set<string>} */
|
|
568
981
|
const carriedCss = new Set();
|
|
569
982
|
try {
|
|
@@ -580,7 +993,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
580
993
|
'The page renders a <script> element. A sandboxed viewer blocks it, and anywhere else it runs when the file is opened; remove it from the page.',
|
|
581
994
|
});
|
|
582
995
|
}
|
|
583
|
-
for (const m of markup.matchAll(
|
|
996
|
+
for (const m of markup.matchAll(
|
|
997
|
+
/<(link|iframe|object|embed)\b[^>]*?\s(?:href|src|data)="([^"]*)"/gi,
|
|
998
|
+
)) {
|
|
584
999
|
if (/^(data:|#)/i.test(m[2])) continue;
|
|
585
1000
|
warnings.push({
|
|
586
1001
|
code: 'remote-asset',
|
|
@@ -589,7 +1004,8 @@ export async function renderPage(entry, options = {}) {
|
|
|
589
1004
|
}
|
|
590
1005
|
} catch (e) {
|
|
591
1006
|
const err = /** @type {any} */ (e);
|
|
592
|
-
if (err instanceof RenderAssetError)
|
|
1007
|
+
if (err instanceof RenderAssetError)
|
|
1008
|
+
throw new RenderError(err.code, err.message, err.detail);
|
|
593
1009
|
throw e;
|
|
594
1010
|
}
|
|
595
1011
|
const used = classesIn(markup);
|
|
@@ -604,11 +1020,22 @@ export async function renderPage(entry, options = {}) {
|
|
|
604
1020
|
/** A stylesheet's rules cut to the page, with its own imports inlined. @param {string} file @param {string} text */
|
|
605
1021
|
const sheet = (file, text) => {
|
|
606
1022
|
try {
|
|
607
|
-
const own = expandImports(file, text, {
|
|
608
|
-
|
|
1023
|
+
const own = expandImports(file, text, {
|
|
1024
|
+
warnings,
|
|
1025
|
+
carried: carriedCss,
|
|
1026
|
+
included,
|
|
1027
|
+
packageSheets,
|
|
1028
|
+
served,
|
|
1029
|
+
});
|
|
1030
|
+
return inlineAssets(cutCss(own, used), 'css', {
|
|
1031
|
+
...ctx,
|
|
1032
|
+
dir: path.dirname(file),
|
|
1033
|
+
});
|
|
609
1034
|
} catch (e) {
|
|
610
1035
|
if (e instanceof RenderAssetError || e instanceof RenderError) throw e;
|
|
611
|
-
const reason =
|
|
1036
|
+
const reason =
|
|
1037
|
+
/** @type {any} */ (e)?.reason ??
|
|
1038
|
+
(e instanceof Error ? e.message : String(e));
|
|
612
1039
|
throw new RenderError(
|
|
613
1040
|
'ERR_RENDER_COMPILE',
|
|
614
1041
|
`${path.relative(dir, file).split(path.sep).join('/')} is not valid CSS: ${reason}`,
|
|
@@ -618,14 +1045,21 @@ export async function renderPage(entry, options = {}) {
|
|
|
618
1045
|
sheetText.forEach((text, i) => {
|
|
619
1046
|
css += sheet(sheetFiles[i], text);
|
|
620
1047
|
});
|
|
621
|
-
for (const {
|
|
1048
|
+
for (const {
|
|
1049
|
+
file,
|
|
1050
|
+
css: text,
|
|
1051
|
+
} of /** @type {{file: string, css: string}[]} */ (
|
|
1052
|
+
message.importedCss ?? []
|
|
1053
|
+
)) {
|
|
622
1054
|
css += sheet(file, text);
|
|
623
1055
|
}
|
|
624
|
-
for (const spec of packageSheets)
|
|
1056
|
+
for (const spec of packageSheets)
|
|
1057
|
+
if (!sheets.includes(spec)) sheets.push(spec);
|
|
625
1058
|
if (message.css) css += inlineAssets(message.css, 'css', ctx);
|
|
626
1059
|
} catch (e) {
|
|
627
1060
|
const err = /** @type {any} */ (e);
|
|
628
|
-
if (err instanceof RenderAssetError)
|
|
1061
|
+
if (err instanceof RenderAssetError)
|
|
1062
|
+
throw new RenderError(err.code, err.message, err.detail);
|
|
629
1063
|
throw e;
|
|
630
1064
|
}
|
|
631
1065
|
// Keep inlined CSS from ending its own <style> element.
|
|
@@ -645,18 +1079,36 @@ export async function renderPage(entry, options = {}) {
|
|
|
645
1079
|
for (const t of /** @type {any[]} */ (message.texts ?? [])) {
|
|
646
1080
|
if (t.hidden || t.text.length < 2 || plainText.includes(t.text)) continue;
|
|
647
1081
|
// The code around it ran: other text from the same function rendered.
|
|
648
|
-
const around = /** @type {string[]} */ (
|
|
1082
|
+
const around = /** @type {string[]} */ (
|
|
1083
|
+
message.fnTexts?.[t.fn] ?? []
|
|
1084
|
+
).filter(o => o !== t.text);
|
|
649
1085
|
if (!around.some(o => plainText.includes(o))) continue;
|
|
650
1086
|
warnings.push({
|
|
651
1087
|
code: 'dropped-children',
|
|
652
1088
|
message: `<${t.component}> on line ${t.line} did not render the text "${t.text.length > 60 ? `${t.text.slice(0, 57)}...` : t.text}" it was given; it takes that text through a prop (often label=), so check its props.`,
|
|
653
1089
|
});
|
|
654
1090
|
}
|
|
1091
|
+
// The file runs no script, so a media query the page asks in JavaScript
|
|
1092
|
+
// keeps the answer it got on the server, whatever the reader's screen.
|
|
1093
|
+
const screenQueries = [
|
|
1094
|
+
...new Set(/** @type {{call: string}[]} */ (message.screenQueries ?? []).map(q => q.call)),
|
|
1095
|
+
];
|
|
1096
|
+
if (screenQueries.length > 0) {
|
|
1097
|
+
warnings.push({
|
|
1098
|
+
code: 'screen-query',
|
|
1099
|
+
message: `The page asks ${screenQueries.join(', ')} in JavaScript, which this file never runs: readers on every screen get its server answer, so fold the layout with CSS: Grid columns={{minWidth}}, or a StyleX @media or @container style.`,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
655
1102
|
// A chart the render did not draw is an empty box: a ResponsiveContainer
|
|
656
1103
|
// holds only its sizing box, and a chart of fixed size an empty wrapper.
|
|
657
1104
|
const blankCharts =
|
|
658
|
-
(
|
|
659
|
-
|
|
1105
|
+
(
|
|
1106
|
+
markup.match(
|
|
1107
|
+
/<div class="recharts-responsive-container[" ][^>]*><div[^>]*><\/div><\/div>/g,
|
|
1108
|
+
) ?? []
|
|
1109
|
+
).length +
|
|
1110
|
+
(markup.match(/<div\b[^>]*\bclass="recharts-wrapper"[^>]*><\/div>/g) ?? [])
|
|
1111
|
+
.length +
|
|
660
1112
|
(message.chartsFailed ?? 0);
|
|
661
1113
|
if (blankCharts > 0) {
|
|
662
1114
|
warnings.push({
|
|
@@ -667,8 +1119,10 @@ export async function renderPage(entry, options = {}) {
|
|
|
667
1119
|
if (message.chartsAlone) {
|
|
668
1120
|
/** @type {Record<string, string>} */
|
|
669
1121
|
const causes = {
|
|
670
|
-
changed:
|
|
671
|
-
|
|
1122
|
+
changed:
|
|
1123
|
+
'The page changed its charts once its effects ran (their data or props, or which charts it shows)',
|
|
1124
|
+
rerendered:
|
|
1125
|
+
"A component that makes a chart rendered again once the page's effects ran",
|
|
672
1126
|
error: 'The page could not be drawn again without a browser',
|
|
673
1127
|
};
|
|
674
1128
|
const why = causes[message.chartsAlone] ?? causes.error;
|
|
@@ -683,7 +1137,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
683
1137
|
message: `The page imports ${sheet}, a Sass or Less stylesheet, which a render does not compile, so its styles are missing.`,
|
|
684
1138
|
});
|
|
685
1139
|
}
|
|
686
|
-
for (const log of /** @type {{level: string, text: string}[]} */ (
|
|
1140
|
+
for (const log of /** @type {{level: string, text: string}[]} */ (
|
|
1141
|
+
message.logs ?? []
|
|
1142
|
+
).slice(0, 5)) {
|
|
687
1143
|
warnings.push({
|
|
688
1144
|
code: 'page-output',
|
|
689
1145
|
message: `The page printed while rendering (${log.level}): ${log.text.split('\n')[0].slice(0, 200)}`,
|
|
@@ -696,30 +1152,113 @@ export async function renderPage(entry, options = {}) {
|
|
|
696
1152
|
// (`<img src="./logo.png">`, `url(./bg.png)`) are carried too, so the page
|
|
697
1153
|
// comes back with them; a package's own files are not.
|
|
698
1154
|
for (const sheet of carriedCss) {
|
|
699
|
-
|
|
700
|
-
|
|
1155
|
+
if (
|
|
1156
|
+
!isInside(sheet, scope) ||
|
|
1157
|
+
path.relative(scope, sheet).split(path.sep).includes('node_modules')
|
|
1158
|
+
)
|
|
1159
|
+
continue;
|
|
701
1160
|
if (!files.includes(sheet)) files.push(sheet);
|
|
702
1161
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1162
|
+
/** Assets named in a warning already, so each is named once. @type {Set<string>} */
|
|
1163
|
+
const notCarried = new Set();
|
|
1164
|
+
/**
|
|
1165
|
+
* Carry an image, font or media file of the project's own. It is carried
|
|
1166
|
+
* only when its bytes are a known image, font or media format, the same
|
|
1167
|
+
* test --reverse applies, so the file always comes back.
|
|
1168
|
+
* @param {string} asset absolute
|
|
1169
|
+
* @param {string} how how the page uses it, for the warning
|
|
1170
|
+
*/
|
|
1171
|
+
const carryAsset = (asset, how) => {
|
|
1172
|
+
if (
|
|
1173
|
+
!isInside(asset, scope) ||
|
|
1174
|
+
path.relative(scope, asset).split(path.sep).includes('node_modules')
|
|
1175
|
+
)
|
|
1176
|
+
return;
|
|
1177
|
+
if (files.includes(asset) || notCarried.has(asset)) return;
|
|
1178
|
+
/** @param {string} why */
|
|
1179
|
+
const leaveOut = why => {
|
|
1180
|
+
notCarried.add(asset);
|
|
710
1181
|
warnings.push({
|
|
711
1182
|
code: 'not-embedded',
|
|
712
|
-
message: `${path.relative(dir, asset).split(path.sep).join('/')} is
|
|
1183
|
+
message: `${path.relative(dir, asset).split(path.sep).join('/')} is ${how} but not carried in the file: ${why}, so --reverse cannot give it back.`,
|
|
713
1184
|
});
|
|
714
|
-
|
|
1185
|
+
};
|
|
1186
|
+
/** @type {Buffer} */
|
|
1187
|
+
let head;
|
|
1188
|
+
try {
|
|
1189
|
+
// The same limit as a file the page shows, which a render inlines.
|
|
1190
|
+
if (fs.statSync(asset).size > MAX_ASSET_BYTES) {
|
|
1191
|
+
leaveOut(
|
|
1192
|
+
`it is larger than ${MAX_ASSET_BYTES / 1048576} MB, the most a rendered page carries of one file`,
|
|
1193
|
+
);
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
head = headOf(asset);
|
|
1197
|
+
} catch (e) {
|
|
1198
|
+
leaveOut(
|
|
1199
|
+
`it cannot be read (${/** @type {NodeJS.ErrnoException} */ (e).code ?? 'an error from the file system'})`,
|
|
1200
|
+
);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
if (!isAssetBytes(head)) {
|
|
1204
|
+
leaveOut('its bytes are not a known image, font or media format');
|
|
1205
|
+
return;
|
|
715
1206
|
}
|
|
716
1207
|
files.push(asset);
|
|
1208
|
+
};
|
|
1209
|
+
for (const asset of ctx.localAssets) carryAsset(asset, 'shown inline');
|
|
1210
|
+
// A carried module or stylesheet can name an image, font or media file by
|
|
1211
|
+
// a relative path. --reverse expects each such file back, also when this
|
|
1212
|
+
// render does not show it, when it lies inside the folder that holds the
|
|
1213
|
+
// carried files (a name that climbs out of it is not the page's file).
|
|
1214
|
+
let named = dir;
|
|
1215
|
+
for (const f of files) {
|
|
1216
|
+
while (!isInside(f, named)) named = path.dirname(named);
|
|
1217
|
+
}
|
|
1218
|
+
const carriedText = files.filter(
|
|
1219
|
+
f =>
|
|
1220
|
+
/\.(?:[cm]?[jt]sx?|css)$/i.test(f) &&
|
|
1221
|
+
(f === entry ||
|
|
1222
|
+
!embeddedPathProblem(
|
|
1223
|
+
path.relative(named, f).split(path.sep).join('/'),
|
|
1224
|
+
)),
|
|
1225
|
+
);
|
|
1226
|
+
for (const file of carriedText) {
|
|
1227
|
+
let text;
|
|
1228
|
+
try {
|
|
1229
|
+
text = fs.readFileSync(file, 'utf8');
|
|
1230
|
+
} catch {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
for (const ref of assetRefsOf(text, file)) {
|
|
1234
|
+
const asset = path.resolve(path.dirname(file), ref);
|
|
1235
|
+
if (!isInside(asset, named)) continue;
|
|
1236
|
+
if (isFileAt(asset)) {
|
|
1237
|
+
carryAsset(
|
|
1238
|
+
asset,
|
|
1239
|
+
`named in ${path.relative(dir, file).split(path.sep).join('/')}`,
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
717
1243
|
}
|
|
718
1244
|
// Paths are kept relative to the folder that holds every file: the page's
|
|
719
|
-
// folder, or an ancestor when the page imports from above it
|
|
1245
|
+
// folder, or an ancestor when the page imports from above it, but never one
|
|
1246
|
+
// from which the page's own path holds a name a reverse refuses (a
|
|
1247
|
+
// dot-folder): a file above that stays out of the file, and is named.
|
|
720
1248
|
let base = dir;
|
|
721
1249
|
for (const f of files) {
|
|
722
|
-
while (
|
|
1250
|
+
while (!isInside(f, base)) {
|
|
1251
|
+
const up = path.dirname(base);
|
|
1252
|
+
if (
|
|
1253
|
+
up === base ||
|
|
1254
|
+
embeddedPathProblem(
|
|
1255
|
+
path.relative(up, entry).split(path.sep).join('/'),
|
|
1256
|
+
{page: true},
|
|
1257
|
+
)
|
|
1258
|
+
)
|
|
1259
|
+
break;
|
|
1260
|
+
base = up;
|
|
1261
|
+
}
|
|
723
1262
|
}
|
|
724
1263
|
// Page first, so the reader knows which file is the page. Only files a
|
|
725
1264
|
// rendered page may carry are embedded (see embedded-files.mjs).
|
|
@@ -737,16 +1276,101 @@ export async function renderPage(entry, options = {}) {
|
|
|
737
1276
|
}
|
|
738
1277
|
embedded.push({path: rel, bytes: fs.readFileSync(f)});
|
|
739
1278
|
}
|
|
740
|
-
const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1279
|
+
const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i
|
|
1280
|
+
.exec(markup)?.[1]
|
|
1281
|
+
?.replace(/<[^>]*>/g, '')
|
|
1282
|
+
.trim();
|
|
1283
|
+
const title =
|
|
1284
|
+
options.title ??
|
|
1285
|
+
(heading
|
|
1286
|
+
? decodeAttr(heading)
|
|
1287
|
+
: path.basename(entry).replace(/\.[^.]+$/, ''));
|
|
1288
|
+
const generator = `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">`;
|
|
1289
|
+
const style = `<style>${SCHEME_CSS}${markup.includes('class="recharts-responsive-container"') ? CHART_CSS : ''}${css}</style>`;
|
|
1290
|
+
let html;
|
|
1291
|
+
if (options.output) {
|
|
1292
|
+
// The charset and generator metas come first: a browser reads the
|
|
1293
|
+
// charset only from the first 1024 bytes, and a CLI decides whether a
|
|
1294
|
+
// render wrote a file from its first 4096.
|
|
1295
|
+
const setDirs = new Map(
|
|
1296
|
+
/** @type {{name: string, dir: string}[]} */ (message.fromSet ?? []).map(
|
|
1297
|
+
p => [p.name, p.dir],
|
|
1298
|
+
),
|
|
1299
|
+
);
|
|
1300
|
+
const names = new Set([
|
|
1301
|
+
...(message.packages ?? []),
|
|
1302
|
+
...setDirs.keys(),
|
|
1303
|
+
'react',
|
|
1304
|
+
'react-dom',
|
|
1305
|
+
]);
|
|
1306
|
+
if (hasCore) names.add('@astryxdesign/core');
|
|
1307
|
+
/** @type {Record<string, string>} */
|
|
1308
|
+
const packages = {};
|
|
1309
|
+
for (const name of [...names].sort()) {
|
|
1310
|
+
if (name.startsWith('node:') || builtinModules.includes(name)) continue;
|
|
1311
|
+
const version = installedVersion(name, dir, setDirs);
|
|
1312
|
+
if (version) packages[name] = version;
|
|
1313
|
+
}
|
|
1314
|
+
const file = path.basename(options.output);
|
|
1315
|
+
const facts = {
|
|
1316
|
+
cli: options.version ?? null,
|
|
1317
|
+
format: formatFor(embedded),
|
|
1318
|
+
file,
|
|
1319
|
+
page: projectOf(dir)
|
|
1320
|
+
? path.relative(root, entry).split(path.sep).join('/')
|
|
1321
|
+
: embedded[0].path,
|
|
1322
|
+
restored: `${file.replace(/\.[^.]+$/, '')}-restored/${embedded[0].path}`,
|
|
1323
|
+
files: embedded.map(f => f.path),
|
|
1324
|
+
packages,
|
|
1325
|
+
install: Object.entries(packages)
|
|
1326
|
+
.filter(([name]) => !isServedPackage(name, []))
|
|
1327
|
+
.map(([name, version]) => `${name}@${version}`),
|
|
1328
|
+
...(options.title === undefined ? {} : {title: options.title}),
|
|
1329
|
+
};
|
|
1330
|
+
// The file each alias import named, for the files the page carries, so a
|
|
1331
|
+
// reverse where no alias names it still finds the file.
|
|
1332
|
+
const carried = new Map(
|
|
1333
|
+
embedded.map(f => [path.resolve(base, f.path), f.path]),
|
|
1334
|
+
);
|
|
1335
|
+
/** @type {Record<string, string>} */
|
|
1336
|
+
const aliases = {};
|
|
1337
|
+
for (const {
|
|
1338
|
+
spec,
|
|
1339
|
+
file: named,
|
|
1340
|
+
} of /** @type {{spec: string, file: string}[]} */ (
|
|
1341
|
+
message.aliasImports ?? []
|
|
1342
|
+
).sort((a, b) => (a.spec < b.spec ? -1 : a.spec > b.spec ? 1 : 0))) {
|
|
1343
|
+
const rel = carried.get(path.resolve(named));
|
|
1344
|
+
if (rel && aliasOnly(spec)) aliases[spec] = rel;
|
|
1345
|
+
}
|
|
1346
|
+
const record = {
|
|
1347
|
+
...(facts.cli ? {cli: facts.cli} : {}),
|
|
1348
|
+
page: facts.page,
|
|
1349
|
+
...(options.title === undefined ? {} : {title: options.title}),
|
|
1350
|
+
packages,
|
|
1351
|
+
...(Object.keys(aliases).length > 0 ? {aliases} : {}),
|
|
1352
|
+
markup: {
|
|
1353
|
+
sha256: sha256(asParsed(markup)),
|
|
1354
|
+
style: sha256(asParsed(style)),
|
|
1355
|
+
text: Buffer.from(
|
|
1356
|
+
JSON.stringify({title, runs: textRuns(markup)}),
|
|
1357
|
+
).toString('base64'),
|
|
1358
|
+
},
|
|
1359
|
+
};
|
|
1360
|
+
html =
|
|
1361
|
+
`<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">${generator}\n${headerNote(facts)}\n` +
|
|
1362
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1363
|
+
'<meta name="color-scheme" content="light dark">' +
|
|
1364
|
+
`<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
|
|
1365
|
+
`${sourceBlock(path.basename(entry), embedded, record)}\n${endNote(facts)}\n</body></html>\n`;
|
|
1366
|
+
} else {
|
|
1367
|
+
html =
|
|
1368
|
+
`<!doctype html><html lang="en"${rootThemeAttrs(markup)}><head><meta charset="utf-8">` +
|
|
1369
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1370
|
+
'<meta name="color-scheme" content="light dark">' +
|
|
1371
|
+
`${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
|
|
1372
|
+
`${sourceBlock(path.basename(entry), embedded)}</body></html>\n`;
|
|
1373
|
+
}
|
|
750
1374
|
return {
|
|
751
1375
|
html,
|
|
752
1376
|
files: embedded.map(f => f.path),
|
|
@@ -755,7 +1379,9 @@ export async function renderPage(entry, options = {}) {
|
|
|
755
1379
|
cssBytes: Buffer.byteLength(css),
|
|
756
1380
|
markupBytes: Buffer.byteLength(markup),
|
|
757
1381
|
images: new Set([
|
|
758
|
-
...[...ctx.counted]
|
|
1382
|
+
...[...ctx.counted]
|
|
1383
|
+
.filter(k => k.startsWith('file:'))
|
|
1384
|
+
.map(k => k.slice(5)),
|
|
759
1385
|
...(message.assets ?? []),
|
|
760
1386
|
]).size,
|
|
761
1387
|
warnings,
|