@astryxdesign/cli 0.7.16 → 0.7.17-canary.g0404a74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -86
- package/api/build/_adapter.d.mts +17 -0
- package/api/build/_adapter.mjs +53 -34
- package/api/build/blocks/blocks.d.mts +7 -5
- package/api/build/blocks/blocks.mjs +113 -26
- package/api/build/blocks/blocks.weights.json +1 -1
- package/api/build/build.doc.mjs +4 -3
- package/api/build/build.type.d.mts +2 -2
- package/api/build/build.type.mjs +3 -3
- package/api/build/kit/kind.d.mts +2 -1
- package/api/build/kit/kind.mjs +199 -10
- package/api/build/kit/kit.mjs +6 -4
- package/api/build/kit/rank.d.mts +6 -4
- package/api/build/kit/rank.mjs +132 -28
- package/api/build/kit/signals.d.mts +7 -1
- package/api/build/kit/signals.mjs +21 -10
- package/api/build/kit/start.d.mts +5 -4
- package/api/build/kit/start.mjs +14 -9
- package/api/build/kit/weights.d.mts +39 -3
- package/api/build/kit/weights.json +1 -1
- package/api/build/kit/weights.mjs +351 -46
- package/api/build/kit/word-model.d.mts +23 -0
- package/api/build/kit/word-model.mjs +46 -0
- package/api/build/kit/words.d.mts +86 -0
- package/api/build/kit/words.mjs +241 -1
- package/api/build/tree.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -6
- package/api/component/_adapter.d.mts +26 -2
- package/api/component/_adapter.mjs +135 -8
- package/api/component/component.mjs +14 -1
- package/api/component/list/list.d.mts +1 -1
- package/api/component/list/list.mjs +48 -6
- package/api/discover/_adapter.d.mts +11 -1
- package/api/discover/_adapter.mjs +95 -1
- package/api/discover/detail/item/item.mjs +5 -0
- package/api/discover/discover.mjs +12 -3
- package/api/discover/discover.type.d.mts +16 -3
- package/api/discover/discover.type.mjs +13 -3
- package/api/discover/search/search.mjs +3 -2
- package/api/docs/_adapter.d.mts +57 -2
- package/api/docs/_adapter.mjs +266 -33
- package/api/docs/_entry-names-lazily.d.mts +22 -0
- package/api/docs/_entry-names-lazily.mjs +25 -0
- package/api/docs/_entry-names.d.mts +23 -0
- package/api/docs/_entry-names.mjs +105 -0
- package/api/docs/docs.d.mts +3 -0
- package/api/docs/docs.doc.mjs +7 -1
- package/api/docs/docs.mjs +12 -0
- package/api/docs/docs.type.d.mts +5 -0
- package/api/docs/docs.type.mjs +2 -0
- package/api/docs/node/node.mjs +1 -1
- package/api/doctor/_adapter.d.mts +54 -5
- package/api/doctor/_adapter.mjs +162 -11
- package/api/doctor/built-checks.mjs +40 -14
- package/api/doctor/doctor.d.mts +15 -3
- package/api/doctor/doctor.doc.mjs +1 -1
- package/api/doctor/doctor.mjs +31 -7
- package/api/doctor/theme-checks.d.mts +35 -3
- package/api/doctor/theme-checks.mjs +377 -29
- package/api/hook/_adapter.d.mts +10 -4
- package/api/hook/_adapter.mjs +41 -5
- package/api/hook/detail/detail.mjs +5 -2
- package/api/hook/detail/params/params.mjs +10 -3
- package/api/icon/_records.mjs +2 -1
- package/api/index.d.mts +2 -0
- package/api/index.mjs +2 -0
- package/api/integration/_adapter.d.mts +44 -0
- package/api/integration/_adapter.mjs +77 -1
- package/api/integration/add-helpers.mjs +10 -0
- package/api/integration/authoring-checks.mjs +11 -8
- package/api/integration/example-scope.d.mts +14 -0
- package/api/integration/example-scope.mjs +44 -0
- package/api/integration/example-scope.type.d.mts +29 -0
- package/api/integration/example-scope.type.mjs +25 -0
- package/api/integration/integrationExampleScope.doc.d.mts +11 -0
- package/api/integration/integrationExampleScope.doc.mjs +59 -0
- package/api/integration/pack-check.mjs +16 -1
- package/api/integration/validate-integration.d.mts +18 -6
- package/api/integration/validate-integration.mjs +129 -15
- package/api/integration/validate-integration.type.d.mts +22 -0
- package/api/integration/validate-integration.type.mjs +2 -1
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/render/_adapter.mjs +591 -195
- package/api/render/render.doc.mjs +11 -3
- package/api/render/render.type.d.mts +53 -1
- package/api/render/render.type.mjs +32 -2
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.d.mts +9 -0
- package/api/search/_adapter.mjs +85 -0
- package/api/search/_candidate-score.d.mts +9 -4
- package/api/search/_candidate-score.mjs +133 -46
- package/api/search/_fit-order.mjs +3 -3
- package/api/search/_gather-components.d.mts +3 -2
- package/api/search/_gather-components.mjs +12 -3
- package/api/search/_lexical.d.mts +14 -0
- package/api/search/_lexical.mjs +93 -11
- package/api/search/_result.d.mts +11 -9
- package/api/search/_result.mjs +4 -4
- package/api/search/_score.d.mts +6 -1
- package/api/search/_score.mjs +15 -3
- package/api/search/search-index.mjs +7 -1
- package/api/search/search.d.mts +1 -1
- package/api/template/_adapter.d.mts +16 -0
- package/api/template/_adapter.mjs +39 -2
- package/api/template/cdn/cdn.mjs +37 -8
- package/api/template/copy/copy.d.mts +6 -3
- package/api/template/copy/copy.mjs +40 -8
- package/api/template/template.doc.mjs +3 -3
- package/api/template/template.mjs +63 -11
- package/api/template/template.type.d.mts +1 -0
- package/api/template/template.type.mjs +1 -0
- package/api/theme/_adapter.d.mts +12 -1
- package/api/theme/_adapter.mjs +132 -13
- package/api/theme/_app-provider.d.mts +31 -0
- package/api/theme/_app-provider.mjs +135 -0
- package/api/theme/add/add.mjs +3 -1
- package/api/theme/build/build.d.mts +142 -1
- package/api/theme/build/build.mjs +692 -284
- package/api/theme/build/core-interception.d.mts +10 -0
- package/api/theme/build/core-interception.mjs +10 -0
- package/api/theme/build/font-warning.d.mts +80 -5
- package/api/theme/build/font-warning.mjs +323 -55
- package/api/theme/build/icon-imports.mjs +51 -9
- package/api/theme/build/null-values.d.mts +28 -0
- package/api/theme/build/null-values.mjs +191 -0
- package/api/theme/list/list.mjs +17 -1
- package/api/theme/remove/remove.d.mts +2 -1
- package/api/theme/remove/remove.mjs +7 -3
- package/api/theme/theme.type.d.mts +78 -1
- package/api/theme/theme.type.mjs +38 -2
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +8 -5
- package/api/theme-edit/_adapter.d.mts +116 -4
- package/api/theme-edit/_adapter.mjs +1058 -93
- package/api/theme-edit/_catalog.d.mts +46 -2
- package/api/theme-edit/_catalog.mjs +115 -14
- package/api/theme-edit/_check.d.mts +133 -24
- package/api/theme-edit/_check.mjs +3392 -531
- package/api/theme-edit/_color.d.mts +26 -0
- package/api/theme-edit/_color.mjs +92 -2
- package/api/theme-edit/_compiler.d.mts +5 -1
- package/api/theme-edit/_compiler.mjs +141 -17
- package/api/theme-edit/_context.d.mts +74 -6
- package/api/theme-edit/_context.mjs +468 -76
- package/api/theme-edit/_css.d.mts +21 -0
- package/api/theme-edit/_css.mjs +87 -14
- package/api/theme-edit/_edit.d.mts +74 -7
- package/api/theme-edit/_edit.mjs +4426 -319
- package/api/theme-edit/_how-commands.d.mts +76 -1
- package/api/theme-edit/_how-commands.mjs +793 -9
- package/api/theme-edit/_how-question.d.mts +97 -6
- package/api/theme-edit/_how-question.mjs +9184 -747
- package/api/theme-edit/_how.d.mts +5 -2
- package/api/theme-edit/_how.mjs +255 -46
- package/api/theme-edit/_importers.d.mts +38 -0
- package/api/theme-edit/_importers.mjs +188 -0
- package/api/theme-edit/_marks.d.mts +31 -5
- package/api/theme-edit/_marks.mjs +57 -5
- package/api/theme-edit/_name-rule.d.mts +11 -0
- package/api/theme-edit/_name-rule.mjs +12 -0
- package/api/theme-edit/_normal.d.mts +322 -0
- package/api/theme-edit/_normal.mjs +1630 -0
- package/api/theme-edit/_palette.d.mts +49 -0
- package/api/theme-edit/_palette.mjs +180 -38
- package/api/theme-edit/_part-words.d.mts +39 -0
- package/api/theme-edit/_part-words.mjs +152 -0
- package/api/theme-edit/_parts.d.mts +55 -3
- package/api/theme-edit/_parts.mjs +421 -36
- package/api/theme-edit/_preview-app.d.mts +7 -13
- package/api/theme-edit/_preview-app.mjs +1108 -599
- package/api/theme-edit/_preview.d.mts +156 -19
- package/api/theme-edit/_preview.mjs +809 -180
- package/api/theme-edit/_project.d.mts +61 -1
- package/api/theme-edit/_project.mjs +177 -6
- package/api/theme-edit/_settings.d.mts +619 -48
- package/api/theme-edit/_settings.mjs +4910 -617
- package/api/theme-edit/_tables.d.mts +41 -0
- package/api/theme-edit/_tables.mjs +261 -41
- package/api/theme-edit/_vet.d.mts +31 -0
- package/api/theme-edit/_vet.mjs +114 -8
- package/api/theme-edit/theme-edit.type.d.mts +34 -2
- package/api/theme-edit/theme-edit.type.mjs +18 -3
- package/api/theme-edit/themeEditHow.doc.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -1
- package/api/theme-edit/themeEditNew.doc.mjs +7 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +3 -3
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +2 -2
- package/api/upgrade/run/run.mjs +4 -3
- package/api/upgrade/upgrade.mjs +16 -1
- package/assets/codemods/integration-discovery.mjs +2 -1
- package/assets/codemods/integration-runner.mjs +1 -1
- package/assets/codemods/jscodeshift.d.ts +1 -1
- package/assets/codemods/run-codemod.mjs +151 -18
- package/assets/codemods/runner.mjs +1 -4
- package/assets/codemods/transforms/next/index.mjs +11 -1
- package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
- package/assets/component-list.generated.json +1 -0
- package/assets/docs/author-a-theme.doc.mjs +2 -0
- package/assets/docs/theme.doc.dense.mjs +76 -7
- package/assets/docs/theme.doc.mjs +66 -2
- package/assets/docs/theme.doc.zh.mjs +51 -1
- package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
- package/assets/docs/tree/checks.doc.mjs +2 -2
- package/assets/docs/tree/cli-command.doc.mjs +2 -3
- package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +1 -1
- package/assets/docs/tree/fonts-and-assets.doc.mjs +1 -1
- package/assets/docs/tree/render-pages.doc.mjs +46 -5
- package/assets/docs/tree/share-a-page.doc.mjs +157 -0
- package/assets/docs/tree/single-component.doc.mjs +4 -0
- package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
- package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
- package/assets/docs/tree/write-good-templates.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +2 -2
- package/assets/docs-routes.generated.json +1 -0
- package/assets/docs.generated.json +2 -2
- package/assets/search-catalog.generated.json +2 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/ChatComposerInput/useSpeechRecognitionHookUsage.tsx +43 -0
- package/assets/templates/blocks/components/Hooks/useContainerRevealHookUsage.tsx +2 -2
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat/template.doc.mjs +5 -4
- package/assets/templates/pages/ai-chat-landing/page.tsx +31 -4
- package/assets/templates/pages/ai-chat-landing/template.doc.mjs +5 -1
- package/assets/templates/pages/blank/template.doc.mjs +1 -1
- package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
- package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
- package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
- package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
- package/assets/templates/pages/dashboard-alert-rail/page.tsx +1 -1
- package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-cohort-funnel/page.tsx +1 -1
- package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-comparison/page.tsx +2 -2
- package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
- package/assets/templates/pages/dashboard-progress/page.tsx +1 -1
- package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
- package/assets/templates/pages/detail-page/page.tsx +60 -7
- package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
- package/assets/templates/pages/documentation/template.doc.mjs +4 -1
- package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
- package/assets/templates/pages/documentation-technical/page.tsx +13 -13
- package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
- package/assets/templates/pages/editor/page.tsx +14 -2
- package/assets/templates/pages/editor/template.doc.mjs +2 -8
- package/assets/templates/pages/file-explorer/page.tsx +9 -0
- package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
- package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
- package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
- package/assets/templates/pages/form-wizard-vertical/page.tsx +23 -3
- package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
- package/assets/templates/pages/ide/page.tsx +33 -2
- package/assets/templates/pages/kanban-board/page.tsx +12 -2
- package/assets/templates/pages/kanban-board/template.doc.mjs +1 -9
- package/assets/templates/pages/library/template.doc.mjs +4 -1
- package/assets/templates/pages/login/template.doc.mjs +2 -1
- package/assets/templates/pages/login-card/page.tsx +16 -0
- package/assets/templates/pages/login-card/template.doc.mjs +2 -1
- package/assets/templates/pages/login-split/page.tsx +19 -6
- package/assets/templates/pages/login-split/template.doc.mjs +2 -1
- package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
- package/assets/templates/pages/messaging-shell/template.doc.mjs +6 -0
- package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/payment-form/page.tsx +30 -4
- package/assets/templates/pages/product-detail/page.tsx +26 -2
- package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
- package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-dialog/page.tsx +162 -12
- package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
- package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
- package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
- package/assets/templates/pages/shell-side-nav/page.tsx +11 -3
- package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
- package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
- package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
- package/assets/templates/pages/table-filter/page.tsx +9 -0
- package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
- package/assets/templates/pages/table-grouped/page.tsx +161 -133
- package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
- package/assets/templates/pages/table-page/page.tsx +14 -1
- package/assets/templates/pages/table-page/template.doc.mjs +5 -4
- package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -9
- package/assets/templates/pages/work-item-detail/page.tsx +47 -7
- package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
- package/assets/theme.template.ts +9 -2
- package/authoring/debug/parse.d.mts +3 -3
- package/authoring/doctypes/_schema.d.mts +9 -9
- package/authoring/doctypes/command/command.doc.mjs +1 -1
- package/authoring/doctypes/component/categories.d.mts +37 -0
- package/authoring/doctypes/component/categories.mjs +54 -0
- package/authoring/doctypes/template/template.doc.mjs +1 -1
- package/authoring/doctypes/template/type.ts +9 -0
- package/authoring/example/example.doc.d.mts +12 -0
- package/authoring/example/example.doc.mjs +69 -0
- package/authoring/example/preview.d.mts +92 -0
- package/authoring/example/preview.mjs +994 -0
- package/authoring/example/type.ts +102 -0
- package/authoring/index.d.mts +1 -0
- package/authoring/index.d.ts +12 -0
- package/authoring/index.mjs +3 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +24 -1
- package/authoring/integration/schema.mjs +126 -4
- package/authoring/integration/type.ts +14 -0
- package/clients/cli/bin/astryx.mjs +6 -9
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/component.doc.mjs +1 -1
- package/clients/cli/commands/component.mjs +22 -3
- package/clients/cli/commands/discover.mjs +70 -3
- package/clients/cli/commands/docs.doc.mjs +7 -1
- package/clients/cli/commands/docs.mjs +44 -6
- package/clients/cli/commands/doctor.mjs +84 -16
- package/clients/cli/commands/experimental/render.mjs +42 -1
- package/clients/cli/commands/experimental/theme.mjs +1032 -134
- package/clients/cli/commands/experimental-render.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +87 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +10 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +2 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +4 -4
- package/clients/cli/commands/experimental-theme.doc.mjs +5 -1
- package/clients/cli/commands/search.doc.mjs +2 -1
- package/clients/cli/commands/search.mjs +6 -1
- package/clients/cli/commands/template.doc.mjs +1 -1
- package/clients/cli/commands/template.mjs +15 -2
- package/clients/cli/commands/theme-add.doc.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +5 -1
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +13 -5
- package/clients/cli/commands/theme.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +849 -441
- package/clients/cli/commands/upgrade.mjs +46 -8
- package/clients/cli/index.mjs +9 -19
- package/clients/cli/lib/cli-error.mjs +2 -1
- package/clients/cli/lib/component-format.mjs +205 -98
- package/clients/cli/lib/hook-format.mjs +9 -19
- package/clients/cli/lib/json-shim.mjs +265 -29
- package/clients/cli/lib/manifest.mjs +3 -2
- package/clients/cli/lib/stray-option.mjs +478 -0
- package/clients/cli/lib/unknown-command.mjs +353 -0
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/config/project.d.mts +8 -0
- package/foundation/config/project.mjs +26 -29
- package/foundation/config/theme-state.d.mts +31 -2
- package/foundation/config/theme-state.mjs +140 -8
- package/foundation/discovery/authoring-self-docs.mjs +1 -0
- package/foundation/discovery/cli-self-doc-names.d.mts +13 -0
- package/foundation/discovery/cli-self-doc-names.mjs +51 -0
- package/foundation/discovery/cli-self-docs.d.mts +0 -2
- package/foundation/discovery/cli-self-docs.mjs +2 -15
- package/foundation/discovery/component-discovery.d.mts +11 -0
- package/foundation/discovery/component-discovery.mjs +59 -10
- package/foundation/discovery/component-replacement.mjs +130 -1
- package/foundation/discovery/copied-passages.mjs +2 -1
- package/foundation/discovery/core-component-docs.d.mts +29 -0
- package/foundation/discovery/core-component-docs.mjs +83 -0
- package/foundation/discovery/core-theme-facts.d.mts +70 -0
- package/foundation/discovery/core-theme-facts.mjs +384 -0
- package/foundation/discovery/doc-types.mjs +4 -3
- package/foundation/discovery/docs-discovery.d.mts +66 -9
- package/foundation/discovery/docs-discovery.mjs +126 -60
- package/foundation/discovery/entry-name-files.d.mts +106 -0
- package/foundation/discovery/entry-name-files.mjs +354 -0
- package/foundation/discovery/hook-discovery.d.mts +18 -2
- package/foundation/discovery/hook-discovery.mjs +93 -42
- package/foundation/discovery/icon-definition-discovery.mjs +2 -1
- package/foundation/discovery/icon-set-checks.mjs +2 -1
- package/foundation/discovery/icon-set-discovery.mjs +2 -1
- package/foundation/discovery/integration-component-views.d.mts +15 -0
- package/foundation/discovery/integration-component-views.mjs +91 -0
- package/foundation/discovery/integration-doc-files.mjs +2 -1
- package/foundation/discovery/module-exports.d.mts +26 -1
- package/foundation/discovery/module-exports.mjs +114 -40
- package/foundation/discovery/name-roots.d.mts +38 -0
- package/foundation/discovery/name-roots.mjs +108 -0
- package/foundation/discovery/next-routes.d.mts +48 -0
- package/foundation/discovery/next-routes.mjs +181 -0
- package/foundation/discovery/package-exports.d.mts +10 -0
- package/foundation/discovery/package-exports.mjs +56 -3
- package/foundation/discovery/prop-drift.mjs +9 -9
- package/foundation/discovery/runner-allowlist.d.mts +1 -0
- package/foundation/discovery/runner-allowlist.mjs +2 -0
- package/foundation/discovery/stored-component-list.d.mts +43 -0
- package/foundation/discovery/stored-component-list.mjs +90 -0
- package/foundation/discovery/stored-search-catalog.d.mts +115 -0
- package/foundation/discovery/stored-search-catalog.mjs +297 -0
- package/foundation/discovery/stored-self-audit.d.mts +26 -10
- package/foundation/discovery/stored-self-audit.mjs +40 -18
- package/foundation/discovery/template-adapter.d.mts +49 -29
- package/foundation/discovery/template-adapter.mjs +89 -99
- package/foundation/discovery/template-destination.d.mts +28 -0
- package/foundation/discovery/template-destination.mjs +104 -0
- package/foundation/discovery/template-icons.mjs +2 -1
- package/foundation/discovery/template-ids.d.mts +69 -0
- package/foundation/discovery/template-ids.mjs +199 -0
- package/foundation/discovery/theme-discovery.d.mts +12 -0
- package/foundation/discovery/theme-discovery.mjs +34 -4
- package/foundation/discovery/theme-imports.d.mts +24 -0
- package/foundation/discovery/theme-imports.mjs +61 -4
- package/foundation/discovery/theming-targets.d.mts +13 -5
- package/foundation/discovery/theming-targets.mjs +41 -47
- package/foundation/doc-compiler/generated-levels.d.mts +43 -0
- package/foundation/doc-compiler/generated-levels.mjs +72 -0
- package/foundation/doc-compiler/import.mjs +7 -1
- package/foundation/doc-compiler/inputs.mjs +3 -2
- package/foundation/doc-compiler/literal-doc.d.mts +12 -0
- package/foundation/doc-compiler/literal-doc.mjs +322 -0
- package/foundation/doc-compiler/parse-readable.mjs +4 -1
- package/foundation/doc-compiler/stored-docs.d.mts +29 -0
- package/foundation/doc-compiler/stored-docs.mjs +63 -1
- package/foundation/doc-compiler/tree.d.mts +4 -84
- package/foundation/doc-compiler/tree.mjs +4 -62
- package/foundation/env/semver.mjs +3 -1
- package/foundation/fonts/font-stylesheet.d.mts +46 -0
- package/foundation/fonts/font-stylesheet.mjs +173 -0
- package/foundation/fs/cache-eviction.d.mts +21 -0
- package/foundation/fs/cache-eviction.mjs +73 -0
- package/foundation/fs/exact-codec.d.mts +12 -2
- package/foundation/fs/exact-codec.mjs +23 -6
- package/foundation/fs/file-protection.mjs +16 -5
- package/foundation/fs/gather-cache.d.mts +94 -4
- package/foundation/fs/gather-cache.mjs +671 -106
- package/foundation/fs/glob.d.mts +16 -0
- package/foundation/fs/glob.mjs +105 -0
- package/foundation/fs/jiti-cache.d.mts +19 -1
- package/foundation/fs/jiti-cache.mjs +130 -6
- package/foundation/fs/kept-tree.d.mts +80 -0
- package/foundation/fs/kept-tree.mjs +240 -0
- package/foundation/fs/listing-cache.d.mts +7 -0
- package/foundation/fs/listing-cache.mjs +10 -0
- package/foundation/fs/module-loader.d.mts +24 -2
- package/foundation/fs/module-loader.mjs +94 -21
- package/foundation/fs/path-safety.d.mts +11 -2
- package/foundation/fs/path-safety.mjs +108 -18
- package/foundation/fs/paths.d.mts +18 -0
- package/foundation/fs/paths.mjs +15 -2
- package/foundation/fs/read-record.d.mts +56 -7
- package/foundation/fs/read-record.mjs +280 -56
- package/foundation/fs/regular-file.d.mts +29 -0
- package/foundation/fs/regular-file.mjs +77 -0
- package/foundation/fs/stop-cleanup.d.mts +12 -0
- package/foundation/fs/stop-cleanup.mjs +66 -0
- package/foundation/identity/provider-identity.d.mts +6 -0
- package/foundation/identity/provider-identity.mjs +10 -1
- package/foundation/integrations/contribution-inventory.mjs +4 -3
- package/foundation/integrations/example-code.d.mts +63 -0
- package/foundation/integrations/example-code.mjs +416 -0
- package/foundation/integrations/integrations.d.mts +23 -1
- package/foundation/integrations/integrations.mjs +18 -1
- package/foundation/integrations/pack-state.d.mts +75 -0
- package/foundation/integrations/pack-state.mjs +314 -0
- package/foundation/integrations/public-imports.d.mts +9 -0
- package/foundation/integrations/public-imports.mjs +3 -2
- package/foundation/integrations/shipped-imports.d.mts +122 -0
- package/foundation/integrations/shipped-imports.mjs +497 -0
- package/foundation/integrations/validate-contributions.d.mts +0 -17
- package/foundation/integrations/validate-contributions.mjs +59 -333
- package/foundation/render/assets.mjs +52 -7
- package/foundation/render/charts.d.mts +78 -27
- package/foundation/render/charts.mjs +266 -90
- package/foundation/render/embedded-files.d.mts +6 -0
- package/foundation/render/embedded-files.mjs +25 -5
- package/foundation/render/embedded-imports.d.mts +70 -7
- package/foundation/render/embedded-imports.mjs +132 -41
- package/foundation/render/file-header.d.mts +66 -0
- package/foundation/render/file-header.mjs +118 -0
- package/foundation/render/host-answer.d.mts +18 -0
- package/foundation/render/host-answer.mjs +46 -0
- package/foundation/render/host-exit.d.mts +1 -0
- package/foundation/render/host-exit.mjs +6 -1
- package/foundation/render/html-reader.d.mts +55 -2
- package/foundation/render/html-reader.mjs +145 -26
- package/foundation/render/layers.d.mts +30 -0
- package/foundation/render/layers.mjs +158 -0
- package/foundation/render/markup-edits.d.mts +57 -0
- package/foundation/render/markup-edits.mjs +182 -0
- package/foundation/render/offline.d.mts +32 -0
- package/foundation/render/offline.mjs +56 -0
- package/foundation/render/page-host.mjs +29 -12
- package/foundation/render/page-worker.mjs +354 -21
- package/foundation/render/picture-chrome.d.mts +4 -0
- package/foundation/render/picture-chrome.mjs +192 -0
- package/foundation/render/picture-playwright.d.mts +4 -0
- package/foundation/render/picture-playwright.mjs +46 -0
- package/foundation/render/rebuild.mjs +2 -1
- package/foundation/render/render-page.d.mts +79 -5
- package/foundation/render/render-page.mjs +735 -109
- package/foundation/render/source-block.d.mts +85 -6
- package/foundation/render/source-block.mjs +211 -20
- package/foundation/render/ts-paths.d.mts +69 -6
- package/foundation/render/ts-paths.mjs +326 -40
- package/foundation/response/error-codes.d.mts +3 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +12 -1
- package/foundation/response/error-codes.mjs +11 -1
- package/foundation/response/response-types.doc.mjs +6 -6
- package/foundation/suggest/name-index.d.mts +148 -0
- package/foundation/suggest/name-index.mjs +317 -0
- package/foundation/suggest/other-command.d.mts +140 -0
- package/foundation/suggest/other-command.mjs +756 -0
- package/foundation/text/compare-text.d.mts +14 -0
- package/foundation/text/compare-text.mjs +68 -0
- package/foundation/text/css-escape.d.mts +18 -0
- package/foundation/text/css-escape.mjs +35 -0
- package/foundation/text/entry-names.d.mts +14 -0
- package/foundation/text/entry-names.mjs +14 -0
- package/foundation/text/string-utils.d.mts +46 -6
- package/foundation/text/string-utils.mjs +118 -20
- package/foundation/text/suggest-order.d.mts +47 -4
- package/foundation/text/suggest-order.mjs +174 -5
- package/foundation/xle/browser.d.mts +2 -2
- package/foundation/xle/expand.mjs +2 -1
- package/host/index.mjs +8 -6
- package/package.json +7 -6
|
@@ -17,38 +17,70 @@
|
|
|
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, by theme build
|
|
25
|
+
* (foundation/discovery/core-theme-facts.mjs) for what it checks a theme
|
|
26
|
+
* against in Core's component docs,
|
|
27
|
+
* by `doctor` (api/doctor/_adapter.mjs) for its file-only docs checks and
|
|
28
|
+
* its theme-wiring scan, by the docs adapter (api/docs/_adapter.mjs) for
|
|
29
|
+
* the CLI's own docs tree, which `docs` and `search` read,
|
|
30
|
+
* in a run that records modules and variables to its end, and, through
|
|
31
|
+
* `persistedSummary`, by kept-tree.mjs for summaries of folder trees, the
|
|
32
|
+
* lookup commands' not-found hint's name index among them
|
|
33
|
+
* (foundation/suggest/name-index.mjs), each kept while every path it
|
|
34
|
+
* stamped but the CLI's own files (which its build id covers) is
|
|
35
|
+
* unchanged, in any command. The commands whose runs keep the other
|
|
36
|
+
* entries are `search`, `build`, `component`, `template`, `theme`,
|
|
37
|
+
* `discover`, `docs` and `doctor`. The first such run on a machine makes the
|
|
38
|
+
* folder and keeps its gathers at once, so the next run (most often the same
|
|
39
|
+
* session's next command) uses them; doctor never makes it. A run through
|
|
40
|
+
* the host entry keeps them too, keyed on what the host passed
|
|
41
|
+
* (hostInputs). Only a published CLI stores anything:
|
|
27
42
|
* its build id (clients/cli/build-id.generated.json, written at `prepack`)
|
|
28
43
|
* names its exact code, so a checkout, whose code may change between runs
|
|
29
44
|
* under the same version, always gathers.
|
|
30
45
|
*
|
|
46
|
+
* An entry stores only the states that the kept entries it builds on do
|
|
47
|
+
* not hold: it names each of them, at the version it read, and is used
|
|
48
|
+
* only while each is still there at that version and holds. A run checks
|
|
49
|
+
* each kept entry once, so entries that read the same files (the component
|
|
50
|
+
* list, its replacements, the project's issues) check those files once. An
|
|
51
|
+
* entry built on is marked as used after the entries built on it, so
|
|
52
|
+
* eviction removes it after them. A gather's entry file holds two lines:
|
|
53
|
+
* what the entry is and stands for (its format, key, version, the entries
|
|
54
|
+
* it builds on, its states and variables), then its value. Checking an
|
|
55
|
+
* entry, or one an entry builds on, parses only the first line.
|
|
56
|
+
*
|
|
31
57
|
* The folder is `catalogs` in the user's cache folder (userCacheDir):
|
|
32
58
|
* created 0700, used only while it is a real folder owned by the user and
|
|
33
59
|
* 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
|
|
60
|
+
* CACHE_LIMIT_BYTES (cache-eviction.mjs). Any failure to read, check, parse or write is silent
|
|
35
61
|
* and the run gathers fresh, as it would with no cache.
|
|
36
62
|
*/
|
|
37
63
|
|
|
38
|
-
import {createHash} from 'node:crypto';
|
|
64
|
+
import {createHash, randomBytes} from 'node:crypto';
|
|
39
65
|
import * as fs from 'node:fs';
|
|
40
66
|
import * as nodeModule from 'node:module';
|
|
41
67
|
import * as os from 'node:os';
|
|
42
68
|
import * as path from 'node:path';
|
|
43
69
|
import {fileURLToPath} from 'node:url';
|
|
44
70
|
import {isDeepStrictEqual} from 'node:util';
|
|
45
|
-
import {CLI_ROOT} from './paths.mjs';
|
|
71
|
+
import {CLI_ROOT, realDir} from './paths.mjs';
|
|
46
72
|
import {mayHaveIntegrations} from '../integrations/may-have-integrations.mjs';
|
|
47
73
|
import {currentUid, isPrivateDir} from '../env/private-dir.mjs';
|
|
48
74
|
import {userCacheDir} from '../env/user-dirs.mjs';
|
|
49
75
|
import {jitiCacheDir} from './jiti-cache.mjs';
|
|
76
|
+
import {hostedRun} from '../runtime/package-root.mjs';
|
|
77
|
+
import {cliDoor} from '../env/cli-command.mjs';
|
|
78
|
+
import {CACHE_LIMIT_BYTES, evictOldest} from './cache-eviction.mjs';
|
|
50
79
|
import {
|
|
80
|
+
PRESENT,
|
|
81
|
+
lookedUp,
|
|
51
82
|
fileStamp,
|
|
83
|
+
keepState,
|
|
52
84
|
recordReads,
|
|
53
85
|
recordStates,
|
|
54
86
|
stillInState,
|
|
@@ -78,7 +110,9 @@ const KEPT_COMMANDS = new Set([
|
|
|
78
110
|
'theme',
|
|
79
111
|
'discover',
|
|
80
112
|
'docs',
|
|
81
|
-
//
|
|
113
|
+
// Its project check, with or without `--built`, keeps its docs checks and
|
|
114
|
+
// theme-wiring scan; its `integration` checks run neither, and keep only
|
|
115
|
+
// the project gathers they load, as the commands above do.
|
|
82
116
|
'doctor',
|
|
83
117
|
]);
|
|
84
118
|
|
|
@@ -90,11 +124,15 @@ export const BUILD_ID_FILE = path.join(
|
|
|
90
124
|
'build-id.generated.json',
|
|
91
125
|
);
|
|
92
126
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Whether a file in the folder is a kept entry, which eviction counts.
|
|
129
|
+
* @param {string} name
|
|
130
|
+
* @returns {boolean}
|
|
131
|
+
*/
|
|
132
|
+
const isEntry = name => name.startsWith('gather-');
|
|
95
133
|
|
|
96
134
|
/** The stored format; a different one is a miss. */
|
|
97
|
-
const FORMAT =
|
|
135
|
+
const FORMAT = 2;
|
|
98
136
|
|
|
99
137
|
/** A variable the run read that was unset, as stored. */
|
|
100
138
|
const UNSET = null;
|
|
@@ -106,7 +144,7 @@ const UNSET = null;
|
|
|
106
144
|
* variables only while the run is armed: from its start to the end of its
|
|
107
145
|
* first gather, and during each later gather, or, in a run armed throughout
|
|
108
146
|
* (`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}
|
|
147
|
+
* @type {{reads: Map<string, string>, env: Map<string, string | null>, arm: () => boolean, disarm: () => void, armedThroughout: boolean, realEnv: NodeJS.ProcessEnv, confirmed: Confirmed} | null}
|
|
110
148
|
*/
|
|
111
149
|
let run = null;
|
|
112
150
|
|
|
@@ -129,14 +167,27 @@ let lastOutcome = null;
|
|
|
129
167
|
* those it was stored with and that a hit has just found unchanged, or those
|
|
130
168
|
* a fresh gather was stored with. A derived value keys on them, so an edit to
|
|
131
169
|
* the CLI's code in an installed copy, which misses the gather, misses the
|
|
132
|
-
* derived value too. Null before any kept gather in the run.
|
|
133
|
-
*
|
|
170
|
+
* derived value too. Null before any kept gather in the run. A hit leaves
|
|
171
|
+
* how to work them out, since only a derived value after it reads them.
|
|
172
|
+
* @type {[string, string][] | (() => [string, string][]) | null}
|
|
134
173
|
*/
|
|
135
174
|
let gatherCode = null;
|
|
136
175
|
|
|
137
176
|
/** How many persistedGather calls are running, nested inside one another. */
|
|
138
177
|
let gatherDepth = 0;
|
|
139
178
|
|
|
179
|
+
/**
|
|
180
|
+
* The kept entries a recorded run has read back or stored, by file: the
|
|
181
|
+
* version each holds, every state it stands for (its own and those of the
|
|
182
|
+
* entries it builds on, as the lists each stores, once each), and every entry
|
|
183
|
+
* it builds on, directly or not. A later entry stores only the states none of
|
|
184
|
+
* them holds and names the ones it builds on, so a run checks each state
|
|
185
|
+
* once. A kept entry is checked before the run's command writes anything; the
|
|
186
|
+
* record ends with the run.
|
|
187
|
+
* @typedef {{version: string, lists: [string, string][][], under: Set<string>, deps: string[], merged?: [string, string][]}} ConfirmedEntry
|
|
188
|
+
* @typedef {Map<string, ConfirmedEntry>} Confirmed
|
|
189
|
+
*/
|
|
190
|
+
|
|
140
191
|
/**
|
|
141
192
|
* The outcome of the last kept gather in this process: whether it was a hit,
|
|
142
193
|
* and why it missed. Null when no kept gather ran.
|
|
@@ -241,8 +292,6 @@ export async function recordRunFor(argv, fn) {
|
|
|
241
292
|
if (
|
|
242
293
|
!command ||
|
|
243
294
|
!KEPT_COMMANDS.has(command) ||
|
|
244
|
-
(command === 'doctor' &&
|
|
245
|
-
argv.filter(arg => !arg.startsWith('-')).length > 1) ||
|
|
246
295
|
runsUnderPnp() ||
|
|
247
296
|
currentUid() == null ||
|
|
248
297
|
withoutRecording(buildId) == null ||
|
|
@@ -254,22 +303,11 @@ export async function recordRunFor(argv, fn) {
|
|
|
254
303
|
) {
|
|
255
304
|
return fn();
|
|
256
305
|
}
|
|
257
|
-
//
|
|
258
|
-
//
|
|
259
|
-
//
|
|
260
|
-
|
|
261
|
-
if (
|
|
262
|
-
// Once the per-user cache folder exists doctor uses it; it never makes
|
|
263
|
-
// it, so a doctor alone changes nothing on the machine (nor its own
|
|
264
|
-
// cache row).
|
|
265
|
-
if (command === 'doctor') return fn();
|
|
266
|
-
try {
|
|
267
|
-
withoutRecording(() => fs.mkdirSync(dir, {recursive: true, mode: 0o700}));
|
|
268
|
-
} catch {
|
|
269
|
-
// A folder that cannot be made keeps no catalogs; nothing more.
|
|
270
|
-
}
|
|
271
|
-
return fn();
|
|
272
|
-
}
|
|
306
|
+
// The first recorded run on a machine (search, build, component, template,
|
|
307
|
+
// theme, discover or docs) makes the folder and keeps its gathers at once.
|
|
308
|
+
// Once the per-user cache folder exists doctor uses it; it never makes it,
|
|
309
|
+
// so a doctor alone changes nothing on the machine (nor its own cache row).
|
|
310
|
+
if (command !== 'doctor') makeGatherCacheDir();
|
|
273
311
|
// A folder the cache would refuse (not the user's own, open to others, a
|
|
274
312
|
// link) leaves the run exactly as without the cache: no hook is installed.
|
|
275
313
|
if (withoutRecording(gatherCacheDir) == null) return fn();
|
|
@@ -279,6 +317,35 @@ export async function recordRunFor(argv, fn) {
|
|
|
279
317
|
return recordRun(fn, {armedThroughout: command === 'doctor'});
|
|
280
318
|
}
|
|
281
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Make the kept catalogs' folder where this run could keep entries in it and
|
|
322
|
+
* it does not exist yet: an installed CLI with a build id, outside Yarn
|
|
323
|
+
* Plug'n'Play, on a system with user ids. Recorded runs make it at their
|
|
324
|
+
* start; the lookup commands' not-found hint makes it before it keeps its
|
|
325
|
+
* name index, so a project's first miss keeps what later misses read. A
|
|
326
|
+
* folder that cannot be made keeps nothing; nothing more.
|
|
327
|
+
* @returns {boolean} whether this run keeps summaries there
|
|
328
|
+
*/
|
|
329
|
+
export function makeGatherCacheDir() {
|
|
330
|
+
if (
|
|
331
|
+
runsUnderPnp() ||
|
|
332
|
+
currentUid() == null ||
|
|
333
|
+
withoutRecording(buildId) == null
|
|
334
|
+
) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
const dir = cacheDirPath();
|
|
338
|
+
try {
|
|
339
|
+
withoutRecording(() => {
|
|
340
|
+
if (!fs.existsSync(dir))
|
|
341
|
+
fs.mkdirSync(dir, {recursive: true, mode: 0o700});
|
|
342
|
+
});
|
|
343
|
+
} catch {
|
|
344
|
+
// A folder that cannot be made keeps no catalogs.
|
|
345
|
+
}
|
|
346
|
+
return withoutRecording(gatherCacheDir) != null;
|
|
347
|
+
}
|
|
348
|
+
|
|
282
349
|
/**
|
|
283
350
|
* Run `fn` as a recorded run (see `run`), armed from its start. Exported for
|
|
284
351
|
* tests; `recordRunFor` decides which runs are recorded.
|
|
@@ -373,7 +440,8 @@ export async function recordRun(fn, {armedThroughout = false} = {}) {
|
|
|
373
440
|
if (hooks && url.startsWith('file:')) {
|
|
374
441
|
try {
|
|
375
442
|
const file = fileURLToPath(url);
|
|
376
|
-
|
|
443
|
+
// The load reads the module's content: its stamp.
|
|
444
|
+
keepState(reads, file, fileStamp, 'stamp');
|
|
377
445
|
} catch {
|
|
378
446
|
// A URL with no file path holds nothing to check.
|
|
379
447
|
}
|
|
@@ -389,7 +457,15 @@ export async function recordRun(fn, {armedThroughout = false} = {}) {
|
|
|
389
457
|
}
|
|
390
458
|
};
|
|
391
459
|
if (!arm()) return fn();
|
|
392
|
-
run = {
|
|
460
|
+
run = {
|
|
461
|
+
reads,
|
|
462
|
+
env,
|
|
463
|
+
arm,
|
|
464
|
+
disarm,
|
|
465
|
+
armedThroughout,
|
|
466
|
+
realEnv,
|
|
467
|
+
confirmed: new Map(),
|
|
468
|
+
};
|
|
393
469
|
try {
|
|
394
470
|
return await recordReads(reads, fn, {exact: true});
|
|
395
471
|
} finally {
|
|
@@ -424,7 +500,7 @@ function noteLookups(specifier, parentURL, reads) {
|
|
|
424
500
|
for (;;) {
|
|
425
501
|
if (path.basename(dir) !== 'node_modules') {
|
|
426
502
|
const candidate = path.join(dir, 'node_modules', name);
|
|
427
|
-
|
|
503
|
+
keepState(reads, candidate, lookupStamp);
|
|
428
504
|
}
|
|
429
505
|
const up = path.dirname(dir);
|
|
430
506
|
if (up === dir) break;
|
|
@@ -516,9 +592,29 @@ function entryKey(key, id) {
|
|
|
516
592
|
process.platform,
|
|
517
593
|
process.arch,
|
|
518
594
|
...key,
|
|
595
|
+
hostInputs(),
|
|
519
596
|
]);
|
|
520
597
|
}
|
|
521
598
|
|
|
599
|
+
/**
|
|
600
|
+
* What a host passed that decides a gather, or null outside a hosted run: its
|
|
601
|
+
* package sets, by real path and in its order, the integrations it approves,
|
|
602
|
+
* and the command it runs the CLI as, which kept findings print. A run reads
|
|
603
|
+
* only some of a package set's files, so their stamps cannot tell a hosted
|
|
604
|
+
* run from a run of the bin in the same folder, and no file holds the
|
|
605
|
+
* command. The run's folder is in each gather's own key.
|
|
606
|
+
* @returns {{roots: string[], integrations: string[], door: string | null} | null}
|
|
607
|
+
*/
|
|
608
|
+
function hostInputs() {
|
|
609
|
+
const hosted = hostedRun();
|
|
610
|
+
if (hosted == null) return null;
|
|
611
|
+
return {
|
|
612
|
+
roots: hosted.roots.map(root => withoutRecording(() => realDir(root))),
|
|
613
|
+
integrations: [...hosted.integrations],
|
|
614
|
+
door: cliDoor() ?? null,
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
|
|
522
618
|
/**
|
|
523
619
|
* Whether every stored state still holds: files, folders and modules, and the
|
|
524
620
|
* environment.
|
|
@@ -541,11 +637,214 @@ function staleReason(stamps, env) {
|
|
|
541
637
|
}
|
|
542
638
|
}
|
|
543
639
|
for (const [file, state] of stamps) {
|
|
544
|
-
if (!stillInState(file, state))
|
|
640
|
+
if (!stillInState(file, state)) {
|
|
641
|
+
return 'a file or folder it read changed';
|
|
642
|
+
}
|
|
545
643
|
}
|
|
546
644
|
return null;
|
|
547
645
|
}
|
|
548
646
|
|
|
647
|
+
/**
|
|
648
|
+
* The states of the kept entries an entry builds on, each found unchanged
|
|
649
|
+
* once per run, with every entry under them and the files of the ones it
|
|
650
|
+
* names; or null when one is gone, holds another version, or changed.
|
|
651
|
+
* @param {string} dir
|
|
652
|
+
* @param {unknown} deps - [entry file name, version] pairs, as stored
|
|
653
|
+
* @param {Confirmed} confirmed - the entries already found unchanged
|
|
654
|
+
* @param {Set<string>} [reading] - entries being checked, so a loop of
|
|
655
|
+
* entries that name each other is a miss
|
|
656
|
+
* @returns {{lists: [string, string][][], under: Set<string>, direct: string[]} | null}
|
|
657
|
+
*/
|
|
658
|
+
function builtOn(dir, deps, confirmed, reading = new Set()) {
|
|
659
|
+
if (!Array.isArray(deps)) return null;
|
|
660
|
+
/** @type {[string, string][][]} */
|
|
661
|
+
const lists = [];
|
|
662
|
+
// Two entries this one names may build on one entry: its list counts once.
|
|
663
|
+
/** @type {Set<[string, string][]>} */
|
|
664
|
+
const listed = new Set();
|
|
665
|
+
/** @type {Set<string>} */
|
|
666
|
+
const under = new Set();
|
|
667
|
+
/** @type {string[]} */
|
|
668
|
+
const direct = [];
|
|
669
|
+
for (const dep of deps) {
|
|
670
|
+
if (!Array.isArray(dep) || typeof dep[0] !== 'string') return null;
|
|
671
|
+
const file = path.join(dir, path.basename(dep[0]));
|
|
672
|
+
const entry = confirmedEntry(file, dep[1], confirmed, reading);
|
|
673
|
+
if (entry == null) return null;
|
|
674
|
+
for (const list of entry.lists) {
|
|
675
|
+
if (listed.has(list)) continue;
|
|
676
|
+
listed.add(list);
|
|
677
|
+
lists.push(list);
|
|
678
|
+
}
|
|
679
|
+
direct.push(file);
|
|
680
|
+
under.add(file);
|
|
681
|
+
for (const below of entry.under) under.add(below);
|
|
682
|
+
}
|
|
683
|
+
return {lists, under, direct};
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Every state a confirmed entry stands for, one per path: its lists, merged
|
|
688
|
+
* the first time something needs them as one (choosing what a new entry
|
|
689
|
+
* builds on).
|
|
690
|
+
* @param {ConfirmedEntry} entry
|
|
691
|
+
* @returns {[string, string][]}
|
|
692
|
+
*/
|
|
693
|
+
function statesOf(entry) {
|
|
694
|
+
entry.merged ??= mergeStates(...entry.lists);
|
|
695
|
+
return entry.merged;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* States from several lists, one per path, as a run's record keeps them
|
|
700
|
+
* (keepState).
|
|
701
|
+
* @param {...[string, string][]} lists
|
|
702
|
+
* @returns {[string, string][]}
|
|
703
|
+
*/
|
|
704
|
+
function mergeStates(...lists) {
|
|
705
|
+
/** @type {Map<string, string>} */
|
|
706
|
+
const merged = new Map();
|
|
707
|
+
for (const list of lists) {
|
|
708
|
+
for (const [at, state] of list) {
|
|
709
|
+
const had = merged.get(at);
|
|
710
|
+
if (had === undefined) merged.set(at, state);
|
|
711
|
+
else if (had !== state) keepState(merged, at, state);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return [...merged];
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Mark an entry as used now, and each kept entry it builds on as used a
|
|
719
|
+
* millisecond (the finest step of a file time set from a Date) after the
|
|
720
|
+
* latest entry built on it, so eviction, which removes the least recently
|
|
721
|
+
* used entries first, never removes an entry before one built on it.
|
|
722
|
+
* @param {string} file
|
|
723
|
+
* @param {Confirmed} confirmed
|
|
724
|
+
*/
|
|
725
|
+
function markUsed(file, confirmed) {
|
|
726
|
+
/** @type {Map<string, number>} */
|
|
727
|
+
const times = new Map();
|
|
728
|
+
/** @type {Set<string>} */
|
|
729
|
+
const onPath = new Set();
|
|
730
|
+
/**
|
|
731
|
+
* @param {string} at
|
|
732
|
+
* @param {number} time
|
|
733
|
+
*/
|
|
734
|
+
const visit = (at, time) => {
|
|
735
|
+
if (onPath.has(at) || (times.get(at) ?? -Infinity) >= time) return;
|
|
736
|
+
times.set(at, time);
|
|
737
|
+
onPath.add(at);
|
|
738
|
+
for (const dep of confirmed.get(at)?.deps ?? []) visit(dep, time + 1);
|
|
739
|
+
onPath.delete(at);
|
|
740
|
+
};
|
|
741
|
+
visit(file, Date.now());
|
|
742
|
+
for (const [at, time] of times) {
|
|
743
|
+
try {
|
|
744
|
+
const when = new Date(time);
|
|
745
|
+
withoutRecording(() => fs.utimesSync(at, when, when));
|
|
746
|
+
} catch {
|
|
747
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* A kept entry at `version`, found unchanged as a hit finds it: read and
|
|
754
|
+
* checked the first time the run meets it, after that from `confirmed`.
|
|
755
|
+
* @param {string} file
|
|
756
|
+
* @param {unknown} version
|
|
757
|
+
* @param {Confirmed} confirmed
|
|
758
|
+
* @param {Set<string>} reading
|
|
759
|
+
* @returns {ConfirmedEntry | null}
|
|
760
|
+
*/
|
|
761
|
+
function confirmedEntry(file, version, confirmed, reading) {
|
|
762
|
+
const known = confirmed.get(file);
|
|
763
|
+
if (known) return known.version === version ? known : null;
|
|
764
|
+
if (reading.has(file)) return null;
|
|
765
|
+
reading.add(file);
|
|
766
|
+
try {
|
|
767
|
+
const stored = readHead(file);
|
|
768
|
+
if (
|
|
769
|
+
stored?.format !== FORMAT ||
|
|
770
|
+
typeof stored.version !== 'string' ||
|
|
771
|
+
stored.version !== version ||
|
|
772
|
+
staleReason(stored.stamps, stored.env) != null
|
|
773
|
+
) {
|
|
774
|
+
return null;
|
|
775
|
+
}
|
|
776
|
+
const base = builtOn(path.dirname(file), stored.deps, confirmed, reading);
|
|
777
|
+
if (base == null) return null;
|
|
778
|
+
/** @type {ConfirmedEntry} */
|
|
779
|
+
const entry = {
|
|
780
|
+
version: stored.version,
|
|
781
|
+
lists: [...base.lists, stored.stamps],
|
|
782
|
+
under: base.under,
|
|
783
|
+
deps: base.direct,
|
|
784
|
+
};
|
|
785
|
+
confirmed.set(file, entry);
|
|
786
|
+
return entry;
|
|
787
|
+
} catch {
|
|
788
|
+
return null;
|
|
789
|
+
} finally {
|
|
790
|
+
reading.delete(file);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The kept entries a new entry builds on: those the run has read back or
|
|
796
|
+
* stored whose every state the run read too, as it holds them, largest
|
|
797
|
+
* first, each only when it holds a state the others do not. Never one that
|
|
798
|
+
* builds on the new entry's own file. An entry that only checked whether a
|
|
799
|
+
* path is there still holds where the run read more of that path (holdsIn);
|
|
800
|
+
* the new entry stores that fuller state, and the rest of its states,
|
|
801
|
+
* itself.
|
|
802
|
+
* @param {string} file - the new entry's file
|
|
803
|
+
* @param {[string, string][]} stamps - every state the run read
|
|
804
|
+
* @param {Confirmed} confirmed
|
|
805
|
+
* @returns {{deps: [string, string][], own: [string, string][], under: Set<string>}}
|
|
806
|
+
*/
|
|
807
|
+
function chooseBase(file, stamps, confirmed) {
|
|
808
|
+
const states = new Map(stamps);
|
|
809
|
+
/** @type {Set<string>} */
|
|
810
|
+
const covered = new Set();
|
|
811
|
+
/** @type {[string, string][]} */
|
|
812
|
+
const deps = [];
|
|
813
|
+
/** @type {Set<string>} */
|
|
814
|
+
const under = new Set();
|
|
815
|
+
const candidates = [...confirmed]
|
|
816
|
+
.filter(([other, entry]) => other !== file && !entry.under.has(file))
|
|
817
|
+
.map(([other, entry]) => ({other, entry, held: statesOf(entry)}))
|
|
818
|
+
.sort((a, b) => b.held.length - a.held.length);
|
|
819
|
+
for (const {other, entry, held} of candidates) {
|
|
820
|
+
if (held.length === 0) continue;
|
|
821
|
+
if (!held.every(([at, state]) => holdsIn(states.get(at), state))) continue;
|
|
822
|
+
const same = held.filter(([at, state]) => states.get(at) === state);
|
|
823
|
+
if (same.every(([at]) => covered.has(at))) continue;
|
|
824
|
+
deps.push([path.basename(other), entry.version]);
|
|
825
|
+
under.add(other);
|
|
826
|
+
for (const below of entry.under) under.add(below);
|
|
827
|
+
for (const [at] of same) covered.add(at);
|
|
828
|
+
}
|
|
829
|
+
return {deps, own: stamps.filter(([at]) => !covered.has(at)), under};
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Whether a state an entry holds agrees with the state the run read of the
|
|
834
|
+
* same path: the same state, or the entry holds only that the path is there,
|
|
835
|
+
* or what a real-path lookup of it gave (confirmed this run), and the run
|
|
836
|
+
* read it there.
|
|
837
|
+
* @param {string | undefined} read - the run's state of the path
|
|
838
|
+
* @param {string} held - the entry's state of it
|
|
839
|
+
* @returns {boolean}
|
|
840
|
+
*/
|
|
841
|
+
function holdsIn(read, held) {
|
|
842
|
+
return (
|
|
843
|
+
read === held ||
|
|
844
|
+
((held === PRESENT || lookedUp(held)) && read !== undefined && read !== '-')
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
|
|
549
848
|
/**
|
|
550
849
|
* The gather `load` returns, or the one a run with the same key stored while
|
|
551
850
|
* every input it read is unchanged (see the file header).
|
|
@@ -604,21 +903,45 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
604
903
|
const file = entryFile(dir, key, id);
|
|
605
904
|
let reason = 'no entry';
|
|
606
905
|
try {
|
|
607
|
-
const stored =
|
|
608
|
-
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
609
|
-
);
|
|
906
|
+
const {head: stored, value: storedValue} = readEntry(file);
|
|
610
907
|
if (stored?.format !== FORMAT) {
|
|
611
908
|
reason = 'another format';
|
|
612
909
|
} else if (stored.key !== entryKey(key, id)) {
|
|
613
910
|
reason = 'an entry for other inputs';
|
|
614
911
|
} else {
|
|
615
|
-
|
|
616
|
-
|
|
912
|
+
// An entry the run already found unchanged, as one an earlier entry
|
|
913
|
+
// builds on, is not checked again. Outside a recorded run nothing is
|
|
914
|
+
// remembered from one gather to the next.
|
|
915
|
+
const confirmed = run?.confirmed ?? new Map();
|
|
916
|
+
const known = confirmed.get(file);
|
|
917
|
+
const seen =
|
|
918
|
+
typeof stored.version === 'string' && known?.version === stored.version
|
|
919
|
+
? known
|
|
920
|
+
: null;
|
|
921
|
+
const own = seen ? null : staleReason(stored.stamps, stored.env);
|
|
922
|
+
const base =
|
|
923
|
+
seen || own != null ? null : builtOn(dir, stored.deps, confirmed);
|
|
924
|
+
const stale =
|
|
925
|
+
own ??
|
|
926
|
+
(seen == null && base == null
|
|
927
|
+
? 'a kept entry it builds on changed'
|
|
928
|
+
: null);
|
|
929
|
+
const value = stale == null ? readBack(storedValue, codec) : undefined;
|
|
617
930
|
if (stale == null && value === undefined) {
|
|
618
931
|
// Gathered again below, and stored over the bad entry.
|
|
619
932
|
reason = 'a malformed value';
|
|
620
933
|
} else if (stale == null) {
|
|
621
|
-
|
|
934
|
+
/** @type {ConfirmedEntry} */
|
|
935
|
+
const entry = seen ?? {
|
|
936
|
+
version: stored.version,
|
|
937
|
+
lists: [...(base?.lists ?? []), stored.stamps],
|
|
938
|
+
under: base?.under ?? new Set(),
|
|
939
|
+
deps: base?.direct ?? [],
|
|
940
|
+
};
|
|
941
|
+
confirmed.set(file, entry);
|
|
942
|
+
// Recorded list by list, which keeps one state per path as a merge
|
|
943
|
+
// would (recordStates).
|
|
944
|
+
for (const list of entry.lists) recordStates(list);
|
|
622
945
|
// A gather around this one depends on what this one read, the
|
|
623
946
|
// environment included: a hit hands its variables on, as a fresh
|
|
624
947
|
// gather's reads would be.
|
|
@@ -627,16 +950,15 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
627
950
|
if (!run.env.has(name)) run.env.set(name, value);
|
|
628
951
|
}
|
|
629
952
|
}
|
|
630
|
-
|
|
953
|
+
// The CLI's own files, one state per path, in the order a fresh
|
|
954
|
+
// gather reads them: merging only those is merging all, then picking
|
|
955
|
+
// them out.
|
|
956
|
+
const {lists} = entry;
|
|
957
|
+
gatherCode = () => mergeStates(...lists.map(cliStates));
|
|
631
958
|
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
|
-
}
|
|
959
|
+
markUsed(file, confirmed);
|
|
638
960
|
return value;
|
|
639
|
-
} else {
|
|
961
|
+
} else if (stale != null) {
|
|
640
962
|
reason = stale;
|
|
641
963
|
}
|
|
642
964
|
}
|
|
@@ -650,6 +972,10 @@ async function gatherAt(key, load, codec, keep) {
|
|
|
650
972
|
const value = await load();
|
|
651
973
|
if (run && armed && keep(value)) {
|
|
652
974
|
withoutRecording(() => store(dir, file, entryKey(key, id), value, codec));
|
|
975
|
+
} else {
|
|
976
|
+
// A value worked out from a gather that is not kept is not kept either.
|
|
977
|
+
// The code a gather inside this one recorded did not build this one.
|
|
978
|
+
gatherCode = null;
|
|
653
979
|
}
|
|
654
980
|
return value;
|
|
655
981
|
}
|
|
@@ -702,6 +1028,7 @@ function codeStamp(code, inputs) {
|
|
|
702
1028
|
*/
|
|
703
1029
|
export function persistedDerived(key, compute, codec, inputs = []) {
|
|
704
1030
|
if (!run || gatherCode == null) return compute();
|
|
1031
|
+
if (typeof gatherCode === 'function') gatherCode = gatherCode();
|
|
705
1032
|
const id = withoutRecording(buildId);
|
|
706
1033
|
const dir = id == null ? null : withoutRecording(gatherCacheDir);
|
|
707
1034
|
if (id == null || dir == null) return compute();
|
|
@@ -716,7 +1043,7 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
716
1043
|
stored?.format === FORMAT &&
|
|
717
1044
|
stored.derived === true &&
|
|
718
1045
|
stored.key === entry
|
|
719
|
-
? readBack(stored, codec)
|
|
1046
|
+
? readBack(() => stored.value, codec)
|
|
720
1047
|
: undefined;
|
|
721
1048
|
if (value !== undefined) {
|
|
722
1049
|
try {
|
|
@@ -733,37 +1060,266 @@ export function persistedDerived(key, compute, codec, inputs = []) {
|
|
|
733
1060
|
const value = compute();
|
|
734
1061
|
withoutRecording(() => {
|
|
735
1062
|
try {
|
|
736
|
-
const
|
|
1063
|
+
const body = storedText(codec, value);
|
|
1064
|
+
if (body === undefined) return;
|
|
1065
|
+
const head = JSON.stringify({format: FORMAT, derived: true, key: entry});
|
|
1066
|
+
// The value's text goes in as checked, as the head's last field.
|
|
1067
|
+
const text = `${head.slice(0, -1)},"value":${body}}`;
|
|
1068
|
+
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
1069
|
+
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
1070
|
+
fs.renameSync(temp, file);
|
|
1071
|
+
evictOldest(dir, isEntry);
|
|
1072
|
+
} catch {
|
|
1073
|
+
// A value that cannot be stored is computed again next time.
|
|
1074
|
+
}
|
|
1075
|
+
});
|
|
1076
|
+
return value;
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* How old every stamped time must be before a summary is stored. A file
|
|
1081
|
+
* system can store times as coarsely as 2 s, so a change within one tick of
|
|
1082
|
+
* the last can leave a stamp as it was.
|
|
1083
|
+
*/
|
|
1084
|
+
const SUMMARY_SETTLE_MS = 2000;
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Whether every stamp in `stamps` was taken longer than
|
|
1088
|
+
* {@link SUMMARY_SETTLE_MS} ago, by its modification and change times.
|
|
1089
|
+
* @param {[string, string][]} stamps
|
|
1090
|
+
* @returns {boolean}
|
|
1091
|
+
*/
|
|
1092
|
+
function settled(stamps) {
|
|
1093
|
+
const limit = Date.now() - SUMMARY_SETTLE_MS;
|
|
1094
|
+
return stamps.every(([, stamp]) => {
|
|
1095
|
+
if (stamp === '-') return true;
|
|
1096
|
+
const [, mtime, ctime] = stamp.split(':').map(Number);
|
|
1097
|
+
return mtime < limit && ctime < limit;
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/**
|
|
1102
|
+
* A summary of files and folders, made at once, kept as an entry beside the
|
|
1103
|
+
* gathers, in or out of a recorded run: the stored value while every path
|
|
1104
|
+
* `make` stamped has the stamp it was stored with (the CLI's own files are
|
|
1105
|
+
* covered by the build id instead: inCliBuild), else the one
|
|
1106
|
+
* `make` gives now, which is stored unless a stamp is younger than
|
|
1107
|
+
* {@link SUMMARY_SETTLE_MS}. The folder, the build id, the Yarn Plug'n'Play
|
|
1108
|
+
* rule, the 0600 rename write and the eviction are those of a kept gather;
|
|
1109
|
+
* anywhere a gather is not kept, or on any read or write error, `make` runs
|
|
1110
|
+
* as before.
|
|
1111
|
+
* @template T
|
|
1112
|
+
* @param {unknown[]} key - Everything else the summary depends on.
|
|
1113
|
+
* @param {() => {value: T, stamps: [string, string][]}} make - The summary,
|
|
1114
|
+
* with the stamp ({@link fileStamp}) of each path it depends on, each taken
|
|
1115
|
+
* before the path was read.
|
|
1116
|
+
* @param {{accept?: (value: T) => boolean}} [options] - `accept`: whether a
|
|
1117
|
+
* stored value serves this call, else it is made again and stored over (a
|
|
1118
|
+
* summary that holds more only once a caller asks for it).
|
|
1119
|
+
* @returns {T}
|
|
1120
|
+
*/
|
|
1121
|
+
export function persistedSummary(key, make, {accept = () => true} = {}) {
|
|
1122
|
+
const at = summaryAt(key);
|
|
1123
|
+
if (!at) return make().value;
|
|
1124
|
+
const stored = storedSummary(at);
|
|
1125
|
+
if (stored && accept(stored.value)) return stored.value;
|
|
1126
|
+
const {value, stamps} = make();
|
|
1127
|
+
storeSummary(at, value, stamps);
|
|
1128
|
+
return value;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
/**
|
|
1132
|
+
* {@link persistedSummary} for a summary that `make` works out
|
|
1133
|
+
* asynchronously.
|
|
1134
|
+
* @template T
|
|
1135
|
+
* @param {unknown[]} key
|
|
1136
|
+
* @param {() => Promise<{value: T, stamps: [string, string][]}>} make
|
|
1137
|
+
* @param {{accept?: (value: T) => boolean}} [options] - As for
|
|
1138
|
+
* {@link persistedSummary}.
|
|
1139
|
+
* @returns {Promise<T>}
|
|
1140
|
+
*/
|
|
1141
|
+
export async function persistedSummaryAsync(
|
|
1142
|
+
key,
|
|
1143
|
+
make,
|
|
1144
|
+
{accept = () => true} = {},
|
|
1145
|
+
) {
|
|
1146
|
+
const at = summaryAt(key);
|
|
1147
|
+
if (!at) return (await make()).value;
|
|
1148
|
+
const stored = storedSummary(at);
|
|
1149
|
+
if (stored && accept(stored.value)) return stored.value;
|
|
1150
|
+
const {value, stamps} = await make();
|
|
1151
|
+
storeSummary(at, value, stamps);
|
|
1152
|
+
return value;
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Where the summary for `key` is kept, or null where none is kept.
|
|
1157
|
+
* @param {unknown[]} key
|
|
1158
|
+
* @returns {{dir: string, file: string, entry: string} | null}
|
|
1159
|
+
*/
|
|
1160
|
+
function summaryAt(key) {
|
|
1161
|
+
const id = withoutRecording(buildId);
|
|
1162
|
+
const dir =
|
|
1163
|
+
id == null || runsUnderPnp() ? null : withoutRecording(gatherCacheDir);
|
|
1164
|
+
if (id == null || dir == null) return null;
|
|
1165
|
+
const summaryKey = ['summary', ...key];
|
|
1166
|
+
return {
|
|
1167
|
+
dir,
|
|
1168
|
+
file: entryFile(dir, summaryKey, id),
|
|
1169
|
+
entry: entryKey(summaryKey, id),
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
/**
|
|
1174
|
+
* The kept summary at `at`, while every path it stamped has its stamp, else
|
|
1175
|
+
* undefined.
|
|
1176
|
+
* @param {{file: string, entry: string}} at
|
|
1177
|
+
* @returns {{value: any} | undefined}
|
|
1178
|
+
*/
|
|
1179
|
+
function storedSummary({file, entry}) {
|
|
1180
|
+
try {
|
|
1181
|
+
const stored = JSON.parse(
|
|
1182
|
+
withoutRecording(() => fs.readFileSync(file, 'utf-8')),
|
|
1183
|
+
);
|
|
1184
|
+
if (
|
|
1185
|
+
stored?.format === FORMAT &&
|
|
1186
|
+
stored.summary === true &&
|
|
1187
|
+
stored.key === entry &&
|
|
1188
|
+
Object.hasOwn(stored, 'value') &&
|
|
1189
|
+
Array.isArray(stored.stamps) &&
|
|
1190
|
+
stored.stamps.every(
|
|
1191
|
+
(/** @type {[string, string]} */ [at, stamp]) =>
|
|
1192
|
+
typeof at === 'string' && fileStamp(at) === stamp,
|
|
1193
|
+
)
|
|
1194
|
+
) {
|
|
1195
|
+
try {
|
|
1196
|
+
const now = new Date();
|
|
1197
|
+
withoutRecording(() => fs.utimesSync(file, now, now));
|
|
1198
|
+
} catch {
|
|
1199
|
+
// An entry that cannot be touched is evicted sooner; nothing more.
|
|
1200
|
+
}
|
|
1201
|
+
return {value: stored.value};
|
|
1202
|
+
}
|
|
1203
|
+
} catch {
|
|
1204
|
+
// No usable entry: made again.
|
|
1205
|
+
}
|
|
1206
|
+
return undefined;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
/**
|
|
1210
|
+
* Whether `file` is one of the installed CLI's own files: under its folder,
|
|
1211
|
+
* outside the node_modules folder inside it. A summary is kept only by an
|
|
1212
|
+
* installed CLI, under its build id (summaryAt), which names the exact code
|
|
1213
|
+
* of that build, so the build id covers its files; a package placed in that
|
|
1214
|
+
* node_modules folder is not part of the build.
|
|
1215
|
+
* @param {string} file
|
|
1216
|
+
* @returns {boolean}
|
|
1217
|
+
*/
|
|
1218
|
+
function inCliBuild(file) {
|
|
1219
|
+
const root = CLI_ROOT + path.sep;
|
|
1220
|
+
return (
|
|
1221
|
+
file.startsWith(root) && !file.startsWith(root + 'node_modules' + path.sep)
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
/**
|
|
1226
|
+
* Keep `value` at `at` with its stamps, unless a stamp is too young or the
|
|
1227
|
+
* value does not read back the same. Silent on any failure. A file in jiti's
|
|
1228
|
+
* cache is not kept as a stamp, as for a kept gather (inJitiCache), nor is
|
|
1229
|
+
* one of the CLI's own files: the build id in the summary's key covers them
|
|
1230
|
+
* (inCliBuild), so a new build makes the summary again. Every other file,
|
|
1231
|
+
* an installed package's included, keeps its own stamp: an edit in place
|
|
1232
|
+
* makes the summary again.
|
|
1233
|
+
* @param {{dir: string, file: string, entry: string}} at
|
|
1234
|
+
* @param {unknown} value
|
|
1235
|
+
* @param {[string, string][]} made the stamps the summary was made with
|
|
1236
|
+
*/
|
|
1237
|
+
function storeSummary({dir, file, entry}, value, made) {
|
|
1238
|
+
const stamps = made.filter(([at]) => !inJitiCache(at) && !inCliBuild(at));
|
|
1239
|
+
if (!settled(stamps)) return;
|
|
1240
|
+
withoutRecording(() => {
|
|
1241
|
+
try {
|
|
737
1242
|
const text = JSON.stringify({
|
|
738
1243
|
format: FORMAT,
|
|
739
|
-
|
|
1244
|
+
summary: true,
|
|
740
1245
|
key: entry,
|
|
741
|
-
|
|
1246
|
+
stamps,
|
|
1247
|
+
value,
|
|
742
1248
|
});
|
|
743
|
-
if (!isDeepStrictEqual(JSON.parse(text).value,
|
|
1249
|
+
if (!isDeepStrictEqual(JSON.parse(text).value, value)) return;
|
|
744
1250
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
745
1251
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
746
1252
|
fs.renameSync(temp, file);
|
|
747
|
-
|
|
1253
|
+
evictOldest(dir, isEntry);
|
|
748
1254
|
} catch {
|
|
749
|
-
// A
|
|
1255
|
+
// A summary that cannot be stored is made again next time.
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* A gather's entry file: its first line, parsed, and a reader of its value,
|
|
1262
|
+
* the second line, parsed only when called. A file of one line, as an entry
|
|
1263
|
+
* of another format, is all head and has no value.
|
|
1264
|
+
* @param {string} file
|
|
1265
|
+
* @returns {{head: any, value: () => unknown}}
|
|
1266
|
+
*/
|
|
1267
|
+
function readEntry(file) {
|
|
1268
|
+
const text = withoutRecording(() => fs.readFileSync(file, 'utf-8'));
|
|
1269
|
+
const cut = text.indexOf('\n');
|
|
1270
|
+
return {
|
|
1271
|
+
head: JSON.parse(cut < 0 ? text : text.slice(0, cut)),
|
|
1272
|
+
value: () => (cut < 0 ? undefined : JSON.parse(text.slice(cut + 1))),
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
/** How much of an entry file one read takes while looking for its first line. */
|
|
1277
|
+
const HEAD_READ_BYTES = 64 * 1024;
|
|
1278
|
+
|
|
1279
|
+
/**
|
|
1280
|
+
* A gather's entry file's first line, parsed, read without the value after
|
|
1281
|
+
* it: an entry another builds on is checked, never read back. A newline byte
|
|
1282
|
+
* is never part of a longer UTF-8 character, so the bytes before the first
|
|
1283
|
+
* one are the whole line.
|
|
1284
|
+
* @param {string} file
|
|
1285
|
+
* @returns {any}
|
|
1286
|
+
*/
|
|
1287
|
+
function readHead(file) {
|
|
1288
|
+
return withoutRecording(() => {
|
|
1289
|
+
const fd = fs.openSync(file, 'r');
|
|
1290
|
+
try {
|
|
1291
|
+
/** @type {Buffer[]} */
|
|
1292
|
+
const chunks = [];
|
|
1293
|
+
const chunk = Buffer.allocUnsafe(HEAD_READ_BYTES);
|
|
1294
|
+
for (let at = 0; ;) {
|
|
1295
|
+
const read = fs.readSync(fd, chunk, 0, chunk.length, at);
|
|
1296
|
+
if (read === 0) break;
|
|
1297
|
+
const piece = chunk.subarray(0, read);
|
|
1298
|
+
const end = piece.indexOf(0x0a);
|
|
1299
|
+
chunks.push(Buffer.from(end < 0 ? piece : piece.subarray(0, end)));
|
|
1300
|
+
if (end >= 0) break;
|
|
1301
|
+
at += read;
|
|
1302
|
+
}
|
|
1303
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf-8'));
|
|
1304
|
+
} finally {
|
|
1305
|
+
fs.closeSync(fd);
|
|
750
1306
|
}
|
|
751
1307
|
});
|
|
752
|
-
return value;
|
|
753
1308
|
}
|
|
754
1309
|
|
|
755
1310
|
/**
|
|
756
1311
|
* A stored entry's value, decoded, or undefined when it has none, its decode
|
|
757
1312
|
* throws, or the decoded value fails the codec's shape check (`valid`): such
|
|
758
1313
|
* an entry is a miss, worked out again and stored over.
|
|
759
|
-
* @param {
|
|
1314
|
+
* @param {() => unknown} read - reads the entry's value
|
|
760
1315
|
* @param {{decode: (stored: any) => any, valid?: (value: any) => boolean}} codec
|
|
761
1316
|
* @returns {any}
|
|
762
1317
|
*/
|
|
763
|
-
function readBack(
|
|
764
|
-
if (!Object.hasOwn(stored, 'value') || stored.value == null) return undefined;
|
|
1318
|
+
function readBack(read, codec) {
|
|
765
1319
|
try {
|
|
766
|
-
const
|
|
1320
|
+
const stored = read();
|
|
1321
|
+
if (stored == null) return undefined;
|
|
1322
|
+
const value = codec.decode(stored);
|
|
767
1323
|
if (value == null) return undefined;
|
|
768
1324
|
return !codec.valid || codec.valid(value) ? value : undefined;
|
|
769
1325
|
} catch {
|
|
@@ -771,6 +1327,26 @@ function readBack(stored, codec) {
|
|
|
771
1327
|
}
|
|
772
1328
|
}
|
|
773
1329
|
|
|
1330
|
+
/**
|
|
1331
|
+
* The JSON text a kept value is stored as, checked once to read back as what
|
|
1332
|
+
* the codec meant: the codec's own checked text when it gives one
|
|
1333
|
+
* (`encodeText`, as EXACT_CODEC does), else its plain form, written and
|
|
1334
|
+
* checked to read back as that form. Undefined for a value that does not
|
|
1335
|
+
* read back exactly, which is never kept; a codec's refusal throws.
|
|
1336
|
+
* @template T
|
|
1337
|
+
* @param {{encode: (value: T) => unknown, encodeText?: (value: T) => string}} codec
|
|
1338
|
+
* @param {T} value
|
|
1339
|
+
* @returns {string | undefined}
|
|
1340
|
+
*/
|
|
1341
|
+
function storedText(codec, value) {
|
|
1342
|
+
if (codec.encodeText) return codec.encodeText(value);
|
|
1343
|
+
const encoded = codec.encode(value);
|
|
1344
|
+
const text = JSON.stringify(encoded);
|
|
1345
|
+
return text !== undefined && isDeepStrictEqual(JSON.parse(text), encoded)
|
|
1346
|
+
? text
|
|
1347
|
+
: undefined;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
774
1350
|
/**
|
|
775
1351
|
* Store a fresh gather with what the run read, unless its plain form does not
|
|
776
1352
|
* read back as the same value. Silent on any failure.
|
|
@@ -784,57 +1360,38 @@ function readBack(stored, codec) {
|
|
|
784
1360
|
function store(dir, file, entry, value, codec) {
|
|
785
1361
|
if (!run) return;
|
|
786
1362
|
try {
|
|
787
|
-
const
|
|
1363
|
+
const body = storedText(codec, value);
|
|
1364
|
+
if (body === undefined) return;
|
|
788
1365
|
const stamps = [...run.reads].filter(([file]) => !inJitiCache(file));
|
|
789
1366
|
gatherCode = cliStates(stamps);
|
|
790
|
-
const
|
|
1367
|
+
const {deps, own, under} = chooseBase(file, stamps, run.confirmed);
|
|
1368
|
+
const version = randomBytes(12).toString('hex');
|
|
1369
|
+
const head = JSON.stringify({
|
|
791
1370
|
format: FORMAT,
|
|
792
1371
|
key: entry,
|
|
793
|
-
|
|
1372
|
+
version,
|
|
1373
|
+
deps,
|
|
1374
|
+
stamps: own,
|
|
794
1375
|
env: [...run.env],
|
|
795
|
-
value: encoded,
|
|
796
1376
|
});
|
|
797
|
-
|
|
1377
|
+
// JSON text holds no line break, so the first one ends the head.
|
|
1378
|
+
const text = `${head}\n${body}`;
|
|
798
1379
|
const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
799
1380
|
fs.writeFileSync(temp, text, {mode: 0o600, flag: 'wx'});
|
|
800
1381
|
fs.renameSync(temp, file);
|
|
801
|
-
|
|
1382
|
+
run.confirmed.set(file, {
|
|
1383
|
+
version,
|
|
1384
|
+
lists: [stamps],
|
|
1385
|
+
under,
|
|
1386
|
+
deps: deps.map(([name]) => path.join(dir, name)),
|
|
1387
|
+
});
|
|
1388
|
+
markUsed(file, run.confirmed);
|
|
1389
|
+
evictOldest(dir, isEntry);
|
|
802
1390
|
} catch {
|
|
803
1391
|
// A gather that cannot be stored is gathered again next time.
|
|
804
1392
|
}
|
|
805
1393
|
}
|
|
806
1394
|
|
|
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
1395
|
/**
|
|
839
1396
|
* Whether this run is under Yarn Plug'n'Play's loader (`yarn astryx` in a PnP
|
|
840
1397
|
* project): Node's module hooks hand PnP's resolver options it refuses, so
|
|
@@ -849,15 +1406,16 @@ export function runsUnderPnp() {
|
|
|
849
1406
|
/**
|
|
850
1407
|
* The cache folder and how much it holds, for `doctor`: null when the CLI
|
|
851
1408
|
* 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)
|
|
1409
|
+
* @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null}
|
|
1410
|
+
* `pnp`: whether this run is under Yarn Plug'n'Play's loader (runsUnderPnp);
|
|
1411
|
+
* `limitBytes`: the most the folder, and jiti's folder `jitiDir`, holds
|
|
854
1412
|
*/
|
|
855
1413
|
export function gatherCacheSummary() {
|
|
856
1414
|
// The cache's own bookkeeping, never an input of what it keeps.
|
|
857
1415
|
return withoutRecording(summarize);
|
|
858
1416
|
}
|
|
859
1417
|
|
|
860
|
-
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean} | null} */
|
|
1418
|
+
/** @returns {{dir: string, bytes: number, entries: number, pnp: boolean, limitBytes: number, jitiDir: string} | null} */
|
|
861
1419
|
function summarize() {
|
|
862
1420
|
if (buildId() == null) return null;
|
|
863
1421
|
const dir = gatherCacheDir();
|
|
@@ -877,5 +1435,12 @@ function summarize() {
|
|
|
877
1435
|
} catch {
|
|
878
1436
|
return null;
|
|
879
1437
|
}
|
|
880
|
-
return {
|
|
1438
|
+
return {
|
|
1439
|
+
dir,
|
|
1440
|
+
bytes,
|
|
1441
|
+
entries,
|
|
1442
|
+
pnp: runsUnderPnp(),
|
|
1443
|
+
limitBytes: CACHE_LIMIT_BYTES,
|
|
1444
|
+
jitiDir: jitiCacheDir(),
|
|
1445
|
+
};
|
|
881
1446
|
}
|