@reqvire-org/ads 0.4.0 → 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 +105 -86
- 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 +5 -5
- package/dist/atomic-composition.mjs +191 -70
- package/dist/atomic-trace.mjs +120 -50
- package/dist/behavior-libraries.mjs +106 -37
- package/dist/behaviors.mjs +219 -77
- package/dist/boundaries.mjs +135 -38
- package/dist/brand-assets.mjs +219 -47
- package/dist/brands.mjs +86 -27
- package/dist/bun-compiler.mjs +28 -14
- package/dist/bun-worker.mjs +7 -5
- package/dist/capture/worker.mjs +15 -4
- package/dist/capture-store.mjs +4 -2
- package/dist/capture.mjs +17 -14
- package/dist/check-service.mjs +40 -57
- package/dist/check.mjs +749 -188
- package/dist/cli.mjs +200 -99
- package/dist/color-values.mjs +21 -21
- package/dist/component-contrast.mjs +2 -2
- package/dist/config.mjs +303 -135
- package/dist/construction-styles.cjs +10 -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 +2 -2
- package/dist/foundation-views.mjs +238 -0
- package/dist/foundation.mjs +63 -39
- package/dist/generated-entries.mjs +101 -34
- package/dist/icons.mjs +79 -32
- package/dist/image-attributes.mjs +109 -36
- package/dist/image-size.mjs +1 -1
- package/dist/index.mjs +0 -2
- package/dist/init.mjs +122 -41
- package/dist/investigations.mjs +2 -2
- package/dist/layers.mjs +298 -129
- package/dist/layout-widths.mjs +180 -85
- package/dist/linaria/preserve-values.cjs +7 -0
- package/dist/linaria/spatial-inputs.cjs +56 -0
- package/dist/lockup-composition.mjs +44 -0
- package/dist/lockup-model.cjs +64 -0
- package/dist/mcp/THIRD_PARTY_NOTICES.md +51 -1
- package/dist/mcp/apps.mjs +4 -30
- package/dist/mcp/behavior-pages.mjs +72 -24
- package/dist/mcp/build-status.mjs +257 -64
- package/dist/mcp/catalog.mjs +90 -26
- package/dist/mcp/context.mjs +17 -18
- package/dist/mcp/draft-discovery.mjs +44 -21
- package/dist/mcp/drafts.mjs +901 -281
- package/dist/mcp/execution-coordinator.mjs +417 -167
- package/dist/mcp/execution-results.mjs +7 -7
- package/dist/mcp/mutations.mjs +670 -234
- package/dist/mcp/preview-watch.mjs +448 -170
- package/dist/mcp/preview-widget.bundle.js +44 -50
- package/dist/mcp/prompts.mjs +5 -5
- package/dist/mcp/result-pages.mjs +1 -1
- package/dist/mcp/sandbox-host.mjs +1 -1
- package/dist/mcp/server.mjs +2402 -577
- package/dist/mcp/showcase-host.mjs +165 -41
- package/dist/mcp/skills.mjs +1 -1
- package/dist/mcp/text-diff.mjs +29 -10
- package/dist/paint-contracts.mjs +174 -81
- package/dist/palette-generated.mjs +2 -2
- package/dist/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 +8 -34
- package/dist/project-documents.mjs +1 -1
- package/dist/public-api.mjs +69 -31
- package/dist/public-props.mjs +39 -22
- package/dist/{browser-audit → render-audit}/axe-run.mjs +3 -3
- package/dist/{browser-audit → render-audit}/image-shape.mjs +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 +719 -378
- package/dist/scenarios-vite.d.mts +1 -3
- package/dist/scenarios-vite.mjs +2 -81
- package/dist/scenarios.mjs +421 -157
- package/dist/selector-match.mjs +2 -2
- package/dist/showcase/client.bundle.js +57 -56
- package/dist/showcase/draft-navigation.js +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 +130 -119
- package/dist/skills/ads-designer/references/accessibility.md +12 -13
- package/dist/skills/ads-designer/references/atomic-styles.md +4 -4
- package/dist/skills/ads-designer/references/behaviors.md +30 -27
- package/dist/skills/ads-designer/references/branding.md +98 -10
- package/dist/skills/ads-designer/references/captures.md +25 -0
- package/dist/skills/ads-designer/references/cli.md +21 -24
- package/dist/skills/ads-designer/references/contracts.md +7 -6
- package/dist/skills/ads-designer/references/design-data.md +49 -52
- package/dist/skills/ads-designer/references/drafts.md +20 -17
- package/dist/skills/ads-designer/references/evidence.md +1 -5
- package/dist/skills/ads-designer/references/guarded-editing.md +14 -18
- package/dist/skills/ads-designer/references/layers.md +1 -1
- package/dist/skills/ads-designer/references/layout.md +347 -0
- package/dist/skills/ads-designer/references/mobile.md +2 -1
- package/dist/skills/{ads-motion/references/performance.md → ads-designer/references/motion-performance.md} +5 -1
- package/dist/skills/{ads-motion/references/build.md → ads-designer/references/motion.md} +73 -5
- package/dist/skills/ads-designer/references/review.md +37 -34
- package/dist/skills/ads-designer/references/runtimes.md +33 -30
- package/dist/skills/ads-designer/references/scenarios.md +16 -18
- package/dist/skills/{ads-break-ui/references/catalog.md → ads-designer/references/stress-catalog.md} +3 -1
- package/dist/skills/ads-designer/references/stress-test.md +68 -0
- package/dist/skills/ads-designer/references/validation.md +83 -75
- package/dist/skills/ads-designer/references/workflows.md +8 -33
- package/dist/skills/ads-import/SKILL.md +43 -325
- package/dist/skills/ads-import/references/atomic-styles.md +4 -4
- package/dist/skills/ads-import/references/behaviors.md +30 -27
- package/dist/skills/ads-import/references/branding.md +5 -5
- package/dist/skills/ads-import/references/captures.md +25 -0
- package/dist/skills/ads-import/references/cli.md +21 -24
- package/dist/skills/ads-import/references/compatibility.md +1 -1
- package/dist/skills/ads-import/references/contracts.md +7 -6
- package/dist/skills/ads-import/references/design-data.md +49 -52
- package/dist/skills/ads-import/references/drafts.md +20 -17
- package/dist/skills/ads-import/references/evidence.md +1 -5
- package/dist/skills/ads-import/references/guarded-editing.md +14 -18
- package/dist/skills/ads-import/references/implementation.md +2 -1
- package/dist/skills/ads-import/references/layers.md +1 -1
- package/dist/skills/ads-import/references/layout.md +347 -0
- package/dist/skills/ads-import/references/review.md +37 -34
- package/dist/skills/ads-import/references/runtimes.md +33 -30
- package/dist/skills/ads-import/references/scenarios.md +16 -18
- package/dist/skills/ads-import/references/tokens.md +3 -3
- package/dist/skills/ads-import/references/validation.md +83 -75
- package/dist/skills/ads-import/references/workflows.md +8 -33
- package/dist/skills/ads-migrate/SKILL.md +56 -0
- package/dist/skills/ads-migrate/references/0.4.1-to-0.4.2.md +602 -0
- package/dist/skills/ads-port/SKILL.md +54 -343
- package/dist/skills/ads-port/references/atomic-styles.md +4 -4
- package/dist/skills/ads-port/references/behaviors.md +30 -27
- package/dist/skills/ads-port/references/captures.md +25 -0
- package/dist/skills/ads-port/references/cli.md +21 -24
- package/dist/skills/ads-port/references/contracts.md +7 -6
- package/dist/skills/ads-port/references/design-data.md +49 -52
- package/dist/skills/ads-port/references/drafts.md +20 -17
- package/dist/skills/ads-port/references/evidence.md +1 -5
- package/dist/skills/ads-port/references/guarded-editing.md +14 -18
- package/dist/skills/ads-port/references/layers.md +1 -1
- package/dist/skills/ads-port/references/layout.md +347 -0
- package/dist/skills/ads-port/references/lint-and-docs.md +8 -11
- package/dist/skills/ads-port/references/native-implementation.md +2 -1
- package/dist/skills/ads-port/references/review.md +37 -34
- package/dist/skills/ads-port/references/runtimes.md +33 -30
- package/dist/skills/ads-port/references/scenarios.md +16 -18
- package/dist/skills/ads-port/references/validation.md +83 -75
- package/dist/skills/ads-port/references/workflows.md +8 -33
- package/dist/source-symbols.mjs +1 -8
- package/dist/source-values.mjs +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 +25 -6
- package/dist/starters/preact/package.json +4 -8
- package/dist/starters/preact/tsconfig.json +4 -5
- package/dist/starters/preact/vite.config.ts +3 -3
- package/dist/starters/react/ADS.md +42 -47
- package/dist/starters/react/README.md +47 -49
- package/dist/starters/react/design-system/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/composition/Workspace/WorkspacePage/README.md +5 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.fixture.ts +13 -0
- package/dist/starters/react/design-system/composition/Workspace/WorkspacePage/WorkspacePage.ads.scenario.tsx +22 -0
- package/dist/starters/react/design-system/index.ts +2 -1
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.fixture.ts +7 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.ads.scenario.tsx +15 -0
- package/dist/starters/react/design-system/patterns/Conversation/Conversation.tsx +105 -0
- package/dist/starters/react/design-system/patterns/Conversation/README.md +9 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Floating.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/README.md +43 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.fixture.ts +5 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.ads.scenario.tsx +21 -0
- package/dist/starters/react/design-system/patterns/Shell/Shell.tsx +274 -0
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.ads.review.tsx +7 -0
- package/dist/starters/react/design-system/review/index.ads.review.ts +4 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.exports.ts +1 -0
- package/dist/starters/react/design-system/review/region-block/RegionBlock.ads.review.tsx +6 -0
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.exports.ts +1 -1
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.ads.review.tsx +10 -0
- package/dist/starters/react/design-system/showcase/mcp/{main.tsx → main.ads.mount.tsx} +4 -2
- package/dist/starters/react/design-system/tokens/catalog.ads.json +1221 -0
- package/dist/starters/react/design-system/tokens/colors.css +1 -1
- package/dist/starters/react/design-system/tokens/spacing.css +22 -32
- package/dist/starters/react/design-system/tokens/spatial.ads.json +70 -0
- package/dist/starters/react/design-system/tokens/themes.generated.ts +1 -1
- package/dist/starters/react/ds.config.json +25 -6
- package/dist/starters/react/package.json +2 -6
- package/dist/starters/react/tsconfig.json +2 -3
- package/dist/starters/react/vite.config.ts +3 -3
- package/dist/style-boundaries.mjs +70 -25
- package/dist/task-cache.mjs +173 -72
- package/dist/task-worker.mjs +22 -11
- package/dist/test-boundaries.mjs +132 -59
- package/dist/themes-generated.mjs +1 -1
- package/dist/themes-watch.mjs +57 -22
- package/dist/themes.mjs +176 -73
- package/dist/token-export.mjs +39 -14
- package/dist/token-policy.mjs +6 -3
- package/dist/token-quality.mjs +6 -6
- package/dist/token-samples.mjs +16 -5
- package/dist/tokens.mjs +71 -26
- package/dist/ui-framework.mjs +16 -14
- package/dist/unit-contracts.mjs +251 -104
- package/dist/units.mjs +208 -98
- package/dist/usage.mjs +138 -38
- package/dist/validation-checks.mjs +115 -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 +90 -79
- package/docs/ARCHITECTURE.md +294 -136
- package/docs/BEHAVIORS.md +29 -25
- package/docs/CACHING.md +52 -17
- package/docs/CHANGELOG.md +309 -17
- package/docs/CONTRACTS.md +12 -4
- package/docs/DESIGN-REFERENCES.md +40 -0
- package/docs/GUIDE.md +270 -258
- package/docs/MCP.md +181 -324
- 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 -429
- package/dist/create.mjs +0 -48
- package/dist/lint-config.mjs +0 -50
- package/dist/mcp/project-widget.bundle.js +0 -114
- package/dist/mcp/reports.mjs +0 -101
- package/dist/mcp/widget.bundle.js +0 -147
- package/dist/oxlint.mjs +0 -89
- package/dist/preview-builder.mjs +0 -133
- package/dist/preview-workers.mjs +0 -184
- package/dist/showcase.mjs +0 -77
- package/dist/skills/ads-break-ui/LICENSE.upstream +0 -21
- package/dist/skills/ads-break-ui/README.md +0 -16
- package/dist/skills/ads-break-ui/SKILL.md +0 -412
- package/dist/skills/ads-break-ui/agents/openai.yaml +0 -4
- package/dist/skills/ads-break-ui/references/atomic-styles.md +0 -293
- package/dist/skills/ads-break-ui/references/behaviors.md +0 -412
- package/dist/skills/ads-break-ui/references/captures.md +0 -135
- package/dist/skills/ads-break-ui/references/contracts.md +0 -317
- package/dist/skills/ads-break-ui/references/design-data.md +0 -354
- package/dist/skills/ads-break-ui/references/drafts.md +0 -194
- package/dist/skills/ads-break-ui/references/evidence.md +0 -128
- package/dist/skills/ads-break-ui/references/guarded-editing.md +0 -165
- package/dist/skills/ads-break-ui/references/layers.md +0 -145
- package/dist/skills/ads-break-ui/references/reporting.md +0 -101
- package/dist/skills/ads-break-ui/references/review.md +0 -97
- package/dist/skills/ads-break-ui/references/runtimes.md +0 -203
- package/dist/skills/ads-break-ui/references/scenarios.md +0 -246
- package/dist/skills/ads-break-ui/references/validation.md +0 -166
- package/dist/skills/ads-break-ui/references/verification.md +0 -58
- package/dist/skills/ads-break-ui/references/workflows.md +0 -90
- package/dist/skills/ads-designer/references/reporting.md +0 -101
- package/dist/skills/ads-import/references/reporting.md +0 -101
- package/dist/skills/ads-motion/LICENSE.upstream +0 -21
- package/dist/skills/ads-motion/README.md +0 -22
- package/dist/skills/ads-motion/SKILL.md +0 -385
- package/dist/skills/ads-motion/agents/openai.yaml +0 -4
- package/dist/skills/ads-motion/references/atomic-styles.md +0 -293
- package/dist/skills/ads-motion/references/audit.md +0 -44
- package/dist/skills/ads-motion/references/behaviors.md +0 -412
- package/dist/skills/ads-motion/references/captures.md +0 -135
- package/dist/skills/ads-motion/references/contracts.md +0 -317
- package/dist/skills/ads-motion/references/design-data.md +0 -354
- package/dist/skills/ads-motion/references/drafts.md +0 -194
- package/dist/skills/ads-motion/references/evidence.md +0 -128
- package/dist/skills/ads-motion/references/guarded-editing.md +0 -165
- package/dist/skills/ads-motion/references/layers.md +0 -145
- package/dist/skills/ads-motion/references/motion-review.md +0 -35
- package/dist/skills/ads-motion/references/reporting.md +0 -101
- package/dist/skills/ads-motion/references/review.md +0 -97
- package/dist/skills/ads-motion/references/runtimes.md +0 -203
- package/dist/skills/ads-motion/references/scenarios.md +0 -246
- package/dist/skills/ads-motion/references/validation.md +0 -166
- package/dist/skills/ads-motion/references/verification.md +0 -39
- package/dist/skills/ads-motion/references/workflows.md +0 -90
- package/dist/skills/ads-port/references/reporting.md +0 -101
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/components/Layout/Grid/Grid.tsx +0 -76
- package/dist/starters/preact/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/preact/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/preact/design-system/showcase/mcp/main.tsx +0 -6
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Icons/AppIcon/AppIcon.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.fixture.ts +0 -7
- package/dist/starters/react/design-system/brand/Identity/Logo/Logo.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.fixture.ts +0 -12
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.ads.scenario.tsx +0 -17
- package/dist/starters/react/design-system/components/Layout/Grid/Grid.tsx +0 -75
- package/dist/starters/react/design-system/components/Layout/Grid/README.md +0 -21
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +0 -112
- package/dist/starters/react/design-system/review/demo-frame/DemoFrame.tsx +0 -29
- package/dist/starters/react/design-system/review/grid-cell/GridCell.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/grid-cell/GridCell.tsx +0 -18
- package/dist/starters/react/design-system/review/index.ts +0 -6
- package/dist/starters/react/design-system/review/screen-frame/ScreenFrame.tsx +0 -34
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.contract.ts +0 -6
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.ads.exports.ts +0 -1
- package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +0 -137
- package/dist/starters/react/design-system/showcase/mcp/index.html +0 -1
- package/dist/starters/react/design-system/tokens/Color.ads.fixture.ts +0 -124
- package/dist/starters/react/design-system/tokens/Color.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Layout.ads.fixture.ts +0 -39
- package/dist/starters/react/design-system/tokens/Layout.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Motion.ads.fixture.ts +0 -18
- package/dist/starters/react/design-system/tokens/Motion.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Shape.ads.fixture.ts +0 -30
- package/dist/starters/react/design-system/tokens/Shape.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Space.ads.fixture.ts +0 -37
- package/dist/starters/react/design-system/tokens/Space.ads.scenario.tsx +0 -4
- package/dist/starters/react/design-system/tokens/Type.ads.fixture.ts +0 -29
- package/dist/starters/react/design-system/tokens/Type.ads.scenario.tsx +0 -4
- package/dist/starters/react/package-lock.json +0 -4707
- package/dist/token-fixtures.mjs +0 -30
- package/docs/benchmarks/bun-previews.md +0 -91
- package/docs/benchmarks/preview-memory.md +0 -147
- package/docs/benchmarks/turbo-poc.md +0 -284
- package/docs/plans/execution-coordination.md +0 -57
- /package/dist/{browser-audit → render-audit}/first-render.mjs +0 -0
- /package/dist/{browser-audit → render-audit}/layout-shift.mjs +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
3
|
+
import { API } from "typescript/async";
|
|
4
|
+
import { createFileSystemLayer, serverFS } from "typescript/fs";
|
|
5
|
+
import { FileTree } from "./file-tree.mjs";
|
|
6
|
+
import { adaptProgram } from "./native-adapter.mjs";
|
|
7
|
+
import ts from "./syntax.mjs";
|
|
8
|
+
import { nativeCompilerOptions } from "./compiler-options.mjs";
|
|
9
|
+
|
|
10
|
+
const configuration = (file) => /\.(?:jsonc?|lock|ya?ml|toml)$/.test(file);
|
|
11
|
+
function relocate(value, from, to) {
|
|
12
|
+
if (typeof value === "string") return value === from ? to : value.startsWith(from + path.sep) ? to + value.slice(from.length) : value;
|
|
13
|
+
if (Array.isArray(value)) return value.map((item) => relocate(item, from, to));
|
|
14
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, relocate(item, from, to)]));
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** One compiler owns a live project and isolated source revisions. */
|
|
19
|
+
export class NativeProject {
|
|
20
|
+
#api;
|
|
21
|
+
#baseline;
|
|
22
|
+
#views = new Set();
|
|
23
|
+
#generation = 0;
|
|
24
|
+
#closed = false;
|
|
25
|
+
#external = new Map();
|
|
26
|
+
// Live AST identity survives revisions. Each draft owns its relocated wrappers
|
|
27
|
+
// so shared native trees cannot retain discarded draft paths indefinitely.
|
|
28
|
+
#liveNodes = new WeakMap();
|
|
29
|
+
constructor(root) {
|
|
30
|
+
this.root = path.resolve(root);
|
|
31
|
+
const projectPath = (file) => file === this.root || file.startsWith(this.root + path.sep);
|
|
32
|
+
const dependencyPath = (file) => file === path.join(this.root, "node_modules") || file.startsWith(path.join(this.root, "node_modules") + path.sep);
|
|
33
|
+
const memoryOnly = (file) => projectPath(file) && !dependencyPath(file);
|
|
34
|
+
// Request layers provide the complete project view. A file omitted from a
|
|
35
|
+
// candidate must never become visible through the live filesystem fallback.
|
|
36
|
+
this.#api = new API({
|
|
37
|
+
cwd: this.root,
|
|
38
|
+
runExternalCode: false,
|
|
39
|
+
fs: {
|
|
40
|
+
directoryExists: (file) => (memoryOnly(file) ? false : this.#externalInput("directory", file)),
|
|
41
|
+
fileExists: (file) => (memoryOnly(file) ? false : this.#externalInput("exists", file)),
|
|
42
|
+
getAccessibleEntries: (file) => (memoryOnly(file) ? { files: [], directories: [], symlinks: [] } : JSON.parse(this.#externalInput("entries", file))),
|
|
43
|
+
readFile: (file) => (memoryOnly(file) ? undefined : this.#externalInput("text", file)),
|
|
44
|
+
realpath: (file) => (memoryOnly(file) ? serverFS.identity : this.#externalInput("realpath", file)),
|
|
45
|
+
stat: serverFS.fakeStat,
|
|
46
|
+
writeFile: serverFS.error,
|
|
47
|
+
removeFile: serverFS.error,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
this.stats = { compilerStarts: 1, baselines: 0, branches: 0, programs: 0, compactions: 0, changedFiles: 0, transmittedBytes: 0 };
|
|
51
|
+
}
|
|
52
|
+
#externalValue(kind, file) {
|
|
53
|
+
try {
|
|
54
|
+
if (kind === "text") return readFileSync(file, "utf8");
|
|
55
|
+
if (kind === "realpath") return realpathSync(file);
|
|
56
|
+
if (kind === "directory") return statSync(file).isDirectory();
|
|
57
|
+
if (kind === "exists") return existsSync(file);
|
|
58
|
+
const result = { files: [], directories: [], symlinks: [] };
|
|
59
|
+
for (const entry of readdirSync(file, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
60
|
+
if (entry.isSymbolicLink()) result.symlinks.push(entry.name);
|
|
61
|
+
const stat = entry.isSymbolicLink() ? statSync(path.join(file, entry.name), { throwIfNoEntry: false }) : entry;
|
|
62
|
+
if (stat?.isFile()) result.files.push(entry.name);
|
|
63
|
+
else if (stat?.isDirectory()) result.directories.push(entry.name);
|
|
64
|
+
}
|
|
65
|
+
return JSON.stringify(result);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (!["ENOENT", "ENOTDIR"].includes(error.code)) throw error;
|
|
68
|
+
return kind === "text" ? undefined : kind === "realpath" ? file : kind === "entries" ? '{"files":[],"directories":[],"symlinks":[]}' : false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
#externalInput(kind, file) {
|
|
72
|
+
const key = `${kind}\0${file}`;
|
|
73
|
+
if (!this.#external.has(key)) this.#external.set(key, { kind, file, value: this.#externalValue(kind, file) });
|
|
74
|
+
return this.#external.get(key).value;
|
|
75
|
+
}
|
|
76
|
+
#refreshExternal() {
|
|
77
|
+
let changed = false;
|
|
78
|
+
// Content comparison catches same-size and preserved-mtime dependency edits,
|
|
79
|
+
// including a module that was missing during the previous resolution.
|
|
80
|
+
for (const input of this.#external.values()) {
|
|
81
|
+
const value = this.#externalValue(input.kind, input.file);
|
|
82
|
+
if (value !== input.value) {
|
|
83
|
+
input.value = value;
|
|
84
|
+
changed = true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return changed;
|
|
88
|
+
}
|
|
89
|
+
#normalize(entries) {
|
|
90
|
+
return new Map(
|
|
91
|
+
[...entries].map(([name, content]) => {
|
|
92
|
+
const file = path.resolve(this.root, name);
|
|
93
|
+
if (!file.startsWith(this.root + path.sep) || file.includes(`${path.sep}node_modules${path.sep}`))
|
|
94
|
+
throw new Error("Analysis input must be a project-owned file.");
|
|
95
|
+
if (content !== null && typeof content !== "string") throw new Error("Analysis input must be source text or null.");
|
|
96
|
+
return [file, content];
|
|
97
|
+
}),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
#changes(before, after) {
|
|
101
|
+
return new Map(
|
|
102
|
+
[...new Set([...before.keys(), ...after.keys()])]
|
|
103
|
+
.filter((file) => (before.get(file) ?? null) !== (after.get(file) ?? null))
|
|
104
|
+
.map((file) => [file, after.get(file) ?? null]),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
#layer(changes, previous, invalidateAll = false) {
|
|
108
|
+
const created = [],
|
|
109
|
+
changed = [],
|
|
110
|
+
deleted = [],
|
|
111
|
+
files = [];
|
|
112
|
+
for (const [file, content] of changes) {
|
|
113
|
+
(content === null ? deleted : previous.has(file) ? changed : created).push(file);
|
|
114
|
+
if (content !== null) files.push([file, content]);
|
|
115
|
+
this.stats.changedFiles++;
|
|
116
|
+
this.stats.transmittedBytes += content === null ? 0 : Buffer.byteLength(content);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
fileSystem: createFileSystemLayer(files, { removedPaths: deleted }),
|
|
120
|
+
fileNotifications: { created, changed, deleted, ...(invalidateAll || [...changes.keys()].some(configuration) ? { invalidateAll: true } : {}) },
|
|
121
|
+
ensurePrograms: true,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
#record(root, snapshot, files, tree, programs = new Map(), generation = this.#generation, nodes) {
|
|
125
|
+
const view = {
|
|
126
|
+
root: path.resolve(root),
|
|
127
|
+
snapshot,
|
|
128
|
+
files,
|
|
129
|
+
tree,
|
|
130
|
+
programs: new Map(programs),
|
|
131
|
+
generation,
|
|
132
|
+
snapshots: new Set([snapshot]),
|
|
133
|
+
adapters: new Map(),
|
|
134
|
+
nodes: nodes ?? (path.resolve(root) === this.root ? this.#liveNodes : new WeakMap()),
|
|
135
|
+
resolvers: new Map(),
|
|
136
|
+
usedPrograms: new Set(),
|
|
137
|
+
closed: false,
|
|
138
|
+
queue: Promise.resolve(),
|
|
139
|
+
};
|
|
140
|
+
this.#views.add(view);
|
|
141
|
+
return view;
|
|
142
|
+
}
|
|
143
|
+
#assert(view) {
|
|
144
|
+
if (this.#closed || view.closed || !this.#views.has(view)) throw new Error("Analysis revision is no longer available.");
|
|
145
|
+
}
|
|
146
|
+
/** Ingest a fenced live inventory. Contents come from the caller's input read. */
|
|
147
|
+
async synchronize(entries, dependencyRevision = "") {
|
|
148
|
+
if (this.#closed) throw new Error("Analysis project is closed.");
|
|
149
|
+
const files = this.#normalize(entries);
|
|
150
|
+
for (const [file, content] of files) if (content === null) files.delete(file);
|
|
151
|
+
const previous = this.#baseline;
|
|
152
|
+
const changes = this.#changes(previous?.files ?? new Map(), files);
|
|
153
|
+
const externalChanged = this.#refreshExternal();
|
|
154
|
+
if (previous && !changes.size && !externalChanged && previous.dependencyRevision === dependencyRevision) return previous;
|
|
155
|
+
const snapshot = previous
|
|
156
|
+
? await previous.snapshot.update(this.#layer(changes, previous.files, externalChanged || previous.dependencyRevision !== dependencyRevision))
|
|
157
|
+
: await this.#api.createSnapshot({ fileSystem: createFileSystemLayer([...files]) });
|
|
158
|
+
this.#generation++;
|
|
159
|
+
this.stats.baselines++;
|
|
160
|
+
const view = this.#record(
|
|
161
|
+
this.root,
|
|
162
|
+
snapshot,
|
|
163
|
+
files,
|
|
164
|
+
previous ? previous.tree.withChanges(changes) : new FileTree().withChanges(files),
|
|
165
|
+
previous?.programs,
|
|
166
|
+
);
|
|
167
|
+
view.dependencyRevision = dependencyRevision;
|
|
168
|
+
this.#baseline = view;
|
|
169
|
+
if (previous) await this.release(previous);
|
|
170
|
+
return view;
|
|
171
|
+
}
|
|
172
|
+
/** Fork a full candidate inventory; only its delta crosses the compiler API. */
|
|
173
|
+
async branch(root, entries) {
|
|
174
|
+
if (!this.#baseline) throw new Error("Supply a live baseline before a draft.");
|
|
175
|
+
if (this.#views.size >= 32) throw new Error("Too many active analysis revisions.");
|
|
176
|
+
const files = this.#normalize(entries);
|
|
177
|
+
for (const [file, content] of files) if (content === null) files.delete(file);
|
|
178
|
+
const changes = this.#changes(this.#baseline.files, files);
|
|
179
|
+
const snapshot = await this.#baseline.snapshot.update(this.#layer(changes, this.#baseline.files));
|
|
180
|
+
this.stats.branches++;
|
|
181
|
+
return this.#record(root, snapshot, files, this.#baseline.tree.withChanges(changes), this.#baseline.programs);
|
|
182
|
+
}
|
|
183
|
+
async update(view, entries) {
|
|
184
|
+
this.#assert(view);
|
|
185
|
+
if (view === this.#baseline) throw new Error("Use synchronize for live inputs.");
|
|
186
|
+
const files = this.#normalize(entries);
|
|
187
|
+
for (const [file, content] of files) if (content === null) files.delete(file);
|
|
188
|
+
const changes = this.#changes(view.files, files);
|
|
189
|
+
if (!changes.size) return view;
|
|
190
|
+
const snapshot = await view.snapshot.update(this.#layer(changes, view.files));
|
|
191
|
+
const next = this.#record(view.root, snapshot, files, view.tree.withChanges(changes), view.programs, view.generation, view.nodes);
|
|
192
|
+
await this.release(view);
|
|
193
|
+
return next;
|
|
194
|
+
}
|
|
195
|
+
text(view, file) {
|
|
196
|
+
this.#assert(view);
|
|
197
|
+
return view.tree.get(path.resolve(this.root, path.relative(view.root, file)));
|
|
198
|
+
}
|
|
199
|
+
files(view, directory) {
|
|
200
|
+
this.#assert(view);
|
|
201
|
+
return view.tree.files(path.resolve(this.root, path.relative(view.root, directory)))
|
|
202
|
+
.map((file) => path.resolve(view.root, path.relative(this.root, file)));
|
|
203
|
+
}
|
|
204
|
+
async source(view, file) {
|
|
205
|
+
this.#assert(view);
|
|
206
|
+
for (const pending of view.adapters.values()) {
|
|
207
|
+
const program = await pending;
|
|
208
|
+
if (program.hasSourceFile(file)) return program.getSourceFile(file);
|
|
209
|
+
}
|
|
210
|
+
const roots = [...view.files.keys()].filter((file) => /\.[cm]?[jt]sx?$/.test(file)).map((file) => path.resolve(view.root, path.relative(this.root, file)));
|
|
211
|
+
return (
|
|
212
|
+
await this.program(view, "syntax", roots, {
|
|
213
|
+
allowJs: true,
|
|
214
|
+
noResolve: true,
|
|
215
|
+
noLib: true,
|
|
216
|
+
types: [],
|
|
217
|
+
target: ts.ScriptTarget.Latest,
|
|
218
|
+
module: ts.ModuleKind.ESNext,
|
|
219
|
+
jsx: ts.JsxEmit.Preserve,
|
|
220
|
+
})
|
|
221
|
+
).getSourceFile(file);
|
|
222
|
+
}
|
|
223
|
+
async resolve(view, specifier, file, compilerOptions) {
|
|
224
|
+
this.#assert(view);
|
|
225
|
+
const compiler = nativeCompilerOptions(relocate(compilerOptions, view.root, this.root), this.root),
|
|
226
|
+
key = JSON.stringify(compiler);
|
|
227
|
+
if (!view.resolvers.has(key)) view.resolvers.set(key, this.#api.createModuleResolver(compiler));
|
|
228
|
+
const directory = relocate(path.dirname(file), view.root, this.root);
|
|
229
|
+
const result = await (await view.resolvers.get(key)).resolveModuleName(specifier, directory, undefined, { snapshot: view.snapshot });
|
|
230
|
+
return result.resolvedModule && relocate(result.resolvedModule.resolvedFileName, this.root, view.root);
|
|
231
|
+
}
|
|
232
|
+
/** Rules call through the context; this is the only native program factory. */
|
|
233
|
+
program(view, purpose, rootNames, compilerOptions) {
|
|
234
|
+
const pending = view.queue.then(() => this.#program(view, purpose, rootNames, compilerOptions));
|
|
235
|
+
view.queue = pending.then(
|
|
236
|
+
() => {},
|
|
237
|
+
() => {},
|
|
238
|
+
);
|
|
239
|
+
return pending;
|
|
240
|
+
}
|
|
241
|
+
async #program(view, _purpose, rootNames, compilerOptions) {
|
|
242
|
+
this.#assert(view);
|
|
243
|
+
const canonical = (value) => relocate(value, view.root, this.root);
|
|
244
|
+
const roots = rootNames.map(canonical),
|
|
245
|
+
compiler = nativeCompilerOptions(canonical(compilerOptions), this.root);
|
|
246
|
+
const key = JSON.stringify([roots, compiler]);
|
|
247
|
+
view.usedPrograms.add(key);
|
|
248
|
+
if (view.adapters.has(key)) return view.adapters.get(key);
|
|
249
|
+
let id = view.programs.get(key);
|
|
250
|
+
if (!id) {
|
|
251
|
+
let next;
|
|
252
|
+
if (view.programs.size >= 32) {
|
|
253
|
+
const retained = [...view.programs.keys()].filter((candidate) => view.usedPrograms.has(candidate));
|
|
254
|
+
if (retained.length >= 32) throw new Error("Too many distinct compiler configurations in one analysis revision.");
|
|
255
|
+
// 7.1 beta can crash when removing a dirty program from an incremental
|
|
256
|
+
// snapshot. Compact infrequently into a fresh snapshot on the SAME API
|
|
257
|
+
// process; keep old snapshots alive for facades used by this request.
|
|
258
|
+
const keys = [...retained, key];
|
|
259
|
+
next = await this.#api.createSnapshot({
|
|
260
|
+
fileSystem: createFileSystemLayer([...view.files]),
|
|
261
|
+
createPrograms: keys.map((key) => {
|
|
262
|
+
const [rootFiles, compilerOptions] = JSON.parse(key);
|
|
263
|
+
return { rootFiles, compilerOptions };
|
|
264
|
+
}),
|
|
265
|
+
});
|
|
266
|
+
view.programs = new Map(keys.map((key, index) => [key, next.operation.createdPrograms[index].id]));
|
|
267
|
+
id = view.programs.get(key);
|
|
268
|
+
this.stats.compactions++;
|
|
269
|
+
} else {
|
|
270
|
+
next = await view.snapshot.update({ createPrograms: [{ rootFiles: roots, compilerOptions: compiler }] });
|
|
271
|
+
id = next.operation.createdPrograms[0].id;
|
|
272
|
+
}
|
|
273
|
+
view.snapshot = next;
|
|
274
|
+
view.snapshots.add(next);
|
|
275
|
+
view.programs.set(key, id);
|
|
276
|
+
this.stats.programs++;
|
|
277
|
+
}
|
|
278
|
+
const program = adaptProgram({ snapshot: view.snapshot, id, root: view.root, canonicalRoot: this.root, rootNames, compilerOptions, nodes: view.nodes });
|
|
279
|
+
view.adapters.set(key, program);
|
|
280
|
+
return program;
|
|
281
|
+
}
|
|
282
|
+
async promote(view) {
|
|
283
|
+
this.#assert(view);
|
|
284
|
+
if (view.generation !== this.#generation) throw new Error("Live inputs changed; the draft must be rebased.");
|
|
285
|
+
if (view === this.#baseline) return;
|
|
286
|
+
const previous = this.#baseline;
|
|
287
|
+
view.dependencyRevision = previous.dependencyRevision;
|
|
288
|
+
this.#generation++;
|
|
289
|
+
view.generation = this.#generation;
|
|
290
|
+
this.#baseline = view;
|
|
291
|
+
await this.release(previous);
|
|
292
|
+
// Program inventory is bounded and compacted in program(), without the
|
|
293
|
+
// beta compiler's unsafe removePrograms operation.
|
|
294
|
+
view.root = this.root;
|
|
295
|
+
view.adapters.clear();
|
|
296
|
+
view.nodes = this.#liveNodes;
|
|
297
|
+
for (const snapshot of view.snapshots) if (snapshot !== view.snapshot) await snapshot.dispose();
|
|
298
|
+
view.snapshots = new Set([view.snapshot]);
|
|
299
|
+
}
|
|
300
|
+
async release(view) {
|
|
301
|
+
this.#assert(view);
|
|
302
|
+
if (view === this.#baseline) return;
|
|
303
|
+
view.closed = true;
|
|
304
|
+
view.adapters.clear();
|
|
305
|
+
view.nodes = undefined;
|
|
306
|
+
this.#views.delete(view);
|
|
307
|
+
for (const resolver of view.resolvers.values()) await (await resolver).dispose();
|
|
308
|
+
view.resolvers.clear();
|
|
309
|
+
for (const snapshot of view.snapshots) await snapshot.dispose();
|
|
310
|
+
view.snapshots.clear();
|
|
311
|
+
}
|
|
312
|
+
async close() {
|
|
313
|
+
if (this.#closed) return;
|
|
314
|
+
this.#baseline = undefined;
|
|
315
|
+
try {
|
|
316
|
+
for (const view of this.#views) await this.release(view);
|
|
317
|
+
} finally {
|
|
318
|
+
this.#closed = true;
|
|
319
|
+
this.#liveNodes = new WeakMap();
|
|
320
|
+
await this.#api.close();
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Every owner is an object belonging to one immutable native snapshot. Neither
|
|
2
|
+
// successful results nor pending requests can leak into a changed snapshot.
|
|
3
|
+
const owners = new WeakMap();
|
|
4
|
+
const batchMethods = new Set(["getSymbolAtLocation", "getTypeAtLocation"]);
|
|
5
|
+
|
|
6
|
+
function state(owner) {
|
|
7
|
+
let value = owners.get(owner);
|
|
8
|
+
if (!value) owners.set(owner, (value = { calls: new Map(), ids: new WeakMap(), sequence: 0, batches: new Map() }));
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function argumentKey(value, cache) {
|
|
12
|
+
if (value && typeof value === "object") {
|
|
13
|
+
if (!cache.ids.has(value)) cache.ids.set(value, ++cache.sequence);
|
|
14
|
+
return `object:${cache.ids.get(value)}`;
|
|
15
|
+
}
|
|
16
|
+
return `${typeof value}:${String(value)}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Memoize pending requests too. Failed requests are retryable, including cancellation. */
|
|
20
|
+
export function query(owner, method, ...args) {
|
|
21
|
+
const cache = state(owner),
|
|
22
|
+
key = JSON.stringify([method, ...args.map((value) => argumentKey(value, cache))]);
|
|
23
|
+
if (cache.calls.has(key)) return cache.calls.get(key);
|
|
24
|
+
let promise;
|
|
25
|
+
if (batchMethods.has(method) && args.length === 1 && args[0] && !Array.isArray(args[0])) {
|
|
26
|
+
promise = new Promise((resolve, reject) => {
|
|
27
|
+
let batch = cache.batches.get(method);
|
|
28
|
+
if (!batch) {
|
|
29
|
+
cache.batches.set(method, (batch = []));
|
|
30
|
+
queueMicrotask(async () => {
|
|
31
|
+
cache.batches.delete(method);
|
|
32
|
+
for (let index = 0; index < batch.length; index += 256) {
|
|
33
|
+
const part = batch.slice(index, index + 256);
|
|
34
|
+
try {
|
|
35
|
+
const results = await owner[method](part.map((item) => item.node));
|
|
36
|
+
if (results.length !== part.length) throw new Error("Native query batch returned an incomplete result.");
|
|
37
|
+
part.forEach((item, offset) => item.resolve(results[offset]));
|
|
38
|
+
} catch (error) {
|
|
39
|
+
part.forEach((item) => item.reject(error));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
batch.push({ node: args[0], resolve, reject });
|
|
45
|
+
});
|
|
46
|
+
} else promise = Promise.resolve().then(() => owner[method](...args));
|
|
47
|
+
cache.calls.set(key, promise);
|
|
48
|
+
promise.catch(() => {
|
|
49
|
+
if (cache.calls.get(key) === promise) cache.calls.delete(key);
|
|
50
|
+
});
|
|
51
|
+
return promise;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Resolve declaration handles through the same immutable-owner cache. */
|
|
55
|
+
export function declaration(handle) {
|
|
56
|
+
return handle ? query(handle, "resolve") : Promise.resolve(undefined);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Ordered asynchronous callbacks: short-circuiting and visitor order are preserved. */
|
|
60
|
+
export async function eachChild(node, visit) {
|
|
61
|
+
const children = [];
|
|
62
|
+
node.forEachChild((child) => {
|
|
63
|
+
children.push(child);
|
|
64
|
+
});
|
|
65
|
+
for (const child of children) {
|
|
66
|
+
const result = await visit(child);
|
|
67
|
+
if (result) return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export async function mapAsync(values, visit) {
|
|
71
|
+
const result = [];
|
|
72
|
+
for (let index = 0; index < values.length; index++) result.push(await visit(values[index], index, values));
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
export async function filterAsync(values, visit) {
|
|
76
|
+
const result = [];
|
|
77
|
+
for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) result.push(values[index]);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
export async function someAsync(values, visit) {
|
|
81
|
+
for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return true;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
export async function everyAsync(values, visit) {
|
|
85
|
+
for (let index = 0; index < values.length; index++) if (!(await visit(values[index], index, values))) return false;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
export async function findAsync(values, visit) {
|
|
89
|
+
for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return values[index];
|
|
90
|
+
}
|
|
91
|
+
export async function flatMapAsync(values, visit) {
|
|
92
|
+
return (await mapAsync(values, visit)).flat();
|
|
93
|
+
}
|
|
94
|
+
export async function forEachAsync(values, visit) {
|
|
95
|
+
for (let index = 0; index < values.length; index++) await visit(values[index], index, values);
|
|
96
|
+
}
|
|
97
|
+
export async function findIndexAsync(values, visit) {
|
|
98
|
+
for (let index = 0; index < values.length; index++) if (await visit(values[index], index, values)) return index;
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
export async function reduceAsync(values, visit, ...initial) {
|
|
102
|
+
let index = 0,
|
|
103
|
+
result;
|
|
104
|
+
if (initial.length) result = initial[0];
|
|
105
|
+
else {
|
|
106
|
+
if (!values.length) throw new TypeError("Reduce of empty array with no initial value");
|
|
107
|
+
result = values[index++];
|
|
108
|
+
}
|
|
109
|
+
for (; index < values.length; index++) result = await visit(result, values[index], index, values);
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
/** Read-only PostCSS walk: false stops the walk, as it does in PostCSS. */
|
|
113
|
+
export async function walkAsync(tree, method, ...args) {
|
|
114
|
+
const visit = args.pop(),
|
|
115
|
+
nodes = [];
|
|
116
|
+
tree[method](...args, (...parameters) => {
|
|
117
|
+
nodes.push(parameters);
|
|
118
|
+
});
|
|
119
|
+
for (const parameters of nodes) if ((await visit(...parameters)) === false) break;
|
|
120
|
+
return tree;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Value-parser walk: false prunes a function's children, not its siblings. */
|
|
124
|
+
export async function walkValuesAsync(tree, visit) {
|
|
125
|
+
async function walk(nodes) {
|
|
126
|
+
for (let index = 0; index < nodes.length; index++) {
|
|
127
|
+
const node = nodes[index];
|
|
128
|
+
if ((await visit(node, index, nodes)) !== false && node.type === "function" && Array.isArray(node.nodes)) await walk(node.nodes);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
await walk(tree.nodes);
|
|
132
|
+
return tree;
|
|
133
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { fork } from "node:child_process";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { readAnalysisInputs } from "./inputs.mjs";
|
|
4
|
+
import { developmentRuntime } from "../development-runtime.mjs";
|
|
5
|
+
|
|
6
|
+
let worker,
|
|
7
|
+
sequence = 0,
|
|
8
|
+
idle;
|
|
9
|
+
const pending = new Map(),
|
|
10
|
+
registered = new Set(),
|
|
11
|
+
baselines = new Map();
|
|
12
|
+
const cancelled = () =>
|
|
13
|
+
Object.assign(new Error("Analysis cancelled."), { code: "ADS_CANCELLED", diagnostic: { rule: "mutation-cancelled", message: "Analysis cancelled." } });
|
|
14
|
+
function failure(error, current = worker) {
|
|
15
|
+
if (current !== worker) return;
|
|
16
|
+
clearTimeout(idle);
|
|
17
|
+
worker = undefined;
|
|
18
|
+
registered.clear();
|
|
19
|
+
baselines.clear();
|
|
20
|
+
for (const task of pending.values()) task.reject(error);
|
|
21
|
+
pending.clear();
|
|
22
|
+
}
|
|
23
|
+
function start() {
|
|
24
|
+
if (worker) return worker;
|
|
25
|
+
worker = fork(new URL("./worker.mjs", import.meta.url), [], {
|
|
26
|
+
execPath: process.execPath,
|
|
27
|
+
execArgv: [],
|
|
28
|
+
serialization: "json",
|
|
29
|
+
stdio: ["ignore", "ignore", "inherit", "ipc"],
|
|
30
|
+
});
|
|
31
|
+
const current = worker;
|
|
32
|
+
current.on("message", ({ id, result, error }) => {
|
|
33
|
+
const task = pending.get(id);
|
|
34
|
+
pending.delete(id);
|
|
35
|
+
if (task) {
|
|
36
|
+
if (error) task.reject(Object.assign(new Error(error.message), error));
|
|
37
|
+
else task.resolve(result);
|
|
38
|
+
}
|
|
39
|
+
if (!pending.size && worker === current) {
|
|
40
|
+
current.unref();
|
|
41
|
+
current.channel?.unref?.();
|
|
42
|
+
idle = setTimeout(() => {
|
|
43
|
+
if (!registered.size) void closeAnalysis().catch(() => {});
|
|
44
|
+
}, 60000);
|
|
45
|
+
idle.unref();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
current.on("error", (error) => failure(error, current));
|
|
49
|
+
current.on("exit", (code) => failure(new Error(`Analysis service exited (${code}).`), current));
|
|
50
|
+
return current;
|
|
51
|
+
}
|
|
52
|
+
function request(message, signal) {
|
|
53
|
+
if (signal?.aborted) return Promise.reject(cancelled());
|
|
54
|
+
clearTimeout(idle);
|
|
55
|
+
const current = start(),
|
|
56
|
+
id = ++sequence;
|
|
57
|
+
current.ref();
|
|
58
|
+
current.channel?.ref?.();
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const abort = () => {
|
|
61
|
+
const task = pending.get(id);
|
|
62
|
+
pending.delete(id);
|
|
63
|
+
task?.reject(cancelled());
|
|
64
|
+
};
|
|
65
|
+
const timer = setTimeout(() => {
|
|
66
|
+
failure(Object.assign(new Error("Analysis request exceeded 60 seconds."), { code: "ADS_ANALYSIS_TIMEOUT" }), current);
|
|
67
|
+
current.kill();
|
|
68
|
+
}, 60000);
|
|
69
|
+
const done = (callback) => (value) => {
|
|
70
|
+
clearTimeout(timer);
|
|
71
|
+
signal?.removeEventListener("abort", abort);
|
|
72
|
+
callback(value);
|
|
73
|
+
};
|
|
74
|
+
pending.set(id, { resolve: done(resolve), reject: done(reject) });
|
|
75
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
76
|
+
current.send({ ...message, id, runtime: developmentRuntime() }, (error) => {
|
|
77
|
+
if (error) failure(error, current);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export function hasAnalysisRevision(root) {
|
|
82
|
+
return registered.has(path.resolve(root));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function registerAnalysisRevision(projectRoot, root, files, changes, dependencyRevision = "", signal) {
|
|
86
|
+
projectRoot = path.resolve(projectRoot);
|
|
87
|
+
root = path.resolve(root);
|
|
88
|
+
// Start before consulting the sent-inventory cache: a restarted worker has no
|
|
89
|
+
// prior baseline. Only changed source bytes cross IPC after the initial read.
|
|
90
|
+
start();
|
|
91
|
+
const saved = baselines.get(projectRoot),
|
|
92
|
+
previous = saved?.files ?? new Map();
|
|
93
|
+
const baselineChanges = [...new Set([...previous.keys(), ...files.keys()])]
|
|
94
|
+
.filter((file) => (previous.get(file) ?? null) !== (files.get(file) ?? null))
|
|
95
|
+
.map((file) => [file, files.get(file) ?? null]);
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
result = await request(
|
|
99
|
+
{ action: "register", projectRoot, root, baselineToken: saved?.token, baselineReset: !saved, baselineChanges, changes, dependencyRevision },
|
|
100
|
+
signal,
|
|
101
|
+
);
|
|
102
|
+
if (result.needsBaseline)
|
|
103
|
+
result = await request({ action: "register", projectRoot, root, baselineReset: true, baselineChanges: [...files], changes, dependencyRevision }, signal);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
// Registration may finish after its caller cancels. Queue disposal behind
|
|
106
|
+
// that request so abandoned drafts cannot pin a compiler revision forever.
|
|
107
|
+
if (worker) await request({ action: "release", root }).catch(() => {});
|
|
108
|
+
baselines.delete(projectRoot);
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
baselines.set(projectRoot, { files: new Map(files), token: result.baselineToken });
|
|
112
|
+
registered.add(root);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
export async function analyze(root, kind = "registry", args = [], signal) {
|
|
116
|
+
root = path.resolve(root);
|
|
117
|
+
const inputs = registered.has(root) ? undefined : await readAnalysisInputs(root);
|
|
118
|
+
if (inputs) baselines.delete(root);
|
|
119
|
+
return request(
|
|
120
|
+
{ action: "analyze", root, kind, args, ...(inputs ? { files: [...inputs.files], dependencyRevision: inputs.dependencyRevision } : {}) },
|
|
121
|
+
signal,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
export async function releaseAnalysisRevision(root) {
|
|
125
|
+
root = path.resolve(root);
|
|
126
|
+
if (!registered.delete(root) || !worker) return;
|
|
127
|
+
await request({ action: "release", root });
|
|
128
|
+
}
|
|
129
|
+
export async function promoteAnalysisRevision(root, projectRoot) {
|
|
130
|
+
root = path.resolve(root);
|
|
131
|
+
const result = await request({ action: "promote", root });
|
|
132
|
+
registered.delete(root);
|
|
133
|
+
baselines.delete(path.resolve(projectRoot));
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
export async function closeAnalysis() {
|
|
137
|
+
clearTimeout(idle);
|
|
138
|
+
if (!worker) return;
|
|
139
|
+
const current = worker;
|
|
140
|
+
try {
|
|
141
|
+
await request({ action: "close" });
|
|
142
|
+
} finally {
|
|
143
|
+
failure(new Error("Analysis service closed."), current);
|
|
144
|
+
current.kill();
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Library callers use the same native session as the service, without a second
|
|
2
|
+
// compiler implementation. A request context scopes discovery and memoization.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { NativeProject } from "./native-project.mjs";
|
|
5
|
+
import { readAnalysisInputs } from "./inputs.mjs";
|
|
6
|
+
import { currentAnalysis, runAnalysis } from "./context.mjs";
|
|
7
|
+
|
|
8
|
+
const projects = new Map();
|
|
9
|
+
let idle;
|
|
10
|
+
export async function closeStandaloneAnalysis() {
|
|
11
|
+
clearTimeout(idle);
|
|
12
|
+
const closing = [...projects.values()];
|
|
13
|
+
projects.clear();
|
|
14
|
+
for (const state of closing) {
|
|
15
|
+
await state.queue;
|
|
16
|
+
await state.project.close();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export async function withProjectAnalysis(root, run) {
|
|
20
|
+
root = path.resolve(root);
|
|
21
|
+
if (currentAnalysis()?.provideProgram && currentAnalysis().root === root) return run();
|
|
22
|
+
clearTimeout(idle);
|
|
23
|
+
let state = projects.get(root);
|
|
24
|
+
if (!state) {
|
|
25
|
+
if (projects.size >= 8) await closeStandaloneAnalysis();
|
|
26
|
+
projects.set(root, (state = { project: new NativeProject(root), queue: Promise.resolve() }));
|
|
27
|
+
}
|
|
28
|
+
const work = state.queue.then(async () => {
|
|
29
|
+
const inputs = await readAnalysisInputs(root);
|
|
30
|
+
const view = await state.project.synchronize(inputs.files, inputs.dependencyRevision);
|
|
31
|
+
return runAnalysis(root, run, {
|
|
32
|
+
revision: view,
|
|
33
|
+
provideProgram: (...args) => state.project.program(view, ...args),
|
|
34
|
+
provideSource: (file) => state.project.source(view, file),
|
|
35
|
+
readText: (file) => state.project.text(view, file),
|
|
36
|
+
listFiles: (directory) => state.project.files(view, directory),
|
|
37
|
+
resolveModule: (...args) => state.project.resolve(view, ...args),
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
state.queue = work.then(
|
|
41
|
+
() => {},
|
|
42
|
+
() => {},
|
|
43
|
+
);
|
|
44
|
+
try {
|
|
45
|
+
return await work;
|
|
46
|
+
} finally {
|
|
47
|
+
idle = setTimeout(() => {
|
|
48
|
+
void closeStandaloneAnalysis();
|
|
49
|
+
}, 1000);
|
|
50
|
+
idle.unref();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function standaloneProgram(purpose, roots, options) {
|
|
54
|
+
const root = purpose.slice(purpose.indexOf(":") + 1);
|
|
55
|
+
if (!path.isAbsolute(root)) throw new Error("A compiler request requires an absolute project root.");
|
|
56
|
+
return withProjectAnalysis(root, () => currentAnalysis().provideProgram(purpose, roots, options));
|
|
57
|
+
}
|