@astryxdesign/cli 0.7.16 → 0.7.17-canary.g335a172
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.mjs +69 -16
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +16 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +251 -35
- 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 +26 -2
- package/api/docs/_adapter.mjs +219 -6
- 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/_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 +60 -0
- package/api/theme/build/build.mjs +210 -54
- package/api/theme/build/font-warning.d.mts +8 -0
- package/api/theme/build/font-warning.mjs +19 -0
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +55 -0
- package/api/theme-edit/_adapter.mjs +673 -42
- package/api/theme-edit/_check.d.mts +28 -22
- package/api/theme-edit/_check.mjs +1858 -312
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +9 -0
- package/api/theme-edit/_context.mjs +60 -3
- package/api/theme-edit/_css.mjs +21 -1
- package/api/theme-edit/_edit.d.mts +22 -0
- package/api/theme-edit/_edit.mjs +1533 -92
- package/api/theme-edit/_how-commands.d.mts +57 -0
- package/api/theme-edit/_how-commands.mjs +587 -1
- package/api/theme-edit/_how-question.d.mts +78 -0
- package/api/theme-edit/_how-question.mjs +4716 -235
- package/api/theme-edit/_how.mjs +134 -8
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_normal.d.mts +219 -0
- package/api/theme-edit/_normal.mjs +1041 -0
- package/api/theme-edit/_palette.mjs +10 -4
- package/api/theme-edit/_parts.d.mts +8 -0
- package/api/theme-edit/_parts.mjs +103 -2
- package/api/theme-edit/_playwright-picture.d.mts +4 -0
- package/api/theme-edit/_playwright-picture.mjs +34 -0
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +394 -74
- package/api/theme-edit/_preview.d.mts +69 -8
- package/api/theme-edit/_preview.mjs +531 -108
- package/api/theme-edit/_settings.d.mts +243 -6
- package/api/theme-edit/_settings.mjs +2415 -147
- package/api/theme-edit/_tables.d.mts +6 -0
- package/api/theme-edit/_tables.mjs +44 -1
- package/api/theme-edit/_vet.d.mts +18 -0
- package/api/theme-edit/_vet.mjs +32 -0
- package/api/theme-edit/theme-edit.type.d.mts +10 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -1
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- 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/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/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 +2 -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 +145 -16
- 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 +2 -2
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- 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/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 +183 -6
- 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 +77 -21
- 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/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-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +52 -0
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +3 -2
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.mjs +3 -2
- 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 +31 -0
- package/foundation/fonts/font-stylesheet.mjs +115 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +25 -4
- package/foundation/fs/gather-cache.mjs +164 -55
- 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/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/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +316 -42
- 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/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
|
@@ -17,22 +17,28 @@
|
|
|
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 {assetDataUri, isAssetBytes, isAssetPath, RenderAssetError} from './assets.mjs';
|
|
26
|
+
import {assetDataUri, isAssetBytes, isAssetPath, MAX_ASSET_BYTES, RenderAssetError} from './assets.mjs';
|
|
25
27
|
import {classesIn, cutCss, layerOrderOf} from './css-cut.mjs';
|
|
26
|
-
import {sourceBlock} from './source-block.mjs';
|
|
28
|
+
import {asParsed, formatFor, sha256, sourceBlock} from './source-block.mjs';
|
|
27
29
|
import {embeddedPathProblem} from './embedded-files.mjs';
|
|
28
|
-
import {
|
|
30
|
+
import {aliasOnly, assetRefsOf} from './embedded-imports.mjs';
|
|
31
|
+
import {isServedPackage, resolveServed} from './served-packages.mjs';
|
|
29
32
|
import {CHART_CSS} from './charts.mjs';
|
|
30
33
|
import {HOST_EXIT} from './host-exit.mjs';
|
|
34
|
+
import {endNote, headerNote} from './file-header.mjs';
|
|
35
|
+
import {textRuns} from './markup-edits.mjs';
|
|
36
|
+
import {findNodeModulesPackage, isInside} from '../fs/paths.mjs';
|
|
31
37
|
|
|
32
38
|
/** How long one page may take to render before it is stopped. */
|
|
33
39
|
export const RENDER_TIMEOUT_MS = 60_000;
|
|
34
40
|
|
|
35
|
-
export {PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
41
|
+
export {MODULE_EXTENSIONS, PAGE_EXTENSIONS} from './embedded-files.mjs';
|
|
36
42
|
|
|
37
43
|
/**
|
|
38
44
|
* @typedef {object} RenderWarning
|
|
@@ -68,19 +74,59 @@ export class RenderError extends Error {
|
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
/**
|
|
71
|
-
* The nearest folder at or above `dir` with a package.json,
|
|
77
|
+
* The nearest folder at or above `dir` with a package.json, or null outside
|
|
78
|
+
* a project.
|
|
72
79
|
* @param {string} dir
|
|
80
|
+
* @returns {string | null}
|
|
73
81
|
*/
|
|
74
|
-
function
|
|
75
|
-
let d = dir;
|
|
76
|
-
for (;;) {
|
|
82
|
+
function projectOf(dir) {
|
|
83
|
+
for (let d = dir; ; d = path.dirname(d)) {
|
|
77
84
|
if (fs.existsSync(path.join(d, 'package.json'))) return d;
|
|
78
|
-
|
|
79
|
-
if (up === d) return dir;
|
|
80
|
-
d = up;
|
|
85
|
+
if (path.dirname(d) === d) return null;
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Whether a path names a file. A name the system cannot look up (a segment
|
|
91
|
+
* too long, a folder it may not read) names none.
|
|
92
|
+
* @param {string} file
|
|
93
|
+
*/
|
|
94
|
+
function isFileAt(file) {
|
|
95
|
+
try {
|
|
96
|
+
return fs.statSync(file).isFile();
|
|
97
|
+
} catch {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The first bytes of a file, enough to tell its format.
|
|
104
|
+
* @param {string} file
|
|
105
|
+
*/
|
|
106
|
+
function headOf(file) {
|
|
107
|
+
const fd = fs.openSync(file, 'r');
|
|
108
|
+
try {
|
|
109
|
+
const head = Buffer.alloc(4096);
|
|
110
|
+
return head.subarray(0, fs.readSync(fd, head, 0, head.length, 0));
|
|
111
|
+
} finally {
|
|
112
|
+
fs.closeSync(fd);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The folder whose modules the page carries: its project's. Outside a
|
|
118
|
+
* project, the current folder when it holds the page, so a page with
|
|
119
|
+
* neighbours above its own folder (as a restore lays them out) carries them;
|
|
120
|
+
* else the page's folder.
|
|
121
|
+
* @param {string} dir
|
|
122
|
+
* @param {string} [cwd]
|
|
123
|
+
*/
|
|
124
|
+
function carryScopeOf(dir, cwd) {
|
|
125
|
+
const project = projectOf(dir);
|
|
126
|
+
if (project) return project;
|
|
127
|
+
return cwd && (dir === cwd || isInside(dir, cwd)) ? cwd : dir;
|
|
128
|
+
}
|
|
129
|
+
|
|
84
130
|
/** @param {string} s */
|
|
85
131
|
const escapeHtml = s =>
|
|
86
132
|
s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
@@ -305,24 +351,61 @@ function hostEndError(/** @type {number | null} */ code) {
|
|
|
305
351
|
if (code === HOST_EXIT.timeout) {
|
|
306
352
|
return new RenderError('ERR_RENDER_TIMEOUT', "The page's process stopped at its own time limit before this process read an answer.", {reason: 'host-timeout', exit: code});
|
|
307
353
|
}
|
|
354
|
+
if (code === HOST_EXIT.sendFailed) {
|
|
355
|
+
return new RenderError('ERR_RENDER_FAILED', "The page's process could not send its answer to this process.", {reason: 'send-failed', exit: code});
|
|
356
|
+
}
|
|
308
357
|
return new RenderError('ERR_RENDER_FAILED', `The page's process ended without an answer (exit ${code}).`, {reason: 'host-ended', exit: code});
|
|
309
358
|
}
|
|
310
359
|
|
|
360
|
+
/**
|
|
361
|
+
* The error for a host that ended with no answer reaching this process, from
|
|
362
|
+
* the state it left in its per-run file: an answer it sent that never
|
|
363
|
+
* arrived, or the stage it ended in.
|
|
364
|
+
* @param {number | null} code
|
|
365
|
+
* @param {string | undefined} stateFile
|
|
366
|
+
*/
|
|
367
|
+
function noMessageError(code, stateFile) {
|
|
368
|
+
if (code !== 0 && code !== null && Object.values(HOST_EXIT).includes(code)) return hostEndError(code);
|
|
369
|
+
/** @type {any} */
|
|
370
|
+
let saved = null;
|
|
371
|
+
try {
|
|
372
|
+
saved = stateFile ? JSON.parse(fs.readFileSync(stateFile, 'utf8')) : null;
|
|
373
|
+
} catch {
|
|
374
|
+
// No readable state: fall back to the bare message below.
|
|
375
|
+
}
|
|
376
|
+
if (!saved) return hostEndError(code);
|
|
377
|
+
const detail = {exit: code, stage: saved.stage, elapsedMs: saved.elapsedMs, rssMb: saved.rssMb, freeMb: saved.freeMb, ...(saved.stderrTail ? {stderrTail: saved.stderrTail} : {})};
|
|
378
|
+
if (saved.answered === 'sent') {
|
|
379
|
+
return new RenderError('ERR_RENDER_FAILED', `The page's process sent its answer, but this process did not receive it (exit ${code}).`, {reason: 'answer-lost', ...detail});
|
|
380
|
+
}
|
|
381
|
+
if (saved.answered === 'sending') {
|
|
382
|
+
return new RenderError('ERR_RENDER_FAILED', `The page's process ended while it sent its answer (exit ${code}).`, {reason: 'ended-while-sending', ...detail});
|
|
383
|
+
}
|
|
384
|
+
const seconds = Math.round((saved.elapsedMs ?? 0) / 1000);
|
|
385
|
+
const last = saved.stderrTail ? ` Its last output: ${String(saved.stderrTail).split('\n').at(-1)}` : '';
|
|
386
|
+
return new RenderError(
|
|
387
|
+
'ERR_RENDER_FAILED',
|
|
388
|
+
`The page's process ended without an answer (exit ${code}) while ${saved.stage}, after ${seconds} seconds, with ${saved.freeMb} MB of memory free.${last}`,
|
|
389
|
+
{reason: 'host-ended', ...detail},
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
311
393
|
/**
|
|
312
394
|
* Run the page in a host process (page-host.mjs), stopping it after
|
|
313
395
|
* `timeoutMs`. The host runs the page in a worker thread, and it exits when
|
|
314
396
|
* this process goes away.
|
|
315
|
-
* @param {{entry: string, root: string, served: ServedSet | null, withoutSegmenter: boolean}} input
|
|
397
|
+
* @param {{entry: string, root: string, scope: string, served: ServedSet | null, withoutSegmenter: boolean}} input
|
|
316
398
|
* @param {number} timeoutMs
|
|
317
399
|
* @returns {Promise<any>} the page's answer, or `{crashed: how}` when a
|
|
318
400
|
* native crash ended the host
|
|
319
401
|
*/
|
|
320
402
|
function runWorker(input, timeoutMs) {
|
|
321
|
-
return
|
|
403
|
+
return withHostStateFile(stateFile => {
|
|
322
404
|
const data = {
|
|
323
405
|
...input,
|
|
324
406
|
served: input.served ? {dir: input.served.dir, integrations: [...input.served.integrations]} : null,
|
|
325
407
|
timeoutMs,
|
|
408
|
+
stateFile,
|
|
326
409
|
};
|
|
327
410
|
const host = fork(fileURLToPath(new URL('./page-host.mjs', import.meta.url)), [JSON.stringify(data)], {
|
|
328
411
|
// Never the CLI's own flags (such as --input-type).
|
|
@@ -330,6 +413,52 @@ function runWorker(input, timeoutMs) {
|
|
|
330
413
|
stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
|
|
331
414
|
serialization: 'advanced',
|
|
332
415
|
});
|
|
416
|
+
return awaitHost(host, {timeoutMs, withoutSegmenter: input.withoutSegmenter, stateFile});
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Run `use` with a state file for one host in a new folder under the system's
|
|
422
|
+
* temporary folder, never in the project, and remove the folder after. The
|
|
423
|
+
* state file only explains a failure: without a temporary folder, `use` gets
|
|
424
|
+
* none and the render runs without it.
|
|
425
|
+
* @template T
|
|
426
|
+
* @param {(stateFile: string | undefined) => Promise<T>} use
|
|
427
|
+
* @param {{makeTempDir?: (prefix: string) => string}} [options]
|
|
428
|
+
* @returns {Promise<T>}
|
|
429
|
+
*/
|
|
430
|
+
export async function withHostStateFile(
|
|
431
|
+
use,
|
|
432
|
+
{makeTempDir = prefix => fs.mkdtempSync(prefix)} = {},
|
|
433
|
+
) {
|
|
434
|
+
/** @type {string} */
|
|
435
|
+
let dir;
|
|
436
|
+
try {
|
|
437
|
+
dir = makeTempDir(path.join(os.tmpdir(), 'astryx-render-'));
|
|
438
|
+
} catch {
|
|
439
|
+
// No temporary folder (missing or read-only): render without the state file.
|
|
440
|
+
return use(undefined);
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
return await use(path.join(dir, 'host-state.json'));
|
|
444
|
+
} finally {
|
|
445
|
+
try {
|
|
446
|
+
fs.rmSync(dir, {recursive: true, force: true, maxRetries: 3});
|
|
447
|
+
} catch {
|
|
448
|
+
// Best effort: a removal that fails (a file still held open) never
|
|
449
|
+
// replaces the render's own result.
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* The page's answer from its host process, or the reason it has none.
|
|
456
|
+
* @param {import('node:child_process').ChildProcess} host
|
|
457
|
+
* @param {{timeoutMs: number, withoutSegmenter: boolean, stateFile?: string}} options
|
|
458
|
+
* @returns {Promise<any>}
|
|
459
|
+
*/
|
|
460
|
+
export function awaitHost(host, {timeoutMs, withoutSegmenter, stateFile}) {
|
|
461
|
+
return new Promise((resolve, reject) => {
|
|
333
462
|
let settled = false;
|
|
334
463
|
/** @param {() => void} settle */
|
|
335
464
|
const finish = settle => {
|
|
@@ -369,12 +498,14 @@ function runWorker(input, timeoutMs) {
|
|
|
369
498
|
host.once('error', error => {
|
|
370
499
|
finish(() => reject(new RenderError('ERR_RENDER_FAILED', `The page could not be rendered: ${String(error?.message ?? error).split('\n')[0]}`)));
|
|
371
500
|
});
|
|
372
|
-
|
|
501
|
+
// 'close' comes after the IPC channel drains, so an answer the host sent
|
|
502
|
+
// just before it exited still wins; 'exit' can come first under load.
|
|
503
|
+
host.once('close', (code, signal) => {
|
|
373
504
|
finish(() => {
|
|
374
505
|
const crash = crashOf(code, signal);
|
|
375
506
|
if (crash) resolve({crashed: crash});
|
|
376
|
-
else if (signal) reject(crashError(signal, {crashed: false, withoutSegmenter
|
|
377
|
-
else reject(
|
|
507
|
+
else if (signal) reject(crashError(signal, {crashed: false, withoutSegmenter}));
|
|
508
|
+
else reject(noMessageError(code, stateFile));
|
|
378
509
|
});
|
|
379
510
|
});
|
|
380
511
|
});
|
|
@@ -383,7 +514,7 @@ function runWorker(input, timeoutMs) {
|
|
|
383
514
|
/**
|
|
384
515
|
* Run the page. When this Node crashes in Intl.Segmenter, run it once more
|
|
385
516
|
* without Intl.Segmenter and say so in a warning.
|
|
386
|
-
* @param {{entry: string, root: string, served: ServedSet | null}} input
|
|
517
|
+
* @param {{entry: string, root: string, scope: string, served: ServedSet | null}} input
|
|
387
518
|
* @param {number} timeoutMs
|
|
388
519
|
* @param {RenderWarning[]} warnings
|
|
389
520
|
*/
|
|
@@ -484,6 +615,26 @@ function inlineAssets(text, kind, ctx) {
|
|
|
484
615
|
});
|
|
485
616
|
}
|
|
486
617
|
|
|
618
|
+
/**
|
|
619
|
+
* The version of a package the page rendered with: the package set's copy
|
|
620
|
+
* when the page took it from there, else the copy Node's resolver finds from
|
|
621
|
+
* the page's folder.
|
|
622
|
+
* @param {string} name
|
|
623
|
+
* @param {string} dir the page's folder
|
|
624
|
+
* @param {Map<string, string>} setDirs the packages the page took from the package set: their folders
|
|
625
|
+
* @returns {string | null}
|
|
626
|
+
*/
|
|
627
|
+
function installedVersion(name, dir, setDirs) {
|
|
628
|
+
const packageDir = setDirs.get(name) ?? findNodeModulesPackage(dir, name)?.packageDir;
|
|
629
|
+
if (!packageDir) return null;
|
|
630
|
+
try {
|
|
631
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
|
|
632
|
+
return pkg?.name === name && typeof pkg.version === 'string' ? pkg.version : null;
|
|
633
|
+
} catch {
|
|
634
|
+
return null;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
487
638
|
/** The light and dark switch every rendered page carries. */
|
|
488
639
|
const SCHEME_CSS =
|
|
489
640
|
':root{color-scheme:light dark}:root[data-theme="light"]{color-scheme:light}:root[data-theme="dark"]{color-scheme:dark}';
|
|
@@ -491,18 +642,27 @@ const SCHEME_CSS =
|
|
|
491
642
|
/**
|
|
492
643
|
* Render a page module to one self-contained HTML file.
|
|
493
644
|
* @param {string} entry absolute path of the page module
|
|
494
|
-
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null}} [options]
|
|
645
|
+
* @param {{title?: string, timeoutMs?: number, version?: string, served?: ServedSet | null, output?: string, cwd?: string}} [options]
|
|
495
646
|
* `served`: the Core of the package set the CLI runs from, for the packages
|
|
496
|
-
* the page's folder has no copy of
|
|
647
|
+
* the page's folder has no copy of; `output`: the file the HTML goes to;
|
|
648
|
+
* `cwd`: the current folder, whose files are the page's own outside a
|
|
649
|
+
* project.
|
|
650
|
+
* With `output`, the file describes itself: notes at its top and end name
|
|
651
|
+
* what made it and the commands that give the page back and render it
|
|
652
|
+
* again, and its embedded source records the CLI version, the packages
|
|
653
|
+
* the page rendered with, and the markup as rendered.
|
|
497
654
|
* @returns {Promise<RenderedPage>}
|
|
498
655
|
*/
|
|
499
656
|
export async function renderPage(entry, options = {}) {
|
|
500
657
|
const dir = path.dirname(entry);
|
|
501
|
-
|
|
658
|
+
// The project's folder, else the page's: where its tsconfig.json and
|
|
659
|
+
// public/ images are read.
|
|
660
|
+
const root = projectOf(dir) ?? dir;
|
|
661
|
+
const scope = carryScopeOf(dir, options.cwd);
|
|
502
662
|
const served = options.served ?? null;
|
|
503
663
|
/** @type {RenderWarning[]} */
|
|
504
664
|
const warnings = [];
|
|
505
|
-
const message = await runPage({entry, root, served}, options.timeoutMs ?? RENDER_TIMEOUT_MS, warnings);
|
|
665
|
+
const message = await runPage({entry, root, scope, served}, options.timeoutMs ?? RENDER_TIMEOUT_MS, warnings);
|
|
506
666
|
if (!message.ok) {
|
|
507
667
|
throw new RenderError(message.error.code, message.error.message, message.error.detail);
|
|
508
668
|
}
|
|
@@ -696,30 +856,86 @@ export async function renderPage(entry, options = {}) {
|
|
|
696
856
|
// (`<img src="./logo.png">`, `url(./bg.png)`) are carried too, so the page
|
|
697
857
|
// comes back with them; a package's own files are not.
|
|
698
858
|
for (const sheet of carriedCss) {
|
|
699
|
-
|
|
700
|
-
if (rel.startsWith('..') || path.isAbsolute(rel) || rel.split(path.sep).includes('node_modules')) continue;
|
|
859
|
+
if (!isInside(sheet, scope) || path.relative(scope, sheet).split(path.sep).includes('node_modules')) continue;
|
|
701
860
|
if (!files.includes(sheet)) files.push(sheet);
|
|
702
861
|
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
862
|
+
/** Assets named in a warning already, so each is named once. @type {Set<string>} */
|
|
863
|
+
const notCarried = new Set();
|
|
864
|
+
/**
|
|
865
|
+
* Carry an image, font or media file of the project's own. It is carried
|
|
866
|
+
* only when its bytes are a known image, font or media format, the same
|
|
867
|
+
* test --reverse applies, so the file always comes back.
|
|
868
|
+
* @param {string} asset absolute
|
|
869
|
+
* @param {string} how how the page uses it, for the warning
|
|
870
|
+
*/
|
|
871
|
+
const carryAsset = (asset, how) => {
|
|
872
|
+
if (!isInside(asset, scope) || path.relative(scope, asset).split(path.sep).includes('node_modules')) return;
|
|
873
|
+
if (files.includes(asset) || notCarried.has(asset)) return;
|
|
874
|
+
/** @param {string} why */
|
|
875
|
+
const leaveOut = why => {
|
|
876
|
+
notCarried.add(asset);
|
|
710
877
|
warnings.push({
|
|
711
878
|
code: 'not-embedded',
|
|
712
|
-
message: `${path.relative(dir, asset).split(path.sep).join('/')} is
|
|
879
|
+
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
880
|
});
|
|
714
|
-
|
|
881
|
+
};
|
|
882
|
+
/** @type {Buffer} */
|
|
883
|
+
let head;
|
|
884
|
+
try {
|
|
885
|
+
// The same limit as a file the page shows, which a render inlines.
|
|
886
|
+
if (fs.statSync(asset).size > MAX_ASSET_BYTES) {
|
|
887
|
+
leaveOut(`it is larger than ${MAX_ASSET_BYTES / 1048576} MB, the most a rendered page carries of one file`);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
head = headOf(asset);
|
|
891
|
+
} catch (e) {
|
|
892
|
+
leaveOut(`it cannot be read (${/** @type {NodeJS.ErrnoException} */ (e).code ?? 'an error from the file system'})`);
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
if (!isAssetBytes(head)) {
|
|
896
|
+
leaveOut('its bytes are not a known image, font or media format');
|
|
897
|
+
return;
|
|
715
898
|
}
|
|
716
899
|
files.push(asset);
|
|
900
|
+
};
|
|
901
|
+
for (const asset of ctx.localAssets) carryAsset(asset, 'shown inline');
|
|
902
|
+
// A carried module or stylesheet can name an image, font or media file by
|
|
903
|
+
// a relative path. --reverse expects each such file back, also when this
|
|
904
|
+
// render does not show it, when it lies inside the folder that holds the
|
|
905
|
+
// carried files (a name that climbs out of it is not the page's file).
|
|
906
|
+
let named = dir;
|
|
907
|
+
for (const f of files) {
|
|
908
|
+
while (!isInside(f, named)) named = path.dirname(named);
|
|
909
|
+
}
|
|
910
|
+
const carriedText = files.filter(
|
|
911
|
+
f => /\.(?:[cm]?[jt]sx?|css)$/i.test(f) && (f === entry || !embeddedPathProblem(path.relative(named, f).split(path.sep).join('/'))),
|
|
912
|
+
);
|
|
913
|
+
for (const file of carriedText) {
|
|
914
|
+
let text;
|
|
915
|
+
try {
|
|
916
|
+
text = fs.readFileSync(file, 'utf8');
|
|
917
|
+
} catch {
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
for (const ref of assetRefsOf(text, file)) {
|
|
921
|
+
const asset = path.resolve(path.dirname(file), ref);
|
|
922
|
+
if (!isInside(asset, named)) continue;
|
|
923
|
+
if (isFileAt(asset)) {
|
|
924
|
+
carryAsset(asset, `named in ${path.relative(dir, file).split(path.sep).join('/')}`);
|
|
925
|
+
}
|
|
926
|
+
}
|
|
717
927
|
}
|
|
718
928
|
// 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
|
|
929
|
+
// folder, or an ancestor when the page imports from above it, but never one
|
|
930
|
+
// from which the page's own path holds a name a reverse refuses (a
|
|
931
|
+
// dot-folder): a file above that stays out of the file, and is named.
|
|
720
932
|
let base = dir;
|
|
721
933
|
for (const f of files) {
|
|
722
|
-
while (
|
|
934
|
+
while (!isInside(f, base)) {
|
|
935
|
+
const up = path.dirname(base);
|
|
936
|
+
if (up === base || embeddedPathProblem(path.relative(up, entry).split(path.sep).join('/'), {page: true})) break;
|
|
937
|
+
base = up;
|
|
938
|
+
}
|
|
723
939
|
}
|
|
724
940
|
// Page first, so the reader knows which file is the page. Only files a
|
|
725
941
|
// rendered page may carry are embedded (see embedded-files.mjs).
|
|
@@ -739,14 +955,72 @@ export async function renderPage(entry, options = {}) {
|
|
|
739
955
|
}
|
|
740
956
|
const heading = /<h1\b[^>]*>([\s\S]*?)<\/h1>/i.exec(markup)?.[1]?.replace(/<[^>]*>/g, '').trim();
|
|
741
957
|
const title = options.title ?? (heading ? decodeAttr(heading) : path.basename(entry).replace(/\.[^.]+$/, ''));
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
958
|
+
const generator = `<meta name="generator" content="Astryx${options.version ? ` ${escapeHtml(options.version)}` : ''}">`;
|
|
959
|
+
const style = `<style>${SCHEME_CSS}${markup.includes('class="recharts-responsive-container"') ? CHART_CSS : ''}${css}</style>`;
|
|
960
|
+
let html;
|
|
961
|
+
if (options.output) {
|
|
962
|
+
// The charset and generator metas come first: a browser reads the
|
|
963
|
+
// charset only from the first 1024 bytes, and a CLI decides whether a
|
|
964
|
+
// render wrote a file from its first 4096.
|
|
965
|
+
const setDirs = new Map(/** @type {{name: string, dir: string}[]} */ (message.fromSet ?? []).map(p => [p.name, p.dir]));
|
|
966
|
+
const names = new Set([...(message.packages ?? []), ...setDirs.keys(), 'react', 'react-dom']);
|
|
967
|
+
if (hasCore) names.add('@astryxdesign/core');
|
|
968
|
+
/** @type {Record<string, string>} */
|
|
969
|
+
const packages = {};
|
|
970
|
+
for (const name of [...names].sort()) {
|
|
971
|
+
if (name.startsWith('node:') || builtinModules.includes(name)) continue;
|
|
972
|
+
const version = installedVersion(name, dir, setDirs);
|
|
973
|
+
if (version) packages[name] = version;
|
|
974
|
+
}
|
|
975
|
+
const file = path.basename(options.output);
|
|
976
|
+
const facts = {
|
|
977
|
+
cli: options.version ?? null,
|
|
978
|
+
format: formatFor(embedded),
|
|
979
|
+
file,
|
|
980
|
+
page: projectOf(dir) ? path.relative(root, entry).split(path.sep).join('/') : embedded[0].path,
|
|
981
|
+
restored: `${file.replace(/\.[^.]+$/, '')}-restored/${embedded[0].path}`,
|
|
982
|
+
files: embedded.map(f => f.path),
|
|
983
|
+
packages,
|
|
984
|
+
install: Object.entries(packages)
|
|
985
|
+
.filter(([name]) => !isServedPackage(name, []))
|
|
986
|
+
.map(([name, version]) => `${name}@${version}`),
|
|
987
|
+
...(options.title === undefined ? {} : {title: options.title}),
|
|
988
|
+
};
|
|
989
|
+
// The file each alias import named, for the files the page carries, so a
|
|
990
|
+
// reverse where no alias names it still finds the file.
|
|
991
|
+
const carried = new Map(embedded.map(f => [path.resolve(base, f.path), f.path]));
|
|
992
|
+
/** @type {Record<string, string>} */
|
|
993
|
+
const aliases = {};
|
|
994
|
+
for (const {spec, file: named} of /** @type {{spec: string, file: string}[]} */ (message.aliasImports ?? []).sort((a, b) => (a.spec < b.spec ? -1 : a.spec > b.spec ? 1 : 0))) {
|
|
995
|
+
const rel = carried.get(path.resolve(named));
|
|
996
|
+
if (rel && aliasOnly(spec)) aliases[spec] = rel;
|
|
997
|
+
}
|
|
998
|
+
const record = {
|
|
999
|
+
...(facts.cli ? {cli: facts.cli} : {}),
|
|
1000
|
+
page: facts.page,
|
|
1001
|
+
...(options.title === undefined ? {} : {title: options.title}),
|
|
1002
|
+
packages,
|
|
1003
|
+
...(Object.keys(aliases).length > 0 ? {aliases} : {}),
|
|
1004
|
+
markup: {
|
|
1005
|
+
sha256: sha256(asParsed(markup)),
|
|
1006
|
+
style: sha256(asParsed(style)),
|
|
1007
|
+
text: Buffer.from(JSON.stringify({title, runs: textRuns(markup)})).toString('base64'),
|
|
1008
|
+
},
|
|
1009
|
+
};
|
|
1010
|
+
html =
|
|
1011
|
+
`<!doctype html><html lang="en"><head><meta charset="utf-8">${generator}\n${headerNote(facts)}\n` +
|
|
1012
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1013
|
+
'<meta name="color-scheme" content="light dark">' +
|
|
1014
|
+
`<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
|
|
1015
|
+
`${sourceBlock(path.basename(entry), embedded, record)}\n${endNote(facts)}\n</body></html>\n`;
|
|
1016
|
+
} else {
|
|
1017
|
+
html =
|
|
1018
|
+
'<!doctype html><html lang="en"><head><meta charset="utf-8">' +
|
|
1019
|
+
'<meta name="viewport" content="width=device-width,initial-scale=1">' +
|
|
1020
|
+
'<meta name="color-scheme" content="light dark">' +
|
|
1021
|
+
`${generator}<title>${escapeHtml(title)}</title>${style}</head><body>${markup}` +
|
|
1022
|
+
`${sourceBlock(path.basename(entry), embedded)}</body></html>\n`;
|
|
1023
|
+
}
|
|
750
1024
|
return {
|
|
751
1025
|
html,
|
|
752
1026
|
files: embedded.map(f => f.path),
|
|
@@ -1,20 +1,29 @@
|
|
|
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 render format a file that carries these files says, the page first.
|
|
6
|
+
* @param {{path: string}[]} files
|
|
7
|
+
* @returns {number}
|
|
8
|
+
*/
|
|
9
|
+
export function formatFor(files: {
|
|
10
|
+
path: string;
|
|
11
|
+
}[]): number;
|
|
4
12
|
/**
|
|
5
13
|
* The data block for a page's files.
|
|
6
14
|
* @param {string} entry the page's file name
|
|
7
15
|
* @param {{path: string, bytes: Buffer}[]} files the page first
|
|
16
|
+
* @param {RenderRecord} [record] what the render records about itself
|
|
8
17
|
* @returns {string}
|
|
9
18
|
*/
|
|
10
19
|
export function sourceBlock(entry: string, files: {
|
|
11
20
|
path: string;
|
|
12
21
|
bytes: Buffer;
|
|
13
|
-
}[]): string;
|
|
22
|
+
}[], record?: RenderRecord): string;
|
|
14
23
|
/**
|
|
15
24
|
* Read the embedded source from a rendered file.
|
|
16
25
|
* @param {string} html
|
|
17
|
-
* @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string}}
|
|
26
|
+
* @returns {{found: false} | {found: true, source: EmbeddedSource} | {found: true, damaged: string} | {found: true, newer: {format: number, cli: string | null}}}
|
|
18
27
|
*/
|
|
19
28
|
export function readSourceBlock(html: string): {
|
|
20
29
|
found: false;
|
|
@@ -24,10 +33,49 @@ export function readSourceBlock(html: string): {
|
|
|
24
33
|
} | {
|
|
25
34
|
found: true;
|
|
26
35
|
damaged: string;
|
|
36
|
+
} | {
|
|
37
|
+
found: true;
|
|
38
|
+
newer: {
|
|
39
|
+
format: number;
|
|
40
|
+
cli: string | null;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The markup between `<body>` and the embedded source: what a render wrote
|
|
45
|
+
* there, unless someone changed it since. Null when the file no longer has
|
|
46
|
+
* that shape.
|
|
47
|
+
* @param {string} html
|
|
48
|
+
* @returns {string | null}
|
|
49
|
+
*/
|
|
50
|
+
export function renderedMarkupOf(html: string): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* The title and the <style> element a render wrote in <head>, unless someone
|
|
53
|
+
* changed them since.
|
|
54
|
+
* @param {string} html
|
|
55
|
+
* @returns {{title: string | null, style: string | null}}
|
|
56
|
+
*/
|
|
57
|
+
export function renderedHeadOf(html: string): {
|
|
58
|
+
title: string | null;
|
|
59
|
+
style: string | null;
|
|
27
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* The title and the runs of text a record keeps, or null when the record
|
|
63
|
+
* keeps none or they do not decode.
|
|
64
|
+
* @param {{text?: unknown}} markup
|
|
65
|
+
* @returns {{title: string | null, runs: string[]} | null}
|
|
66
|
+
*/
|
|
67
|
+
export function recordedText(markup: {
|
|
68
|
+
text?: unknown;
|
|
69
|
+
}): {
|
|
70
|
+
title: string | null;
|
|
71
|
+
runs: string[];
|
|
72
|
+
} | null;
|
|
28
73
|
/** The script type of the embedded-source block. */
|
|
29
74
|
export const SOURCE_TYPE: "application/x-astryx-source";
|
|
30
|
-
|
|
75
|
+
/** The newest render format this CLI reads, and the newest it writes. */
|
|
76
|
+
export const RENDER_FORMAT: 2;
|
|
77
|
+
export function sha256(bytes: Buffer | string): string;
|
|
78
|
+
export function asParsed(text: string): string;
|
|
31
79
|
export type EmbeddedFile = {
|
|
32
80
|
/**
|
|
33
81
|
* - Path relative to the folder that holds every embedded file, `/`-separated; the page itself first.
|
|
@@ -42,11 +90,42 @@ export type EmbeddedFile = {
|
|
|
42
90
|
*/
|
|
43
91
|
base64: string;
|
|
44
92
|
};
|
|
45
|
-
|
|
46
|
-
|
|
93
|
+
/**
|
|
94
|
+
* What the render records about itself beside the files. Every field is
|
|
95
|
+
* optional: files from older CLIs have none of them.
|
|
96
|
+
*/
|
|
97
|
+
export type RenderRecord = {
|
|
98
|
+
/**
|
|
99
|
+
* - The version of the CLI that rendered the file.
|
|
100
|
+
*/
|
|
101
|
+
cli?: string | undefined;
|
|
47
102
|
/**
|
|
48
|
-
* - The page's
|
|
103
|
+
* - The page's path from its project's root, `/`-separated; outside a project, its path among the files it carries.
|
|
49
104
|
*/
|
|
105
|
+
page?: string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* - The title given with --title, which a render again needs too.
|
|
108
|
+
*/
|
|
109
|
+
title?: string | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* - The packages the page rendered with, by name: their versions.
|
|
112
|
+
*/
|
|
113
|
+
packages?: Record<string, string> | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* - Each path-alias import a carried module makes that cannot be a package name (`@/…`, `~/…`), as written (without a query), with the embedded path of the carried file it names, so a reverse where no alias names it still finds the file.
|
|
116
|
+
*/
|
|
117
|
+
aliases?: Record<string, string> | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* - The page as rendered, so a reverse can tell what changed after the render: the SHA-256 of the markup in <body> and of the <style> element, and `text`, the base64 of the JSON `{title, runs}` (the title and the markup's runs of text in order). The text stays encoded so that a find-and-replace over the page's text cannot change the record too.
|
|
120
|
+
*/
|
|
121
|
+
markup?: {
|
|
122
|
+
sha256: string;
|
|
123
|
+
style?: string;
|
|
124
|
+
text?: string;
|
|
125
|
+
} | undefined;
|
|
126
|
+
};
|
|
127
|
+
export type EmbeddedSource = RenderRecord & {
|
|
128
|
+
version: number;
|
|
50
129
|
entry: string;
|
|
51
130
|
files: EmbeddedFile[];
|
|
52
131
|
};
|