@reqvire-org/ads 0.4.0 → 0.4.3
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 +115 -87
- package/dist/a11y.mjs +133 -48
- package/dist/analysis/compiler-options.mjs +13 -0
- package/dist/analysis/context.mjs +46 -0
- package/dist/analysis/file-tree.mjs +52 -0
- package/dist/analysis/helpers.mjs +142 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +22 -0
- package/dist/analysis/module-resolvers.mjs +46 -0
- package/dist/analysis/native-adapter.mjs +180 -0
- package/dist/analysis/native-project.mjs +323 -0
- package/dist/analysis/queries.mjs +133 -0
- package/dist/analysis/service.mjs +153 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +179 -0
- package/dist/analysis/worker.mjs +182 -0
- package/dist/assets.mjs +6 -6
- package/dist/atomic-composition.mjs +191 -70
- package/dist/atomic-trace.mjs +120 -50
- package/dist/behavior-libraries.mjs +106 -37
- package/dist/behaviors.mjs +219 -77
- package/dist/boundaries.mjs +140 -41
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +28 -14
- package/dist/bun-worker.mjs +7 -5
- package/dist/capture/worker.mjs +15 -4
- package/dist/capture-store.mjs +4 -2
- package/dist/capture.mjs +17 -14
- package/dist/check-service.mjs +44 -58
- package/dist/check.mjs +754 -188
- package/dist/cli.mjs +200 -99
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +127 -9
- package/dist/config.mjs +303 -135
- package/dist/construction-styles.cjs +10 -0
- package/dist/contrast-composition.mjs +134 -0
- package/dist/control-padding.mjs +45 -25
- package/dist/css-values.mjs +3 -2
- package/dist/declarative-flow.mjs +209 -109
- package/dist/design-values.mjs +136 -51
- package/dist/development-runtime.mjs +4 -6
- package/dist/draft-boundary.mjs +11 -6
- package/dist/evidence.mjs +1 -1
- package/dist/finding-rules.mjs +9 -5
- package/dist/font-rules.mjs +22 -17
- package/dist/fonts-generated.mjs +23 -16
- package/dist/foundation-views.mjs +242 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +101 -34
- package/dist/icons.mjs +79 -32
- package/dist/image-attributes.mjs +143 -66
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +122 -41
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +298 -129
- package/dist/layout-widths.mjs +180 -85
- package/dist/linaria/preserve-values.cjs +7 -0
- package/dist/linaria/spatial-inputs.cjs +56 -0
- package/dist/lockup-composition.mjs +44 -0
- package/dist/lockup-model.cjs +64 -0
- package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
- package/dist/mcp/apps.mjs +4 -30
- package/dist/mcp/behavior-pages.mjs +72 -24
- package/dist/mcp/build-status.mjs +257 -64
- package/dist/mcp/catalog.mjs +90 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +903 -281
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +673 -234
- package/dist/mcp/preview-watch.mjs +448 -170
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +5 -5
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2409 -577
- package/dist/mcp/showcase-host.mjs +165 -41
- package/dist/mcp/skills.mjs +1 -1
- package/dist/mcp/text-diff.mjs +29 -10
- package/dist/paint-contracts.mjs +174 -81
- package/dist/palette-generated.mjs +2 -2
- package/dist/pictogram-model.mjs +59 -0
- package/dist/pictograms.mjs +52 -0
- package/dist/preview-bun.mjs +494 -187
- package/dist/preview-failure.mjs +1 -1
- package/dist/preview-files.mjs +13 -13
- package/dist/preview-imports.mjs +104 -55
- package/dist/preview-inputs.mjs +2 -2
- package/dist/preview-requests.mjs +24 -0
- package/dist/preview-resources.mjs +288 -147
- package/dist/preview-scope.mjs +5 -4
- package/dist/program-cache.mjs +8 -34
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +69 -31
- package/dist/public-props.mjs +39 -22
- package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
- package/dist/{browser-audit → render-audit}/image-shape.mjs +15 -5
- package/dist/{browser-audit → render-audit}/layout-overflow.mjs +86 -23
- package/dist/{browser-audit → render-audit}/non-text-contrast.mjs +86 -27
- package/dist/render-audit/pictograms.mjs +88 -0
- package/dist/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +98 -30
- package/dist/render-audit.mjs +838 -0
- package/dist/render-color-probe.mjs +96 -42
- package/dist/render-composition.mjs +164 -0
- package/dist/resource-limits.mjs +229 -97
- package/dist/runtime-contracts.mjs +467 -185
- package/dist/scenario-groups.mjs +22 -10
- package/dist/scenario-inspector.mjs +6 -43
- package/dist/scenario-program.mjs +8 -25
- package/dist/scenario-registry.mjs +72 -30
- package/dist/scenario-selectors.mjs +161 -64
- package/dist/scenario-slots.mjs +149 -56
- package/dist/scenario-trace.mjs +215 -109
- package/dist/scenarios-compiler.mjs +719 -378
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +421 -157
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +21 -3
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +58 -0
- package/dist/showcase/foundation-view.mjs +255 -0
- package/dist/showcase/guide-controls.ads.review.mjs +32 -0
- package/dist/showcase/icons.js +1 -145
- package/dist/showcase/index.html +3 -31
- package/dist/showcase/pictogram-view.mjs +53 -0
- package/dist/showcase/preview-frame.ads.review.css +46 -0
- package/dist/showcase/preview-frame.ads.review.d.mts +11 -0
- package/dist/showcase/preview-frame.ads.review.mjs +22 -0
- package/dist/showcase/preview-state.js +0 -9
- package/dist/showcase/refresh-scheduler.js +23 -0
- package/dist/showcase/style.css +5 -47
- package/dist/showcase/ui/ui.css +1353 -0
- package/dist/showcase/ui/ui.js +1064 -0
- package/dist/showcase-coverage.mjs +58 -37
- package/dist/skills/README.md +24 -23
- package/dist/skills/ads-designer/README.md +8 -2
- package/dist/skills/ads-designer/SKILL.md +143 -120
- package/dist/skills/ads-designer/references/accessibility.md +78 -15
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +30 -27
- package/dist/skills/ads-designer/references/branding.md +101 -24
- package/dist/skills/ads-designer/references/captures.md +25 -0
- package/dist/skills/ads-designer/references/cli.md +21 -24
- package/dist/skills/ads-designer/references/contracts.md +7 -6
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +20 -17
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +14 -18
- package/dist/skills/ads-designer/references/layers.md +1 -1
- package/dist/skills/ads-designer/references/layout.md +347 -0
- package/dist/skills/ads-designer/references/mobile.md +2 -1
- package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
- package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
- package/dist/skills/ads-designer/references/performance.md +3 -2
- package/dist/skills/ads-designer/references/pictograms.md +131 -0
- package/dist/skills/ads-designer/references/review.md +37 -34
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +16 -18
- package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
- package/dist/skills/ads-designer/references/stress-test.md +68 -0
- package/dist/skills/ads-designer/references/validation.md +83 -75
- package/dist/skills/ads-designer/references/workflows.md +8 -33
- package/dist/skills/ads-import/SKILL.md +43 -325
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +30 -27
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +25 -0
- package/dist/skills/ads-import/references/cli.md +21 -24
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +7 -6
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +20 -17
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +14 -18
- package/dist/skills/ads-import/references/implementation.md +2 -1
- package/dist/skills/ads-import/references/layers.md +1 -1
- package/dist/skills/ads-import/references/layout.md +347 -0
- package/dist/skills/ads-import/references/review.md +37 -34
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +16 -18
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -75
- package/dist/skills/ads-import/references/workflows.md +8 -33
- package/dist/skills/ads-migrate/SKILL.md +56 -0
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
- package/dist/skills/ads-port/SKILL.md +58 -344
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +30 -27
- package/dist/skills/ads-port/references/captures.md +25 -0
- package/dist/skills/ads-port/references/cli.md +21 -24
- package/dist/skills/ads-port/references/contracts.md +7 -6
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +20 -17
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +14 -18
- package/dist/skills/ads-port/references/layers.md +1 -1
- package/dist/skills/ads-port/references/layout.md +347 -0
- package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
- package/dist/skills/ads-port/references/native-implementation.md +2 -1
- package/dist/skills/ads-port/references/review.md +37 -34
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +16 -18
- package/dist/skills/ads-port/references/validation.md +83 -75
- package/dist/skills/ads-port/references/workflows.md +8 -33
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +270 -129
- package/dist/spatial-composition.mjs +322 -0
- package/dist/spatial-contexts.cjs +56 -0
- package/dist/spatial-css.cjs +351 -0
- package/dist/spatial-inputs.cjs +80 -0
- package/dist/spatial-metadata.mjs +18 -0
- package/dist/spatial-model.cjs +322 -0
- package/dist/spatial.mjs +21 -0
- package/dist/stage-timing.cjs +20 -0
- package/dist/starters/preact/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/preact/design-system/patterns/Shell/Shell.tsx +275 -0
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/preact/design-system/showcase/mcp/main.ads.mount.tsx +8 -0
- package/dist/starters/preact/ds.config.json +25 -6
- package/dist/starters/preact/package.json +4 -8
- package/dist/starters/preact/tsconfig.json +4 -5
- package/dist/starters/preact/vite.config.ts +3 -3
- package/dist/starters/react/ADS.md +42 -47
- package/dist/starters/react/README.md +47 -49
- package/dist/starters/react/design-system/assets/pictograms/catalog.ads.json +13 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.dark.svg +7 -0
- package/dist/starters/react/design-system/assets/pictograms/journey.svg +7 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.tsx +18 -2
- package/dist/starters/react/design-system/components/Actions/IconButton/README.md +3 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.fixture.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.ads.scenario.tsx +7 -0
- package/dist/starters/react/design-system/components/Content/Pictogram/Pictogram.tsx +26 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/README.md +5 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
- package/dist/starters/react/design-system/index.ts +2 -1
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
- package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
- package/dist/starters/react/design-system/tokens/colors.css +1 -1
- package/dist/starters/react/design-system/tokens/spacing.css +22 -32
- package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
- package/dist/starters/react/ds.config.json +25 -6
- package/dist/starters/react/package.json +2 -6
- package/dist/starters/react/tsconfig.json +2 -3
- package/dist/starters/react/vite.config.ts +3 -3
- package/dist/style-boundaries.mjs +70 -25
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +132 -59
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +57 -22
- package/dist/themes.mjs +176 -73
- package/dist/token-export.mjs +39 -14
- package/dist/token-policy.mjs +6 -3
- package/dist/token-quality.mjs +6 -6
- package/dist/token-samples.mjs +16 -5
- package/dist/tokens.mjs +71 -26
- package/dist/ui-framework.mjs +16 -14
- package/dist/unit-contracts.mjs +251 -104
- package/dist/units.mjs +209 -99
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +115 -38
- package/dist/validation-inputs.mjs +191 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +96 -80
- package/docs/ARCHITECTURE.md +368 -137
- package/docs/BEHAVIORS.md +29 -25
- package/docs/CACHING.md +77 -17
- package/docs/CHANGELOG.md +332 -17
- package/docs/CONTRACTS.md +12 -4
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +300 -263
- package/docs/MCP.md +187 -324
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +43 -34
- package/dist/browser-audit.mjs +0 -429
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -50
- package/dist/mcp/project-widget.bundle.js +0 -114
- package/dist/mcp/reports.mjs +0 -101
- package/dist/mcp/widget.bundle.js +0 -147
- package/dist/oxlint.mjs +0 -89
- package/dist/preview-builder.mjs +0 -133
- package/dist/preview-workers.mjs +0 -184
- package/dist/showcase.mjs +0 -77
- package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
- package/dist/skills/ads-break-ui/README.md +0 -16
- package/dist/skills/ads-break-ui/SKILL.md +0 -412
- package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
- package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
- package/dist/skills/ads-break-ui/references/behaviors.md +0 -412
- package/dist/skills/ads-break-ui/references/captures.md +0 -135
- package/dist/skills/ads-break-ui/references/contracts.md +0 -317
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -194
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -165
- package/dist/skills/ads-break-ui/references/layers.md +0 -145
- package/dist/skills/ads-break-ui/references/reporting.md +0 -101
- package/dist/skills/ads-break-ui/references/review.md +0 -97
- package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
- package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
- package/dist/skills/ads-break-ui/references/validation.md +0 -166
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -90
- package/dist/skills/ads-designer/references/reporting.md +0 -101
- package/dist/skills/ads-import/references/reporting.md +0 -101
- package/dist/skills/ads-motion/LICENSE.upstream +0 -21
- package/dist/skills/ads-motion/README.md +0 -22
- package/dist/skills/ads-motion/SKILL.md +0 -385
- package/dist/skills/ads-motion/agents/openai.yaml +0 -4
- package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
- package/dist/skills/ads-motion/references/audit.md +0 -44
- package/dist/skills/ads-motion/references/behaviors.md +0 -412
- package/dist/skills/ads-motion/references/captures.md +0 -135
- package/dist/skills/ads-motion/references/contracts.md +0 -317
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -194
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -165
- package/dist/skills/ads-motion/references/layers.md +0 -145
- package/dist/skills/ads-motion/references/motion-review.md +0 -35
- package/dist/skills/ads-motion/references/reporting.md +0 -101
- package/dist/skills/ads-motion/references/review.md +0 -97
- package/dist/skills/ads-motion/references/runtimes.md +0 -203
- package/dist/skills/ads-motion/references/scenarios.md +0 -246
- package/dist/skills/ads-motion/references/validation.md +0 -166
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -90
- package/dist/skills/ads-port/references/reporting.md +0 -101
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -6
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
- package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
- package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
- package/dist/starters/react/package-lock.json +0 -4707
- package/dist/token-fixtures.mjs +0 -30
- package/docs/benchmarks/bun-previews.md +0 -91
- package/docs/benchmarks/preview-memory.md +0 -147
- package/docs/benchmarks/turbo-poc.md +0 -284
- package/docs/plans/execution-coordination.md +0 -57
- /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
- /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { everyAsync, mapAsync } from "./analysis/queries.mjs";
|
|
1
2
|
import { scopedPreviewFailure } from "./preview-failure.mjs";
|
|
2
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
3
4
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
@@ -5,21 +6,30 @@ import path from "node:path";
|
|
|
5
6
|
import { hasProjectConfig } from "./project-boundary.mjs";
|
|
6
7
|
import { isDraftPreviewWorkspace } from "./draft-workspace.mjs";
|
|
7
8
|
import { loadConfig, isInside } from "./config.mjs";
|
|
8
|
-
import {
|
|
9
|
+
import { prepareScenarioRegistryTransfer, releaseScenarioRegistry } from "./scenario-registry.mjs";
|
|
9
10
|
import { artifactDigest, createBuildReporter } from "./mcp/build-status.mjs";
|
|
10
11
|
import { cachedPreviewPublication, previewArtifactHtml, readPreviewManifest } from "./preview-resources.mjs";
|
|
11
12
|
import { previewArtifactPath, withPreviewSession } from "./preview-scope.mjs";
|
|
12
13
|
import { previewSourceRevision } from "./preview-inputs.mjs";
|
|
14
|
+
import { queuePreviewRequests } from "./preview-requests.mjs";
|
|
13
15
|
import { previewFileIgnored, previewWatchDirectories } from "./preview-files.mjs";
|
|
14
16
|
import { createScenarioInspector } from "./scenario-inspector.mjs";
|
|
17
|
+
import { analyze } from "./analysis/service.mjs";
|
|
15
18
|
import { configurationFiles } from "./units.mjs";
|
|
16
19
|
import { validationInputFiles } from "./validation-inputs.mjs";
|
|
17
20
|
import { previewRuntimeFingerprint } from "./runtime-requirements.mjs";
|
|
18
21
|
import { architectureExternalInputs } from "./task-cache.mjs";
|
|
19
22
|
|
|
20
|
-
const digest = value => createHash("sha256").update(value).digest("hex");
|
|
21
|
-
const fileDigest =
|
|
22
|
-
|
|
23
|
+
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
24
|
+
const fileDigest = (file) => {
|
|
25
|
+
try {
|
|
26
|
+
return digest(readFileSync(file));
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const cacheVersion = 3,
|
|
32
|
+
maxCacheBytes = 8 * 1024 * 1024;
|
|
23
33
|
|
|
24
34
|
/** Cache only successful validation + matching source/dependency/output content.
|
|
25
35
|
* Cache state is development output, never proof that a failed build is current. */
|
|
@@ -27,11 +37,35 @@ export function createPreviewCache(options, compilerFiles = []) {
|
|
|
27
37
|
const { root } = options;
|
|
28
38
|
// Build adapters such as Vite set NODE_ENV while configuring a build. Capture
|
|
29
39
|
// the launch environment once; internal compiler setup is not an external edit.
|
|
30
|
-
const launchEnvironment=architectureExternalInputs(root).environment;
|
|
31
|
-
const key =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
const launchEnvironment = architectureExternalInputs(root).environment;
|
|
41
|
+
const key = (file) =>
|
|
42
|
+
isInside(import.meta.dirname, file)
|
|
43
|
+
? `ads-tool/${path.relative(import.meta.dirname, file)}`
|
|
44
|
+
: isInside(root, file)
|
|
45
|
+
? `project/${path.relative(root, file)}`
|
|
46
|
+
: file;
|
|
47
|
+
const adapterFiles = [
|
|
48
|
+
import.meta.filename,
|
|
49
|
+
...[
|
|
50
|
+
"runtime-requirements.mjs",
|
|
51
|
+
"preview-files.mjs",
|
|
52
|
+
"preview-inputs.mjs",
|
|
53
|
+
"preview-requests.mjs",
|
|
54
|
+
"preview-resources.mjs",
|
|
55
|
+
"preview-scope.mjs",
|
|
56
|
+
"scenario-groups.mjs",
|
|
57
|
+
"scenario-inspector.mjs",
|
|
58
|
+
"scenario-registry.mjs",
|
|
59
|
+
"scenarios-vite.mjs",
|
|
60
|
+
"linaria.mjs",
|
|
61
|
+
"linaria/atomic-css.cjs",
|
|
62
|
+
"linaria/atomic-styled.cjs",
|
|
63
|
+
"linaria/preserve-values.cjs",
|
|
64
|
+
].map((file) => path.join(import.meta.dirname, file)),
|
|
65
|
+
...compilerFiles,
|
|
66
|
+
...["package.json", "package-lock.json", "bun.lock", "bun.lockb", "node_modules/.package-lock.json"].map((file) => path.join(root, file)),
|
|
67
|
+
];
|
|
68
|
+
const adapterDigest = () => digest(JSON.stringify(adapterFiles.map((file) => [key(file), fileDigest(file)])));
|
|
35
69
|
const loadedAdapter = adapterDigest();
|
|
36
70
|
const target = path.join(root, ".ds/preview-cache.json");
|
|
37
71
|
let value = { schemaVersion: cacheVersion, validation: null, entries: {}, dependencySets: {} };
|
|
@@ -39,202 +73,333 @@ export function createPreviewCache(options, compilerFiles = []) {
|
|
|
39
73
|
try {
|
|
40
74
|
if (realpathSync(target) === target && statSync(target).size < maxCacheBytes) {
|
|
41
75
|
const stored = JSON.parse(readFileSync(target, "utf8"));
|
|
42
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
stored.schemaVersion === cacheVersion &&
|
|
78
|
+
stored.entries &&
|
|
79
|
+
typeof stored.entries === "object" &&
|
|
80
|
+
stored.dependencySets &&
|
|
81
|
+
typeof stored.dependencySets === "object"
|
|
82
|
+
)
|
|
83
|
+
value = stored;
|
|
43
84
|
}
|
|
44
|
-
} catch {
|
|
85
|
+
} catch {
|
|
86
|
+
/* Missing or corrupt cache means validate and rebuild. */
|
|
87
|
+
}
|
|
45
88
|
}
|
|
46
89
|
reload();
|
|
47
|
-
function inputs() {
|
|
48
|
-
const rows = [
|
|
90
|
+
async function inputs() {
|
|
91
|
+
const rows = [
|
|
92
|
+
["project-inputs", await previewSourceRevision(options)],
|
|
93
|
+
["runtime", previewRuntimeFingerprint()],
|
|
94
|
+
["architecture-environment", { ...architectureExternalInputs(root), environment: launchEnvironment }],
|
|
95
|
+
];
|
|
49
96
|
for (const file of compilerFiles) rows.push([key(file), fileDigest(file)]);
|
|
50
97
|
// Tool upgrades invalidate validation even when the project's lockfile is unchanged.
|
|
51
|
-
for (const name of readdirSync(import.meta.dirname).filter(name => name.endsWith(".mjs"))) {
|
|
98
|
+
for (const name of readdirSync(import.meta.dirname).filter((name) => name.endsWith(".mjs"))) {
|
|
52
99
|
rows.push([`ads-tool/${name}`, fileDigest(path.join(import.meta.dirname, name))]);
|
|
53
100
|
}
|
|
54
|
-
for (const name of readdirSync(path.join(import.meta.dirname, "linaria")))
|
|
101
|
+
for (const name of readdirSync(path.join(import.meta.dirname, "linaria")))
|
|
102
|
+
rows.push([`ads-tool/linaria/${name}`, fileDigest(path.join(import.meta.dirname, "linaria", name))]);
|
|
55
103
|
return digest(JSON.stringify(rows.sort((a, b) => a[0].localeCompare(b[0]))));
|
|
56
104
|
}
|
|
57
105
|
function save() {
|
|
58
106
|
mkdirSync(path.dirname(target), { recursive: true });
|
|
59
107
|
if (realpathSync(path.dirname(target)) !== path.dirname(target)) throw new Error("Preview cache cannot resolve through a symlink.");
|
|
60
|
-
value.compilerFiles = compilerFiles.map(file => isInside(root,file) ? path.relative(root,file) : null);
|
|
61
|
-
const used = new Set(Object.values(value.entries).map(entry => entry.dependencySet));
|
|
62
|
-
value.dependencySets = Object.fromEntries([...used].filter(id=>value.dependencySets[id]).map(id=>[id,value.dependencySets[id]]));
|
|
108
|
+
value.compilerFiles = compilerFiles.map((file) => (isInside(root, file) ? path.relative(root, file) : null));
|
|
109
|
+
const used = new Set(Object.values(value.entries).map((entry) => entry.dependencySet));
|
|
110
|
+
value.dependencySets = Object.fromEntries([...used].filter((id) => value.dependencySets[id]).map((id) => [id, value.dependencySets[id]]));
|
|
63
111
|
const content = JSON.stringify(value);
|
|
64
112
|
if (Buffer.byteLength(content) >= maxCacheBytes) {
|
|
65
|
-
rmSync(target, {force:true});
|
|
113
|
+
rmSync(target, { force: true });
|
|
66
114
|
console.warn("ADS preview cache exceeds 8 MiB after deduplication; this build remains current, but a new compiler will rebuild it.");
|
|
67
115
|
return;
|
|
68
116
|
}
|
|
69
117
|
const temporary = `${target}.${randomUUID()}.tmp`;
|
|
70
|
-
try {
|
|
71
|
-
|
|
118
|
+
try {
|
|
119
|
+
writeFileSync(temporary, content);
|
|
120
|
+
renameSync(temporary, target);
|
|
121
|
+
} finally {
|
|
122
|
+
rmSync(temporary, { force: true });
|
|
123
|
+
}
|
|
72
124
|
}
|
|
73
|
-
function compilerInputs() {
|
|
74
|
-
const configured = new Set([...configurationFiles(options)].filter(file
|
|
75
|
-
const packages = new Set([
|
|
76
|
-
|
|
125
|
+
async function compilerInputs() {
|
|
126
|
+
const configured = new Set([...(await configurationFiles(options))].filter((file) => !/^(?:biome|oxlint|\.oxlint)/.test(file)));
|
|
127
|
+
const packages = new Set([
|
|
128
|
+
"package-lock.json",
|
|
129
|
+
"npm-shrinkwrap.json",
|
|
130
|
+
"yarn.lock",
|
|
131
|
+
"pnpm-lock.yaml",
|
|
132
|
+
"bun.lock",
|
|
133
|
+
"bun.lockb",
|
|
134
|
+
"bunfig.toml",
|
|
135
|
+
".npmrc",
|
|
136
|
+
".yarnrc.yml",
|
|
137
|
+
"installed-dependencies",
|
|
138
|
+
]);
|
|
139
|
+
const opaque = (options.config.validation?.inputs ?? []).map((file) => path.resolve(root, file));
|
|
77
140
|
// Use the same declared configuration/input boundary as guarded copies.
|
|
78
141
|
// Unrelated local launcher JSON must not make a candidate unportable.
|
|
79
|
-
return Object.entries(validationInputFiles(options))
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
142
|
+
return Object.entries(await validationInputFiles(options))
|
|
143
|
+
.filter(([file]) => configured.has(file) || packages.has(file) || opaque.some((directory) => isInside(directory, path.resolve(root, file))))
|
|
144
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
145
|
+
}
|
|
146
|
+
const compilerDigest = async () =>
|
|
147
|
+
digest(
|
|
148
|
+
JSON.stringify([
|
|
149
|
+
["adapter", adapterDigest()],
|
|
150
|
+
...compilerFiles.map((file) => [key(file), fileDigest(file)]),
|
|
151
|
+
...(await compilerInputs()),
|
|
152
|
+
["installed-packages", fileDigest(path.join(root, "node_modules/.package-lock.json"))],
|
|
153
|
+
["scheduler", fileDigest(import.meta.filename)],
|
|
154
|
+
["runtime", previewRuntimeFingerprint()],
|
|
155
|
+
]),
|
|
156
|
+
);
|
|
157
|
+
async function reusable(entry, expectedHtml, inspection) {
|
|
91
158
|
const cached = value.entries[entry.id];
|
|
92
|
-
if (!cached || cached.metadata !== JSON.stringify(entry) || cached.compiler !== (inspection?.compiler ?? compilerDigest())) return false;
|
|
159
|
+
if (!cached || cached.metadata !== JSON.stringify(entry) || cached.compiler !== (inspection?.compiler ?? (await compilerDigest()))) return false;
|
|
93
160
|
const dependencies = value.dependencySets[cached.dependencySet];
|
|
94
161
|
if (!dependencies || !Object.keys(dependencies).length) return false;
|
|
95
162
|
let valid = inspection?.sets.get(cached.dependencySet);
|
|
96
|
-
if (valid === undefined)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
163
|
+
if (valid === undefined)
|
|
164
|
+
valid = !Object.entries(dependencies).some(([file, hash]) => {
|
|
165
|
+
const absolute = path.resolve(root, file);
|
|
166
|
+
if (!inspection) return fileDigest(absolute) !== hash;
|
|
167
|
+
if (!inspection.files.has(absolute)) inspection.files.set(absolute, fileDigest(absolute));
|
|
168
|
+
return inspection.files.get(absolute) !== hash;
|
|
169
|
+
});
|
|
102
170
|
inspection?.sets.set(cached.dependencySet, valid);
|
|
103
171
|
if (!valid) return false;
|
|
104
172
|
if (expectedHtml !== undefined) return cached.artifact === `sha256:${digest(expectedHtml)}`;
|
|
105
173
|
const file = path.join(root, previewArtifactPath(options, entry.artifact));
|
|
106
|
-
try {
|
|
174
|
+
try {
|
|
175
|
+
return cached.artifact === artifactDigest(file);
|
|
176
|
+
} catch {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
107
179
|
}
|
|
108
|
-
function reusableEntries(entries, revision) {
|
|
180
|
+
async function reusableEntries(entries, revision) {
|
|
109
181
|
// Scope memoization to this one operation; the caller still fences source
|
|
110
182
|
// before publication. Never retain hashes across edits or requests.
|
|
111
|
-
const inspection = { compiler: compilerDigest(), files: new Map(), sets: new Map() };
|
|
112
|
-
return entries
|
|
183
|
+
const inspection = { compiler: await compilerDigest(), files: new Map(), sets: new Map() };
|
|
184
|
+
return everyAsync(entries, async (entry) => reusable(entry, previewArtifactHtml(entry.id, revision), inspection));
|
|
113
185
|
}
|
|
114
|
-
function recordEntries(entries, dependencies) {
|
|
115
|
-
const compiler = compilerDigest(),
|
|
186
|
+
async function recordEntries(entries, dependencies) {
|
|
187
|
+
const compiler = await compilerDigest(),
|
|
188
|
+
hashes = new Map();
|
|
116
189
|
for (const entry of entries) {
|
|
117
|
-
const files = [...new Set([path.join(root, entry.file), ...dependencies])]
|
|
118
|
-
|
|
190
|
+
const files = [...new Set([path.join(root, entry.file), ...dependencies])].filter(
|
|
191
|
+
(file) => isInside(root, file) && !file.includes(`${path.sep}node_modules${path.sep}`),
|
|
192
|
+
);
|
|
119
193
|
for (const file of files) if (!hashes.has(file)) hashes.set(file, fileDigest(file));
|
|
120
|
-
const dependencyHashes = Object.fromEntries(files.map(file => [path.relative(root,file),hashes.get(file)]).sort(([a],[b])=>a.localeCompare(b)));
|
|
194
|
+
const dependencyHashes = Object.fromEntries(files.map((file) => [path.relative(root, file), hashes.get(file)]).sort(([a], [b]) => a.localeCompare(b)));
|
|
121
195
|
const dependencySet = digest(JSON.stringify(dependencyHashes));
|
|
122
196
|
value.dependencySets[dependencySet] = dependencyHashes;
|
|
123
|
-
value.entries[entry.id] = {
|
|
124
|
-
|
|
197
|
+
value.entries[entry.id] = {
|
|
198
|
+
metadata: JSON.stringify(entry),
|
|
199
|
+
compiler,
|
|
200
|
+
dependencySet,
|
|
201
|
+
artifact: artifactDigest(path.join(root, previewArtifactPath(options, entry.artifact))),
|
|
202
|
+
};
|
|
125
203
|
}
|
|
126
204
|
}
|
|
127
|
-
function recordCurrent(stamp, update) {
|
|
205
|
+
async function recordCurrent(stamp, update) {
|
|
128
206
|
// Publication and dependency hashing can overlap the next external edit.
|
|
129
207
|
// Never attach the previous output to bytes newer than its compiled stamp.
|
|
130
|
-
if (inputs() !== stamp) return false;
|
|
208
|
+
if ((await inputs()) !== stamp) return false;
|
|
131
209
|
const previous = value;
|
|
132
210
|
value = { ...value, entries: { ...value.entries }, dependencySets: { ...value.dependencySets } };
|
|
133
211
|
try {
|
|
134
|
-
update();
|
|
135
|
-
if (inputs() !== stamp) {
|
|
212
|
+
await update();
|
|
213
|
+
if ((await inputs()) !== stamp) {
|
|
214
|
+
value = previous;
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
136
217
|
save();
|
|
137
218
|
return true;
|
|
138
|
-
} catch (error) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
219
|
+
} catch (error) {
|
|
220
|
+
value = previous;
|
|
221
|
+
throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function graph(revision, entries, stamp) {
|
|
225
|
+
value.graphRevision = revision;
|
|
226
|
+
value.graphInputs = stamp;
|
|
227
|
+
value.registry = entries;
|
|
228
|
+
}
|
|
229
|
+
async function recordGraph(revision, entries, stamp) {
|
|
230
|
+
if (stamp === undefined) stamp = await inputs();
|
|
231
|
+
return recordCurrent(stamp, () => graph(revision, entries, stamp));
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
inputs,
|
|
235
|
+
reusable,
|
|
236
|
+
reusableEntries,
|
|
237
|
+
reload,
|
|
238
|
+
snapshot: () => structuredClone(value),
|
|
239
|
+
seed(state) {
|
|
240
|
+
value = structuredClone(state);
|
|
241
|
+
save();
|
|
242
|
+
},
|
|
243
|
+
graphRevision: () => value.graphRevision,
|
|
244
|
+
recordGraph,
|
|
245
|
+
validated: (stamp) => value.validation === stamp,
|
|
246
|
+
production(stamp) {
|
|
247
|
+
return value.production?.stamp === stamp && value.production.revision === value.graphRevision;
|
|
248
|
+
},
|
|
249
|
+
async recordProduction(stamp) {
|
|
250
|
+
return recordCurrent(stamp, () => {
|
|
251
|
+
value.production = { stamp, revision: value.graphRevision };
|
|
252
|
+
});
|
|
253
|
+
},
|
|
254
|
+
async registry(stamp) {
|
|
255
|
+
if (value.validation !== stamp || value.graphInputs !== stamp || !Array.isArray(value.registry) || !value.registry.length || value.registry.length > 1000)
|
|
256
|
+
return null;
|
|
257
|
+
const valid = value.registry.every(
|
|
258
|
+
(entry) =>
|
|
259
|
+
typeof entry?.id === "string" &&
|
|
260
|
+
/^(?:brand|pictograms|tokens|components|patterns|composition)\/[\w./-]+$/.test(entry.id) &&
|
|
261
|
+
path.posix.normalize(entry.id) === entry.id &&
|
|
262
|
+
typeof entry.file === "string" &&
|
|
263
|
+
isInside(options.dsRoot, path.resolve(root, entry.file)) &&
|
|
264
|
+
entry.artifact === `.ds/scenarios/${entry.id}/index.html`,
|
|
265
|
+
);
|
|
266
|
+
return valid && (await reusableEntries(value.registry, value.graphRevision)) ? structuredClone(value.registry) : null;
|
|
151
267
|
},
|
|
152
268
|
assertCompiler() {
|
|
153
|
-
if (adapterDigest() !== loadedAdapter)
|
|
269
|
+
if (adapterDigest() !== loadedAdapter)
|
|
270
|
+
throw Object.assign(
|
|
271
|
+
new Error("Preview compiler code or dependencies changed. Invoke the preview again to restart the builder and load current code."),
|
|
272
|
+
{ code: "ADS_PREVIEW_RESTART" },
|
|
273
|
+
);
|
|
154
274
|
},
|
|
155
|
-
validate(stamp) {
|
|
156
|
-
|
|
157
|
-
|
|
275
|
+
validate(stamp) {
|
|
276
|
+
value.validation = stamp;
|
|
277
|
+
save();
|
|
278
|
+
},
|
|
279
|
+
async recordAll(entries, dependencies, revision, stamp) {
|
|
280
|
+
if (stamp === undefined) stamp = await inputs();
|
|
281
|
+
return recordCurrent(stamp, async () => {
|
|
282
|
+
await recordEntries(entries, dependencies);
|
|
283
|
+
graph(revision, entries, stamp);
|
|
284
|
+
});
|
|
158
285
|
},
|
|
159
|
-
record(entry, dependencies, stamp = inputs()) { return recordCurrent(stamp, () => recordEntries([entry], dependencies)); },
|
|
160
286
|
};
|
|
161
287
|
}
|
|
162
288
|
|
|
163
289
|
/** Accepted source can carry its checked graph out of a guarded candidate.
|
|
164
290
|
* A cache miss is harmless: the regular watcher will prepare the preview. */
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
291
|
+
/** The discovered scenario registry, written where the showcase and tools read it. Its folder may not exist yet when startup discovery failed. */
|
|
292
|
+
function writeRegistryManifest(root, scenarios) {
|
|
293
|
+
mkdirSync(path.join(root, ".ds/scenarios"), { recursive: true });
|
|
294
|
+
writeFileSync(path.join(root, ".ds/scenarios/manifest.json"), JSON.stringify({ schemaVersion: 1, scenarios }, null, 2));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export async function preparePreviewCache(candidate, target) {
|
|
298
|
+
if (candidate.config.framework !== target.config.framework) return false;
|
|
299
|
+
const file = path.join(candidate.root, ".ds/preview-cache.json");
|
|
300
|
+
if (!existsSync(file) || realpathSync(file) !== file || statSync(file).size >= maxCacheBytes) return false;
|
|
301
|
+
const state = JSON.parse(readFileSync(file, "utf8"));
|
|
302
|
+
if (
|
|
303
|
+
state.schemaVersion !== cacheVersion ||
|
|
304
|
+
!Array.isArray(state.compilerFiles) ||
|
|
305
|
+
state.compilerFiles.some((file) => typeof file !== "string" || !isInside(candidate.root, path.resolve(candidate.root, file)))
|
|
306
|
+
)
|
|
307
|
+
return false;
|
|
308
|
+
const source = createPreviewCache(
|
|
309
|
+
candidate,
|
|
310
|
+
state.compilerFiles.map((file) => path.resolve(candidate.root, file)),
|
|
311
|
+
);
|
|
312
|
+
const destination = createPreviewCache(
|
|
313
|
+
target,
|
|
314
|
+
state.compilerFiles.map((file) => path.resolve(target.root, file)),
|
|
315
|
+
);
|
|
316
|
+
const stamp = await source.inputs();
|
|
317
|
+
const entries = await source.registry(stamp);
|
|
318
|
+
if (!entries?.length) return false;
|
|
319
|
+
const publication = cachedPreviewPublication(candidate, entries, state.graphRevision, target);
|
|
320
|
+
if (!publication || (await source.inputs()) !== stamp) return false;
|
|
321
|
+
const snapshot = source.snapshot();
|
|
322
|
+
const transferRegistry = await prepareScenarioRegistryTransfer(candidate, target);
|
|
323
|
+
return async () => {
|
|
324
|
+
if ((await destination.inputs()) !== stamp) return false;
|
|
182
325
|
publication.publish("accepted-mutation");
|
|
183
326
|
destination.seed(snapshot);
|
|
184
|
-
transferRegistry?.();
|
|
185
|
-
return {revision:publication.revision,scenarios:entries.map(entry=>entry.id)};
|
|
327
|
+
await transferRegistry?.();
|
|
328
|
+
return { revision: publication.revision, scenarios: entries.map((entry) => entry.id) };
|
|
186
329
|
};
|
|
187
330
|
}
|
|
188
331
|
|
|
189
332
|
/** An accepted edit writes source before it can publish the graph it checked.
|
|
190
333
|
* The hold keeps a watching compiler from rebuilding that source in the gap.
|
|
191
334
|
* Its age bound lets a crashed process cost one delay, not a stuck preview. */
|
|
192
|
-
const publicationHold = root => path.join(root,".ds/preview-publication.hold"),
|
|
335
|
+
const publicationHold = (root) => path.join(root, ".ds/preview-publication.hold"),
|
|
336
|
+
publicationHoldMs = 15000;
|
|
193
337
|
export function holdLivePreview(root) {
|
|
194
|
-
const file=publicationHold(root);
|
|
195
|
-
mkdirSync(path.dirname(file),{recursive:true});
|
|
196
|
-
|
|
338
|
+
const file = publicationHold(root);
|
|
339
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
340
|
+
writeFileSync(file, "");
|
|
341
|
+
return () => rmSync(file, { force: true });
|
|
197
342
|
}
|
|
198
343
|
|
|
199
|
-
export function promotePreviewCache(candidate,target) {
|
|
344
|
+
export async function promotePreviewCache(candidate, target) {
|
|
345
|
+
const publish = await preparePreviewCache(candidate, target);
|
|
346
|
+
return publish ? await publish() : false;
|
|
347
|
+
}
|
|
200
348
|
|
|
201
349
|
/** Restore a complete verified graph without rediscovering semantic scenarios or
|
|
202
350
|
* starting a compiler. Live build evidence always belongs to this new session. */
|
|
203
351
|
export async function restoreCompiledPreviews(options, compilerFiles) {
|
|
204
|
-
const cache=createPreviewCache(options,compilerFiles),
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
352
|
+
const cache = createPreviewCache(options, compilerFiles),
|
|
353
|
+
stamp = await cache.inputs();
|
|
354
|
+
if (!cache.production(stamp)) return false;
|
|
355
|
+
const entries = await cache.registry(stamp);
|
|
356
|
+
if (!entries?.length) return false;
|
|
357
|
+
const publication = cachedPreviewPublication(options, entries, cache.graphRevision());
|
|
358
|
+
if (!publication) return false;
|
|
210
359
|
// The native graph stamp includes the successful gate's source, tool, runtime,
|
|
211
360
|
// Git tracking and installed-package environment. Do not invoke a second batch
|
|
212
361
|
// runner to revalidate identical evidence already attached to this graph.
|
|
213
|
-
const sourceRevision=previewSourceRevision(options);
|
|
214
|
-
if(cache.inputs()!==stamp)return false;
|
|
215
|
-
const reporter=createBuildReporter(options.root,{apps:entries.map(entry=>({id:entry.id,file:previewArtifactPath(options,entry.artifact)}))});
|
|
362
|
+
const sourceRevision = await previewSourceRevision(options);
|
|
363
|
+
if ((await cache.inputs()) !== stamp) return false;
|
|
364
|
+
const reporter = createBuildReporter(options.root, { apps: entries.map((entry) => ({ id: entry.id, file: previewArtifactPath(options, entry.artifact) })) });
|
|
216
365
|
publication.publish(reporter.session);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
366
|
+
writeRegistryManifest(options.root, entries);
|
|
367
|
+
if ((await cache.inputs()) !== stamp) return false;
|
|
368
|
+
await reporter.batch(async () => {
|
|
369
|
+
for (const entry of entries) {
|
|
370
|
+
const revision = await reporter.begin(entry.id, { sourceRevision });
|
|
371
|
+
reporter.ready(entry.id, revision);
|
|
372
|
+
}
|
|
373
|
+
reporter.progress("idle");
|
|
374
|
+
});
|
|
375
|
+
return { restored: true, revision: publication.revision, scenarios: entries.length };
|
|
222
376
|
}
|
|
223
377
|
|
|
224
378
|
/** One compile at a time in a process: the viewed draft first, then the project's view, then
|
|
225
379
|
* the project's other requests, then drafts' background work. */
|
|
226
380
|
function createScheduler() {
|
|
227
|
-
const queue = [];
|
|
381
|
+
const queue = [];
|
|
382
|
+
let running = false,
|
|
383
|
+
order = 0;
|
|
228
384
|
function pump() {
|
|
229
385
|
if (running || !queue.length) return;
|
|
230
386
|
queue.sort((a, b) => a.priority - b.priority || a.order - b.order);
|
|
231
|
-
const job = queue.shift();
|
|
232
|
-
|
|
387
|
+
const job = queue.shift();
|
|
388
|
+
running = true;
|
|
389
|
+
Promise.resolve()
|
|
390
|
+
.then(job.run)
|
|
391
|
+
.then(job.resolve, job.reject)
|
|
392
|
+
.finally(() => {
|
|
393
|
+
running = false;
|
|
394
|
+
pump();
|
|
395
|
+
});
|
|
233
396
|
}
|
|
234
|
-
return kind
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
397
|
+
return (kind) =>
|
|
398
|
+
(run, { foreground = false } = {}) =>
|
|
399
|
+
new Promise((resolve, reject) => {
|
|
400
|
+
queue.push({ run, resolve, reject, order: order++, priority: foreground ? (kind === "draft" ? 0 : 1) : kind === "draft" ? 3 : 2 });
|
|
401
|
+
pump();
|
|
402
|
+
});
|
|
238
403
|
}
|
|
239
404
|
|
|
240
405
|
/**
|
|
@@ -242,30 +407,62 @@ function createScheduler() {
|
|
|
242
407
|
* with the options setup(root) gives for its own root and a builder of its own. Compiler options
|
|
243
408
|
* fixed to one root cannot build a draft; each draft then reports that instead of waiting.
|
|
244
409
|
*/
|
|
245
|
-
function hostDrafts(file, setup, schedule) {
|
|
410
|
+
async function hostDrafts(file, setup, schedule) {
|
|
246
411
|
const instances = new Map();
|
|
247
412
|
async function reconcile() {
|
|
248
413
|
let wanted = [];
|
|
249
|
-
try {
|
|
250
|
-
|
|
251
|
-
|
|
414
|
+
try {
|
|
415
|
+
wanted = JSON.parse(readFileSync(file, "utf8")).drafts ?? [];
|
|
416
|
+
} catch {
|
|
417
|
+
/* No drafts yet. */
|
|
418
|
+
}
|
|
419
|
+
const sessions = new Set(wanted.map((entry) => entry.session));
|
|
420
|
+
for (const [session, instance] of instances)
|
|
421
|
+
if (!sessions.has(session)) {
|
|
422
|
+
instances.delete(session);
|
|
423
|
+
(await instance)?.stop();
|
|
424
|
+
}
|
|
252
425
|
for (const entry of wanted) {
|
|
253
426
|
if (instances.has(entry.session) || !isDraftPreviewWorkspace(entry.root)) continue;
|
|
254
427
|
const context = { session: entry.session, requestFile: entry.requestFile, statusFile: entry.statusFile, prewarm: false, schedule: schedule("draft") };
|
|
255
428
|
if (!setup) {
|
|
256
429
|
instances.set(entry.session, Promise.resolve(null));
|
|
257
|
-
createBuildReporter(entry.root, { apps: [], session: entry.session, file: entry.statusFile })
|
|
258
|
-
|
|
430
|
+
createBuildReporter(entry.root, { apps: [], session: entry.session, file: entry.statusFile }).failure(
|
|
431
|
+
scopedPreviewFailure(
|
|
432
|
+
new Error(
|
|
433
|
+
"This project's preview compiler passes runScenarioCompiler options for one root, so it cannot build drafts. Pass a function of the root that returns the options instead.",
|
|
434
|
+
),
|
|
435
|
+
"project",
|
|
436
|
+
"discovery",
|
|
437
|
+
),
|
|
438
|
+
);
|
|
259
439
|
continue;
|
|
260
440
|
}
|
|
261
|
-
instances.set(
|
|
262
|
-
|
|
441
|
+
instances.set(
|
|
442
|
+
entry.session,
|
|
443
|
+
runScenarioCompiler(entry.root, (draftRoot) => ({ ...setup(draftRoot), watched: true, context })).catch((error) => {
|
|
444
|
+
console.error(error);
|
|
445
|
+
instances.delete(entry.session);
|
|
446
|
+
}),
|
|
447
|
+
);
|
|
263
448
|
}
|
|
264
449
|
}
|
|
265
|
-
void reconcile();
|
|
450
|
+
void (await reconcile());
|
|
266
451
|
let timer;
|
|
267
|
-
const watcher = watch(path.dirname(file), (_event, name) => {
|
|
268
|
-
|
|
452
|
+
const watcher = watch(path.dirname(file), (_event, name) => {
|
|
453
|
+
if (String(name) === path.basename(file)) {
|
|
454
|
+
clearTimeout(timer);
|
|
455
|
+
timer = setTimeout(async () => void (await reconcile()), 16);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
return {
|
|
459
|
+
async stop() {
|
|
460
|
+
watcher.close();
|
|
461
|
+
clearTimeout(timer);
|
|
462
|
+
for (const instance of instances.values()) (await instance)?.stop();
|
|
463
|
+
instances.clear();
|
|
464
|
+
},
|
|
465
|
+
};
|
|
269
466
|
}
|
|
270
467
|
|
|
271
468
|
/**
|
|
@@ -277,45 +474,77 @@ function hostDrafts(file, setup, schedule) {
|
|
|
277
474
|
*/
|
|
278
475
|
export async function runScenarioCompiler(directory, setup) {
|
|
279
476
|
const root = path.resolve(directory);
|
|
280
|
-
const { watched = false, validate,
|
|
281
|
-
|
|
477
|
+
const { watched = false, validate, buildGraph, compilerFiles = [], context = {} } = typeof setup === "function" ? setup(root) : setup;
|
|
478
|
+
if (typeof buildGraph !== "function") throw new Error("runScenarioCompiler needs buildGraph: previews compile into one shared resource graph.");
|
|
479
|
+
const control = process.env.ADS_MCP_DRAFT_CONTROL,
|
|
480
|
+
hosting = watched && !context.session && control && existsSync(path.dirname(control));
|
|
282
481
|
const scheduler = hosting ? createScheduler() : null;
|
|
283
|
-
const {
|
|
482
|
+
const {
|
|
483
|
+
session: buildSession = process.env.ADS_MCP_BUILD_SESSION,
|
|
484
|
+
requestFile = process.env.ADS_MCP_REQUEST_FILE,
|
|
485
|
+
statusFile = process.env.ADS_MCP_BUILD_STATUS,
|
|
486
|
+
prewarm: prewarmViews = process.env.ADS_MCP_PREWARM_VIEWS === "1",
|
|
487
|
+
schedule = scheduler ? scheduler("project") : (run) => run(),
|
|
488
|
+
} = context;
|
|
284
489
|
let options = withPreviewSession(loadConfig(root), buildSession);
|
|
285
|
-
if (
|
|
490
|
+
if (!options.config.framework) throw new Error("Preview builds require an explicit framework in ds.config.json.");
|
|
286
491
|
const cache = createPreviewCache(options, compilerFiles);
|
|
287
|
-
function registry() {
|
|
492
|
+
async function registry() {
|
|
288
493
|
options = withPreviewSession(loadConfig(root), buildSession);
|
|
289
|
-
const result =
|
|
290
|
-
if (result.diagnostics.length)
|
|
291
|
-
|
|
292
|
-
|
|
494
|
+
const result = await analyze(root, "registry");
|
|
495
|
+
if (result.diagnostics.length)
|
|
496
|
+
throw Object.assign(new Error(result.diagnostics.map((item) => `${item.file}: ${item.message}`).join("\n")), { scenarios: result.scenarios });
|
|
497
|
+
writeRegistryManifest(root, result.scenarios);
|
|
293
498
|
return result.scenarios;
|
|
294
499
|
}
|
|
295
|
-
let entries = [],
|
|
296
|
-
|
|
297
|
-
|
|
500
|
+
let entries = [],
|
|
501
|
+
registryFailure;
|
|
502
|
+
try {
|
|
503
|
+
entries = await registry();
|
|
504
|
+
} catch (error) {
|
|
298
505
|
if (!watched) throw error;
|
|
299
|
-
registryFailure = error;
|
|
506
|
+
registryFailure = error;
|
|
507
|
+
entries = error.scenarios ?? [];
|
|
508
|
+
} finally {
|
|
509
|
+
if (watched) releaseScenarioRegistry(root);
|
|
300
510
|
}
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
511
|
+
const buildApps = () => entries.map((entry) => ({ id: entry.id, file: previewArtifactPath(options, entry.artifact) }));
|
|
512
|
+
const reporter = createBuildReporter(root, {
|
|
513
|
+
apps: buildApps(),
|
|
514
|
+
...(buildSession ? { session: buildSession } : {}),
|
|
515
|
+
...(statusFile ? { file: statusFile } : {}),
|
|
516
|
+
});
|
|
304
517
|
const requested = new Set();
|
|
305
518
|
const pending = new Set();
|
|
306
519
|
let active;
|
|
307
520
|
const prewarm = watched && prewarmViews;
|
|
308
|
-
const warmed = new Set(),
|
|
521
|
+
const warmed = new Set(),
|
|
522
|
+
warmFailures = new Set();
|
|
309
523
|
let preferred, warming;
|
|
310
|
-
if(prewarm)
|
|
524
|
+
if (prewarm)
|
|
525
|
+
try {
|
|
526
|
+
preferred = JSON.parse(readFileSync(path.join(root, ".ds/last-preview.json"), "utf8")).scenario;
|
|
527
|
+
} catch {
|
|
528
|
+
/* First startup warms the first view. */
|
|
529
|
+
}
|
|
311
530
|
function warmProgress() {
|
|
312
|
-
if(!prewarm)return;
|
|
313
|
-
const completed=entries.filter(entry=>warmed.has(entry.id)).length,
|
|
314
|
-
|
|
531
|
+
if (!prewarm) return;
|
|
532
|
+
const completed = entries.filter((entry) => warmed.has(entry.id)).length,
|
|
533
|
+
failed = entries.filter((entry) => warmFailures.has(entry.id)).length;
|
|
534
|
+
reporter.warmup({
|
|
535
|
+
state: completed === entries.length ? "ready" : completed + failed === entries.length ? "error" : "warming",
|
|
536
|
+
completed,
|
|
537
|
+
total: entries.length,
|
|
538
|
+
failed,
|
|
539
|
+
...(warming ? { active: warming } : {}),
|
|
540
|
+
});
|
|
315
541
|
}
|
|
316
542
|
function nextWarm() {
|
|
317
|
-
if(!prewarm||registryFailure)return;
|
|
318
|
-
return
|
|
543
|
+
if (!prewarm || registryFailure) return;
|
|
544
|
+
return (
|
|
545
|
+
entries.find((entry) => entry.id === preferred && !requested.has(entry.id) && !warmed.has(entry.id)) ??
|
|
546
|
+
entries.find((entry) => !requested.has(entry.id) && !warmed.has(entry.id))
|
|
547
|
+
);
|
|
319
548
|
}
|
|
320
549
|
warmProgress();
|
|
321
550
|
let compiling = false;
|
|
@@ -324,138 +553,139 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
324
553
|
let publishedStamp;
|
|
325
554
|
let publishedEntries = new Set();
|
|
326
555
|
let validation;
|
|
327
|
-
let observedSourceRevision = previewSourceRevision(options);
|
|
556
|
+
let observedSourceRevision = await previewSourceRevision(options);
|
|
328
557
|
let invalidation;
|
|
329
558
|
let fullRequest, completedFull;
|
|
330
559
|
// Keep the registry inspector warm while previews are in use: a cold TypeScript program costs ~1.7 s per edit.
|
|
331
|
-
const inspector = watched
|
|
560
|
+
const inspector = watched ? createScenarioInspector(root, { idleMs: 10 * 60 * 1000 }) : null;
|
|
332
561
|
let discovering, unknownRevision;
|
|
333
|
-
let liveCandidate,
|
|
562
|
+
let liveCandidate,
|
|
563
|
+
verifying = false;
|
|
334
564
|
let handle;
|
|
335
|
-
function failure(error) {
|
|
565
|
+
async function failure(error) {
|
|
336
566
|
// A retired draft workspace is deleted while its instance stops: nothing left to report.
|
|
337
|
-
if (watched && !existsSync(root)) {
|
|
338
|
-
|
|
567
|
+
if (watched && !existsSync(root)) {
|
|
568
|
+
await handle?.stop();
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
reporter.failure(scopedPreviewFailure(error, "project", "discovery"));
|
|
573
|
+
} catch (reportError) {
|
|
574
|
+
console.error(reportError);
|
|
575
|
+
}
|
|
339
576
|
console.error(error);
|
|
340
577
|
if (!watched) process.exitCode = 1;
|
|
341
578
|
}
|
|
342
|
-
if (registryFailure) failure(registryFailure);
|
|
579
|
+
if (registryFailure) await failure(registryFailure);
|
|
343
580
|
function gate(stamp) {
|
|
344
581
|
if (isDraftPreviewWorkspace(root)) return Promise.resolve();
|
|
345
582
|
if (cache.validated(stamp)) return Promise.resolve();
|
|
346
|
-
return validation ??= Promise.resolve()
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
583
|
+
return (validation ??= Promise.resolve()
|
|
584
|
+
.then(validate)
|
|
585
|
+
.then(async (valid) => {
|
|
586
|
+
if (stamp !== (await cache.inputs())) throw new Error("Sources changed during preview validation. Waiting for the current build.");
|
|
587
|
+
if (valid !== false) cache.validate(stamp);
|
|
588
|
+
})
|
|
589
|
+
.catch((error) => {
|
|
590
|
+
throw scopedPreviewFailure(error, "project", "validation");
|
|
591
|
+
}));
|
|
350
592
|
}
|
|
351
593
|
async function checkedBuild(stamp, build) {
|
|
352
594
|
const started = generation;
|
|
353
|
-
let checking = true,
|
|
354
|
-
|
|
595
|
+
let checking = true,
|
|
596
|
+
compiling = true;
|
|
597
|
+
function progress() {
|
|
598
|
+
if (started === generation)
|
|
599
|
+
reporter.progress(checking && compiling ? "validation-and-compilation" : checking ? "validation" : compiling ? "compilation" : "publication");
|
|
600
|
+
}
|
|
355
601
|
progress();
|
|
356
602
|
return Promise.allSettled([
|
|
357
|
-
gate(stamp).finally(() => {
|
|
358
|
-
|
|
603
|
+
gate(stamp).finally(() => {
|
|
604
|
+
checking = false;
|
|
605
|
+
progress();
|
|
606
|
+
}),
|
|
607
|
+
Promise.resolve()
|
|
608
|
+
.then(build)
|
|
609
|
+
.finally(() => {
|
|
610
|
+
compiling = false;
|
|
611
|
+
progress();
|
|
612
|
+
}),
|
|
359
613
|
]);
|
|
360
614
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const started = generation;
|
|
365
|
-
try {
|
|
366
|
-
const stamp = cache.inputs();
|
|
367
|
-
cache.assertCompiler();
|
|
368
|
-
const reuse = cache.reusable(entry);
|
|
369
|
-
const dependencies = new Set();
|
|
370
|
-
function assets(directory) {
|
|
371
|
-
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
372
|
-
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
373
|
-
const file = path.join(directory, item.name);
|
|
374
|
-
if (item.isDirectory()) { if (!hasProjectConfig(file)) assets(file); }
|
|
375
|
-
else if (/\.(?:css|svg|png|jpe?g|webp|gif|woff2?|ttf|otf)$/.test(file)) dependencies.add(file);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
// CSS url() inputs may be inlined without becoming Rollup JS modules.
|
|
379
|
-
// Shared foundation/styles/assets conservatively invalidate all previews.
|
|
380
|
-
assets(options.dsRoot);
|
|
381
|
-
const track = { name: "ads-preview-dependencies", generateBundle() {
|
|
382
|
-
// Include modules used during extraction, even when their final JS was
|
|
383
|
-
// tree-shaken. A stylesheet evaluation can depend on those exports.
|
|
384
|
-
for (const id of this.getModuleIds()) {
|
|
385
|
-
const file = id.split("?")[0];
|
|
386
|
-
if (path.isAbsolute(file) && existsSync(file)) dependencies.add(file);
|
|
387
|
-
}
|
|
388
|
-
} };
|
|
389
|
-
const outcomes = await checkedBuild(stamp, () => reuse ? undefined : build(entry, options, track));
|
|
390
|
-
const failure = outcomes.find(outcome => outcome.status === "rejected");
|
|
391
|
-
if (failure) throw failure.reason;
|
|
392
|
-
cache.assertCompiler();
|
|
393
|
-
if (stopped || started !== generation || stamp !== cache.inputs()) return; // Watch queued a newer revision.
|
|
394
|
-
if (!reuse && !cache.record(entry, dependencies, stamp)) return;
|
|
395
|
-
reporter.ready(entry.id, revision);
|
|
396
|
-
reporter.progress("idle");
|
|
397
|
-
} catch (error) {
|
|
398
|
-
if (started !== generation) return;
|
|
399
|
-
reporter.error(entry.id, revision, scopedPreviewFailure(error,"scenario","build"));
|
|
400
|
-
reporter.progress("idle");
|
|
401
|
-
console.error(error);
|
|
402
|
-
if (!watched) process.exitCode = 1;
|
|
403
|
-
}
|
|
615
|
+
// Every preview is part of one shared resource graph.
|
|
616
|
+
async function compile() {
|
|
617
|
+
return watched ? await compileLiveGraph() : await compileGraph();
|
|
404
618
|
}
|
|
405
619
|
async function compileGraph() {
|
|
406
620
|
cache.reload();
|
|
407
|
-
const sourceRevision = previewSourceRevision(options);
|
|
408
|
-
const revisions = new Map(entries
|
|
621
|
+
const sourceRevision = await previewSourceRevision(options);
|
|
622
|
+
const revisions = new Map(await mapAsync(entries, async (entry) => [entry.id, await reporter.begin(entry.id, { sourceRevision })]));
|
|
409
623
|
const started = generation;
|
|
410
624
|
try {
|
|
411
|
-
const stamp = cache.inputs();
|
|
625
|
+
const stamp = await cache.inputs();
|
|
412
626
|
const dependencies = new Set();
|
|
413
627
|
function assets(directory) {
|
|
414
628
|
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
415
629
|
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
416
630
|
const file = path.join(directory, item.name);
|
|
417
|
-
if (item.isDirectory()) {
|
|
418
|
-
|
|
631
|
+
if (item.isDirectory()) {
|
|
632
|
+
if (!hasProjectConfig(file)) assets(file);
|
|
633
|
+
} else if (/\.(?:css|svg|png|jpe?g|webp|gif|woff2?|ttf|otf)$/.test(file)) dependencies.add(file);
|
|
419
634
|
}
|
|
420
635
|
}
|
|
421
636
|
assets(options.dsRoot);
|
|
422
|
-
const track = {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
637
|
+
const track = {
|
|
638
|
+
name: "ads-preview-graph-dependencies",
|
|
639
|
+
generateBundle() {
|
|
640
|
+
for (const id of this.getModuleIds()) {
|
|
641
|
+
const file = id.split("?")[0];
|
|
642
|
+
if (path.isAbsolute(file) && existsSync(file)) dependencies.add(file);
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
};
|
|
428
646
|
cache.assertCompiler();
|
|
429
647
|
const cached = cachedPreviewPublication(options, entries, cache.graphRevision());
|
|
430
|
-
let reusable = cache.production(stamp) && cached && cache.reusableEntries(entries,cached.revision);
|
|
648
|
+
let reusable = cache.production(stamp) && cached && (await cache.reusableEntries(entries, cached.revision));
|
|
431
649
|
if (reusable) {
|
|
432
|
-
try {
|
|
433
|
-
|
|
650
|
+
try {
|
|
651
|
+
readPreviewManifest(options, { verify: true });
|
|
652
|
+
} catch {
|
|
653
|
+
reusable = false;
|
|
654
|
+
}
|
|
434
655
|
}
|
|
435
|
-
const outcomes = await checkedBuild(stamp, () => reusable ? null : buildGraph(entries, options, track, { watched: false, sourceRevision }));
|
|
436
|
-
const failure = outcomes.find(outcome => outcome.status === "rejected");
|
|
656
|
+
const outcomes = await checkedBuild(stamp, async () => (reusable ? null : await buildGraph(entries, options, track, { watched: false, sourceRevision })));
|
|
657
|
+
const failure = outcomes.find((outcome) => outcome.status === "rejected");
|
|
437
658
|
if (failure) throw failure.reason;
|
|
438
659
|
cache.assertCompiler();
|
|
439
|
-
if (stopped || started !== generation || stamp !== cache.inputs()) return;
|
|
660
|
+
if (stopped || started !== generation || stamp !== (await cache.inputs())) return;
|
|
440
661
|
const publication = outcomes[1].value;
|
|
441
662
|
if (publication) {
|
|
442
663
|
publication.publish(reporter.session);
|
|
443
|
-
if (!cache.recordAll(entries, dependencies, publication.revision, stamp)) return;
|
|
664
|
+
if (!(await cache.recordAll(entries, dependencies, publication.revision, stamp))) return;
|
|
444
665
|
} else {
|
|
445
666
|
cached.publish(reporter.session);
|
|
446
|
-
if (!cache.recordGraph(cached.revision,entries,stamp)) return;
|
|
667
|
+
if (!(await cache.recordGraph(cached.revision, entries, stamp))) return;
|
|
668
|
+
}
|
|
669
|
+
for (const entry of entries) {
|
|
670
|
+
pending.delete(entry.id);
|
|
671
|
+
reporter.ready(entry.id, revisions.get(entry.id));
|
|
447
672
|
}
|
|
448
|
-
for (const entry of entries) { pending.delete(entry.id); reporter.ready(entry.id, revisions.get(entry.id)); }
|
|
449
673
|
publishedStamp = stamp;
|
|
450
|
-
publishedEntries = new Set(entries.map(entry => entry.id));
|
|
451
|
-
cache.recordProduction(stamp);
|
|
452
|
-
for(const entry of entries){
|
|
674
|
+
publishedEntries = new Set(entries.map((entry) => entry.id));
|
|
675
|
+
await cache.recordProduction(stamp);
|
|
676
|
+
for (const entry of entries) {
|
|
677
|
+
warmed.add(entry.id);
|
|
678
|
+
warmFailures.delete(entry.id);
|
|
679
|
+
}
|
|
453
680
|
warmProgress();
|
|
454
681
|
reporter.progress("idle");
|
|
455
682
|
return true;
|
|
456
683
|
} catch (error) {
|
|
457
684
|
if (started !== generation) return;
|
|
458
|
-
for (const entry of entries) {
|
|
685
|
+
for (const entry of entries) {
|
|
686
|
+
pending.delete(entry.id);
|
|
687
|
+
reporter.error(entry.id, revisions.get(entry.id), scopedPreviewFailure(error, "graph", "build"));
|
|
688
|
+
}
|
|
459
689
|
reporter.progress("idle");
|
|
460
690
|
console.error(error);
|
|
461
691
|
if (!watched) process.exitCode = 1;
|
|
@@ -463,10 +693,14 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
463
693
|
}
|
|
464
694
|
}
|
|
465
695
|
async function publicationSettled() {
|
|
466
|
-
const file=publicationHold(root);
|
|
467
|
-
while(!stopped){
|
|
468
|
-
try{
|
|
469
|
-
|
|
696
|
+
const file = publicationHold(root);
|
|
697
|
+
while (!stopped) {
|
|
698
|
+
try {
|
|
699
|
+
if (Date.now() - statSync(file).mtimeMs >= publicationHoldMs) return;
|
|
700
|
+
} catch {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
470
704
|
}
|
|
471
705
|
}
|
|
472
706
|
// Visual feedback and verified publication have separate lifecycles. Edits
|
|
@@ -476,8 +710,9 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
476
710
|
await publicationSettled();
|
|
477
711
|
if (stopped) return;
|
|
478
712
|
cache.reload();
|
|
479
|
-
const sourceRevision = previewSourceRevision(options),
|
|
480
|
-
|
|
713
|
+
const sourceRevision = await previewSourceRevision(options),
|
|
714
|
+
stamp = await cache.inputs();
|
|
715
|
+
const prepared = await cache.registry(stamp);
|
|
481
716
|
// A guarded edit can publish a checked graph while this watcher's discovery
|
|
482
717
|
// still describes the previous revision. Adopt its current metadata before
|
|
483
718
|
// comparing registries. A partial watched graph cannot replace the catalogue.
|
|
@@ -489,59 +724,79 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
489
724
|
// Publication/cache identities follow discovery order, never navigation
|
|
490
725
|
// order. Otherwise warming a non-first view produces a full graph that
|
|
491
726
|
// cannot match the next process's canonical registry and rebuilds forever.
|
|
492
|
-
const selected = registryReused ? prepared : entries.filter(entry=>requested.has(entry.id));
|
|
727
|
+
const selected = registryReused ? prepared : entries.filter((entry) => requested.has(entry.id));
|
|
493
728
|
const candidate = { generation, stamp, sourceRevision, registry: [...entries], entries: selected, dependencies: new Set(), registryReused };
|
|
494
729
|
// Retain roots requested by other mounted Apps, without compiling untouched
|
|
495
730
|
// catalogue entries. Production/unwatched builds still cover all entries.
|
|
496
731
|
for (const entry of candidate.entries) pending.delete(entry.id);
|
|
497
|
-
candidate.revisions = reporter.batch(
|
|
732
|
+
candidate.revisions = await reporter.batch(
|
|
733
|
+
async () => new Map(await mapAsync(candidate.entries, async (entry) => [entry.id, await reporter.begin(entry.id, { sourceRevision })])),
|
|
734
|
+
);
|
|
498
735
|
reporter.progress("validation-and-compilation");
|
|
499
|
-
const track = {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
736
|
+
const track = {
|
|
737
|
+
name: "ads-live-preview-dependencies",
|
|
738
|
+
generateBundle() {
|
|
739
|
+
for (const id of this.getModuleIds()) {
|
|
740
|
+
const file = id.split("?")[0];
|
|
741
|
+
if (path.isAbsolute(file) && existsSync(file)) candidate.dependencies.add(file);
|
|
742
|
+
}
|
|
743
|
+
},
|
|
744
|
+
};
|
|
505
745
|
// Include non-module assets conservatively in the verified warm cache.
|
|
506
746
|
function assets(directory) {
|
|
507
747
|
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
508
748
|
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
509
749
|
const file = path.join(directory, item.name);
|
|
510
|
-
if (item.isDirectory()) {
|
|
511
|
-
|
|
750
|
+
if (item.isDirectory()) {
|
|
751
|
+
if (!hasProjectConfig(file)) assets(file);
|
|
752
|
+
} else if (/\.(?:css|svg|png|jpe?g|webp|gif|woff2?|ttf|otf)$/.test(file)) candidate.dependencies.add(file);
|
|
512
753
|
}
|
|
513
754
|
}
|
|
514
755
|
assets(options.dsRoot);
|
|
515
|
-
candidate.build = Promise.resolve().then(() => {
|
|
756
|
+
candidate.build = Promise.resolve().then(async () => {
|
|
516
757
|
cache.assertCompiler();
|
|
517
758
|
const cached = cachedPreviewPublication(options, candidate.entries, cache.graphRevision());
|
|
518
|
-
if (cached && cache.reusableEntries(candidate.entries,cached.revision)) {
|
|
759
|
+
if (cached && (await cache.reusableEntries(candidate.entries, cached.revision))) {
|
|
760
|
+
candidate.reused = true;
|
|
761
|
+
return cached;
|
|
762
|
+
}
|
|
519
763
|
return buildGraph(candidate.entries, options, track, { watched: true, sourceRevision });
|
|
520
764
|
});
|
|
521
765
|
liveCandidate = candidate;
|
|
522
766
|
try {
|
|
523
767
|
const publication = await candidate.build;
|
|
524
|
-
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || stamp !== cache.inputs()) return;
|
|
768
|
+
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || stamp !== (await cache.inputs())) return;
|
|
525
769
|
if (publication.publishLive) {
|
|
526
770
|
publication.publishLive(reporter.session);
|
|
527
771
|
reporter.live({ revision: publication.revision, sourceRevision });
|
|
528
|
-
for(const entry of candidate.entries){
|
|
772
|
+
for (const entry of candidate.entries) {
|
|
773
|
+
warmed.add(entry.id);
|
|
774
|
+
warmFailures.delete(entry.id);
|
|
775
|
+
}
|
|
529
776
|
warmProgress();
|
|
530
777
|
}
|
|
531
778
|
reporter.progress("validation");
|
|
532
779
|
} catch (error) {
|
|
533
780
|
// Syntax/build failures should surface immediately even when an unrelated
|
|
534
781
|
// validation command is still running. This candidate can never publish.
|
|
535
|
-
if (!stopped && candidate === liveCandidate && candidate.generation === generation && stamp === cache.inputs())
|
|
536
|
-
|
|
782
|
+
if (!stopped && candidate === liveCandidate && candidate.generation === generation && stamp === (await cache.inputs()))
|
|
783
|
+
await rejectLive(candidate, error);
|
|
784
|
+
} finally {
|
|
785
|
+
// Verification must not hold the compilation queue: a newly selected
|
|
786
|
+
// view or a newer edit can compile while the current policy check waits.
|
|
787
|
+
void verifyLive().catch(failure);
|
|
788
|
+
}
|
|
537
789
|
}
|
|
538
|
-
function rejectLive(candidate, error) {
|
|
790
|
+
async function rejectLive(candidate, error) {
|
|
539
791
|
candidate.failed = true;
|
|
540
|
-
for(const entry of candidate.entries){
|
|
792
|
+
for (const entry of candidate.entries) {
|
|
793
|
+
warmed.delete(entry.id);
|
|
794
|
+
warmFailures.add(entry.id);
|
|
795
|
+
}
|
|
541
796
|
warmProgress();
|
|
542
|
-
reporter.batch(() => {
|
|
797
|
+
await reporter.batch(() => {
|
|
543
798
|
reporter.live(undefined);
|
|
544
|
-
for (const entry of candidate.entries) reporter.error(entry.id, candidate.revisions.get(entry.id), scopedPreviewFailure(error,"graph","build"));
|
|
799
|
+
for (const entry of candidate.entries) reporter.error(entry.id, candidate.revisions.get(entry.id), scopedPreviewFailure(error, "graph", "build"));
|
|
545
800
|
reporter.progress("idle");
|
|
546
801
|
});
|
|
547
802
|
console.error(error);
|
|
@@ -554,126 +809,182 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
554
809
|
const candidate = liveCandidate;
|
|
555
810
|
const [compiled] = await Promise.allSettled([candidate.build]);
|
|
556
811
|
if (stopped) return;
|
|
557
|
-
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== cache.inputs()) {
|
|
812
|
+
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== (await cache.inputs())) {
|
|
558
813
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
559
814
|
continue;
|
|
560
815
|
}
|
|
561
816
|
// Give compiled feedback priority before starting CPU-heavy validation.
|
|
562
817
|
// An already running check continues; later edits replace its candidate.
|
|
563
|
-
const inspection=
|
|
564
|
-
|
|
818
|
+
const inspection =
|
|
819
|
+
candidate.reused && candidate.registryReused ? Promise.resolve({ scenarios: candidate.registry, diagnostics: [] }) : inspector.inspect();
|
|
820
|
+
const outcomes = [compiled, ...(await Promise.allSettled([gate(candidate.stamp), inspection]))];
|
|
565
821
|
if (stopped) return;
|
|
566
|
-
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== cache.inputs()) {
|
|
822
|
+
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== (await cache.inputs())) {
|
|
567
823
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
568
824
|
continue;
|
|
569
825
|
}
|
|
570
826
|
try {
|
|
571
827
|
if (outcomes[2].status === "rejected") throw outcomes[2].reason;
|
|
572
828
|
const registry = outcomes[2].value;
|
|
573
|
-
if (registry.diagnostics.length)
|
|
829
|
+
if (registry.diagnostics.length)
|
|
830
|
+
throw Object.assign(scopedPreviewFailure(new Error("Scenario registry has errors."), "project", "discovery"), {
|
|
831
|
+
diagnostics: registry.diagnostics,
|
|
832
|
+
});
|
|
574
833
|
if (JSON.stringify(registry.scenarios) !== JSON.stringify(candidate.registry)) {
|
|
575
834
|
entries = registry.scenarios;
|
|
576
|
-
|
|
577
|
-
reporter.batch(() => {
|
|
835
|
+
writeRegistryManifest(root, entries);
|
|
836
|
+
await reporter.batch(() => {
|
|
837
|
+
reporter.setApps(buildApps());
|
|
838
|
+
reporter.live(undefined);
|
|
839
|
+
reporter.progress("idle");
|
|
840
|
+
});
|
|
578
841
|
liveCandidate = undefined;
|
|
579
|
-
for (const id of requested) if (!entries.some(entry => entry.id === id)) requested.delete(id);
|
|
580
|
-
request(false);
|
|
842
|
+
for (const id of requested) if (!entries.some((entry) => entry.id === id)) requested.delete(id);
|
|
843
|
+
await request(false);
|
|
581
844
|
for (const id of requested) pending.add(id);
|
|
582
845
|
void drain();
|
|
583
846
|
continue;
|
|
584
847
|
}
|
|
585
|
-
if (candidate.failed) {
|
|
586
|
-
|
|
848
|
+
if (candidate.failed) {
|
|
849
|
+
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
const failed = outcomes.find((outcome) => outcome.status === "rejected");
|
|
587
853
|
if (failed) throw failed.reason;
|
|
588
854
|
cache.assertCompiler();
|
|
589
855
|
const publication = outcomes[0].value;
|
|
590
|
-
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== cache.inputs()) continue;
|
|
856
|
+
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== (await cache.inputs())) continue;
|
|
591
857
|
publication.publish(reporter.session);
|
|
592
858
|
const recorded = !candidate.reused
|
|
593
|
-
? cache.recordAll(candidate.entries, candidate.dependencies, publication.revision, candidate.stamp)
|
|
594
|
-
: cache.recordGraph(publication.revision,candidate.entries,candidate.stamp);
|
|
595
|
-
if (!recorded) {
|
|
596
|
-
|
|
859
|
+
? await cache.recordAll(candidate.entries, candidate.dependencies, publication.revision, candidate.stamp)
|
|
860
|
+
: await cache.recordGraph(publication.revision, candidate.entries, candidate.stamp);
|
|
861
|
+
if (!recorded) {
|
|
862
|
+
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
863
|
+
continue;
|
|
864
|
+
}
|
|
865
|
+
await reporter.batch(() => {
|
|
597
866
|
for (const entry of candidate.entries) reporter.ready(entry.id, candidate.revisions.get(entry.id));
|
|
598
867
|
reporter.live(undefined);
|
|
599
868
|
reporter.progress("idle");
|
|
600
869
|
});
|
|
601
870
|
publishedStamp = candidate.stamp;
|
|
602
|
-
publishedEntries = new Set(candidate.entries.map(entry => entry.id));
|
|
871
|
+
publishedEntries = new Set(candidate.entries.map((entry) => entry.id));
|
|
603
872
|
} catch (error) {
|
|
604
|
-
if (!candidate.failed) rejectLive(candidate, error);
|
|
873
|
+
if (!candidate.failed) await rejectLive(candidate, error);
|
|
605
874
|
}
|
|
606
875
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
607
876
|
}
|
|
608
|
-
} finally {
|
|
877
|
+
} finally {
|
|
878
|
+
verifying = false;
|
|
879
|
+
}
|
|
609
880
|
}
|
|
610
881
|
async function drain() {
|
|
611
882
|
if (compiling) return;
|
|
612
883
|
compiling = true;
|
|
613
884
|
try {
|
|
614
|
-
while ((pending.size || fullRequest && fullRequest !== completedFull || nextWarm()) && !stopped) {
|
|
885
|
+
while ((pending.size || (fullRequest && fullRequest !== completedFull) || nextWarm()) && !stopped) {
|
|
615
886
|
if (fullRequest && fullRequest !== completedFull) {
|
|
616
|
-
const token = fullRequest,
|
|
887
|
+
const token = fullRequest,
|
|
888
|
+
sourceRevision = await previewSourceRevision(options);
|
|
617
889
|
// Production compilation and incremental compilation never overlap.
|
|
618
890
|
// The same process then serves this checked graph to verification.
|
|
619
|
-
if (verifying) {
|
|
891
|
+
if (verifying) {
|
|
892
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
620
895
|
let ok = false;
|
|
621
896
|
try {
|
|
622
|
-
entries = registry();
|
|
623
|
-
|
|
897
|
+
entries = await registry();
|
|
898
|
+
registryFailure = undefined;
|
|
899
|
+
reporter.setApps(buildApps());
|
|
900
|
+
reporter.clearFailure();
|
|
624
901
|
ok = await compileGraph();
|
|
625
902
|
} catch (error) {
|
|
626
|
-
registryFailure = error;
|
|
627
|
-
|
|
903
|
+
registryFailure = error;
|
|
904
|
+
await failure(error);
|
|
905
|
+
} finally {
|
|
906
|
+
releaseScenarioRegistry(root);
|
|
907
|
+
}
|
|
628
908
|
completedFull = token;
|
|
629
|
-
const file = path.join(root, ".ds", `full-build-${reporter.session}.json`),
|
|
630
|
-
|
|
909
|
+
const file = path.join(root, ".ds", `full-build-${reporter.session}.json`),
|
|
910
|
+
temporary = `${file}.tmp`;
|
|
911
|
+
writeFileSync(temporary, JSON.stringify({ token, ok: !!ok, sourceRevision }));
|
|
912
|
+
renameSync(temporary, file);
|
|
631
913
|
continue;
|
|
632
914
|
}
|
|
633
915
|
if (registryFailure) break;
|
|
634
|
-
if(!pending.size){
|
|
916
|
+
if (!pending.size) {
|
|
635
917
|
// Let incoming foreground selections enter the queue before the next
|
|
636
918
|
// background job in the shared compiler.
|
|
637
|
-
await new Promise(resolve=>setTimeout(resolve,50));
|
|
638
|
-
if(stopped)break;
|
|
639
|
-
if(!pending.size){
|
|
640
|
-
const entry=nextWarm();
|
|
641
|
-
if(entry){
|
|
919
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
920
|
+
if (stopped) break;
|
|
921
|
+
if (!pending.size) {
|
|
922
|
+
const entry = nextWarm();
|
|
923
|
+
if (entry) {
|
|
642
924
|
// Bun can finish the remaining graph in one bounded build after
|
|
643
925
|
// the first view. Rebuilding 1, 2, ... N roots repeats bundling N
|
|
644
926
|
// times despite the persistent per-file transform cache.
|
|
645
|
-
const warm=buildGraph
|
|
646
|
-
for(const item of warm){
|
|
927
|
+
const warm = buildGraph.warmBatch && warmed.size ? entries.filter((item) => !requested.has(item.id) && !warmed.has(item.id)) : [entry];
|
|
928
|
+
for (const item of warm) {
|
|
929
|
+
requested.add(item.id);
|
|
930
|
+
pending.add(item.id);
|
|
931
|
+
}
|
|
647
932
|
}
|
|
648
933
|
}
|
|
649
934
|
}
|
|
650
935
|
const id = pending.has(active) ? active : pending.values().next().value;
|
|
651
936
|
pending.delete(id);
|
|
652
|
-
const entry = entries.find(entry => entry.id === id);
|
|
937
|
+
const entry = entries.find((entry) => entry.id === id);
|
|
653
938
|
// Instances in one process take turns: the viewed draft, then the project, then warming.
|
|
654
|
-
if (entry) {
|
|
939
|
+
if (entry) {
|
|
940
|
+
warming = id;
|
|
941
|
+
warmProgress();
|
|
942
|
+
try {
|
|
943
|
+
await schedule(async () => compile(entry), { foreground: id === active });
|
|
944
|
+
} finally {
|
|
945
|
+
warming = undefined;
|
|
946
|
+
warmProgress();
|
|
947
|
+
}
|
|
948
|
+
}
|
|
655
949
|
}
|
|
656
|
-
} catch (error) {
|
|
657
|
-
|
|
950
|
+
} catch (error) {
|
|
951
|
+
await failure(error);
|
|
952
|
+
} finally {
|
|
953
|
+
compiling = false;
|
|
954
|
+
}
|
|
658
955
|
}
|
|
659
|
-
function discoverUnknownEntries() {
|
|
956
|
+
async function discoverUnknownEntries() {
|
|
660
957
|
if (!inspector || discovering) return;
|
|
661
|
-
const revision = previewSourceRevision(options);
|
|
958
|
+
const revision = await previewSourceRevision(options);
|
|
662
959
|
if (unknownRevision === revision) return;
|
|
663
960
|
unknownRevision = revision;
|
|
664
|
-
discovering = inspector
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
961
|
+
discovering = inspector
|
|
962
|
+
.inspect()
|
|
963
|
+
.then(async (result) => {
|
|
964
|
+
if (stopped) return;
|
|
965
|
+
if ((await previewSourceRevision(options)) !== revision) {
|
|
966
|
+
unknownRevision = undefined;
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
if (result.diagnostics.length) throw new Error(result.diagnostics.map((item) => `${item.file}: ${item.message}`).join("\n"));
|
|
970
|
+
if (JSON.stringify(result.scenarios) === JSON.stringify(entries)) return;
|
|
971
|
+
++generation;
|
|
972
|
+
entries = result.scenarios;
|
|
973
|
+
registryFailure = undefined;
|
|
974
|
+
liveCandidate = undefined;
|
|
975
|
+
reporter.setApps(buildApps());
|
|
976
|
+
writeRegistryManifest(root, entries);
|
|
977
|
+
for (const id of requested) if (!entries.some((entry) => entry.id === id)) requested.delete(id);
|
|
978
|
+
await request();
|
|
979
|
+
})
|
|
980
|
+
.catch(async (error) => {
|
|
981
|
+
if (!stopped) await failure(error);
|
|
982
|
+
})
|
|
983
|
+
.finally(() => {
|
|
984
|
+
discovering = undefined;
|
|
985
|
+
});
|
|
675
986
|
}
|
|
676
|
-
function request(startBuild = true) {
|
|
987
|
+
async function request(startBuild = true) {
|
|
677
988
|
const file = requestFile;
|
|
678
989
|
if (!file || !existsSync(file)) return;
|
|
679
990
|
try {
|
|
@@ -682,125 +993,155 @@ export async function runScenarioCompiler(directory, setup) {
|
|
|
682
993
|
if (typeof value.full === "string" && /^[\w-]{1,100}$/.test(value.full)) fullRequest = value.full;
|
|
683
994
|
if (value.invalidation !== invalidation) {
|
|
684
995
|
invalidation = value.invalidation;
|
|
685
|
-
if (requested.size) sourceChanged("invalidate",options.config.dsDir,true);
|
|
686
|
-
}
|
|
687
|
-
active = entries.find(entry => entry.artifact === value.active)?.id;
|
|
688
|
-
if (value.files.some(file => !entries.some(entry => entry.artifact === file))) discoverUnknownEntries();
|
|
689
|
-
for (const file of value.files) {
|
|
690
|
-
const entry = entries.find(entry => entry.artifact === file);
|
|
691
|
-
if (entry && !requested.has(entry.id)) {
|
|
692
|
-
requested.add(entry.id);
|
|
693
|
-
const covered = liveCandidate && !liveCandidate.failed && liveCandidate.generation === generation
|
|
694
|
-
&& liveCandidate.stamp === cache.inputs() && liveCandidate.entries.some(item => item.id === entry.id);
|
|
695
|
-
if (!buildGraph || (!publishedEntries.has(entry.id) || publishedStamp !== cache.inputs()) && !covered) pending.add(entry.id);
|
|
696
|
-
}
|
|
996
|
+
if (requested.size) sourceChanged("invalidate", options.config.dsDir, true);
|
|
697
997
|
}
|
|
998
|
+
active = entries.find((entry) => entry.artifact === value.active)?.id;
|
|
999
|
+
if (value.files.some((file) => !entries.some((entry) => entry.artifact === file))) await discoverUnknownEntries();
|
|
1000
|
+
await queuePreviewRequests(value.files, cache.inputs, () => ({
|
|
1001
|
+
stopped, entries, requested, pending, liveCandidate, generation, publishedEntries, publishedStamp,
|
|
1002
|
+
}));
|
|
698
1003
|
if (startBuild) void drain();
|
|
699
|
-
} catch (error) {
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
await failure(error);
|
|
1006
|
+
}
|
|
700
1007
|
}
|
|
701
1008
|
if (!watched) {
|
|
702
1009
|
for (const entry of entries) pending.add(entry.id);
|
|
703
|
-
try {
|
|
1010
|
+
try {
|
|
1011
|
+
await drain();
|
|
1012
|
+
} finally {
|
|
1013
|
+
await buildGraph.close?.();
|
|
1014
|
+
}
|
|
704
1015
|
return;
|
|
705
1016
|
}
|
|
706
1017
|
let timer;
|
|
707
1018
|
const changed = new Set();
|
|
708
1019
|
function sourceChanged(_event, file, topology = false) {
|
|
709
|
-
if (!file || !topology && !/\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(file)) return;
|
|
1020
|
+
if (!file || (!topology && !/\.(?:[cm]?[jt]sx?|css|html|json|md|svg|png|jpe?g|webp|gif|woff2?|ttf|otf|lock|lockb)$/.test(file))) return;
|
|
710
1021
|
const absolute = path.join(root, file);
|
|
711
1022
|
if (previewFileIgnored(options, absolute)) return;
|
|
712
1023
|
changed.add(absolute);
|
|
713
1024
|
clearTimeout(timer);
|
|
714
|
-
timer = setTimeout(() => {
|
|
1025
|
+
timer = setTimeout(async () => {
|
|
715
1026
|
++generation;
|
|
716
1027
|
reporter.progress("queued");
|
|
717
1028
|
validation = undefined;
|
|
718
|
-
warmed.clear();
|
|
719
|
-
|
|
1029
|
+
warmed.clear();
|
|
1030
|
+
warmFailures.clear();
|
|
1031
|
+
warmProgress();
|
|
1032
|
+
const changes = [...changed];
|
|
1033
|
+
changed.clear();
|
|
720
1034
|
try {
|
|
721
1035
|
// Registry inspection for live graphs runs in the verification worker.
|
|
722
1036
|
// Existing entry identities can compile immediately while it checks.
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
observedSourceRevision = previewSourceRevision(options);
|
|
1037
|
+
options = withPreviewSession(loadConfig(root), buildSession);
|
|
1038
|
+
observedSourceRevision = await previewSourceRevision(options);
|
|
726
1039
|
registryFailure = undefined;
|
|
727
1040
|
reporter.setApps(buildApps());
|
|
728
1041
|
reporter.clearFailure();
|
|
729
|
-
request(false);
|
|
730
|
-
for (const id of requested)
|
|
1042
|
+
await request(false);
|
|
1043
|
+
for (const id of requested)
|
|
1044
|
+
if (!entries.some((entry) => entry.id === id)) {
|
|
1045
|
+
requested.delete(id);
|
|
1046
|
+
pending.delete(id);
|
|
1047
|
+
}
|
|
731
1048
|
// Every source change needs validation; unaffected artifacts need no
|
|
732
1049
|
// compilation. Check active first, then rebuild only changed dependencies.
|
|
733
1050
|
for (const id of requested) {
|
|
734
|
-
const entry = entries.find(entry => entry.id === id);
|
|
735
|
-
if (entry) {
|
|
1051
|
+
const entry = entries.find((entry) => entry.id === id);
|
|
1052
|
+
if (entry) {
|
|
1053
|
+
await reporter.begin(id, { sourceRevision: observedSourceRevision });
|
|
1054
|
+
pending.add(id);
|
|
1055
|
+
}
|
|
736
1056
|
}
|
|
737
1057
|
if (changes.length) void drain();
|
|
738
1058
|
} catch (error) {
|
|
739
|
-
registryFailure = error;
|
|
1059
|
+
registryFailure = error;
|
|
1060
|
+
await failure(error);
|
|
740
1061
|
}
|
|
741
1062
|
}, 16);
|
|
742
1063
|
}
|
|
743
1064
|
// Do not allocate recursive OS watches for node_modules or generated trees.
|
|
744
1065
|
const watchers = new Map();
|
|
745
|
-
function addWatch(directory, callback, recursive = false) {
|
|
1066
|
+
async function addWatch(directory, callback, recursive = false) {
|
|
746
1067
|
if (stopped) return false;
|
|
747
1068
|
try {
|
|
748
|
-
const stat = statSync(directory),
|
|
1069
|
+
const stat = statSync(directory),
|
|
1070
|
+
identity = `${stat.dev}:${stat.ino}`;
|
|
749
1071
|
if (watchers.get(directory)?.identity === identity) return false;
|
|
750
1072
|
watchers.get(directory)?.watcher.close();
|
|
751
|
-
const watcher = watch(directory, { recursive }, (event, file) => callback(event, file, event === "rename"));
|
|
1073
|
+
const watcher = watch(directory, { recursive }, async (event, file) => callback(event, file, event === "rename"));
|
|
752
1074
|
watchers.set(directory, { watcher, identity });
|
|
753
|
-
watcher.on("error", error => {
|
|
1075
|
+
watcher.on("error", async (error) => {
|
|
754
1076
|
watcher.close();
|
|
755
1077
|
if (watchers.get(directory)?.watcher === watcher) watchers.delete(directory);
|
|
756
|
-
failure(error);
|
|
1078
|
+
await failure(error);
|
|
757
1079
|
});
|
|
758
1080
|
return true;
|
|
759
|
-
} catch (error) {
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
await failure(error);
|
|
1083
|
+
}
|
|
760
1084
|
}
|
|
761
|
-
function reconcileWatches(initial = false) {
|
|
1085
|
+
async function reconcileWatches(initial = false) {
|
|
762
1086
|
if (stopped) return;
|
|
763
1087
|
try {
|
|
764
|
-
addWatch(root, sourceChanged);
|
|
1088
|
+
await addWatch(root, sourceChanged);
|
|
765
1089
|
const wanted = new Set([root, path.join(root, ".ds")]);
|
|
766
1090
|
for (const directory of previewWatchDirectories(options)) {
|
|
767
1091
|
if (directory === root) continue;
|
|
768
1092
|
wanted.add(directory);
|
|
769
1093
|
const relative = path.relative(root, directory);
|
|
770
|
-
if (addWatch(directory, (event, file, topology) => sourceChanged(event, file && path.join(relative, file), topology)) && !initial)
|
|
1094
|
+
if ((await addWatch(directory, (event, file, topology) => sourceChanged(event, file && path.join(relative, file), topology))) && !initial)
|
|
1095
|
+
sourceChanged("rename", relative, true);
|
|
771
1096
|
}
|
|
772
1097
|
mkdirSync(path.join(root, ".ds"), { recursive: true });
|
|
773
|
-
addWatch(path.join(root, ".ds"), (_event, file) => {
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
1098
|
+
await addWatch(path.join(root, ".ds"), async (_event, file) => {
|
|
1099
|
+
if (file === path.basename(requestFile ?? "")) await request();
|
|
1100
|
+
});
|
|
1101
|
+
for (const [directory, { watcher }] of watchers)
|
|
1102
|
+
if (!wanted.has(directory) || !existsSync(directory)) {
|
|
1103
|
+
watcher.close();
|
|
1104
|
+
watchers.delete(directory);
|
|
1105
|
+
if (!initial && directory !== root && directory !== path.join(root, ".ds")) sourceChanged("rename", path.relative(root, directory), true);
|
|
1106
|
+
}
|
|
1107
|
+
} catch (error) {
|
|
1108
|
+
await failure(error);
|
|
1109
|
+
}
|
|
779
1110
|
}
|
|
780
|
-
reconcileWatches(true);
|
|
781
|
-
const reconcileTimer = setInterval(() => {
|
|
1111
|
+
await reconcileWatches(true);
|
|
1112
|
+
const reconcileTimer = setInterval(async () => {
|
|
782
1113
|
// A retired draft workspace disappears before its host stops this instance.
|
|
783
|
-
if (!existsSync(root)) {
|
|
784
|
-
|
|
1114
|
+
if (!existsSync(root)) {
|
|
1115
|
+
await handle.stop();
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
await reconcileWatches();
|
|
785
1119
|
try {
|
|
786
|
-
const current = previewSourceRevision(options);
|
|
1120
|
+
const current = await previewSourceRevision(options);
|
|
787
1121
|
if (current !== observedSourceRevision) {
|
|
788
1122
|
observedSourceRevision = current;
|
|
789
|
-
sourceChanged("reconcile",options.config.dsDir,true);
|
|
1123
|
+
sourceChanged("reconcile", options.config.dsDir, true);
|
|
790
1124
|
}
|
|
791
|
-
request();
|
|
792
|
-
} catch (error) {
|
|
1125
|
+
await request();
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
await failure(error);
|
|
1128
|
+
}
|
|
793
1129
|
}, 1000);
|
|
794
|
-
request();
|
|
795
|
-
if(prewarm)void drain();
|
|
796
|
-
console.log(`Scenario compiler ready: ${entries.length} entries; ${prewarm?"sequential background warming enabled":"builds are requested on demand"}.`);
|
|
797
|
-
const drafts = hosting ? hostDrafts(control, typeof setup === "function" ? setup : null, scheduler) : null;
|
|
798
|
-
handle = {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1130
|
+
await request();
|
|
1131
|
+
if (prewarm) void drain();
|
|
1132
|
+
console.log(`Scenario compiler ready: ${entries.length} entries; ${prewarm ? "sequential background warming enabled" : "builds are requested on demand"}.`);
|
|
1133
|
+
const drafts = hosting ? await hostDrafts(control, typeof setup === "function" ? setup : null, scheduler) : null;
|
|
1134
|
+
handle = {
|
|
1135
|
+
async stop() {
|
|
1136
|
+
if (stopped) return;
|
|
1137
|
+
stopped = true;
|
|
1138
|
+
clearTimeout(timer);
|
|
1139
|
+
clearInterval(reconcileTimer);
|
|
1140
|
+
for (const { watcher } of watchers.values()) watcher.close();
|
|
1141
|
+
void (await drafts?.stop());
|
|
1142
|
+
void (await inspector?.close());
|
|
1143
|
+
void (await buildGraph.close?.());
|
|
1144
|
+
},
|
|
1145
|
+
};
|
|
805
1146
|
return handle;
|
|
806
1147
|
}
|