@reqvire-org/ads 0.3.53 → 0.4.2
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 +114 -94
- package/dist/a11y.mjs +108 -29
- 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 +140 -0
- package/dist/analysis/impact.mjs +20 -0
- package/dist/analysis/inputs.mjs +15 -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 +146 -0
- package/dist/analysis/standalone.mjs +57 -0
- package/dist/analysis/syntax.mjs +164 -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 +222 -79
- package/dist/boundaries.mjs +137 -40
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +34 -13
- 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 +66 -0
- package/dist/check.mjs +756 -196
- package/dist/cli.mjs +203 -100
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +2 -2
- package/dist/config.mjs +308 -163
- package/dist/construction-styles.cjs +10 -0
- package/dist/contracts.d.mts +9 -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 +7 -5
- package/dist/font-rules.mjs +2 -2
- package/dist/fonts-generated.mjs +4 -2
- package/dist/foundation-views.mjs +238 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +198 -0
- package/dist/icons.mjs +80 -33
- package/dist/image-attributes.mjs +109 -36
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +128 -68
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +300 -127
- 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 +91 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +978 -343
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +701 -219
- package/dist/mcp/preview-watch.mjs +465 -161
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +6 -6
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2436 -570
- package/dist/mcp/showcase-host.mjs +176 -39
- 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/preview-bun.mjs +493 -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 +10 -0
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +70 -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 +2 -2
- 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/{browser-audit → render-audit}/render-states.mjs +208 -52
- package/dist/{browser-audit → render-audit}/worker.mjs +86 -30
- package/dist/render-audit.mjs +828 -0
- package/dist/render-color-probe.mjs +96 -42
- 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 +768 -359
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +424 -159
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +18 -0
- package/dist/showcase/favicon.ico +0 -0
- package/dist/showcase/favicon.svg +1 -0
- package/dist/showcase/foundation-view.css +55 -0
- package/dist/showcase/foundation-view.mjs +252 -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/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 +1062 -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 +152 -144
- package/dist/skills/ads-designer/references/accessibility.md +14 -11
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +34 -30
- package/dist/skills/ads-designer/references/branding.md +98 -10
- package/dist/skills/ads-designer/references/captures.md +31 -31
- package/dist/skills/ads-designer/references/cli.md +21 -20
- package/dist/skills/ads-designer/references/contracts.md +63 -29
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +71 -52
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +58 -51
- 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/review.md +42 -38
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +17 -19
- 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 -71
- package/dist/skills/ads-designer/references/workflows.md +19 -37
- package/dist/skills/ads-import/SKILL.md +43 -328
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +34 -30
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +31 -31
- package/dist/skills/ads-import/references/cli.md +21 -20
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +63 -29
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +71 -52
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +58 -51
- 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 +42 -38
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +17 -19
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -71
- package/dist/skills/ads-import/references/workflows.md +19 -37
- 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 +54 -346
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +34 -30
- package/dist/skills/ads-port/references/captures.md +31 -31
- package/dist/skills/ads-port/references/cli.md +21 -20
- package/dist/skills/ads-port/references/contracts.md +63 -29
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +71 -52
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +58 -51
- 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 +8 -7
- package/dist/skills/ads-port/references/review.md +42 -38
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +17 -19
- package/dist/skills/ads-port/references/validation.md +83 -71
- package/dist/skills/ads-port/references/workflows.md +19 -37
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +266 -128
- 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 +24 -19
- 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 +54 -52
- package/dist/starters/react/design-system/components/Actions/Button/Button.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Actions/IconButton/IconButton.ads.exports.ts +1 -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/Icon/Icon.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Image/Image.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Content/Logo/Logo.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/components/Forms/TextField/TextField.ads.exports.ts +1 -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/controllers/Palette/Palette.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/index.ts +5 -8
- 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/Search/SearchBar/SearchBar.ads.exports.ts +1 -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 -0
- 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 -0
- 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/styles.css +1 -0
- 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 +24 -19
- 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 +73 -27
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +133 -60
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +60 -19
- 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 +270 -89
- package/dist/units.mjs +215 -180
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +121 -38
- package/dist/validation-inputs.mjs +187 -78
- package/dist/validation.mjs +268 -102
- package/dist/verification/browser.mjs +27 -5
- package/dist/verification.mjs +711 -187
- package/docs/ADS.md +100 -89
- package/docs/ARCHITECTURE.md +353 -159
- package/docs/BEHAVIORS.md +33 -28
- package/docs/CACHING.md +55 -11
- package/docs/CHANGELOG.md +358 -17
- package/docs/COMPARISON.md +1 -1
- package/docs/CONTRACTS.md +22 -29
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +313 -292
- package/docs/MCP.md +261 -439
- package/docs/SPATIAL-CHECKS.md +69 -0
- package/docs/benchmarks/README.md +39 -0
- package/package.json +42 -34
- package/dist/browser-audit.mjs +0 -424
- package/dist/contract-migration.mjs +0 -110
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -48
- package/dist/mcp/draft-exports.mjs +0 -40
- package/dist/mcp/edit-preparation.mjs +0 -115
- 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 -88
- 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 -415
- 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 -411
- package/dist/skills/ads-break-ui/references/captures.md +0 -160
- package/dist/skills/ads-break-ui/references/contracts.md +0 -284
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -178
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -154
- 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 -96
- 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 -162
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -83
- 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 -388
- 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 -411
- package/dist/skills/ads-motion/references/captures.md +0 -160
- package/dist/skills/ads-motion/references/contracts.md +0 -284
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -178
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -154
- 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 -96
- 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 -162
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -83
- package/dist/skills/ads-port/references/reporting.md +0 -101
- 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.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.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.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.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -5
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- 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,226 +73,478 @@ 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|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 };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** One compile at a time in a process: the viewed draft first, then the project's view, then
|
|
379
|
+
* the project's other requests, then drafts' background work. */
|
|
380
|
+
function createScheduler() {
|
|
381
|
+
const queue = [];
|
|
382
|
+
let running = false,
|
|
383
|
+
order = 0;
|
|
384
|
+
function pump() {
|
|
385
|
+
if (running || !queue.length) return;
|
|
386
|
+
queue.sort((a, b) => a.priority - b.priority || a.order - b.order);
|
|
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
|
+
});
|
|
396
|
+
}
|
|
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
|
+
});
|
|
222
403
|
}
|
|
223
404
|
|
|
224
|
-
/**
|
|
225
|
-
|
|
405
|
+
/**
|
|
406
|
+
* The draft workspaces the MCP server lists in its control file compile in this process, each
|
|
407
|
+
* with the options setup(root) gives for its own root and a builder of its own. Compiler options
|
|
408
|
+
* fixed to one root cannot build a draft; each draft then reports that instead of waiting.
|
|
409
|
+
*/
|
|
410
|
+
async function hostDrafts(file, setup, schedule) {
|
|
411
|
+
const instances = new Map();
|
|
412
|
+
async function reconcile() {
|
|
413
|
+
let wanted = [];
|
|
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
|
+
}
|
|
425
|
+
for (const entry of wanted) {
|
|
426
|
+
if (instances.has(entry.session) || !isDraftPreviewWorkspace(entry.root)) continue;
|
|
427
|
+
const context = { session: entry.session, requestFile: entry.requestFile, statusFile: entry.statusFile, prewarm: false, schedule: schedule("draft") };
|
|
428
|
+
if (!setup) {
|
|
429
|
+
instances.set(entry.session, Promise.resolve(null));
|
|
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
|
+
);
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
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
|
+
);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
void (await reconcile());
|
|
451
|
+
let timer;
|
|
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
|
+
};
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* One project's compiler; the project supplies its own React/Preact build. `setup` is the
|
|
470
|
+
* options, or a function of the project root that returns them. A process may host several
|
|
471
|
+
* watched instances, the project and its draft workspaces, each with its own session, request
|
|
472
|
+
* and status file: the project instance hosts the drafts the MCP server lists, building each
|
|
473
|
+
* from setup(draftRoot), so it needs the function form.
|
|
474
|
+
*/
|
|
475
|
+
export async function runScenarioCompiler(directory, setup) {
|
|
226
476
|
const root = path.resolve(directory);
|
|
227
|
-
|
|
228
|
-
if (buildGraph
|
|
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));
|
|
481
|
+
const scheduler = hosting ? createScheduler() : null;
|
|
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;
|
|
489
|
+
let options = withPreviewSession(loadConfig(root), buildSession);
|
|
490
|
+
if (!options.config.framework) throw new Error("Preview builds require an explicit framework in ds.config.json.");
|
|
229
491
|
const cache = createPreviewCache(options, compilerFiles);
|
|
230
|
-
function registry() {
|
|
231
|
-
options = withPreviewSession(loadConfig(root),
|
|
232
|
-
const result =
|
|
233
|
-
if (result.diagnostics.length)
|
|
234
|
-
|
|
235
|
-
|
|
492
|
+
async function registry() {
|
|
493
|
+
options = withPreviewSession(loadConfig(root), buildSession);
|
|
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);
|
|
236
498
|
return result.scenarios;
|
|
237
499
|
}
|
|
238
|
-
let entries = [],
|
|
239
|
-
|
|
240
|
-
|
|
500
|
+
let entries = [],
|
|
501
|
+
registryFailure;
|
|
502
|
+
try {
|
|
503
|
+
entries = await registry();
|
|
504
|
+
} catch (error) {
|
|
241
505
|
if (!watched) throw error;
|
|
242
|
-
registryFailure = error;
|
|
506
|
+
registryFailure = error;
|
|
507
|
+
entries = error.scenarios ?? [];
|
|
508
|
+
} finally {
|
|
509
|
+
if (watched) releaseScenarioRegistry(root);
|
|
243
510
|
}
|
|
244
|
-
|
|
245
|
-
const
|
|
246
|
-
|
|
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
|
+
});
|
|
247
517
|
const requested = new Set();
|
|
248
518
|
const pending = new Set();
|
|
249
519
|
let active;
|
|
250
|
-
const prewarm = watched &&
|
|
251
|
-
const warmed = new Set(),
|
|
520
|
+
const prewarm = watched && prewarmViews;
|
|
521
|
+
const warmed = new Set(),
|
|
522
|
+
warmFailures = new Set();
|
|
252
523
|
let preferred, warming;
|
|
253
|
-
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
|
+
}
|
|
254
530
|
function warmProgress() {
|
|
255
|
-
if(!prewarm)return;
|
|
256
|
-
const completed=entries.filter(entry=>warmed.has(entry.id)).length,
|
|
257
|
-
|
|
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
|
+
});
|
|
258
541
|
}
|
|
259
542
|
function nextWarm() {
|
|
260
|
-
if(!prewarm||registryFailure)return;
|
|
261
|
-
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
|
+
);
|
|
262
548
|
}
|
|
263
549
|
warmProgress();
|
|
264
550
|
let compiling = false;
|
|
@@ -267,134 +553,139 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
267
553
|
let publishedStamp;
|
|
268
554
|
let publishedEntries = new Set();
|
|
269
555
|
let validation;
|
|
270
|
-
let observedSourceRevision = previewSourceRevision(options);
|
|
556
|
+
let observedSourceRevision = await previewSourceRevision(options);
|
|
271
557
|
let invalidation;
|
|
272
558
|
let fullRequest, completedFull;
|
|
273
|
-
|
|
559
|
+
// Keep the registry inspector warm while previews are in use: a cold TypeScript program costs ~1.7 s per edit.
|
|
560
|
+
const inspector = watched ? createScenarioInspector(root, { idleMs: 10 * 60 * 1000 }) : null;
|
|
274
561
|
let discovering, unknownRevision;
|
|
275
|
-
let liveCandidate,
|
|
276
|
-
|
|
277
|
-
|
|
562
|
+
let liveCandidate,
|
|
563
|
+
verifying = false;
|
|
564
|
+
let handle;
|
|
565
|
+
async function failure(error) {
|
|
566
|
+
// A retired draft workspace is deleted while its instance stops: nothing left to report.
|
|
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
|
+
}
|
|
278
576
|
console.error(error);
|
|
279
577
|
if (!watched) process.exitCode = 1;
|
|
280
578
|
}
|
|
281
|
-
if (registryFailure) failure(registryFailure);
|
|
579
|
+
if (registryFailure) await failure(registryFailure);
|
|
282
580
|
function gate(stamp) {
|
|
283
581
|
if (isDraftPreviewWorkspace(root)) return Promise.resolve();
|
|
284
582
|
if (cache.validated(stamp)) return Promise.resolve();
|
|
285
|
-
return validation ??= Promise.resolve()
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
+
}));
|
|
289
592
|
}
|
|
290
593
|
async function checkedBuild(stamp, build) {
|
|
291
594
|
const started = generation;
|
|
292
|
-
let checking = true,
|
|
293
|
-
|
|
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
|
+
}
|
|
294
601
|
progress();
|
|
295
602
|
return Promise.allSettled([
|
|
296
|
-
gate(stamp).finally(() => {
|
|
297
|
-
|
|
603
|
+
gate(stamp).finally(() => {
|
|
604
|
+
checking = false;
|
|
605
|
+
progress();
|
|
606
|
+
}),
|
|
607
|
+
Promise.resolve()
|
|
608
|
+
.then(build)
|
|
609
|
+
.finally(() => {
|
|
610
|
+
compiling = false;
|
|
611
|
+
progress();
|
|
612
|
+
}),
|
|
298
613
|
]);
|
|
299
614
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const started = generation;
|
|
304
|
-
try {
|
|
305
|
-
const stamp = cache.inputs();
|
|
306
|
-
cache.assertCompiler();
|
|
307
|
-
const reuse = cache.reusable(entry);
|
|
308
|
-
const dependencies = new Set();
|
|
309
|
-
function assets(directory) {
|
|
310
|
-
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
311
|
-
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
312
|
-
const file = path.join(directory, item.name);
|
|
313
|
-
if (item.isDirectory()) { if (!hasProjectConfig(file)) assets(file); }
|
|
314
|
-
else if (/\.(?:css|svg|png|jpe?g|webp|gif|woff2?|ttf|otf)$/.test(file)) dependencies.add(file);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
// CSS url() inputs may be inlined without becoming Rollup JS modules.
|
|
318
|
-
// Shared foundation/styles/assets conservatively invalidate all previews.
|
|
319
|
-
assets(options.dsRoot);
|
|
320
|
-
const track = { name: "ads-preview-dependencies", generateBundle() {
|
|
321
|
-
// Include modules used during extraction, even when their final JS was
|
|
322
|
-
// tree-shaken. A stylesheet evaluation can depend on those exports.
|
|
323
|
-
for (const id of this.getModuleIds()) {
|
|
324
|
-
const file = id.split("?")[0];
|
|
325
|
-
if (path.isAbsolute(file) && existsSync(file)) dependencies.add(file);
|
|
326
|
-
}
|
|
327
|
-
} };
|
|
328
|
-
const outcomes = await checkedBuild(stamp, () => reuse ? undefined : build(entry, options, track));
|
|
329
|
-
const failure = outcomes.find(outcome => outcome.status === "rejected");
|
|
330
|
-
if (failure) throw failure.reason;
|
|
331
|
-
cache.assertCompiler();
|
|
332
|
-
if (stopped || started !== generation || stamp !== cache.inputs()) return; // Watch queued a newer revision.
|
|
333
|
-
if (!reuse && !cache.record(entry, dependencies, stamp)) return;
|
|
334
|
-
reporter.ready(entry.id, revision);
|
|
335
|
-
reporter.progress("idle");
|
|
336
|
-
} catch (error) {
|
|
337
|
-
if (started !== generation) return;
|
|
338
|
-
reporter.error(entry.id, revision, scopedPreviewFailure(error,"scenario","build"));
|
|
339
|
-
reporter.progress("idle");
|
|
340
|
-
console.error(error);
|
|
341
|
-
if (!watched) process.exitCode = 1;
|
|
342
|
-
}
|
|
615
|
+
// Every preview is part of one shared resource graph.
|
|
616
|
+
async function compile() {
|
|
617
|
+
return watched ? await compileLiveGraph() : await compileGraph();
|
|
343
618
|
}
|
|
344
619
|
async function compileGraph() {
|
|
345
620
|
cache.reload();
|
|
346
|
-
const sourceRevision = previewSourceRevision(options);
|
|
347
|
-
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 })]));
|
|
348
623
|
const started = generation;
|
|
349
624
|
try {
|
|
350
|
-
const stamp = cache.inputs();
|
|
625
|
+
const stamp = await cache.inputs();
|
|
351
626
|
const dependencies = new Set();
|
|
352
627
|
function assets(directory) {
|
|
353
628
|
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
354
629
|
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
355
630
|
const file = path.join(directory, item.name);
|
|
356
|
-
if (item.isDirectory()) {
|
|
357
|
-
|
|
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);
|
|
358
634
|
}
|
|
359
635
|
}
|
|
360
636
|
assets(options.dsRoot);
|
|
361
|
-
const track = {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
+
};
|
|
367
646
|
cache.assertCompiler();
|
|
368
647
|
const cached = cachedPreviewPublication(options, entries, cache.graphRevision());
|
|
369
|
-
let reusable = cache.production(stamp) && cached && cache.reusableEntries(entries,cached.revision);
|
|
648
|
+
let reusable = cache.production(stamp) && cached && (await cache.reusableEntries(entries, cached.revision));
|
|
370
649
|
if (reusable) {
|
|
371
|
-
try {
|
|
372
|
-
|
|
650
|
+
try {
|
|
651
|
+
readPreviewManifest(options, { verify: true });
|
|
652
|
+
} catch {
|
|
653
|
+
reusable = false;
|
|
654
|
+
}
|
|
373
655
|
}
|
|
374
|
-
const outcomes = await checkedBuild(stamp, () => reusable ? null : buildGraph(entries, options, track, { watched: false, sourceRevision }));
|
|
375
|
-
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");
|
|
376
658
|
if (failure) throw failure.reason;
|
|
377
659
|
cache.assertCompiler();
|
|
378
|
-
if (stopped || started !== generation || stamp !== cache.inputs()) return;
|
|
660
|
+
if (stopped || started !== generation || stamp !== (await cache.inputs())) return;
|
|
379
661
|
const publication = outcomes[1].value;
|
|
380
662
|
if (publication) {
|
|
381
663
|
publication.publish(reporter.session);
|
|
382
|
-
if (!cache.recordAll(entries, dependencies, publication.revision, stamp)) return;
|
|
664
|
+
if (!(await cache.recordAll(entries, dependencies, publication.revision, stamp))) return;
|
|
383
665
|
} else {
|
|
384
666
|
cached.publish(reporter.session);
|
|
385
|
-
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));
|
|
386
672
|
}
|
|
387
|
-
for (const entry of entries) { pending.delete(entry.id); reporter.ready(entry.id, revisions.get(entry.id)); }
|
|
388
673
|
publishedStamp = stamp;
|
|
389
|
-
publishedEntries = new Set(entries.map(entry => entry.id));
|
|
390
|
-
cache.recordProduction(stamp);
|
|
391
|
-
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
|
+
}
|
|
392
680
|
warmProgress();
|
|
393
681
|
reporter.progress("idle");
|
|
394
682
|
return true;
|
|
395
683
|
} catch (error) {
|
|
396
684
|
if (started !== generation) return;
|
|
397
|
-
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
|
+
}
|
|
398
689
|
reporter.progress("idle");
|
|
399
690
|
console.error(error);
|
|
400
691
|
if (!watched) process.exitCode = 1;
|
|
@@ -402,10 +693,14 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
402
693
|
}
|
|
403
694
|
}
|
|
404
695
|
async function publicationSettled() {
|
|
405
|
-
const file=publicationHold(root);
|
|
406
|
-
while(!stopped){
|
|
407
|
-
try{
|
|
408
|
-
|
|
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));
|
|
409
704
|
}
|
|
410
705
|
}
|
|
411
706
|
// Visual feedback and verified publication have separate lifecycles. Edits
|
|
@@ -415,8 +710,9 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
415
710
|
await publicationSettled();
|
|
416
711
|
if (stopped) return;
|
|
417
712
|
cache.reload();
|
|
418
|
-
const sourceRevision = previewSourceRevision(options),
|
|
419
|
-
|
|
713
|
+
const sourceRevision = await previewSourceRevision(options),
|
|
714
|
+
stamp = await cache.inputs();
|
|
715
|
+
const prepared = await cache.registry(stamp);
|
|
420
716
|
// A guarded edit can publish a checked graph while this watcher's discovery
|
|
421
717
|
// still describes the previous revision. Adopt its current metadata before
|
|
422
718
|
// comparing registries. A partial watched graph cannot replace the catalogue.
|
|
@@ -428,59 +724,79 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
428
724
|
// Publication/cache identities follow discovery order, never navigation
|
|
429
725
|
// order. Otherwise warming a non-first view produces a full graph that
|
|
430
726
|
// cannot match the next process's canonical registry and rebuilds forever.
|
|
431
|
-
const selected = registryReused ? prepared : entries.filter(entry=>requested.has(entry.id));
|
|
727
|
+
const selected = registryReused ? prepared : entries.filter((entry) => requested.has(entry.id));
|
|
432
728
|
const candidate = { generation, stamp, sourceRevision, registry: [...entries], entries: selected, dependencies: new Set(), registryReused };
|
|
433
729
|
// Retain roots requested by other mounted Apps, without compiling untouched
|
|
434
730
|
// catalogue entries. Production/unwatched builds still cover all entries.
|
|
435
731
|
for (const entry of candidate.entries) pending.delete(entry.id);
|
|
436
|
-
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
|
+
);
|
|
437
735
|
reporter.progress("validation-and-compilation");
|
|
438
|
-
const track = {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
+
};
|
|
444
745
|
// Include non-module assets conservatively in the verified warm cache.
|
|
445
746
|
function assets(directory) {
|
|
446
747
|
for (const item of readdirSync(directory, { withFileTypes: true })) {
|
|
447
748
|
if (item.isSymbolicLink() || ["node_modules", ".ds", ".vite", "dist"].includes(item.name)) continue;
|
|
448
749
|
const file = path.join(directory, item.name);
|
|
449
|
-
if (item.isDirectory()) {
|
|
450
|
-
|
|
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);
|
|
451
753
|
}
|
|
452
754
|
}
|
|
453
755
|
assets(options.dsRoot);
|
|
454
|
-
candidate.build = Promise.resolve().then(() => {
|
|
756
|
+
candidate.build = Promise.resolve().then(async () => {
|
|
455
757
|
cache.assertCompiler();
|
|
456
758
|
const cached = cachedPreviewPublication(options, candidate.entries, cache.graphRevision());
|
|
457
|
-
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
|
+
}
|
|
458
763
|
return buildGraph(candidate.entries, options, track, { watched: true, sourceRevision });
|
|
459
764
|
});
|
|
460
765
|
liveCandidate = candidate;
|
|
461
766
|
try {
|
|
462
767
|
const publication = await candidate.build;
|
|
463
|
-
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || stamp !== cache.inputs()) return;
|
|
768
|
+
if (stopped || candidate !== liveCandidate || candidate.generation !== generation || stamp !== (await cache.inputs())) return;
|
|
464
769
|
if (publication.publishLive) {
|
|
465
770
|
publication.publishLive(reporter.session);
|
|
466
771
|
reporter.live({ revision: publication.revision, sourceRevision });
|
|
467
|
-
for(const entry of candidate.entries){
|
|
772
|
+
for (const entry of candidate.entries) {
|
|
773
|
+
warmed.add(entry.id);
|
|
774
|
+
warmFailures.delete(entry.id);
|
|
775
|
+
}
|
|
468
776
|
warmProgress();
|
|
469
777
|
}
|
|
470
778
|
reporter.progress("validation");
|
|
471
779
|
} catch (error) {
|
|
472
780
|
// Syntax/build failures should surface immediately even when an unrelated
|
|
473
781
|
// validation command is still running. This candidate can never publish.
|
|
474
|
-
if (!stopped && candidate === liveCandidate && candidate.generation === generation && stamp === cache.inputs())
|
|
475
|
-
|
|
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
|
+
}
|
|
476
789
|
}
|
|
477
|
-
function rejectLive(candidate, error) {
|
|
790
|
+
async function rejectLive(candidate, error) {
|
|
478
791
|
candidate.failed = true;
|
|
479
|
-
for(const entry of candidate.entries){
|
|
792
|
+
for (const entry of candidate.entries) {
|
|
793
|
+
warmed.delete(entry.id);
|
|
794
|
+
warmFailures.add(entry.id);
|
|
795
|
+
}
|
|
480
796
|
warmProgress();
|
|
481
|
-
reporter.batch(() => {
|
|
797
|
+
await reporter.batch(() => {
|
|
482
798
|
reporter.live(undefined);
|
|
483
|
-
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"));
|
|
484
800
|
reporter.progress("idle");
|
|
485
801
|
});
|
|
486
802
|
console.error(error);
|
|
@@ -493,246 +809,339 @@ export async function runScenarioCompiler(directory, { watched = false, validate
|
|
|
493
809
|
const candidate = liveCandidate;
|
|
494
810
|
const [compiled] = await Promise.allSettled([candidate.build]);
|
|
495
811
|
if (stopped) return;
|
|
496
|
-
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== cache.inputs()) {
|
|
812
|
+
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== (await cache.inputs())) {
|
|
497
813
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
498
814
|
continue;
|
|
499
815
|
}
|
|
500
816
|
// Give compiled feedback priority before starting CPU-heavy validation.
|
|
501
817
|
// An already running check continues; later edits replace its candidate.
|
|
502
|
-
const inspection=
|
|
503
|
-
|
|
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]))];
|
|
504
821
|
if (stopped) return;
|
|
505
|
-
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== cache.inputs()) {
|
|
822
|
+
if (candidate !== liveCandidate || candidate.generation !== generation || candidate.stamp !== (await cache.inputs())) {
|
|
506
823
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
507
824
|
continue;
|
|
508
825
|
}
|
|
509
826
|
try {
|
|
510
827
|
if (outcomes[2].status === "rejected") throw outcomes[2].reason;
|
|
511
828
|
const registry = outcomes[2].value;
|
|
512
|
-
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
|
+
});
|
|
513
833
|
if (JSON.stringify(registry.scenarios) !== JSON.stringify(candidate.registry)) {
|
|
514
834
|
entries = registry.scenarios;
|
|
515
|
-
|
|
516
|
-
reporter.batch(() => {
|
|
835
|
+
writeRegistryManifest(root, entries);
|
|
836
|
+
await reporter.batch(() => {
|
|
837
|
+
reporter.setApps(buildApps());
|
|
838
|
+
reporter.live(undefined);
|
|
839
|
+
reporter.progress("idle");
|
|
840
|
+
});
|
|
517
841
|
liveCandidate = undefined;
|
|
518
|
-
for (const id of requested) if (!entries.some(entry => entry.id === id)) requested.delete(id);
|
|
519
|
-
request(false);
|
|
842
|
+
for (const id of requested) if (!entries.some((entry) => entry.id === id)) requested.delete(id);
|
|
843
|
+
await request(false);
|
|
520
844
|
for (const id of requested) pending.add(id);
|
|
521
845
|
void drain();
|
|
522
846
|
continue;
|
|
523
847
|
}
|
|
524
|
-
if (candidate.failed) {
|
|
525
|
-
|
|
848
|
+
if (candidate.failed) {
|
|
849
|
+
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
850
|
+
continue;
|
|
851
|
+
}
|
|
852
|
+
const failed = outcomes.find((outcome) => outcome.status === "rejected");
|
|
526
853
|
if (failed) throw failed.reason;
|
|
527
854
|
cache.assertCompiler();
|
|
528
855
|
const publication = outcomes[0].value;
|
|
529
|
-
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;
|
|
530
857
|
publication.publish(reporter.session);
|
|
531
858
|
const recorded = !candidate.reused
|
|
532
|
-
? cache.recordAll(candidate.entries, candidate.dependencies, publication.revision, candidate.stamp)
|
|
533
|
-
: cache.recordGraph(publication.revision,candidate.entries,candidate.stamp);
|
|
534
|
-
if (!recorded) {
|
|
535
|
-
|
|
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(() => {
|
|
536
866
|
for (const entry of candidate.entries) reporter.ready(entry.id, candidate.revisions.get(entry.id));
|
|
537
867
|
reporter.live(undefined);
|
|
538
868
|
reporter.progress("idle");
|
|
539
869
|
});
|
|
540
870
|
publishedStamp = candidate.stamp;
|
|
541
|
-
publishedEntries = new Set(candidate.entries.map(entry => entry.id));
|
|
871
|
+
publishedEntries = new Set(candidate.entries.map((entry) => entry.id));
|
|
542
872
|
} catch (error) {
|
|
543
|
-
if (!candidate.failed) rejectLive(candidate, error);
|
|
873
|
+
if (!candidate.failed) await rejectLive(candidate, error);
|
|
544
874
|
}
|
|
545
875
|
if (candidate === liveCandidate) liveCandidate = undefined;
|
|
546
876
|
}
|
|
547
|
-
} finally {
|
|
877
|
+
} finally {
|
|
878
|
+
verifying = false;
|
|
879
|
+
}
|
|
548
880
|
}
|
|
549
881
|
async function drain() {
|
|
550
882
|
if (compiling) return;
|
|
551
883
|
compiling = true;
|
|
552
884
|
try {
|
|
553
|
-
while ((pending.size || fullRequest && fullRequest !== completedFull || nextWarm()) && !stopped) {
|
|
885
|
+
while ((pending.size || (fullRequest && fullRequest !== completedFull) || nextWarm()) && !stopped) {
|
|
554
886
|
if (fullRequest && fullRequest !== completedFull) {
|
|
555
|
-
const token = fullRequest,
|
|
887
|
+
const token = fullRequest,
|
|
888
|
+
sourceRevision = await previewSourceRevision(options);
|
|
556
889
|
// Production compilation and incremental compilation never overlap.
|
|
557
890
|
// The same process then serves this checked graph to verification.
|
|
558
|
-
if (verifying) {
|
|
891
|
+
if (verifying) {
|
|
892
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
893
|
+
continue;
|
|
894
|
+
}
|
|
559
895
|
let ok = false;
|
|
560
896
|
try {
|
|
561
|
-
entries = registry();
|
|
562
|
-
|
|
897
|
+
entries = await registry();
|
|
898
|
+
registryFailure = undefined;
|
|
899
|
+
reporter.setApps(buildApps());
|
|
900
|
+
reporter.clearFailure();
|
|
563
901
|
ok = await compileGraph();
|
|
564
902
|
} catch (error) {
|
|
565
|
-
registryFailure = error;
|
|
566
|
-
|
|
903
|
+
registryFailure = error;
|
|
904
|
+
await failure(error);
|
|
905
|
+
} finally {
|
|
906
|
+
releaseScenarioRegistry(root);
|
|
907
|
+
}
|
|
567
908
|
completedFull = token;
|
|
568
|
-
const file = path.join(root, ".ds", `full-build-${reporter.session}.json`),
|
|
569
|
-
|
|
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);
|
|
570
913
|
continue;
|
|
571
914
|
}
|
|
572
915
|
if (registryFailure) break;
|
|
573
|
-
if(!pending.size){
|
|
916
|
+
if (!pending.size) {
|
|
574
917
|
// Let incoming foreground selections enter the queue before the next
|
|
575
918
|
// background job in the shared compiler.
|
|
576
|
-
await new Promise(resolve=>setTimeout(resolve,50));
|
|
577
|
-
if(stopped)break;
|
|
578
|
-
if(!pending.size){
|
|
579
|
-
const entry=nextWarm();
|
|
580
|
-
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) {
|
|
581
924
|
// Bun can finish the remaining graph in one bounded build after
|
|
582
925
|
// the first view. Rebuilding 1, 2, ... N roots repeats bundling N
|
|
583
926
|
// times despite the persistent per-file transform cache.
|
|
584
|
-
const warm=buildGraph
|
|
585
|
-
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
|
+
}
|
|
586
932
|
}
|
|
587
933
|
}
|
|
588
934
|
}
|
|
589
935
|
const id = pending.has(active) ? active : pending.values().next().value;
|
|
590
936
|
pending.delete(id);
|
|
591
|
-
const entry = entries.find(entry => entry.id === id);
|
|
592
|
-
|
|
937
|
+
const entry = entries.find((entry) => entry.id === id);
|
|
938
|
+
// Instances in one process take turns: the viewed draft, then the project, then warming.
|
|
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
|
+
}
|
|
593
949
|
}
|
|
594
|
-
} catch (error) {
|
|
595
|
-
|
|
950
|
+
} catch (error) {
|
|
951
|
+
await failure(error);
|
|
952
|
+
} finally {
|
|
953
|
+
compiling = false;
|
|
954
|
+
}
|
|
596
955
|
}
|
|
597
|
-
function discoverUnknownEntries() {
|
|
956
|
+
async function discoverUnknownEntries() {
|
|
598
957
|
if (!inspector || discovering) return;
|
|
599
|
-
const revision = previewSourceRevision(options);
|
|
958
|
+
const revision = await previewSourceRevision(options);
|
|
600
959
|
if (unknownRevision === revision) return;
|
|
601
960
|
unknownRevision = revision;
|
|
602
|
-
discovering = inspector
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
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
|
+
});
|
|
613
986
|
}
|
|
614
|
-
function request(startBuild = true) {
|
|
615
|
-
const file =
|
|
987
|
+
async function request(startBuild = true) {
|
|
988
|
+
const file = requestFile;
|
|
616
989
|
if (!file || !existsSync(file)) return;
|
|
617
990
|
try {
|
|
618
991
|
const value = JSON.parse(readFileSync(file, "utf8"));
|
|
619
|
-
if (value.session !==
|
|
992
|
+
if (value.session !== buildSession) return;
|
|
620
993
|
if (typeof value.full === "string" && /^[\w-]{1,100}$/.test(value.full)) fullRequest = value.full;
|
|
621
994
|
if (value.invalidation !== invalidation) {
|
|
622
995
|
invalidation = value.invalidation;
|
|
623
|
-
if (requested.size) sourceChanged("invalidate",options.config.dsDir,true);
|
|
624
|
-
}
|
|
625
|
-
active = entries.find(entry => entry.artifact === value.active)?.id;
|
|
626
|
-
if (value.files.some(file => !entries.some(entry => entry.artifact === file))) discoverUnknownEntries();
|
|
627
|
-
for (const file of value.files) {
|
|
628
|
-
const entry = entries.find(entry => entry.artifact === file);
|
|
629
|
-
if (entry && !requested.has(entry.id)) {
|
|
630
|
-
requested.add(entry.id);
|
|
631
|
-
const covered = liveCandidate && !liveCandidate.failed && liveCandidate.generation === generation
|
|
632
|
-
&& liveCandidate.stamp === cache.inputs() && liveCandidate.entries.some(item => item.id === entry.id);
|
|
633
|
-
if (!buildGraph || (!publishedEntries.has(entry.id) || publishedStamp !== cache.inputs()) && !covered) pending.add(entry.id);
|
|
634
|
-
}
|
|
996
|
+
if (requested.size) sourceChanged("invalidate", options.config.dsDir, true);
|
|
635
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
|
+
}));
|
|
636
1003
|
if (startBuild) void drain();
|
|
637
|
-
} catch (error) {
|
|
1004
|
+
} catch (error) {
|
|
1005
|
+
await failure(error);
|
|
1006
|
+
}
|
|
638
1007
|
}
|
|
639
1008
|
if (!watched) {
|
|
640
1009
|
for (const entry of entries) pending.add(entry.id);
|
|
641
|
-
try {
|
|
1010
|
+
try {
|
|
1011
|
+
await drain();
|
|
1012
|
+
} finally {
|
|
1013
|
+
await buildGraph.close?.();
|
|
1014
|
+
}
|
|
642
1015
|
return;
|
|
643
1016
|
}
|
|
644
1017
|
let timer;
|
|
645
1018
|
const changed = new Set();
|
|
646
1019
|
function sourceChanged(_event, file, topology = false) {
|
|
647
|
-
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;
|
|
648
1021
|
const absolute = path.join(root, file);
|
|
649
1022
|
if (previewFileIgnored(options, absolute)) return;
|
|
650
1023
|
changed.add(absolute);
|
|
651
1024
|
clearTimeout(timer);
|
|
652
|
-
timer = setTimeout(() => {
|
|
1025
|
+
timer = setTimeout(async () => {
|
|
653
1026
|
++generation;
|
|
654
1027
|
reporter.progress("queued");
|
|
655
1028
|
validation = undefined;
|
|
656
|
-
warmed.clear();
|
|
657
|
-
|
|
1029
|
+
warmed.clear();
|
|
1030
|
+
warmFailures.clear();
|
|
1031
|
+
warmProgress();
|
|
1032
|
+
const changes = [...changed];
|
|
1033
|
+
changed.clear();
|
|
658
1034
|
try {
|
|
659
1035
|
// Registry inspection for live graphs runs in the verification worker.
|
|
660
1036
|
// Existing entry identities can compile immediately while it checks.
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
observedSourceRevision = previewSourceRevision(options);
|
|
1037
|
+
options = withPreviewSession(loadConfig(root), buildSession);
|
|
1038
|
+
observedSourceRevision = await previewSourceRevision(options);
|
|
664
1039
|
registryFailure = undefined;
|
|
665
1040
|
reporter.setApps(buildApps());
|
|
666
1041
|
reporter.clearFailure();
|
|
667
|
-
request(false);
|
|
668
|
-
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
|
+
}
|
|
669
1048
|
// Every source change needs validation; unaffected artifacts need no
|
|
670
1049
|
// compilation. Check active first, then rebuild only changed dependencies.
|
|
671
1050
|
for (const id of requested) {
|
|
672
|
-
const entry = entries.find(entry => entry.id === id);
|
|
673
|
-
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
|
+
}
|
|
674
1056
|
}
|
|
675
1057
|
if (changes.length) void drain();
|
|
676
1058
|
} catch (error) {
|
|
677
|
-
registryFailure = error;
|
|
1059
|
+
registryFailure = error;
|
|
1060
|
+
await failure(error);
|
|
678
1061
|
}
|
|
679
1062
|
}, 16);
|
|
680
1063
|
}
|
|
681
1064
|
// Do not allocate recursive OS watches for node_modules or generated trees.
|
|
682
1065
|
const watchers = new Map();
|
|
683
|
-
function addWatch(directory, callback, recursive = false) {
|
|
1066
|
+
async function addWatch(directory, callback, recursive = false) {
|
|
684
1067
|
if (stopped) return false;
|
|
685
1068
|
try {
|
|
686
|
-
const stat = statSync(directory),
|
|
1069
|
+
const stat = statSync(directory),
|
|
1070
|
+
identity = `${stat.dev}:${stat.ino}`;
|
|
687
1071
|
if (watchers.get(directory)?.identity === identity) return false;
|
|
688
1072
|
watchers.get(directory)?.watcher.close();
|
|
689
|
-
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"));
|
|
690
1074
|
watchers.set(directory, { watcher, identity });
|
|
691
|
-
watcher.on("error", error => {
|
|
1075
|
+
watcher.on("error", async (error) => {
|
|
692
1076
|
watcher.close();
|
|
693
1077
|
if (watchers.get(directory)?.watcher === watcher) watchers.delete(directory);
|
|
694
|
-
failure(error);
|
|
1078
|
+
await failure(error);
|
|
695
1079
|
});
|
|
696
1080
|
return true;
|
|
697
|
-
} catch (error) {
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
await failure(error);
|
|
1083
|
+
}
|
|
698
1084
|
}
|
|
699
|
-
function reconcileWatches(initial = false) {
|
|
1085
|
+
async function reconcileWatches(initial = false) {
|
|
700
1086
|
if (stopped) return;
|
|
701
1087
|
try {
|
|
702
|
-
addWatch(root, sourceChanged);
|
|
1088
|
+
await addWatch(root, sourceChanged);
|
|
703
1089
|
const wanted = new Set([root, path.join(root, ".ds")]);
|
|
704
1090
|
for (const directory of previewWatchDirectories(options)) {
|
|
705
1091
|
if (directory === root) continue;
|
|
706
1092
|
wanted.add(directory);
|
|
707
1093
|
const relative = path.relative(root, directory);
|
|
708
|
-
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);
|
|
709
1096
|
}
|
|
710
1097
|
mkdirSync(path.join(root, ".ds"), { recursive: true });
|
|
711
|
-
addWatch(path.join(root, ".ds"), (_event, file) => {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
+
}
|
|
717
1110
|
}
|
|
718
|
-
reconcileWatches(true);
|
|
719
|
-
const reconcileTimer = setInterval(() => {
|
|
720
|
-
|
|
1111
|
+
await reconcileWatches(true);
|
|
1112
|
+
const reconcileTimer = setInterval(async () => {
|
|
1113
|
+
// A retired draft workspace disappears before its host stops this instance.
|
|
1114
|
+
if (!existsSync(root)) {
|
|
1115
|
+
await handle.stop();
|
|
1116
|
+
return;
|
|
1117
|
+
}
|
|
1118
|
+
await reconcileWatches();
|
|
721
1119
|
try {
|
|
722
|
-
const current = previewSourceRevision(options);
|
|
1120
|
+
const current = await previewSourceRevision(options);
|
|
723
1121
|
if (current !== observedSourceRevision) {
|
|
724
1122
|
observedSourceRevision = current;
|
|
725
|
-
sourceChanged("reconcile",options.config.dsDir,true);
|
|
1123
|
+
sourceChanged("reconcile", options.config.dsDir, true);
|
|
726
1124
|
}
|
|
727
|
-
request();
|
|
728
|
-
} catch (error) {
|
|
1125
|
+
await request();
|
|
1126
|
+
} catch (error) {
|
|
1127
|
+
await failure(error);
|
|
1128
|
+
}
|
|
729
1129
|
}, 1000);
|
|
730
|
-
request();
|
|
731
|
-
if(prewarm)void drain();
|
|
732
|
-
console.log(`Scenario compiler ready: ${entries.length} entries; ${prewarm?"sequential background warming enabled":"builds are requested on demand"}.`);
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
+
};
|
|
1146
|
+
return handle;
|
|
738
1147
|
}
|