@astryxdesign/cli 0.7.16 → 0.7.17-canary.g16fe6a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +12 -0
- package/api/build/_adapter.mjs +51 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +4 -2
- package/api/build/kit/rank.mjs +125 -24
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +12 -8
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +340 -43
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +48 -0
- package/api/build/kit/words.mjs +90 -1
- package/api/component/__fixtures__/resolutions/modules.txt +4 -5
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +1 -1
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +28 -2
- package/api/docs/_adapter.mjs +249 -10
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +27 -5
- package/api/doctor/_adapter.mjs +83 -10
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +4 -3
- package/api/doctor/doctor.mjs +14 -7
- package/api/doctor/theme-checks.mjs +121 -17
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/authoring-checks.mjs +6 -6
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/validate-integration.mjs +19 -1
- package/api/integration/validate-integration.type.d.mts +9 -0
- package/api/integration/validate-integration.type.mjs +1 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +52 -0
- package/api/render/render.type.mjs +31 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.mjs +51 -32
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +5 -0
- package/api/search/_lexical.mjs +8 -2
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/theme/_adapter.mjs +12 -1
- package/api/theme/build/build.d.mts +132 -1
- package/api/theme/build/build.mjs +482 -157
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +44 -5
- package/api/theme/build/font-warning.mjs +118 -10
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +115 -4
- package/api/theme-edit/_adapter.mjs +997 -83
- package/api/theme-edit/_catalog.d.mts +20 -2
- package/api/theme-edit/_catalog.mjs +50 -10
- package/api/theme-edit/_check.d.mts +75 -24
- package/api/theme-edit/_check.mjs +2672 -422
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +54 -1
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +133 -15
- package/api/theme-edit/_context.d.mts +14 -3
- package/api/theme-edit/_context.mjs +225 -65
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +54 -4
- package/api/theme-edit/_edit.mjs +2966 -286
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +770 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6983 -701
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +303 -0
- package/api/theme-edit/_normal.mjs +1517 -0
- package/api/theme-edit/_palette.d.mts +12 -0
- package/api/theme-edit/_palette.mjs +37 -4
- package/api/theme-edit/_part-words.d.mts +31 -0
- package/api/theme-edit/_part-words.mjs +126 -0
- package/api/theme-edit/_parts.d.mts +28 -2
- package/api/theme-edit/_parts.mjs +267 -31
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +814 -406
- package/api/theme-edit/_preview.d.mts +116 -16
- package/api/theme-edit/_preview.mjs +649 -152
- package/api/theme-edit/_project.d.mts +22 -1
- package/api/theme-edit/_project.mjs +83 -3
- package/api/theme-edit/_settings.d.mts +467 -42
- package/api/theme-edit/_settings.mjs +3527 -468
- package/api/theme-edit/_tables.d.mts +21 -0
- package/api/theme-edit/_tables.mjs +97 -3
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +16 -2
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/run-codemod.mjs +87 -7
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +1 -0
- package/assets/docs/theme.doc.dense.mjs +2 -2
- package/assets/docs/theme.doc.mjs +1 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +1 -1
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/render-pages.doc.mjs +44 -3
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +24 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +6 -0
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +3 -3
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +3 -1
- package/clients/cli/commands/doctor.mjs +32 -14
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +573 -119
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.mjs +4 -2
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +718 -438
- package/clients/cli/commands/upgrade.mjs +42 -7
- package/clients/cli/index.mjs +1 -1
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +132 -24
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/theme-state.d.mts +13 -1
- package/foundation/config/theme-state.mjs +47 -7
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +56 -8
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/entry-name-files.d.mts +43 -0
- package/foundation/discovery/entry-name-files.mjs +264 -0
- package/foundation/discovery/hook-discovery.d.mts +8 -2
- package/foundation/discovery/hook-discovery.mjs +22 -8
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +38 -18
- package/foundation/discovery/template-adapter.d.mts +53 -1
- package/foundation/discovery/template-adapter.mjs +176 -12
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/theme-discovery.mjs +31 -4
- package/foundation/discovery/theme-imports.d.mts +14 -0
- package/foundation/discovery/theme-imports.mjs +43 -1
- package/foundation/discovery/theming-targets.d.mts +6 -5
- package/foundation/discovery/theming-targets.mjs +31 -47
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +22 -0
- package/foundation/doc-compiler/stored-docs.mjs +49 -0
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +38 -0
- package/foundation/fonts/font-stylesheet.mjs +141 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +4 -3
- package/foundation/fs/gather-cache.d.mts +62 -4
- package/foundation/fs/gather-cache.mjs +517 -91
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +60 -0
- package/foundation/fs/kept-tree.mjs +154 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +9 -0
- package/foundation/fs/read-record.mjs +19 -11
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/validate-contributions.mjs +17 -45
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +39 -7
- package/foundation/render/embedded-imports.mjs +66 -27
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +121 -13
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +185 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +34 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +35 -3
- package/foundation/render/render-page.mjs +641 -96
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +2 -2
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/string-utils.d.mts +3 -2
- package/foundation/text/string-utils.mjs +18 -4
- package/foundation/text/suggest-order.d.mts +9 -0
- package/foundation/text/suggest-order.mjs +15 -1
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -17,38 +17,64 @@
|
|
|
17
17
|
* integration's contribution-check results and the whole list (with the
|
|
18
18
|
* template and component replacement passes), which `component`,
|
|
19
19
|
* `template`, `theme`, `discover` and `search` report, by template
|
|
20
|
-
* discovery (foundation/discovery/template-adapter.mjs) for its records, by
|
|
21
|
-
* (
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
20
|
+
* discovery (foundation/discovery/template-adapter.mjs) for its records, by
|
|
21
|
+
* the component list (api/component/list/list.mjs) and component
|
|
22
|
+
* replacement (foundation/discovery/component-replacement.mjs), by theme
|
|
23
|
+
* discovery (foundation/discovery/theme-discovery.mjs) for each
|
|
24
|
+
* integration's themes,
|
|
25
|
+
* by `doctor` (api/doctor/_adapter.mjs) for its file-only docs checks and
|
|
26
|
+
* its theme-wiring scan, by the docs adapter (api/docs/_adapter.mjs) for
|
|
27
|
+
* the CLI's own docs tree, which `docs` and `search` read,
|
|
28
|
+
* in a run that records modules and variables to its end, and, through
|
|
29
|
+
* `persistedSummary`, by kept-tree.mjs for the docs not-found hint's
|
|
30
|
+
* summaries of folder trees, each kept while every path it stamped is
|
|
31
|
+
* unchanged, in any command. The commands whose runs keep the other
|
|
32
|
+
* entries are `search`, `build`, `component`, `template`, `theme`,
|
|
33
|
+
* `discover`, `docs` and `doctor`. The first such run on a machine makes the
|
|
34
|
+
* folder and keeps its gathers at once, so the next run (most often the same
|
|
35
|
+
* session's next command) uses them; doctor never makes it. A run through
|
|
36
|
+
* the host entry keeps them too, keyed on what the host passed
|
|
37
|
+
* (hostInputs). Only a published CLI stores anything:
|
|
27
38
|
* its build id (clients/cli/build-id.generated.json, written at `prepack`)
|
|
28
39
|
* names its exact code, so a checkout, whose code may change between runs
|
|
29
40
|
* under the same version, always gathers.
|
|
30
41
|
*
|
|
42
|
+
* An entry stores only the states that the kept entries it builds on do
|
|
43
|
+
* not hold: it names each of them, at the version it read, and is used
|
|
44
|
+
* only while each is still there at that version and holds. A run checks
|
|
45
|
+
* each kept entry once, so entries that read the same files (the component
|
|
46
|
+
* list, its replacements, the project's issues) check those files once. An
|
|
47
|
+
* entry built on is marked as used after the entries built on it, so
|
|
48
|
+
* eviction removes it after them. A gather's entry file holds two lines:
|
|
49
|
+
* what the entry is and stands for (its format, key, version, the entries
|
|
50
|
+
* it builds on, its states and variables), then its value. Checking an
|
|
51
|
+
* entry, or one an entry builds on, parses only the first line.
|
|
52
|
+
*
|
|
31
53
|
* The folder is `catalogs` in the user's cache folder (userCacheDir):
|
|
32
54
|
* created 0700, used only while it is a real folder owned by the user and
|
|
33
55
|
* closed to others (isPrivateDir; never on a system with no user ids), each file written 0600 by a rename, oldest first evicted past
|
|
34
|
-
* CACHE_LIMIT_BYTES. Any failure to read, check, parse or write is silent
|
|
56
|
+
* CACHE_LIMIT_BYTES (cache-eviction.mjs). Any failure to read, check, parse or write is silent
|
|
35
57
|
* and the run gathers fresh, as it would with no cache.
|
|
36
58
|
*/
|
|
37
59
|
|
|
38
|
-
import {createHash} from 'node:crypto';
|
|
60
|
+
import {createHash, randomBytes} from 'node:crypto';
|
|
39
61
|
import * as fs from 'node:fs';
|
|
40
62
|
import * as nodeModule from 'node:module';
|
|
41
63
|
import * as os from 'node:os';
|
|
42
64
|
import * as path from 'node:path';
|
|
43
65
|
import {fileURLToPath} from 'node:url';
|
|
44
66
|
import {isDeepStrictEqual} from 'node:util';
|
|
45
|
-
import {CLI_ROOT} from './paths.mjs';
|
|
67
|
+
import {CLI_ROOT, realDir} from './paths.mjs';
|
|
46
68
|
import {mayHaveIntegrations} from '../integrations/may-have-integrations.mjs';
|
|
47
69
|
import {currentUid, isPrivateDir} from '../env/private-dir.mjs';
|
|
48
70
|
import {userCacheDir} from '../env/user-dirs.mjs';
|
|
49
71
|
import {jitiCacheDir} from './jiti-cache.mjs';
|
|
72
|
+
import {hostedRun} from '../runtime/package-root.mjs';
|
|
73
|
+
import {cliDoor} from '../env/cli-command.mjs';
|
|
74
|
+
import {CACHE_LIMIT_BYTES, evictOldest} from './cache-eviction.mjs';
|
|
50
75
|
import {
|
|
51
76
|
fileStamp,
|
|
77
|
+
keepState,
|
|
52
78
|
recordReads,
|
|
53
79
|
recordStates,
|
|
54
80
|
stillInState,
|
|
@@ -78,7 +104,9 @@ const KEPT_COMMANDS = new Set([
|
|
|
78
104
|
'theme',
|
|
79
105
|
'discover',
|
|
80
106
|
'docs',
|
|
81
|
-
//
|
|
107
|
+
// Its project check, with or without `--built`, keeps its docs checks and
|
|
108
|
+
// theme-wiring scan; its `integration` checks run neither, and keep only
|
|
109
|
+
// the project gathers they load, as the commands above do.
|
|
82
110
|
'doctor',
|
|
83
111
|
]);
|
|
84
112
|
|
|
@@ -90,11 +118,15 @@ export const BUILD_ID_FILE = path.join(
|
|
|
90
118
|
'build-id.generated.json',
|
|
91
119
|
);
|
|
92
120
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Whether a file in the folder is a kept entry, which eviction counts.
|
|
123
|
+
* @param {string} name
|
|
124
|
+
* @returns {boolean}
|
|
125
|
+
*/
|
|
126
|
+
const isEntry = name => name.startsWith('gather-');
|
|
95
127
|
|
|
96
128
|
/** The stored format; a different one is a miss. */
|
|
97
|
-
const FORMAT =
|
|
129
|
+
const FORMAT = 2;
|
|
98
130
|
|
|
99
131
|
/** A variable the run read that was unset, as stored. */
|
|
100
132
|
const UNSET = null;
|
|
@@ -106,7 +138,7 @@ const UNSET = null;
|
|
|
106
138
|
* variables only while the run is armed: from its start to the end of its
|
|
107
139
|
* first gather, and during each later gather, or, in a run armed throughout
|
|
108
140
|
* (`doctor`), to its end. Null outside a recorded run.
|
|
109
|
-
* @type {{reads: Map<string, string>, env: Map<string, string | null>, arm: () => boolean, disarm: () => void, armedThroughout: boolean, realEnv: NodeJS.ProcessEnv} | null}
|
|
141
|
+
* @type {{reads: Map<string, string>, env: Map<string, string | null>, arm: () => boolean, disarm: () => void, armedThroughout: boolean, realEnv: NodeJS.ProcessEnv, confirmed: Confirmed} | null}
|
|
110
142
|
*/
|
|
111
143
|
let run = null;
|
|
112
144
|
|
|
@@ -137,6 +169,18 @@ let gatherCode = null;
|
|
|
137
169
|
/** How many persistedGather calls are running, nested inside one another. */
|
|
138
170
|
let gatherDepth = 0;
|
|
139
171
|
|
|
172
|
+
/**
|
|
173
|
+
* The kept entries a recorded run has read back or stored, by file: the
|
|
174
|
+
* version each holds, every state it stands for (its own and those of the
|
|
175
|
+
* entries it builds on, as the lists each stores, once each), and every entry
|
|
176
|
+
* it builds on, directly or not. A later entry stores only the states none of
|
|
177
|
+
* them holds and names the ones it builds on, so a run checks each state
|
|
178
|
+
* once. A kept entry is checked before the run's command writes anything; the
|
|
179
|
+
* record ends with the run.
|
|
180
|
+
* @typedef {{version: string, lists: [string, string][][], under: Set<string>, deps: string[], merged?: [string, string][]}} ConfirmedEntry
|
|
181
|
+
* @typedef {Map<string, ConfirmedEntry>} Confirmed
|
|
182
|
+
*/
|
|
183
|
+
|
|
140
184
|
/**
|
|
141
185
|
* The outcome of the last kept gather in this process: whether it was a hit,
|
|
142
186
|
* and why it missed. Null when no kept gather ran.
|
|
@@ -241,8 +285,6 @@ export async function recordRunFor(argv, fn) {
|
|
|
241
285
|
if (
|
|
242
286
|
!command ||
|
|
243
287
|
!KEPT_COMMANDS.has(command) ||
|
|
244
|
-
(command === 'doctor' &&
|
|
245
|
-
argv.filter(arg => !arg.startsWith('-')).length > 1) ||
|
|
246
288
|
runsUnderPnp() ||
|
|
247
289
|
currentUid() == null ||
|
|
248
290
|
withoutRecording(buildId) == null ||
|
|
@@ -254,9 +296,8 @@ export async function recordRunFor(argv, fn) {
|
|
|
254
296
|
) {
|
|
255
297
|
return fn();
|
|
256
298
|
}
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
// it, so a one-off run never pays to store one.
|
|
299
|
+
// The first recorded run on a machine (search, build, component, template,
|
|
300
|
+
// theme, discover or docs) makes the folder and keeps its gathers at once.
|
|
260
301
|
const dir = cacheDirPath();
|
|
261
302
|
if (!withoutRecording(() => fs.existsSync(dir))) {
|
|
262
303
|
// Once the per-user cache folder exists doctor uses it; it never makes
|
|
@@ -267,8 +308,8 @@ export async function recordRunFor(argv, fn) {
|
|
|
267
308
|
withoutRecording(() => fs.mkdirSync(dir, {recursive: true, mode: 0o700}));
|
|
268
309
|
} catch {
|
|
269
310
|
// A folder that cannot be made keeps no catalogs; nothing more.
|
|
311
|
+
return fn();
|
|
270
312
|
}
|
|
271
|
-
return fn();
|
|
272
313
|
}
|
|
273
314
|
// A folder the cache would refuse (not the user's own, open to others, a
|
|
274
315
|
// link) leaves the run exactly as without the cache: no hook is installed.
|
|
@@ -389,7 +430,15 @@ export async function recordRun(fn, {armedThroughout = false} = {}) {
|
|
|
389
430
|
}
|
|
390
431
|
};
|
|
391
432
|
if (!arm()) return fn();
|
|
392
|
-
run = {
|
|
433
|
+
run = {
|
|
434
|
+
reads,
|
|
435
|
+
env,
|
|
436
|
+
arm,
|
|
437
|
+
disarm,
|
|
438
|
+
armedThroughout,
|
|
439
|
+
realEnv,
|
|
440
|
+
confirmed: new Map(),
|
|
441
|
+
};
|
|
393
442
|
try {
|
|
394
443
|
return await recordReads(reads, fn, {exact: true});
|
|
395
444
|
} finally {
|
|
@@ -516,9 +565,29 @@ function entryKey(key, id) {
|
|
|
516
565
|
process.platform,
|
|
517
566
|
process.arch,
|
|
518
567
|
...key,
|
|
568
|
+
hostInputs(),
|
|
519
569
|
]);
|
|
520
570
|
}
|
|
521
571
|
|
|
572
|
+
/**
|
|
573
|
+
* What a host passed that decides a gather, or null outside a hosted run: its
|
|
574
|
+
* package sets, by real path and in its order, the integrations it approves,
|
|
575
|
+
* and the command it runs the CLI as, which kept findings print. A run reads
|
|
576
|
+
* only some of a package set's files, so their stamps cannot tell a hosted
|
|
577
|
+
* run from a run of the bin in the same folder, and no file holds the
|
|
578
|
+
* command. The run's folder is in each gather's own key.
|
|
579
|
+
* @returns {{roots: string[], integrations: string[], door: string | null} | null}
|
|
580
|
+
*/
|
|
581
|
+
function hostInputs() {
|
|
582
|
+
const hosted = hostedRun();
|
|
583
|
+
if (hosted == null) return null;
|
|
584
|
+
return {
|
|
585
|
+
roots: hosted.roots.map(root => withoutRecording(() => realDir(root))),
|
|
586
|
+
integrations: [...hosted.integrations],
|
|
587
|
+
door: cliDoor() ?? null,
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
|
|
522
591
|
/**
|
|
523
592
|
* Whether every stored state still holds: files, folders and modules, and the
|
|
524
593
|
* environment.
|
|
@@ -546,6 +615,184 @@ function staleReason(stamps, env) {
|
|
|
546
615
|
return null;
|
|
547
616
|
}
|
|
548
617
|
|
|
618
|
+
/**
|
|
619
|
+
* The states of the kept entries an entry builds on, each found unchanged
|
|
620
|
+
* once per run, with every entry under them and the files of the ones it
|
|
621
|
+
* names; or null when one is gone, holds another version, or changed.
|
|
622
|
+
* @param {string} dir
|
|
623
|
+
* @param {unknown} deps - [entry file name, version] pairs, as stored
|
|
624
|
+
* @param {Confirmed} confirmed - the entries already found unchanged
|
|
625
|
+
* @param {Set<string>} [reading] - entries being checked, so a loop of
|
|
626
|
+
* entries that name each other is a miss
|
|
627
|
+
* @returns {{lists: [string, string][][], under: Set<string>, direct: string[]} | null}
|
|
628
|
+
*/
|
|
629
|
+
function builtOn(dir, deps, confirmed, reading = new Set()) {
|
|
630
|
+
if (!Array.isArray(deps)) return null;
|
|
631
|
+
/** @type {[string, string][][]} */
|
|
632
|
+
const lists = [];
|
|
633
|
+
// Two entries this one names may build on one entry: its list counts once.
|
|
634
|
+
/** @type {Set<[string, string][]>} */
|
|
635
|
+
const listed = new Set();
|
|
636
|
+
/** @type {Set<string>} */
|
|
637
|
+
const under = new Set();
|
|
638
|
+
/** @type {string[]} */
|
|
639
|
+
const direct = [];
|
|
640
|
+
for (const dep of deps) {
|
|
641
|
+
if (!Array.isArray(dep) || typeof dep[0] !== 'string') return null;
|
|
642
|
+
const file = path.join(dir, path.basename(dep[0]));
|
|
643
|
+
const entry = confirmedEntry(file, dep[1], confirmed, reading);
|
|
644
|
+
if (entry == null) return null;
|
|
645
|
+
for (const list of entry.lists) {
|
|
646
|
+
if (listed.has(list)) continue;
|
|
647
|
+
listed.add(list);
|
|
648
|
+
lists.push(list);
|
|
649
|
+
}
|
|
650
|
+
direct.push(file);
|
|
651
|
+
under.add(file);
|
|
652
|
+
for (const below of entry.under) under.add(below);
|
|
653
|
+
}
|
|
654
|
+
return {lists, under, direct};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Every state a confirmed entry stands for, one per path: its lists, merged
|
|
659
|
+
* the first time something needs them as one (choosing what a new entry
|
|
660
|
+
* builds on).
|
|
661
|
+
* @param {ConfirmedEntry} entry
|
|
662
|
+
* @returns {[string, string][]}
|
|
663
|
+
*/
|
|
664
|
+
function statesOf(entry) {
|
|
665
|
+
entry.merged ??= mergeStates(...entry.lists);
|
|
666
|
+
return entry.merged;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* States from several lists, one per path, as a run's record keeps them
|
|
671
|
+
* (keepState).
|
|
672
|
+
* @param {...[string, string][]} lists
|
|
673
|
+
* @returns {[string, string][]}
|
|
674
|
+
*/
|
|
675
|
+
function mergeStates(...lists) {
|
|
676
|
+
/** @type {Map<string, string>} */
|
|
677
|
+
const merged = new Map();
|
|
678
|
+
for (const list of lists) {
|
|
679
|
+
for (const [at, state] of list) keepState(merged, at, state);
|
|
680
|
+
}
|
|
681
|
+
return [...merged];
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* Mark an entry as used now, and each kept entry it builds on as used a
|
|
686
|
+
* millisecond (the finest step of a file time set from a Date) after the
|
|
687
|
+
* latest entry built on it, so eviction, which removes the least recently
|
|
688
|
+
* used entries first, never removes an entry before one built on it.
|
|
689
|
+
* @param {string} file
|
|
690
|
+
* @param {Confirmed} confirmed
|
|
691
|
+
*/
|
|
692
|
+
function markUsed(file, confirmed) {
|
|
693
|
+
/** @type {Map<string, number>} */
|
|
694
|
+
const times = new Map();
|
|
695
|
+
/** @type {Set<string>} */
|
|
696
|
+
const onPath = new Set();
|
|
697
|
+
/**
|
|
698
|
+
* @param {string} at
|
|
699
|
+
* @param {number} time
|
|
700
|
+
*/
|
|
701
|
+
const visit = (at, time) => {
|
|
702
|
+
if (onPath.has(at) || (times.get(at) ?? -Infinity) >= time) return;
|
|
703
|
+
times.set(at, time);
|
|
704
|
+
onPath.add(at);
|
|
705
|
+
for (const dep of confirmed.get(at)?.deps ?? []) visit(dep, time + 1);
|
|
706
|
+
onPath.delete(at);
|
|
707
|
+
};
|
|
708
|
+
visit(file, Date.now());
|
|
709
|
+
for (const [at, time] of times) {
|
|
710
|
+
try {
|
|
711
|
+
const when = new Date(time);
|
|
712
|
+
withoutRecording(() => fs.utimesSync(at, when, when));
|
|
713
|
+
} catch {
|
|
714
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* A kept entry at `version`, found unchanged as a hit finds it: read and
|
|
721
|
+
* checked the first time the run meets it, after that from `confirmed`.
|
|
722
|
+
* @param {string} file
|
|
723
|
+
* @param {unknown} version
|
|
724
|
+
* @param {Confirmed} confirmed
|
|
725
|
+
* @param {Set<string>} reading
|
|
726
|
+
* @returns {ConfirmedEntry | null}
|
|
727
|
+
*/
|
|
728
|
+
function confirmedEntry(file, version, confirmed, reading) {
|
|
729
|
+
const known = confirmed.get(file);
|
|
730
|
+
if (known) return known.version === version ? known : null;
|
|
731
|
+
if (reading.has(file)) return null;
|
|
732
|
+
reading.add(file);
|
|
733
|
+
try {
|
|
734
|
+
const stored = readHead(file);
|
|
735
|
+
if (
|
|
736
|
+
stored?.format !== FORMAT ||
|
|
737
|
+
typeof stored.version !== 'string' ||
|
|
738
|
+
stored.version !== version ||
|
|
739
|
+
staleReason(stored.stamps, stored.env) != null
|
|
740
|
+
) {
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
const base = builtOn(path.dirname(file), stored.deps, confirmed, reading);
|
|
744
|
+
if (base == null) return null;
|
|
745
|
+
/** @type {ConfirmedEntry} */
|
|
746
|
+
const entry = {
|
|
747
|
+
version: stored.version,
|
|
748
|
+
lists: [...base.lists, stored.stamps],
|
|
749
|
+
under: base.under,
|
|
750
|
+
deps: base.direct,
|
|
751
|
+
};
|
|
752
|
+
confirmed.set(file, entry);
|
|
753
|
+
return entry;
|
|
754
|
+
} catch {
|
|
755
|
+
return null;
|
|
756
|
+
} finally {
|
|
757
|
+
reading.delete(file);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* The kept entries a new entry builds on: those the run has read back or
|
|
763
|
+
* stored whose every state the run read too, as it holds them, largest
|
|
764
|
+
* first, each only when it holds a state the others do not. Never one that
|
|
765
|
+
* builds on the new entry's own file. The new entry stores the rest of its
|
|
766
|
+
* states itself.
|
|
767
|
+
* @param {string} file - the new entry's file
|
|
768
|
+
* @param {[string, string][]} stamps - every state the run read
|
|
769
|
+
* @param {Confirmed} confirmed
|
|
770
|
+
* @returns {{deps: [string, string][], own: [string, string][], under: Set<string>}}
|
|
771
|
+
*/
|
|
772
|
+
function chooseBase(file, stamps, confirmed) {
|
|
773
|
+
const states = new Map(stamps);
|
|
774
|
+
/** @type {Set<string>} */
|
|
775
|
+
const covered = new Set();
|
|
776
|
+
/** @type {[string, string][]} */
|
|
777
|
+
const deps = [];
|
|
778
|
+
/** @type {Set<string>} */
|
|
779
|
+
const under = new Set();
|
|
780
|
+
const candidates = [...confirmed]
|
|
781
|
+
.filter(([other, entry]) => other !== file && !entry.under.has(file))
|
|
782
|
+
.map(([other, entry]) => ({other, entry, held: statesOf(entry)}))
|
|
783
|
+
.sort((a, b) => b.held.length - a.held.length);
|
|
784
|
+
for (const {other, entry, held} of candidates) {
|
|
785
|
+
if (held.length === 0) continue;
|
|
786
|
+
if (!held.every(([at, state]) => states.get(at) === state)) continue;
|
|
787
|
+
if (held.every(([at]) => covered.has(at))) continue;
|
|
788
|
+
deps.push([path.basename(other), entry.version]);
|
|
789
|
+
under.add(other);
|
|
790
|
+
for (const below of entry.under) under.add(below);
|
|
791
|
+
for (const [at] of held) covered.add(at);
|
|
792
|
+
}
|
|
793
|
+
return {deps, own: stamps.filter(([at]) => !covered.has(at)), under};
|
|
794
|
+
}
|
|
795
|
+
|
|
549
796
|
/**
|
|
550
797
|
* The gather `load` returns, or the one a run with the same key stored while
|
|
551
798
|
* every input it read is unchanged (see the file header).
|
|
@@ -604,21 +851,45 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
604
851
|
const file = entryFile(dir, key, id);
|
|
605
852
|
let reason = 'no entry';
|
|
606
853
|
try {
|
|
607
|
-
const stored =
|
|
608
|
-
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
609
|
-
);
|
|
854
|
+
const {head: stored, value: storedValue} = readEntry(file);
|
|
610
855
|
if (stored?.format !== FORMAT) {
|
|
611
856
|
reason = 'another format';
|
|
612
857
|
} else if (stored.key !== entryKey(key, id)) {
|
|
613
858
|
reason = 'an entry for other inputs';
|
|
614
859
|
} else {
|
|
615
|
-
|
|
616
|
-
|
|
860
|
+
// An entry the run already found unchanged, as one an earlier entry
|
|
861
|
+
// builds on, is not checked again. Outside a recorded run nothing is
|
|
862
|
+
// remembered from one gather to the next.
|
|
863
|
+
const confirmed = run?.confirmed ?? new Map();
|
|
864
|
+
const known = confirmed.get(file);
|
|
865
|
+
const seen =
|
|
866
|
+
typeof stored.version === 'string' && known?.version === stored.version
|
|
867
|
+
? known
|
|
868
|
+
: null;
|
|
869
|
+
const own = seen ? null : staleReason(stored.stamps, stored.env);
|
|
870
|
+
const base =
|
|
871
|
+
seen || own != null ? null : builtOn(dir, stored.deps, confirmed);
|
|
872
|
+
const stale =
|
|
873
|
+
own ??
|
|
874
|
+
(seen == null && base == null
|
|
875
|
+
? 'a kept entry it builds on changed'
|
|
876
|
+
: null);
|
|
877
|
+
const value = stale == null ? readBack(storedValue, codec) : undefined;
|
|
617
878
|
if (stale == null && value === undefined) {
|
|
618
879
|
// Gathered again below, and stored over the bad entry.
|
|
619
880
|
reason = 'a malformed value';
|
|
620
881
|
} else if (stale == null) {
|
|
621
|
-
|
|
882
|
+
/** @type {ConfirmedEntry} */
|
|
883
|
+
const entry = seen ?? {
|
|
884
|
+
version: stored.version,
|
|
885
|
+
lists: [...(base?.lists ?? []), stored.stamps],
|
|
886
|
+
under: base?.under ?? new Set(),
|
|
887
|
+
deps: base?.direct ?? [],
|
|
888
|
+
};
|
|
889
|
+
confirmed.set(file, entry);
|
|
890
|
+
// Recorded list by list, which keeps one state per path as a merge
|
|
891
|
+
// would (recordStates).
|
|
892
|
+
for (const list of entry.lists) recordStates(list);
|
|
622
893
|
// A gather around this one depends on what this one read, the
|
|
623
894
|
// environment included: a hit hands its variables on, as a fresh
|
|
624
895
|
// gather's reads would be.
|
|
@@ -627,16 +898,14 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
627
898
|
if (!run.env.has(name)) run.env.set(name, value);
|
|
628
899
|
}
|
|
629
900
|
}
|
|
630
|
-
|
|
901
|
+
// The CLI's own files, one state per path, in the order a fresh
|
|
902
|
+
// gather reads them: merging only those is merging all, then picking
|
|
903
|
+
// them out.
|
|
904
|
+
gatherCode = mergeStates(...entry.lists.map(cliStates));
|
|
631
905
|
lastOutcome = {hit: true, reason: 'unchanged'};
|
|
632
|
-
|
|
633
|
-
const now = new Date();
|
|
634
|
-
withoutRecording(() => fs.utimesSync(file, now, now));
|
|
635
|
-
} catch {
|
|
636
|
-
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
637
|
-
}
|
|
906
|
+
markUsed(file, confirmed);
|
|
638
907
|
return value;
|
|
639
|
-
} else {
|
|
908
|
+
} else if (stale != null) {
|
|
640
909
|
reason = stale;
|
|
641
910
|
}
|
|
642
911
|
}
|
|
@@ -650,6 +919,10 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
650
919
|
const value = await load();
|
|
651
920
|
if (run && armed && keep(value)) {
|
|
652
921
|
withoutRecording(() => store(dir, file, entryKey(key, id), value, codec));
|
|
922
|
+
} else {
|
|
923
|
+
// A value worked out from a gather that is not kept is not kept either.
|
|
924
|
+
// The code a gather inside this one recorded did not build this one.
|
|
925
|
+
gatherCode = null;
|
|
653
926
|
}
|
|
654
927
|
return value;
|
|
655
928
|
}
|
|
@@ -716,7 +989,7 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
716
989
|
stored?.format === FORMAT &&
|
|
717
990
|
stored.derived === true &&
|
|
718
991
|
stored.key === entry
|
|
719
|
-
? readBack(stored, codec)
|
|
992
|
+
? readBack(() => stored.value, codec)
|
|
720
993
|
: undefined;
|
|
721
994
|
if (value !== undefined) {
|
|
722
995
|
try {
|
|
@@ -733,18 +1006,15 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
733
1006
|
const value = compute();
|
|
734
1007
|
withoutRecording(() => {
|
|
735
1008
|
try {
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
value: encoded,
|
|
742
|
-
});
|
|
743
|
-
if (!isDeepStrictEqual(JSON.parse(text).value, encoded)) return;
|
|
1009
|
+
const body = storedText(codec, value);
|
|
1010
|
+
if (body === undefined) return;
|
|
1011
|
+
const head = JSON.stringify({format: FORMAT, derived: true, key: entry});
|
|
1012
|
+
// The value's text goes in as checked, as the head's last field.
|
|
1013
|
+
const text = `${head.slice(0, -1)},"value":${body}}`;
|
|
744
1014
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
745
1015
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
746
1016
|
fs.renameSync(temp, file);
|
|
747
|
-
|
|
1017
|
+
evictOldest(dir, isEntry);
|
|
748
1018
|
} catch {
|
|
749
1019
|
// A value that cannot be stored is computed again next time.
|
|
750
1020
|
}
|
|
@@ -752,18 +1022,165 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
752
1022
|
return value;
|
|
753
1023
|
}
|
|
754
1024
|
|
|
1025
|
+
/**
|
|
1026
|
+
* How old every stamped time must be before a summary is stored. A file
|
|
1027
|
+
* system can store times as coarsely as 2 s, so a change within one tick of
|
|
1028
|
+
* the last can leave a stamp as it was.
|
|
1029
|
+
*/
|
|
1030
|
+
const SUMMARY_SETTLE_MS = 2000;
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Whether every stamp in `stamps` was taken longer than
|
|
1034
|
+
* {@link SUMMARY_SETTLE_MS} ago, by its modification and change times.
|
|
1035
|
+
* @param {[string, string][]} stamps
|
|
1036
|
+
* @returns {boolean}
|
|
1037
|
+
*/
|
|
1038
|
+
function settled(stamps) {
|
|
1039
|
+
const limit = Date.now() - SUMMARY_SETTLE_MS;
|
|
1040
|
+
return stamps.every(([, stamp]) => {
|
|
1041
|
+
if (stamp === '-') return true;
|
|
1042
|
+
const [, mtime, ctime] = stamp.split(':').map(Number);
|
|
1043
|
+
return mtime < limit && ctime < limit;
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/**
|
|
1048
|
+
* A summary of files and folders, made at once, kept as an entry beside the
|
|
1049
|
+
* gathers, in or out of a recorded run: the stored value while every path
|
|
1050
|
+
* `make` stamped has the stamp it was stored with, else the one `make` gives
|
|
1051
|
+
* now, which is stored unless a stamp is younger than
|
|
1052
|
+
* {@link SUMMARY_SETTLE_MS}. The folder, the build id, the Yarn Plug'n'Play
|
|
1053
|
+
* rule, the 0600 rename write and the eviction are those of a kept gather;
|
|
1054
|
+
* anywhere a gather is not kept, or on any read or write error, `make` runs
|
|
1055
|
+
* as before.
|
|
1056
|
+
* @template T
|
|
1057
|
+
* @param {unknown[]} key - Everything else the summary depends on.
|
|
1058
|
+
* @param {() => {value: T, stamps: [string, string][]}} make - The summary,
|
|
1059
|
+
* with the stamp ({@link fileStamp}) of each path it depends on, each taken
|
|
1060
|
+
* before the path was read.
|
|
1061
|
+
* @returns {T}
|
|
1062
|
+
*/
|
|
1063
|
+
export function persistedSummary(key, make) {
|
|
1064
|
+
const id = withoutRecording(buildId);
|
|
1065
|
+
const dir =
|
|
1066
|
+
id == null || runsUnderPnp() ? null : withoutRecording(gatherCacheDir);
|
|
1067
|
+
if (id == null || dir == null) return make().value;
|
|
1068
|
+
const summaryKey = ['summary', ...key];
|
|
1069
|
+
const file = entryFile(dir, summaryKey, id);
|
|
1070
|
+
const entry = entryKey(summaryKey, id);
|
|
1071
|
+
try {
|
|
1072
|
+
const stored = JSON.parse(
|
|
1073
|
+
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
1074
|
+
);
|
|
1075
|
+
if (
|
|
1076
|
+
stored?.format === FORMAT &&
|
|
1077
|
+
stored.summary === true &&
|
|
1078
|
+
stored.key === entry &&
|
|
1079
|
+
Object.hasOwn(stored, 'value') &&
|
|
1080
|
+
Array.isArray(stored.stamps) &&
|
|
1081
|
+
stored.stamps.every(
|
|
1082
|
+
(/** @type {[string, string]} */ [at, stamp]) =>
|
|
1083
|
+
typeof at === 'string' && fileStamp(at) === stamp,
|
|
1084
|
+
)
|
|
1085
|
+
) {
|
|
1086
|
+
try {
|
|
1087
|
+
const now = new Date();
|
|
1088
|
+
withoutRecording(() => fs.utimesSync(file, now, now));
|
|
1089
|
+
} catch {
|
|
1090
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
1091
|
+
}
|
|
1092
|
+
return stored.value;
|
|
1093
|
+
}
|
|
1094
|
+
} catch {
|
|
1095
|
+
// No usable entry: made below.
|
|
1096
|
+
}
|
|
1097
|
+
const {value, stamps} = make();
|
|
1098
|
+
if (settled(stamps)) {
|
|
1099
|
+
withoutRecording(() => {
|
|
1100
|
+
try {
|
|
1101
|
+
const text = JSON.stringify({
|
|
1102
|
+
format: FORMAT,
|
|
1103
|
+
summary: true,
|
|
1104
|
+
key: entry,
|
|
1105
|
+
stamps,
|
|
1106
|
+
value,
|
|
1107
|
+
});
|
|
1108
|
+
if (!isDeepStrictEqual(JSON.parse(text).value, value)) return;
|
|
1109
|
+
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
1110
|
+
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
1111
|
+
fs.renameSync(temp, file);
|
|
1112
|
+
evictOldest(dir, isEntry);
|
|
1113
|
+
} catch {
|
|
1114
|
+
// A summary that cannot be stored is made again next time.
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
return value;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* A gather's entry file: its first line, parsed, and a reader of its value,
|
|
1123
|
+
* the second line, parsed only when called. A file of one line, as an entry
|
|
1124
|
+
* of another format, is all head and has no value.
|
|
1125
|
+
* @param {string} file
|
|
1126
|
+
* @returns {{head: any, value: () => unknown}}
|
|
1127
|
+
*/
|
|
1128
|
+
function readEntry(file) {
|
|
1129
|
+
const text = withoutRecording(() => fs.readFileSync(file, 'utf-8'));
|
|
1130
|
+
const cut = text.indexOf('\n');
|
|
1131
|
+
return {
|
|
1132
|
+
head: JSON.parse(cut < 0 ? text : text.slice(0, cut)),
|
|
1133
|
+
value: () => (cut < 0 ? undefined : JSON.parse(text.slice(cut + 1))),
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/** How much of an entry file one read takes while looking for its first line. */
|
|
1138
|
+
const HEAD_READ_BYTES = 64 * 1024;
|
|
1139
|
+
|
|
1140
|
+
/**
|
|
1141
|
+
* A gather's entry file's first line, parsed, read without the value after
|
|
1142
|
+
* it: an entry another builds on is checked, never read back. A newline byte
|
|
1143
|
+
* is never part of a longer UTF-8 character, so the bytes before the first
|
|
1144
|
+
* one are the whole line.
|
|
1145
|
+
* @param {string} file
|
|
1146
|
+
* @returns {any}
|
|
1147
|
+
*/
|
|
1148
|
+
function readHead(file) {
|
|
1149
|
+
return withoutRecording(() => {
|
|
1150
|
+
const fd = fs.openSync(file, 'r');
|
|
1151
|
+
try {
|
|
1152
|
+
/** @type {Buffer[]} */
|
|
1153
|
+
const chunks = [];
|
|
1154
|
+
const chunk = Buffer.allocUnsafe(HEAD_READ_BYTES);
|
|
1155
|
+
for (let at = 0; ;) {
|
|
1156
|
+
const read = fs.readSync(fd, chunk, 0, chunk.length, at);
|
|
1157
|
+
if (read === 0) break;
|
|
1158
|
+
const piece = chunk.subarray(0, read);
|
|
1159
|
+
const end = piece.indexOf(0x0a);
|
|
1160
|
+
chunks.push(Buffer.from(end < 0 ? piece : piece.subarray(0, end)));
|
|
1161
|
+
if (end >= 0) break;
|
|
1162
|
+
at += read;
|
|
1163
|
+
}
|
|
1164
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
1165
|
+
} finally {
|
|
1166
|
+
fs.closeSync(fd);
|
|
1167
|
+
}
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
|
|
755
1171
|
/**
|
|
756
1172
|
* A stored entry's value, decoded, or undefined when it has none, its decode
|
|
757
1173
|
* throws, or the decoded value fails the codec's shape check (`valid`): such
|
|
758
1174
|
* an entry is a miss, worked out again and stored over.
|
|
759
|
-
* @param {
|
|
1175
|
+
* @param {() => unknown} read - reads the entry's value
|
|
760
1176
|
* @param {{decode: (stored: any) => any, valid?: (value: any) => boolean}} codec
|
|
761
1177
|
* @returns {any}
|
|
762
1178
|
*/
|
|
763
|
-
function readBack(
|
|
764
|
-
if (!Object.hasOwn(stored, 'value') || stored.value == null) return undefined;
|
|
1179
|
+
function readBack(read, codec) {
|
|
765
1180
|
try {
|
|
766
|
-
const
|
|
1181
|
+
const stored = read();
|
|
1182
|
+
if (stored == null) return undefined;
|
|
1183
|
+
const value = codec.decode(stored);
|
|
767
1184
|
if (value == null) return undefined;
|
|
768
1185
|
return !codec.valid || codec.valid(value) ? value : undefined;
|
|
769
1186
|
} catch {
|
|
@@ -771,6 +1188,26 @@ function readBack(stored, codec) {
|
|
|
771
1188
|
}
|
|
772
1189
|
}
|
|
773
1190
|
|
|
1191
|
+
/**
|
|
1192
|
+
* The JSON text a kept value is stored as, checked once to read back as what
|
|
1193
|
+
* the codec meant: the codec's own checked text when it gives one
|
|
1194
|
+
* (`encodeText`, as EXACT_CODEC does), else its plain form, written and
|
|
1195
|
+
* checked to read back as that form. Undefined for a value that does not
|
|
1196
|
+
* read back exactly, which is never kept; a codec's refusal throws.
|
|
1197
|
+
* @template T
|
|
1198
|
+
* @param {{encode: (value: T) => unknown, encodeText?: (value: T) => string}} codec
|
|
1199
|
+
* @param {T} value
|
|
1200
|
+
* @returns {string | undefined}
|
|
1201
|
+
*/
|
|
1202
|
+
function storedText(codec, value) {
|
|
1203
|
+
if (codec.encodeText) return codec.encodeText(value);
|
|
1204
|
+
const encoded = codec.encode(value);
|
|
1205
|
+
const text = JSON.stringify(encoded);
|
|
1206
|
+
return text !== undefined && isDeepStrictEqual(JSON.parse(text), encoded)
|
|
1207
|
+
? text
|
|
1208
|
+
: undefined;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
774
1211
|
/**
|
|
775
1212
|
* Store a fresh gather with what the run read, unless its plain form does not
|
|
776
1213
|
* read back as the same value. Silent on any failure.
|
|
@@ -784,57 +1221,38 @@ function readBack(stored, codec) {
|
|
|
784
1221
|
function store(dir, file, entry, value, codec) {
|
|
785
1222
|
if (!run) return;
|
|
786
1223
|
try {
|
|
787
|
-
const
|
|
1224
|
+
const body = storedText(codec, value);
|
|
1225
|
+
if (body === undefined) return;
|
|
788
1226
|
const stamps = [...run.reads].filter(([file]) => !inJitiCache(file));
|
|
789
1227
|
gatherCode = cliStates(stamps);
|
|
790
|
-
const
|
|
1228
|
+
const {deps, own, under} = chooseBase(file, stamps, run.confirmed);
|
|
1229
|
+
const version = randomBytes(12).toString('hex');
|
|
1230
|
+
const head = JSON.stringify({
|
|
791
1231
|
format: FORMAT,
|
|
792
1232
|
key: entry,
|
|
793
|
-
|
|
1233
|
+
version,
|
|
1234
|
+
deps,
|
|
1235
|
+
stamps: own,
|
|
794
1236
|
env: [...run.env],
|
|
795
|
-
value: encoded,
|
|
796
1237
|
});
|
|
797
|
-
|
|
1238
|
+
// JSON text holds no line break, so the first one ends the head.
|
|
1239
|
+
const text = `${head}\n${body}`;
|
|
798
1240
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
799
1241
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
800
1242
|
fs.renameSync(temp, file);
|
|
801
|
-
|
|
1243
|
+
run.confirmed.set(file, {
|
|
1244
|
+
version,
|
|
1245
|
+
lists: [stamps],
|
|
1246
|
+
under,
|
|
1247
|
+
deps: deps.map(([name]) => path.join(dir, name)),
|
|
1248
|
+
});
|
|
1249
|
+
markUsed(file, run.confirmed);
|
|
1250
|
+
evictOldest(dir, isEntry);
|
|
802
1251
|
} catch {
|
|
803
1252
|
// A gather that cannot be stored is gathered again next time.
|
|
804
1253
|
}
|
|
805
1254
|
}
|
|
806
1255
|
|
|
807
|
-
/**
|
|
808
|
-
* Delete the oldest entries until the folder holds at most CACHE_LIMIT_BYTES.
|
|
809
|
-
* @param {string} dir
|
|
810
|
-
*/
|
|
811
|
-
function evict(dir) {
|
|
812
|
-
const entries = fs
|
|
813
|
-
.readdirSync(dir)
|
|
814
|
-
.filter(name => name.startsWith('gather-'))
|
|
815
|
-
.map(name => {
|
|
816
|
-
const entry = path.join(dir, name);
|
|
817
|
-
try {
|
|
818
|
-
const {size, mtimeMs} = fs.statSync(entry);
|
|
819
|
-
return {entry, size, mtimeMs};
|
|
820
|
-
} catch {
|
|
821
|
-
return null;
|
|
822
|
-
}
|
|
823
|
-
})
|
|
824
|
-
.filter(e => e != null)
|
|
825
|
-
.sort((a, b) => a.mtimeMs - b.mtimeMs);
|
|
826
|
-
let total = entries.reduce((sum, e) => sum + e.size, 0);
|
|
827
|
-
for (const {entry, size} of entries) {
|
|
828
|
-
if (total <= CACHE_LIMIT_BYTES) break;
|
|
829
|
-
try {
|
|
830
|
-
fs.unlinkSync(entry);
|
|
831
|
-
total -= size;
|
|
832
|
-
} catch {
|
|
833
|
-
// Another run removed it.
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
|
|
838
1256
|
/**
|
|
839
1257
|
* Whether this run is under Yarn Plug'n'Play's loader (`yarn astryx` in a PnP
|
|
840
1258
|
* project): Node's module hooks hand PnP's resolver options it refuses, so
|
|
@@ -849,15 +1267,16 @@ export function runsUnderPnp() {
|
|
|
849
1267
|
/**
|
|
850
1268
|
* The cache folder and how much it holds, for `doctor`: null when the CLI
|
|
851
1269
|
* keeps no gathers (a checkout) or has no usable folder.
|
|
852
|
-
* @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null}
|
|
853
|
-
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp)
|
|
1270
|
+
* @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null}
|
|
1271
|
+
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp);
|
|
1272
|
+
* `limitBytes`: the most the folder, and jiti's folder `jitiDir`, holds
|
|
854
1273
|
*/
|
|
855
1274
|
export function gatherCacheSummary() {
|
|
856
1275
|
// The cache's own bookkeeping, never an input of what it keeps.
|
|
857
1276
|
return withoutRecording(summarize);
|
|
858
1277
|
}
|
|
859
1278
|
|
|
860
|
-
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null} */
|
|
1279
|
+
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null} */
|
|
861
1280
|
function summarize() {
|
|
862
1281
|
if (buildId() == null) return null;
|
|
863
1282
|
const dir = gatherCacheDir();
|
|
@@ -877,5 +1296,12 @@ function summarize() {
|
|
|
877
1296
|
} catch {
|
|
878
1297
|
return null;
|
|
879
1298
|
}
|
|
880
|
-
return {
|
|
1299
|
+
return {
|
|
1300
|
+
dir,
|
|
1301
|
+
bytes,
|
|
1302
|
+
entries,
|
|
1303
|
+
pnp: runsUnderPnp(),
|
|
1304
|
+
limitBytes: CACHE_LIMIT_BYTES,
|
|
1305
|
+
jitiDir: jitiCacheDir(),
|
|
1306
|
+
};
|
|
881
1307
|
}
|