@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0135e03
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 +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/_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 +122 -1
- package/api/theme/build/build.mjs +412 -84
- 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 +23 -3
- package/api/theme/build/font-warning.mjs +54 -5
- package/api/theme/build/icon-imports.mjs +25 -2
- package/api/theme/theme.type.d.mts +10 -0
- package/api/theme/theme.type.mjs +7 -1
- package/api/theme-edit/_adapter.d.mts +103 -3
- package/api/theme-edit/_adapter.mjs +961 -82
- package/api/theme-edit/_catalog.mjs +19 -4
- package/api/theme-edit/_check.d.mts +63 -24
- package/api/theme-edit/_check.mjs +2467 -362
- package/api/theme-edit/_color.d.mts +10 -0
- package/api/theme-edit/_color.mjs +49 -1
- package/api/theme-edit/_compiler.mjs +89 -6
- package/api/theme-edit/_context.d.mts +3 -3
- package/api/theme-edit/_context.mjs +165 -54
- package/api/theme-edit/_css.d.mts +14 -0
- package/api/theme-edit/_css.mjs +46 -1
- package/api/theme-edit/_edit.d.mts +31 -4
- package/api/theme-edit/_edit.mjs +2433 -204
- package/api/theme-edit/_how-commands.d.mts +72 -1
- package/api/theme-edit/_how-commands.mjs +759 -9
- package/api/theme-edit/_how-question.d.mts +82 -5
- package/api/theme-edit/_how-question.mjs +6473 -553
- package/api/theme-edit/_how.d.mts +2 -1
- package/api/theme-edit/_how.mjs +237 -41
- 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 +292 -0
- package/api/theme-edit/_normal.mjs +1454 -0
- package/api/theme-edit/_palette.mjs +10 -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 +18 -1
- package/api/theme-edit/_parts.mjs +246 -23
- package/api/theme-edit/_preview-app.d.mts +7 -1
- package/api/theme-edit/_preview-app.mjs +776 -187
- package/api/theme-edit/_preview.d.mts +100 -14
- package/api/theme-edit/_preview.mjs +582 -139
- package/api/theme-edit/_project.d.mts +4 -0
- package/api/theme-edit/_project.mjs +3 -1
- package/api/theme-edit/_settings.d.mts +417 -42
- package/api/theme-edit/_settings.mjs +3262 -424
- package/api/theme-edit/_tables.d.mts +15 -0
- package/api/theme-edit/_tables.mjs +63 -1
- package/api/theme-edit/_vet.d.mts +20 -0
- package/api/theme-edit/_vet.mjs +47 -2
- 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.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/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 +358 -63
- 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 +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/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 +317 -47
- 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 +92 -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-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.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/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 +512 -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/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,63 @@
|
|
|
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,
|
|
27
|
+
* in a run that records modules and variables to its end, and, through
|
|
28
|
+
* `persistedSummary`, by kept-tree.mjs for the docs not-found hint's
|
|
29
|
+
* summaries of folder trees, each kept while every path it stamped is
|
|
30
|
+
* unchanged, in any command. The commands whose runs keep the other
|
|
31
|
+
* entries are `search`, `build`, `component`, `template`, `theme`,
|
|
32
|
+
* `discover`, `docs` and `doctor`. The first such run on a machine makes the
|
|
33
|
+
* folder and keeps its gathers at once, so the next run (most often the same
|
|
34
|
+
* session's next command) uses them; doctor never makes it. A run through
|
|
35
|
+
* the host entry keeps them too, keyed on what the host passed
|
|
36
|
+
* (hostInputs). Only a published CLI stores anything:
|
|
27
37
|
* its build id (clients/cli/build-id.generated.json, written at `prepack`)
|
|
28
38
|
* names its exact code, so a checkout, whose code may change between runs
|
|
29
39
|
* under the same version, always gathers.
|
|
30
40
|
*
|
|
41
|
+
* An entry stores only the states that the kept entries it builds on do
|
|
42
|
+
* not hold: it names each of them, at the version it read, and is used
|
|
43
|
+
* only while each is still there at that version and holds. A run checks
|
|
44
|
+
* each kept entry once, so entries that read the same files (the component
|
|
45
|
+
* list, its replacements, the project's issues) check those files once. An
|
|
46
|
+
* entry built on is marked as used after the entries built on it, so
|
|
47
|
+
* eviction removes it after them. A gather's entry file holds two lines:
|
|
48
|
+
* what the entry is and stands for (its format, key, version, the entries
|
|
49
|
+
* it builds on, its states and variables), then its value. Checking an
|
|
50
|
+
* entry, or one an entry builds on, parses only the first line.
|
|
51
|
+
*
|
|
31
52
|
* The folder is `catalogs` in the user's cache folder (userCacheDir):
|
|
32
53
|
* created 0700, used only while it is a real folder owned by the user and
|
|
33
54
|
* 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
|
|
55
|
+
* CACHE_LIMIT_BYTES (cache-eviction.mjs). Any failure to read, check, parse or write is silent
|
|
35
56
|
* and the run gathers fresh, as it would with no cache.
|
|
36
57
|
*/
|
|
37
58
|
|
|
38
|
-
import {createHash} from 'node:crypto';
|
|
59
|
+
import {createHash, randomBytes} from 'node:crypto';
|
|
39
60
|
import * as fs from 'node:fs';
|
|
40
61
|
import * as nodeModule from 'node:module';
|
|
41
62
|
import * as os from 'node:os';
|
|
42
63
|
import * as path from 'node:path';
|
|
43
64
|
import {fileURLToPath} from 'node:url';
|
|
44
65
|
import {isDeepStrictEqual} from 'node:util';
|
|
45
|
-
import {CLI_ROOT} from './paths.mjs';
|
|
66
|
+
import {CLI_ROOT, realDir} from './paths.mjs';
|
|
46
67
|
import {mayHaveIntegrations} from '../integrations/may-have-integrations.mjs';
|
|
47
68
|
import {currentUid, isPrivateDir} from '../env/private-dir.mjs';
|
|
48
69
|
import {userCacheDir} from '../env/user-dirs.mjs';
|
|
49
70
|
import {jitiCacheDir} from './jiti-cache.mjs';
|
|
71
|
+
import {hostedRun} from '../runtime/package-root.mjs';
|
|
72
|
+
import {cliDoor} from '../env/cli-command.mjs';
|
|
73
|
+
import {CACHE_LIMIT_BYTES, evictOldest} from './cache-eviction.mjs';
|
|
50
74
|
import {
|
|
51
75
|
fileStamp,
|
|
76
|
+
keepState,
|
|
52
77
|
recordReads,
|
|
53
78
|
recordStates,
|
|
54
79
|
stillInState,
|
|
@@ -78,7 +103,9 @@ const KEPT_COMMANDS = new Set([
|
|
|
78
103
|
'theme',
|
|
79
104
|
'discover',
|
|
80
105
|
'docs',
|
|
81
|
-
//
|
|
106
|
+
// Its project check, with or without `--built`, keeps its docs checks and
|
|
107
|
+
// theme-wiring scan; its `integration` checks run neither, and keep only
|
|
108
|
+
// the project gathers they load, as the commands above do.
|
|
82
109
|
'doctor',
|
|
83
110
|
]);
|
|
84
111
|
|
|
@@ -90,11 +117,15 @@ export const BUILD_ID_FILE = path.join(
|
|
|
90
117
|
'build-id.generated.json',
|
|
91
118
|
);
|
|
92
119
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Whether a file in the folder is a kept entry, which eviction counts.
|
|
122
|
+
* @param {string} name
|
|
123
|
+
* @returns {boolean}
|
|
124
|
+
*/
|
|
125
|
+
const isEntry = name => name.startsWith('gather-');
|
|
95
126
|
|
|
96
127
|
/** The stored format; a different one is a miss. */
|
|
97
|
-
const FORMAT =
|
|
128
|
+
const FORMAT = 2;
|
|
98
129
|
|
|
99
130
|
/** A variable the run read that was unset, as stored. */
|
|
100
131
|
const UNSET = null;
|
|
@@ -106,7 +137,7 @@ const UNSET = null;
|
|
|
106
137
|
* variables only while the run is armed: from its start to the end of its
|
|
107
138
|
* first gather, and during each later gather, or, in a run armed throughout
|
|
108
139
|
* (`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}
|
|
140
|
+
* @type {{reads: Map<string, string>, env: Map<string, string | null>, arm: () => boolean, disarm: () => void, armedThroughout: boolean, realEnv: NodeJS.ProcessEnv, confirmed: Confirmed} | null}
|
|
110
141
|
*/
|
|
111
142
|
let run = null;
|
|
112
143
|
|
|
@@ -137,6 +168,18 @@ let gatherCode = null;
|
|
|
137
168
|
/** How many persistedGather calls are running, nested inside one another. */
|
|
138
169
|
let gatherDepth = 0;
|
|
139
170
|
|
|
171
|
+
/**
|
|
172
|
+
* The kept entries a recorded run has read back or stored, by file: the
|
|
173
|
+
* version each holds, every state it stands for (its own and those of the
|
|
174
|
+
* entries it builds on, as the lists each stores, once each), and every entry
|
|
175
|
+
* it builds on, directly or not. A later entry stores only the states none of
|
|
176
|
+
* them holds and names the ones it builds on, so a run checks each state
|
|
177
|
+
* once. A kept entry is checked before the run's command writes anything; the
|
|
178
|
+
* record ends with the run.
|
|
179
|
+
* @typedef {{version: string, lists: [string, string][][], under: Set<string>, deps: string[], merged?: [string, string][]}} ConfirmedEntry
|
|
180
|
+
* @typedef {Map<string, ConfirmedEntry>} Confirmed
|
|
181
|
+
*/
|
|
182
|
+
|
|
140
183
|
/**
|
|
141
184
|
* The outcome of the last kept gather in this process: whether it was a hit,
|
|
142
185
|
* and why it missed. Null when no kept gather ran.
|
|
@@ -241,8 +284,6 @@ export async function recordRunFor(argv, fn) {
|
|
|
241
284
|
if (
|
|
242
285
|
!command ||
|
|
243
286
|
!KEPT_COMMANDS.has(command) ||
|
|
244
|
-
(command === 'doctor' &&
|
|
245
|
-
argv.filter(arg => !arg.startsWith('-')).length > 1) ||
|
|
246
287
|
runsUnderPnp() ||
|
|
247
288
|
currentUid() == null ||
|
|
248
289
|
withoutRecording(buildId) == null ||
|
|
@@ -254,9 +295,8 @@ export async function recordRunFor(argv, fn) {
|
|
|
254
295
|
) {
|
|
255
296
|
return fn();
|
|
256
297
|
}
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
// it, so a one-off run never pays to store one.
|
|
298
|
+
// The first recorded run on a machine (search, build, component, template,
|
|
299
|
+
// theme, discover or docs) makes the folder and keeps its gathers at once.
|
|
260
300
|
const dir = cacheDirPath();
|
|
261
301
|
if (!withoutRecording(() => fs.existsSync(dir))) {
|
|
262
302
|
// Once the per-user cache folder exists doctor uses it; it never makes
|
|
@@ -267,8 +307,8 @@ export async function recordRunFor(argv, fn) {
|
|
|
267
307
|
withoutRecording(() => fs.mkdirSync(dir, {recursive: true, mode: 0o700}));
|
|
268
308
|
} catch {
|
|
269
309
|
// A folder that cannot be made keeps no catalogs; nothing more.
|
|
310
|
+
return fn();
|
|
270
311
|
}
|
|
271
|
-
return fn();
|
|
272
312
|
}
|
|
273
313
|
// A folder the cache would refuse (not the user's own, open to others, a
|
|
274
314
|
// link) leaves the run exactly as without the cache: no hook is installed.
|
|
@@ -389,7 +429,15 @@ export async function recordRun(fn, {armedThroughout = false} = {}) {
|
|
|
389
429
|
}
|
|
390
430
|
};
|
|
391
431
|
if (!arm()) return fn();
|
|
392
|
-
run = {
|
|
432
|
+
run = {
|
|
433
|
+
reads,
|
|
434
|
+
env,
|
|
435
|
+
arm,
|
|
436
|
+
disarm,
|
|
437
|
+
armedThroughout,
|
|
438
|
+
realEnv,
|
|
439
|
+
confirmed: new Map(),
|
|
440
|
+
};
|
|
393
441
|
try {
|
|
394
442
|
return await recordReads(reads, fn, {exact: true});
|
|
395
443
|
} finally {
|
|
@@ -516,9 +564,29 @@ function entryKey(key, id) {
|
|
|
516
564
|
process.platform,
|
|
517
565
|
process.arch,
|
|
518
566
|
...key,
|
|
567
|
+
hostInputs(),
|
|
519
568
|
]);
|
|
520
569
|
}
|
|
521
570
|
|
|
571
|
+
/**
|
|
572
|
+
* What a host passed that decides a gather, or null outside a hosted run: its
|
|
573
|
+
* package sets, by real path and in its order, the integrations it approves,
|
|
574
|
+
* and the command it runs the CLI as, which kept findings print. A run reads
|
|
575
|
+
* only some of a package set's files, so their stamps cannot tell a hosted
|
|
576
|
+
* run from a run of the bin in the same folder, and no file holds the
|
|
577
|
+
* command. The run's folder is in each gather's own key.
|
|
578
|
+
* @returns {{roots: string[], integrations: string[], door: string | null} | null}
|
|
579
|
+
*/
|
|
580
|
+
function hostInputs() {
|
|
581
|
+
const hosted = hostedRun();
|
|
582
|
+
if (hosted == null) return null;
|
|
583
|
+
return {
|
|
584
|
+
roots: hosted.roots.map(root => withoutRecording(() => realDir(root))),
|
|
585
|
+
integrations: [...hosted.integrations],
|
|
586
|
+
door: cliDoor() ?? null,
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
522
590
|
/**
|
|
523
591
|
* Whether every stored state still holds: files, folders and modules, and the
|
|
524
592
|
* environment.
|
|
@@ -546,6 +614,184 @@ function staleReason(stamps, env) {
|
|
|
546
614
|
return null;
|
|
547
615
|
}
|
|
548
616
|
|
|
617
|
+
/**
|
|
618
|
+
* The states of the kept entries an entry builds on, each found unchanged
|
|
619
|
+
* once per run, with every entry under them and the files of the ones it
|
|
620
|
+
* names; or null when one is gone, holds another version, or changed.
|
|
621
|
+
* @param {string} dir
|
|
622
|
+
* @param {unknown} deps - [entry file name, version] pairs, as stored
|
|
623
|
+
* @param {Confirmed} confirmed - the entries already found unchanged
|
|
624
|
+
* @param {Set<string>} [reading] - entries being checked, so a loop of
|
|
625
|
+
* entries that name each other is a miss
|
|
626
|
+
* @returns {{lists: [string, string][][], under: Set<string>, direct: string[]} | null}
|
|
627
|
+
*/
|
|
628
|
+
function builtOn(dir, deps, confirmed, reading = new Set()) {
|
|
629
|
+
if (!Array.isArray(deps)) return null;
|
|
630
|
+
/** @type {[string, string][][]} */
|
|
631
|
+
const lists = [];
|
|
632
|
+
// Two entries this one names may build on one entry: its list counts once.
|
|
633
|
+
/** @type {Set<[string, string][]>} */
|
|
634
|
+
const listed = new Set();
|
|
635
|
+
/** @type {Set<string>} */
|
|
636
|
+
const under = new Set();
|
|
637
|
+
/** @type {string[]} */
|
|
638
|
+
const direct = [];
|
|
639
|
+
for (const dep of deps) {
|
|
640
|
+
if (!Array.isArray(dep) || typeof dep[0] !== 'string') return null;
|
|
641
|
+
const file = path.join(dir, path.basename(dep[0]));
|
|
642
|
+
const entry = confirmedEntry(file, dep[1], confirmed, reading);
|
|
643
|
+
if (entry == null) return null;
|
|
644
|
+
for (const list of entry.lists) {
|
|
645
|
+
if (listed.has(list)) continue;
|
|
646
|
+
listed.add(list);
|
|
647
|
+
lists.push(list);
|
|
648
|
+
}
|
|
649
|
+
direct.push(file);
|
|
650
|
+
under.add(file);
|
|
651
|
+
for (const below of entry.under) under.add(below);
|
|
652
|
+
}
|
|
653
|
+
return {lists, under, direct};
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* Every state a confirmed entry stands for, one per path: its lists, merged
|
|
658
|
+
* the first time something needs them as one (choosing what a new entry
|
|
659
|
+
* builds on).
|
|
660
|
+
* @param {ConfirmedEntry} entry
|
|
661
|
+
* @returns {[string, string][]}
|
|
662
|
+
*/
|
|
663
|
+
function statesOf(entry) {
|
|
664
|
+
entry.merged ??= mergeStates(...entry.lists);
|
|
665
|
+
return entry.merged;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* States from several lists, one per path, as a run's record keeps them
|
|
670
|
+
* (keepState).
|
|
671
|
+
* @param {...[string, string][]} lists
|
|
672
|
+
* @returns {[string, string][]}
|
|
673
|
+
*/
|
|
674
|
+
function mergeStates(...lists) {
|
|
675
|
+
/** @type {Map<string, string>} */
|
|
676
|
+
const merged = new Map();
|
|
677
|
+
for (const list of lists) {
|
|
678
|
+
for (const [at, state] of list) keepState(merged, at, state);
|
|
679
|
+
}
|
|
680
|
+
return [...merged];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
/**
|
|
684
|
+
* Mark an entry as used now, and each kept entry it builds on as used a
|
|
685
|
+
* millisecond (the finest step of a file time set from a Date) after the
|
|
686
|
+
* latest entry built on it, so eviction, which removes the least recently
|
|
687
|
+
* used entries first, never removes an entry before one built on it.
|
|
688
|
+
* @param {string} file
|
|
689
|
+
* @param {Confirmed} confirmed
|
|
690
|
+
*/
|
|
691
|
+
function markUsed(file, confirmed) {
|
|
692
|
+
/** @type {Map<string, number>} */
|
|
693
|
+
const times = new Map();
|
|
694
|
+
/** @type {Set<string>} */
|
|
695
|
+
const onPath = new Set();
|
|
696
|
+
/**
|
|
697
|
+
* @param {string} at
|
|
698
|
+
* @param {number} time
|
|
699
|
+
*/
|
|
700
|
+
const visit = (at, time) => {
|
|
701
|
+
if (onPath.has(at) || (times.get(at) ?? -Infinity) >= time) return;
|
|
702
|
+
times.set(at, time);
|
|
703
|
+
onPath.add(at);
|
|
704
|
+
for (const dep of confirmed.get(at)?.deps ?? []) visit(dep, time + 1);
|
|
705
|
+
onPath.delete(at);
|
|
706
|
+
};
|
|
707
|
+
visit(file, Date.now());
|
|
708
|
+
for (const [at, time] of times) {
|
|
709
|
+
try {
|
|
710
|
+
const when = new Date(time);
|
|
711
|
+
withoutRecording(() => fs.utimesSync(at, when, when));
|
|
712
|
+
} catch {
|
|
713
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* A kept entry at `version`, found unchanged as a hit finds it: read and
|
|
720
|
+
* checked the first time the run meets it, after that from `confirmed`.
|
|
721
|
+
* @param {string} file
|
|
722
|
+
* @param {unknown} version
|
|
723
|
+
* @param {Confirmed} confirmed
|
|
724
|
+
* @param {Set<string>} reading
|
|
725
|
+
* @returns {ConfirmedEntry | null}
|
|
726
|
+
*/
|
|
727
|
+
function confirmedEntry(file, version, confirmed, reading) {
|
|
728
|
+
const known = confirmed.get(file);
|
|
729
|
+
if (known) return known.version === version ? known : null;
|
|
730
|
+
if (reading.has(file)) return null;
|
|
731
|
+
reading.add(file);
|
|
732
|
+
try {
|
|
733
|
+
const stored = readHead(file);
|
|
734
|
+
if (
|
|
735
|
+
stored?.format !== FORMAT ||
|
|
736
|
+
typeof stored.version !== 'string' ||
|
|
737
|
+
stored.version !== version ||
|
|
738
|
+
staleReason(stored.stamps, stored.env) != null
|
|
739
|
+
) {
|
|
740
|
+
return null;
|
|
741
|
+
}
|
|
742
|
+
const base = builtOn(path.dirname(file), stored.deps, confirmed, reading);
|
|
743
|
+
if (base == null) return null;
|
|
744
|
+
/** @type {ConfirmedEntry} */
|
|
745
|
+
const entry = {
|
|
746
|
+
version: stored.version,
|
|
747
|
+
lists: [...base.lists, stored.stamps],
|
|
748
|
+
under: base.under,
|
|
749
|
+
deps: base.direct,
|
|
750
|
+
};
|
|
751
|
+
confirmed.set(file, entry);
|
|
752
|
+
return entry;
|
|
753
|
+
} catch {
|
|
754
|
+
return null;
|
|
755
|
+
} finally {
|
|
756
|
+
reading.delete(file);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* The kept entries a new entry builds on: those the run has read back or
|
|
762
|
+
* stored whose every state the run read too, as it holds them, largest
|
|
763
|
+
* first, each only when it holds a state the others do not. Never one that
|
|
764
|
+
* builds on the new entry's own file. The new entry stores the rest of its
|
|
765
|
+
* states itself.
|
|
766
|
+
* @param {string} file - the new entry's file
|
|
767
|
+
* @param {[string, string][]} stamps - every state the run read
|
|
768
|
+
* @param {Confirmed} confirmed
|
|
769
|
+
* @returns {{deps: [string, string][], own: [string, string][], under: Set<string>}}
|
|
770
|
+
*/
|
|
771
|
+
function chooseBase(file, stamps, confirmed) {
|
|
772
|
+
const states = new Map(stamps);
|
|
773
|
+
/** @type {Set<string>} */
|
|
774
|
+
const covered = new Set();
|
|
775
|
+
/** @type {[string, string][]} */
|
|
776
|
+
const deps = [];
|
|
777
|
+
/** @type {Set<string>} */
|
|
778
|
+
const under = new Set();
|
|
779
|
+
const candidates = [...confirmed]
|
|
780
|
+
.filter(([other, entry]) => other !== file && !entry.under.has(file))
|
|
781
|
+
.map(([other, entry]) => ({other, entry, held: statesOf(entry)}))
|
|
782
|
+
.sort((a, b) => b.held.length - a.held.length);
|
|
783
|
+
for (const {other, entry, held} of candidates) {
|
|
784
|
+
if (held.length === 0) continue;
|
|
785
|
+
if (!held.every(([at, state]) => states.get(at) === state)) continue;
|
|
786
|
+
if (held.every(([at]) => covered.has(at))) continue;
|
|
787
|
+
deps.push([path.basename(other), entry.version]);
|
|
788
|
+
under.add(other);
|
|
789
|
+
for (const below of entry.under) under.add(below);
|
|
790
|
+
for (const [at] of held) covered.add(at);
|
|
791
|
+
}
|
|
792
|
+
return {deps, own: stamps.filter(([at]) => !covered.has(at)), under};
|
|
793
|
+
}
|
|
794
|
+
|
|
549
795
|
/**
|
|
550
796
|
* The gather `load` returns, or the one a run with the same key stored while
|
|
551
797
|
* every input it read is unchanged (see the file header).
|
|
@@ -604,21 +850,45 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
604
850
|
const file = entryFile(dir, key, id);
|
|
605
851
|
let reason = 'no entry';
|
|
606
852
|
try {
|
|
607
|
-
const stored =
|
|
608
|
-
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
609
|
-
);
|
|
853
|
+
const {head: stored, value: storedValue} = readEntry(file);
|
|
610
854
|
if (stored?.format !== FORMAT) {
|
|
611
855
|
reason = 'another format';
|
|
612
856
|
} else if (stored.key !== entryKey(key, id)) {
|
|
613
857
|
reason = 'an entry for other inputs';
|
|
614
858
|
} else {
|
|
615
|
-
|
|
616
|
-
|
|
859
|
+
// An entry the run already found unchanged, as one an earlier entry
|
|
860
|
+
// builds on, is not checked again. Outside a recorded run nothing is
|
|
861
|
+
// remembered from one gather to the next.
|
|
862
|
+
const confirmed = run?.confirmed ?? new Map();
|
|
863
|
+
const known = confirmed.get(file);
|
|
864
|
+
const seen =
|
|
865
|
+
typeof stored.version === 'string' && known?.version === stored.version
|
|
866
|
+
? known
|
|
867
|
+
: null;
|
|
868
|
+
const own = seen ? null : staleReason(stored.stamps, stored.env);
|
|
869
|
+
const base =
|
|
870
|
+
seen || own != null ? null : builtOn(dir, stored.deps, confirmed);
|
|
871
|
+
const stale =
|
|
872
|
+
own ??
|
|
873
|
+
(seen == null && base == null
|
|
874
|
+
? 'a kept entry it builds on changed'
|
|
875
|
+
: null);
|
|
876
|
+
const value = stale == null ? readBack(storedValue, codec) : undefined;
|
|
617
877
|
if (stale == null && value === undefined) {
|
|
618
878
|
// Gathered again below, and stored over the bad entry.
|
|
619
879
|
reason = 'a malformed value';
|
|
620
880
|
} else if (stale == null) {
|
|
621
|
-
|
|
881
|
+
/** @type {ConfirmedEntry} */
|
|
882
|
+
const entry = seen ?? {
|
|
883
|
+
version: stored.version,
|
|
884
|
+
lists: [...(base?.lists ?? []), stored.stamps],
|
|
885
|
+
under: base?.under ?? new Set(),
|
|
886
|
+
deps: base?.direct ?? [],
|
|
887
|
+
};
|
|
888
|
+
confirmed.set(file, entry);
|
|
889
|
+
// Recorded list by list, which keeps one state per path as a merge
|
|
890
|
+
// would (recordStates).
|
|
891
|
+
for (const list of entry.lists) recordStates(list);
|
|
622
892
|
// A gather around this one depends on what this one read, the
|
|
623
893
|
// environment included: a hit hands its variables on, as a fresh
|
|
624
894
|
// gather's reads would be.
|
|
@@ -627,16 +897,14 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
627
897
|
if (!run.env.has(name)) run.env.set(name, value);
|
|
628
898
|
}
|
|
629
899
|
}
|
|
630
|
-
|
|
900
|
+
// The CLI's own files, one state per path, in the order a fresh
|
|
901
|
+
// gather reads them: merging only those is merging all, then picking
|
|
902
|
+
// them out.
|
|
903
|
+
gatherCode = mergeStates(...entry.lists.map(cliStates));
|
|
631
904
|
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
|
-
}
|
|
905
|
+
markUsed(file, confirmed);
|
|
638
906
|
return value;
|
|
639
|
-
} else {
|
|
907
|
+
} else if (stale != null) {
|
|
640
908
|
reason = stale;
|
|
641
909
|
}
|
|
642
910
|
}
|
|
@@ -716,7 +984,7 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
716
984
|
stored?.format === FORMAT &&
|
|
717
985
|
stored.derived === true &&
|
|
718
986
|
stored.key === entry
|
|
719
|
-
? readBack(stored, codec)
|
|
987
|
+
? readBack(() => stored.value, codec)
|
|
720
988
|
: undefined;
|
|
721
989
|
if (value !== undefined) {
|
|
722
990
|
try {
|
|
@@ -733,18 +1001,15 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
733
1001
|
const value = compute();
|
|
734
1002
|
withoutRecording(() => {
|
|
735
1003
|
try {
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
value: encoded,
|
|
742
|
-
});
|
|
743
|
-
if (!isDeepStrictEqual(JSON.parse(text).value, encoded)) return;
|
|
1004
|
+
const body = storedText(codec, value);
|
|
1005
|
+
if (body === undefined) return;
|
|
1006
|
+
const head = JSON.stringify({format: FORMAT, derived: true, key: entry});
|
|
1007
|
+
// The value's text goes in as checked, as the head's last field.
|
|
1008
|
+
const text = `${head.slice(0, -1)},"value":${body}}`;
|
|
744
1009
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
745
1010
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
746
1011
|
fs.renameSync(temp, file);
|
|
747
|
-
|
|
1012
|
+
evictOldest(dir, isEntry);
|
|
748
1013
|
} catch {
|
|
749
1014
|
// A value that cannot be stored is computed again next time.
|
|
750
1015
|
}
|
|
@@ -752,18 +1017,165 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
752
1017
|
return value;
|
|
753
1018
|
}
|
|
754
1019
|
|
|
1020
|
+
/**
|
|
1021
|
+
* How old every stamped time must be before a summary is stored. A file
|
|
1022
|
+
* system can store times as coarsely as 2 s, so a change within one tick of
|
|
1023
|
+
* the last can leave a stamp as it was.
|
|
1024
|
+
*/
|
|
1025
|
+
const SUMMARY_SETTLE_MS = 2000;
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Whether every stamp in `stamps` was taken longer than
|
|
1029
|
+
* {@link SUMMARY_SETTLE_MS} ago, by its modification and change times.
|
|
1030
|
+
* @param {[string, string][]} stamps
|
|
1031
|
+
* @returns {boolean}
|
|
1032
|
+
*/
|
|
1033
|
+
function settled(stamps) {
|
|
1034
|
+
const limit = Date.now() - SUMMARY_SETTLE_MS;
|
|
1035
|
+
return stamps.every(([, stamp]) => {
|
|
1036
|
+
if (stamp === '-') return true;
|
|
1037
|
+
const [, mtime, ctime] = stamp.split(':').map(Number);
|
|
1038
|
+
return mtime < limit && ctime < limit;
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* A summary of files and folders, made at once, kept as an entry beside the
|
|
1044
|
+
* gathers, in or out of a recorded run: the stored value while every path
|
|
1045
|
+
* `make` stamped has the stamp it was stored with, else the one `make` gives
|
|
1046
|
+
* now, which is stored unless a stamp is younger than
|
|
1047
|
+
* {@link SUMMARY_SETTLE_MS}. The folder, the build id, the Yarn Plug'n'Play
|
|
1048
|
+
* rule, the 0600 rename write and the eviction are those of a kept gather;
|
|
1049
|
+
* anywhere a gather is not kept, or on any read or write error, `make` runs
|
|
1050
|
+
* as before.
|
|
1051
|
+
* @template T
|
|
1052
|
+
* @param {unknown[]} key - Everything else the summary depends on.
|
|
1053
|
+
* @param {() => {value: T, stamps: [string, string][]}} make - The summary,
|
|
1054
|
+
* with the stamp ({@link fileStamp}) of each path it depends on, each taken
|
|
1055
|
+
* before the path was read.
|
|
1056
|
+
* @returns {T}
|
|
1057
|
+
*/
|
|
1058
|
+
export function persistedSummary(key, make) {
|
|
1059
|
+
const id = withoutRecording(buildId);
|
|
1060
|
+
const dir =
|
|
1061
|
+
id == null || runsUnderPnp() ? null : withoutRecording(gatherCacheDir);
|
|
1062
|
+
if (id == null || dir == null) return make().value;
|
|
1063
|
+
const summaryKey = ['summary', ...key];
|
|
1064
|
+
const file = entryFile(dir, summaryKey, id);
|
|
1065
|
+
const entry = entryKey(summaryKey, id);
|
|
1066
|
+
try {
|
|
1067
|
+
const stored = JSON.parse(
|
|
1068
|
+
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
1069
|
+
);
|
|
1070
|
+
if (
|
|
1071
|
+
stored?.format === FORMAT &&
|
|
1072
|
+
stored.summary === true &&
|
|
1073
|
+
stored.key === entry &&
|
|
1074
|
+
Object.hasOwn(stored, 'value') &&
|
|
1075
|
+
Array.isArray(stored.stamps) &&
|
|
1076
|
+
stored.stamps.every(
|
|
1077
|
+
(/** @type {[string, string]} */ [at, stamp]) =>
|
|
1078
|
+
typeof at === 'string' && fileStamp(at) === stamp,
|
|
1079
|
+
)
|
|
1080
|
+
) {
|
|
1081
|
+
try {
|
|
1082
|
+
const now = new Date();
|
|
1083
|
+
withoutRecording(() => fs.utimesSync(file, now, now));
|
|
1084
|
+
} catch {
|
|
1085
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
1086
|
+
}
|
|
1087
|
+
return stored.value;
|
|
1088
|
+
}
|
|
1089
|
+
} catch {
|
|
1090
|
+
// No usable entry: made below.
|
|
1091
|
+
}
|
|
1092
|
+
const {value, stamps} = make();
|
|
1093
|
+
if (settled(stamps)) {
|
|
1094
|
+
withoutRecording(() => {
|
|
1095
|
+
try {
|
|
1096
|
+
const text = JSON.stringify({
|
|
1097
|
+
format: FORMAT,
|
|
1098
|
+
summary: true,
|
|
1099
|
+
key: entry,
|
|
1100
|
+
stamps,
|
|
1101
|
+
value,
|
|
1102
|
+
});
|
|
1103
|
+
if (!isDeepStrictEqual(JSON.parse(text).value, value)) return;
|
|
1104
|
+
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
1105
|
+
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
1106
|
+
fs.renameSync(temp, file);
|
|
1107
|
+
evictOldest(dir, isEntry);
|
|
1108
|
+
} catch {
|
|
1109
|
+
// A summary that cannot be stored is made again next time.
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
return value;
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* A gather's entry file: its first line, parsed, and a reader of its value,
|
|
1118
|
+
* the second line, parsed only when called. A file of one line, as an entry
|
|
1119
|
+
* of another format, is all head and has no value.
|
|
1120
|
+
* @param {string} file
|
|
1121
|
+
* @returns {{head: any, value: () => unknown}}
|
|
1122
|
+
*/
|
|
1123
|
+
function readEntry(file) {
|
|
1124
|
+
const text = withoutRecording(() => fs.readFileSync(file, 'utf-8'));
|
|
1125
|
+
const cut = text.indexOf('\n');
|
|
1126
|
+
return {
|
|
1127
|
+
head: JSON.parse(cut < 0 ? text : text.slice(0, cut)),
|
|
1128
|
+
value: () => (cut < 0 ? undefined : JSON.parse(text.slice(cut + 1))),
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
/** How much of an entry file one read takes while looking for its first line. */
|
|
1133
|
+
const HEAD_READ_BYTES = 64 * 1024;
|
|
1134
|
+
|
|
1135
|
+
/**
|
|
1136
|
+
* A gather's entry file's first line, parsed, read without the value after
|
|
1137
|
+
* it: an entry another builds on is checked, never read back. A newline byte
|
|
1138
|
+
* is never part of a longer UTF-8 character, so the bytes before the first
|
|
1139
|
+
* one are the whole line.
|
|
1140
|
+
* @param {string} file
|
|
1141
|
+
* @returns {any}
|
|
1142
|
+
*/
|
|
1143
|
+
function readHead(file) {
|
|
1144
|
+
return withoutRecording(() => {
|
|
1145
|
+
const fd = fs.openSync(file, 'r');
|
|
1146
|
+
try {
|
|
1147
|
+
/** @type {Buffer[]} */
|
|
1148
|
+
const chunks = [];
|
|
1149
|
+
const chunk = Buffer.allocUnsafe(HEAD_READ_BYTES);
|
|
1150
|
+
for (let at = 0; ;) {
|
|
1151
|
+
const read = fs.readSync(fd, chunk, 0, chunk.length, at);
|
|
1152
|
+
if (read === 0) break;
|
|
1153
|
+
const piece = chunk.subarray(0, read);
|
|
1154
|
+
const end = piece.indexOf(0x0a);
|
|
1155
|
+
chunks.push(Buffer.from(end < 0 ? piece : piece.subarray(0, end)));
|
|
1156
|
+
if (end >= 0) break;
|
|
1157
|
+
at += read;
|
|
1158
|
+
}
|
|
1159
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
1160
|
+
} finally {
|
|
1161
|
+
fs.closeSync(fd);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
}
|
|
1165
|
+
|
|
755
1166
|
/**
|
|
756
1167
|
* A stored entry's value, decoded, or undefined when it has none, its decode
|
|
757
1168
|
* throws, or the decoded value fails the codec's shape check (`valid`): such
|
|
758
1169
|
* an entry is a miss, worked out again and stored over.
|
|
759
|
-
* @param {
|
|
1170
|
+
* @param {() => unknown} read - reads the entry's value
|
|
760
1171
|
* @param {{decode: (stored: any) => any, valid?: (value: any) => boolean}} codec
|
|
761
1172
|
* @returns {any}
|
|
762
1173
|
*/
|
|
763
|
-
function readBack(
|
|
764
|
-
if (!Object.hasOwn(stored, 'value') || stored.value == null) return undefined;
|
|
1174
|
+
function readBack(read, codec) {
|
|
765
1175
|
try {
|
|
766
|
-
const
|
|
1176
|
+
const stored = read();
|
|
1177
|
+
if (stored == null) return undefined;
|
|
1178
|
+
const value = codec.decode(stored);
|
|
767
1179
|
if (value == null) return undefined;
|
|
768
1180
|
return !codec.valid || codec.valid(value) ? value : undefined;
|
|
769
1181
|
} catch {
|
|
@@ -771,6 +1183,26 @@ function readBack(stored, codec) {
|
|
|
771
1183
|
}
|
|
772
1184
|
}
|
|
773
1185
|
|
|
1186
|
+
/**
|
|
1187
|
+
* The JSON text a kept value is stored as, checked once to read back as what
|
|
1188
|
+
* the codec meant: the codec's own checked text when it gives one
|
|
1189
|
+
* (`encodeText`, as EXACT_CODEC does), else its plain form, written and
|
|
1190
|
+
* checked to read back as that form. Undefined for a value that does not
|
|
1191
|
+
* read back exactly, which is never kept; a codec's refusal throws.
|
|
1192
|
+
* @template T
|
|
1193
|
+
* @param {{encode: (value: T) => unknown, encodeText?: (value: T) => string}} codec
|
|
1194
|
+
* @param {T} value
|
|
1195
|
+
* @returns {string | undefined}
|
|
1196
|
+
*/
|
|
1197
|
+
function storedText(codec, value) {
|
|
1198
|
+
if (codec.encodeText) return codec.encodeText(value);
|
|
1199
|
+
const encoded = codec.encode(value);
|
|
1200
|
+
const text = JSON.stringify(encoded);
|
|
1201
|
+
return text !== undefined && isDeepStrictEqual(JSON.parse(text), encoded)
|
|
1202
|
+
? text
|
|
1203
|
+
: undefined;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
774
1206
|
/**
|
|
775
1207
|
* Store a fresh gather with what the run read, unless its plain form does not
|
|
776
1208
|
* read back as the same value. Silent on any failure.
|
|
@@ -784,57 +1216,38 @@ function readBack(stored, codec) {
|
|
|
784
1216
|
function store(dir, file, entry, value, codec) {
|
|
785
1217
|
if (!run) return;
|
|
786
1218
|
try {
|
|
787
|
-
const
|
|
1219
|
+
const body = storedText(codec, value);
|
|
1220
|
+
if (body === undefined) return;
|
|
788
1221
|
const stamps = [...run.reads].filter(([file]) => !inJitiCache(file));
|
|
789
1222
|
gatherCode = cliStates(stamps);
|
|
790
|
-
const
|
|
1223
|
+
const {deps, own, under} = chooseBase(file, stamps, run.confirmed);
|
|
1224
|
+
const version = randomBytes(12).toString('hex');
|
|
1225
|
+
const head = JSON.stringify({
|
|
791
1226
|
format: FORMAT,
|
|
792
1227
|
key: entry,
|
|
793
|
-
|
|
1228
|
+
version,
|
|
1229
|
+
deps,
|
|
1230
|
+
stamps: own,
|
|
794
1231
|
env: [...run.env],
|
|
795
|
-
value: encoded,
|
|
796
1232
|
});
|
|
797
|
-
|
|
1233
|
+
// JSON text holds no line break, so the first one ends the head.
|
|
1234
|
+
const text = `${head}\n${body}`;
|
|
798
1235
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
799
1236
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
800
1237
|
fs.renameSync(temp, file);
|
|
801
|
-
|
|
1238
|
+
run.confirmed.set(file, {
|
|
1239
|
+
version,
|
|
1240
|
+
lists: [stamps],
|
|
1241
|
+
under,
|
|
1242
|
+
deps: deps.map(([name]) => path.join(dir, name)),
|
|
1243
|
+
});
|
|
1244
|
+
markUsed(file, run.confirmed);
|
|
1245
|
+
evictOldest(dir, isEntry);
|
|
802
1246
|
} catch {
|
|
803
1247
|
// A gather that cannot be stored is gathered again next time.
|
|
804
1248
|
}
|
|
805
1249
|
}
|
|
806
1250
|
|
|
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
1251
|
/**
|
|
839
1252
|
* Whether this run is under Yarn Plug'n'Play's loader (`yarn astryx` in a PnP
|
|
840
1253
|
* project): Node's module hooks hand PnP's resolver options it refuses, so
|
|
@@ -849,15 +1262,16 @@ export function runsUnderPnp() {
|
|
|
849
1262
|
/**
|
|
850
1263
|
* The cache folder and how much it holds, for `doctor`: null when the CLI
|
|
851
1264
|
* 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)
|
|
1265
|
+
* @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null}
|
|
1266
|
+
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp);
|
|
1267
|
+
* `limitBytes`: the most the folder, and jiti's folder `jitiDir`, holds
|
|
854
1268
|
*/
|
|
855
1269
|
export function gatherCacheSummary() {
|
|
856
1270
|
// The cache's own bookkeeping, never an input of what it keeps.
|
|
857
1271
|
return withoutRecording(summarize);
|
|
858
1272
|
}
|
|
859
1273
|
|
|
860
|
-
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null} */
|
|
1274
|
+
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null} */
|
|
861
1275
|
function summarize() {
|
|
862
1276
|
if (buildId() == null) return null;
|
|
863
1277
|
const dir = gatherCacheDir();
|
|
@@ -877,5 +1291,12 @@ function summarize() {
|
|
|
877
1291
|
} catch {
|
|
878
1292
|
return null;
|
|
879
1293
|
}
|
|
880
|
-
return {
|
|
1294
|
+
return {
|
|
1295
|
+
dir,
|
|
1296
|
+
bytes,
|
|
1297
|
+
entries,
|
|
1298
|
+
pnp: runsUnderPnp(),
|
|
1299
|
+
limitBytes: CACHE_LIMIT_BYTES,
|
|
1300
|
+
jitiDir: jitiCacheDir(),
|
|
1301
|
+
};
|
|
881
1302
|
}
|