@motion-proto/live-tokens 0.77.0 → 0.79.0

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.
Files changed (177) hide show
  1. package/.claude/skills/live-tokens-check-compliance/SKILL.md +60 -29
  2. package/.claude/skills/live-tokens-create-component/SKILL.md +23 -28
  3. package/.claude/skills/live-tokens-create-component/references/contract-tests.md +61 -0
  4. package/.claude/skills/live-tokens-create-component/references/sketch-mode.md +2 -2
  5. package/.claude/skills/live-tokens-create-component/references/token-naming.md +6 -15
  6. package/.claude/skills/live-tokens-create-page/SKILL.md +9 -6
  7. package/.claude/skills/live-tokens-create-theme/references/design-directions.md +1 -1
  8. package/.claude/skills/live-tokens-pick-component/SKILL.md +3 -3
  9. package/.claude/skills/live-tokens-set-colors/references/color-anchors.md +1 -1
  10. package/.claude/skills/live-tokens-set-geometry/SKILL.md +1 -1
  11. package/.claude/skills/live-tokens-set-geometry/references/geometry-anchors.md +1 -1
  12. package/CHANGELOG.md +284 -0
  13. package/README.md +9 -15
  14. package/bin/check-component.mjs +152 -551
  15. package/bin/check-page.mjs +56 -420
  16. package/bin/cli.mjs +83 -15
  17. package/bin/contractRunner.mjs +380 -120
  18. package/bin/lib/catalogue.mjs +161 -34
  19. package/bin/lib/componentSource.mjs +152 -0
  20. package/bin/lib/cssValues.mjs +9 -0
  21. package/bin/lib/dataDir.mjs +126 -0
  22. package/bin/lib/findings.mjs +103 -12
  23. package/bin/lib/fixers.mjs +64 -0
  24. package/bin/lib/geometry.mjs +92 -0
  25. package/bin/lib/pageRoutes.mjs +309 -0
  26. package/bin/lib/pageSource.mjs +230 -0
  27. package/bin/lib/report.mjs +57 -59
  28. package/bin/lib/tokenVocabulary.mjs +104 -34
  29. package/bin/rules/componentStructure.mjs +344 -0
  30. package/bin/rules/componentUse.mjs +313 -0
  31. package/bin/rules/importsAndRoutes.mjs +136 -0
  32. package/bin/rules/testRuns.mjs +122 -0
  33. package/bin/rules/tokens.mjs +363 -0
  34. package/bin/setup-claude.mjs +1 -2
  35. package/dist-plugin/{chunk-PDNL4NC5.js → chunk-D4WRIKEZ.js} +7 -2
  36. package/dist-plugin/{chunk-SWXRVZKT.js → chunk-REBHE3ZM.js} +414 -1
  37. package/dist-plugin/index.cjs +432 -15
  38. package/dist-plugin/index.js +8 -9
  39. package/dist-plugin/migrateData/index.cjs +422 -4
  40. package/dist-plugin/migrateData/index.js +2 -2
  41. package/dist-plugin/setColors/index.cjs +414 -1
  42. package/dist-plugin/setColors/index.d.cts +1 -1
  43. package/dist-plugin/setColors/index.d.ts +1 -1
  44. package/dist-plugin/setColors/index.js +1 -1
  45. package/dist-plugin/setGeometry/index.cjs +423 -13
  46. package/dist-plugin/setGeometry/index.d.cts +3 -3
  47. package/dist-plugin/setGeometry/index.d.ts +3 -3
  48. package/dist-plugin/setGeometry/index.js +10 -13
  49. package/dist-plugin/setType/index.d.cts +1 -1
  50. package/dist-plugin/setType/index.d.ts +1 -1
  51. package/dist-plugin/{themeTypes-BxRtuN5V.d.cts → themeTypes-B8_Idrp4.d.cts} +2 -2
  52. package/dist-plugin/{themeTypes-BxRtuN5V.d.ts → themeTypes-B8_Idrp4.d.ts} +2 -2
  53. package/package.json +6 -4
  54. package/src/editor/component-editor/CalloutEditor.svelte +2 -2
  55. package/src/editor/component-editor/CollapsibleSectionEditor.svelte +14 -15
  56. package/src/editor/component-editor/CornerBadgeEditor.svelte +14 -14
  57. package/src/editor/component-editor/DialogEditor.svelte +5 -5
  58. package/src/editor/component-editor/InlineEditActionsEditor.svelte +2 -2
  59. package/src/editor/component-editor/RadioButtonEditor.svelte +21 -21
  60. package/src/editor/component-editor/SectionDividerEditor.svelte +7 -7
  61. package/src/editor/component-editor/SegmentedControlEditor.svelte +5 -5
  62. package/src/editor/component-editor/SideNavigationEditor.svelte +25 -25
  63. package/src/editor/component-editor/TabBarEditor.svelte +6 -6
  64. package/src/editor/component-editor/TableEditor.svelte +6 -6
  65. package/src/editor/component-editor/ToggleEditor.svelte +2 -2
  66. package/src/editor/component-editor/index.ts +3 -0
  67. package/src/editor/component-editor/registry.ts +57 -1
  68. package/src/editor/component-editor/scaffolding/TokenLayout.svelte +14 -14
  69. package/src/editor/component-editor/scaffolding/VariantGroup.svelte +3 -0
  70. package/src/editor/component-editor/scaffolding/types.ts +15 -0
  71. package/src/editor/core/components/adjustAliases.ts +4 -4
  72. package/src/editor/core/components/aliasKinds.ts +20 -19
  73. package/src/editor/core/sketch/sketchLayer.ts +3 -3
  74. package/src/editor/core/themes/migrateComponentConfig.ts +14 -6
  75. package/src/editor/core/themes/migrations/2026-09-13-badge-brand.ts +42 -0
  76. package/src/editor/core/themes/migrations/2026-09-13-collapsiblesection-open.ts +33 -0
  77. package/src/editor/core/themes/migrations/2026-09-13-cornerbadge-prefix.ts +70 -0
  78. package/src/editor/core/themes/migrations/2026-09-13-hairline.ts +92 -0
  79. package/src/editor/core/themes/migrations/2026-09-13-indicator.ts +54 -0
  80. package/src/editor/core/themes/migrations/2026-09-13-sectiondivider-surface.ts +36 -0
  81. package/src/editor/core/themes/migrations/2026-09-13-selected-state.ts +124 -0
  82. package/src/editor/core/themes/migrations/2026-09-13-toggle-label.ts +31 -0
  83. package/src/editor/core/themes/migrations/index.ts +16 -0
  84. package/src/editor/core/themes/themeService.ts +3 -3
  85. package/src/editor/core/themes/themeTypes.ts +13 -15
  86. package/src/editor/docs/Docs.svelte +1 -1
  87. package/src/editor/docs/content/light-and-dark.md +3 -3
  88. package/src/editor/docs/content.generated.ts +1 -1
  89. package/src/editor/index.ts +1 -0
  90. package/src/editor/overlay/ColumnsOverlay.svelte +1 -1
  91. package/src/editor/overlay/LiveEditorOverlay.svelte +16 -0
  92. package/src/editor/overlay/LiveTokensRouter.svelte +1 -0
  93. package/src/editor/skill-atlas/SkillAtlas.svelte +4 -4
  94. package/src/editor/skill-atlas/TreeNodeCard.svelte +4 -4
  95. package/src/editor/skill-atlas/skillSources.generated.ts +11 -14
  96. package/src/editor/skill-atlas/skillTrees.ts +1 -3
  97. package/src/editor/skill-atlas/trees/check-compliance.ts +258 -93
  98. package/src/editor/skill-atlas/trees/create-component.ts +73 -62
  99. package/src/editor/skill-atlas/trees/create-page.ts +54 -33
  100. package/src/editor/skill-atlas/trees/pick-component.ts +3 -3
  101. package/src/editor/skill-atlas/trees/set-geometry.ts +1 -1
  102. package/src/editor/ui/UIPaletteSelector.svelte +11 -15
  103. package/src/editor/ui/variantScales.ts +8 -8
  104. package/src/live-tokens/data/themes/autumn.json +188 -188
  105. package/src/live-tokens/data/themes/halloween.json +188 -188
  106. package/src/live-tokens/data/themes/midnight-study.json +245 -245
  107. package/src/live-tokens/data/themes/ocean.json +188 -188
  108. package/src/live-tokens/data/themes/royal-velvet.json +188 -188
  109. package/src/live-tokens/data/themes/sketchy.json +188 -188
  110. package/src/live-tokens/data/themes/spring-meadow.json +188 -188
  111. package/src/live-tokens/data/themes/sunset.json +188 -188
  112. package/src/system/components/Badge.svelte +27 -23
  113. package/src/system/components/Button.svelte +13 -7
  114. package/src/system/components/Callout.svelte +16 -11
  115. package/src/system/components/Card.svelte +22 -15
  116. package/src/system/components/CodeSnippet.svelte +10 -6
  117. package/src/system/components/CollapsibleSection.svelte +68 -63
  118. package/src/system/components/CornerBadge.svelte +78 -72
  119. package/src/system/components/Dialog.svelte +21 -18
  120. package/src/system/components/IconButton.svelte +13 -9
  121. package/src/system/components/Image.svelte +14 -8
  122. package/src/system/components/ImageLightbox.svelte +10 -6
  123. package/src/system/components/InlineEditActions.svelte +17 -14
  124. package/src/system/components/Input.svelte +13 -7
  125. package/src/system/components/MenuSelect.svelte +13 -7
  126. package/src/system/components/Notification.svelte +17 -11
  127. package/src/system/components/Panel.svelte +13 -6
  128. package/src/system/components/ProgressBar.svelte +10 -5
  129. package/src/system/components/RadioButton.svelte +33 -30
  130. package/src/system/components/SectionDivider.svelte +28 -21
  131. package/src/system/components/SegmentedControl.svelte +27 -23
  132. package/src/system/components/SideNavigation.svelte +175 -171
  133. package/src/system/components/Slider.svelte +11 -7
  134. package/src/system/components/TabBar.svelte +53 -49
  135. package/src/system/components/Table.svelte +20 -15
  136. package/src/system/components/Toggle.svelte +14 -10
  137. package/src/system/components/Tooltip.svelte +10 -6
  138. package/src/system/styles/CONVENTIONS.md +3 -4
  139. package/src/testing-js/chunk-3UKGXCDL.js +48 -0
  140. package/src/testing-js/chunk-3UKGXCDL.js.map +1 -0
  141. package/src/testing-js/{chunk-ZMSX6CXR.js → chunk-NB3NZRBM.js} +13 -2
  142. package/src/testing-js/chunk-NB3NZRBM.js.map +1 -0
  143. package/src/testing-js/{chunk-FAFOAWYL.js → chunk-Q3YIAAG3.js} +17 -3
  144. package/src/testing-js/chunk-Q3YIAAG3.js.map +1 -0
  145. package/src/testing-js/{chunk-7TI7Z6Y6.js → chunk-U7OJE5DU.js} +19 -19
  146. package/src/testing-js/chunk-U7OJE5DU.js.map +1 -0
  147. package/src/testing-js/{chunk-L73N4NSO.js → chunk-WIZ6W7UT.js} +2 -2
  148. package/src/testing-js/{chunk-4JQX6WWL.js → chunk-ZMZQZ33J.js} +474 -166
  149. package/src/testing-js/chunk-ZMZQZ33J.js.map +1 -0
  150. package/src/testing-js/component-alias.contract.js +2 -2
  151. package/src/testing-js/component-behavior.contract.js +155 -0
  152. package/src/testing-js/component-behavior.contract.js.map +1 -0
  153. package/src/testing-js/component-editor.contract.js +7 -5
  154. package/src/testing-js/component-editor.contract.js.map +1 -1
  155. package/src/testing-js/component-render.contract.js +15 -11
  156. package/src/testing-js/component-render.contract.js.map +1 -1
  157. package/src/testing-js/index.d.ts +50 -4
  158. package/src/testing-js/index.js +32 -8
  159. package/src/testing-js/index.js.map +1 -1
  160. package/src/testing-js/page-compliance.contract.js +867 -0
  161. package/src/testing-js/page-compliance.contract.js.map +1 -0
  162. package/src/testing-js/registry.contract.js +5 -3
  163. package/src/testing-js/registry.contract.js.map +1 -1
  164. package/src/testing-js/{vitest-BE6uGF31.d.ts → vitest-BMLIbDs2.d.ts} +29 -3
  165. package/src/testing-js/vitest.d.ts +1 -1
  166. package/src/testing-js/vitest.js +3 -2
  167. package/template/README.md +16 -9
  168. package/template/package.json +2 -2
  169. package/template/src/pages/Home.svelte +13 -0
  170. package/.claude/skills/live-tokens-create-component/SKILL copy.md +0 -196
  171. package/.claude/skills/live-tokens-fix-findings/SKILL.md +0 -98
  172. package/src/editor/skill-atlas/trees/fix-findings.ts +0 -469
  173. package/src/testing-js/chunk-4JQX6WWL.js.map +0 -1
  174. package/src/testing-js/chunk-7TI7Z6Y6.js.map +0 -1
  175. package/src/testing-js/chunk-FAFOAWYL.js.map +0 -1
  176. package/src/testing-js/chunk-ZMSX6CXR.js.map +0 -1
  177. /package/src/testing-js/{chunk-L73N4NSO.js.map → chunk-WIZ6W7UT.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { PlaywrightTestProject, PlaywrightTestConfig } from '@playwright/test';
2
- import { L as LiveTokensTestingConfig } from './vitest-BE6uGF31.js';
3
- export { C as COMPONENTS_PATH_ENV, a as COMPONENT_ENV, R as ResolvedTestingConfig, T as TESTING_CONFIG_FILE, V as VitestConfigOptions, c as createVitestConfig, d as defineTestingConfig, b as devServerCommand, r as resolveTestingConfig } from './vitest-BE6uGF31.js';
2
+ import { L as LiveTokensTestingConfig } from './vitest-BMLIbDs2.js';
3
+ export { C as COMPONENTS_PATH_ENV, a as COMPONENT_ENV, D as DEFAULT_PAGE_VIEWPORTS, P as PAGES_ENV, b as PAGE_VIEWPORTS_ENV, c as PageViewport, R as ResolvedTestingConfig, T as TESTING_CONFIG_FILE, V as VitestConfigOptions, d as createVitestConfig, e as defineTestingConfig, f as devServerCommand, r as resolveTestingConfig } from './vitest-BMLIbDs2.js';
4
4
  import 'vite';
5
5
  import 'vitest/config';
6
6
 
@@ -11,6 +11,12 @@ interface PlaywrightConfigOptions extends LiveTokensTestingConfig {
11
11
  extraProjects?: PlaywrightTestProject[];
12
12
  /** Where projects that declare no `testDir` of their own look. */
13
13
  testDir?: string;
14
+ /** Bounds the whole run. Default fifteen minutes, the same bound
15
+ * `check-component --tests` and `check-page --tests` hold their spawned
16
+ * child to (`LIVE_TOKENS_TESTS_TIMEOUT` in `bin/contractRunner.mjs`), so a
17
+ * hung run stops here too, for a caller that invokes this factory
18
+ * directly rather than through the CLI. */
19
+ globalTimeout?: number;
14
20
  }
15
21
  /**
16
22
  * The contract project, its dev server, and the data isolation the two share.
@@ -54,7 +60,7 @@ declare const PORT_ENV = "LIVE_TOKENS_TEST_PORT";
54
60
  */
55
61
  declare function resolvePort(preferred?: number): number;
56
62
 
57
- type ContractRule = 'contract-listed' | 'contract-render' | 'contract-alias' | 'contract-persist' | 'contract-theme' | 'contract-preview' | 'contract-sketch' | 'contract-missing';
63
+ type ContractRule = 'contract-listed' | 'contract-render' | 'contract-alias' | 'contract-persist' | 'contract-theme' | 'contract-states' | 'contract-interaction' | 'contract-behavior' | 'contract-sketch' | 'contract-missing';
58
64
  /**
59
65
  * A failed obligation, carrying the rule id the CLI reports it under. A defect
60
66
  * fixture names the rule it expects, and `check-component --tests` maps a
@@ -235,6 +241,44 @@ interface InteractionExpectation {
235
241
  role: string;
236
242
  cases: InteractionCase[];
237
243
  }
244
+ /**
245
+ * One mounted case under happy-dom: props in, a DOM event, one assertion. It
246
+ * carries what a browser cannot reach, the callback a controlled component
247
+ * calls instead of moving its own state.
248
+ */
249
+ interface BehaviorCase {
250
+ name: string;
251
+ /** Props the fixture mounts with. A snippet-valued prop is not
252
+ * expressible; a component whose behavior needs one records that case
253
+ * as inapplicable with the reason. */
254
+ props?: Record<string, unknown>;
255
+ action?: {
256
+ kind: 'click' | 'keydown' | 'input';
257
+ part: string;
258
+ key?: string;
259
+ value?: string;
260
+ };
261
+ expect: {
262
+ kind: 'callback';
263
+ prop: string;
264
+ args: unknown[];
265
+ } | {
266
+ kind: 'no-callback';
267
+ prop: string;
268
+ } | {
269
+ kind: 'attribute';
270
+ part: string;
271
+ name: string;
272
+ value: string | null;
273
+ } | {
274
+ kind: 'text';
275
+ part: string;
276
+ value: string;
277
+ };
278
+ }
279
+ interface BehaviorExpectation {
280
+ cases: BehaviorCase[];
281
+ }
238
282
  interface SketchPartExpectation {
239
283
  part: string;
240
284
  /** The design token `--sketch-fill` must resolve to on this part. */
@@ -273,6 +317,8 @@ interface ComponentContract {
273
317
  persistence: PersistenceExpectation;
274
318
  theme: ThemeExpectation;
275
319
  interaction: InteractionExpectation | Inapplicable;
320
+ /** What the component does when it is driven, proven under happy-dom. */
321
+ behavior: BehaviorExpectation | Inapplicable;
276
322
  sketch: SketchExpectation | Inapplicable;
277
323
  }
278
324
  declare function requiresInteraction(role: string | null): boolean;
@@ -290,4 +336,4 @@ declare function allContracts(contracts?: ComponentContract[]): Promise<Componen
290
336
  /** The contracts a run covers, narrowed by `LIVE_TOKENS_COMPONENT`. */
291
337
  declare function selectedContracts(contracts?: ComponentContract[]): Promise<ComponentContract[]>;
292
338
 
293
- export { CONTRACTS_MODULE_ENV, type ComponentContract, type ContractRule, ContractViolation, type ControlStep, DATA_DIR_ENV, type Inapplicable, type InteractionAction, type InteractionCase, type InteractionExpectation, type InteractionOutcome, type IsolatedData, LiveTokensTestingConfig, PORT_ENV, type PaintMap, type PartDeclaration, type PartLocator, type PersistenceCase, type PersistenceExpectation, type PersistenceShape, type PlaywrightConfigOptions, type PropertyExpectation, type SetupStep, type SketchExpectation, type SketchPartExpectation, type StateExpectation, TEST_DATA_DIR_ENV, type ThemeExpectation, type View, allContracts, createPlaywrightConfig, isInapplicable, isolateDataDir, partLocator, requiresInteraction, resolvePort, selectedContracts, shippedContracts };
339
+ export { type BehaviorCase, type BehaviorExpectation, CONTRACTS_MODULE_ENV, type ComponentContract, type ContractRule, ContractViolation, type ControlStep, DATA_DIR_ENV, type Inapplicable, type InteractionAction, type InteractionCase, type InteractionExpectation, type InteractionOutcome, type IsolatedData, LiveTokensTestingConfig, PORT_ENV, type PaintMap, type PartDeclaration, type PartLocator, type PersistenceCase, type PersistenceExpectation, type PersistenceShape, type PlaywrightConfigOptions, type PropertyExpectation, type SetupStep, type SketchExpectation, type SketchPartExpectation, type StateExpectation, TEST_DATA_DIR_ENV, type ThemeExpectation, type View, allContracts, createPlaywrightConfig, isInapplicable, isolateDataDir, partLocator, requiresInteraction, resolvePort, selectedContracts, shippedContracts };
@@ -1,24 +1,29 @@
1
1
  import {
2
- CONTRACTS_MODULE_ENV,
3
2
  ContractViolation,
4
- allContracts,
5
3
  isInapplicable,
6
4
  partLocator,
7
- requiresInteraction,
8
- selectedContracts,
9
- shippedContracts
10
- } from "./chunk-4JQX6WWL.js";
5
+ requiresInteraction
6
+ } from "./chunk-3UKGXCDL.js";
11
7
  import {
12
8
  createVitestConfig
13
- } from "./chunk-FAFOAWYL.js";
9
+ } from "./chunk-Q3YIAAG3.js";
14
10
  import {
15
11
  COMPONENTS_PATH_ENV,
16
12
  COMPONENT_ENV,
13
+ DEFAULT_PAGE_VIEWPORTS,
14
+ PAGES_ENV,
15
+ PAGE_VIEWPORTS_ENV,
17
16
  TESTING_CONFIG_FILE,
18
17
  defineTestingConfig,
19
18
  devServerCommand,
20
19
  resolveTestingConfig
21
- } from "./chunk-ZMSX6CXR.js";
20
+ } from "./chunk-NB3NZRBM.js";
21
+ import {
22
+ CONTRACTS_MODULE_ENV,
23
+ allContracts,
24
+ selectedContracts,
25
+ shippedContracts
26
+ } from "./chunk-ZMZQZ33J.js";
22
27
 
23
28
  // src/testing/playwright.ts
24
29
  import path2 from "path";
@@ -109,12 +114,14 @@ function resolvePort(preferred) {
109
114
  // src/testing/playwright.ts
110
115
  var HOST = "127.0.0.1";
111
116
  var CONTRACT_TEST_DIR = path2.dirname(fileURLToPath(import.meta.url));
117
+ var DEFAULT_GLOBAL_TIMEOUT_MS = 15 * 6e4;
112
118
  async function createPlaywrightConfig(options = {}) {
113
119
  const settings = resolveTestingConfig(options, options.root);
114
120
  const { dataDir } = isolateDataDir(settings.dataDir);
115
121
  const port = resolvePort(settings.port);
116
122
  const baseURL = `http://${HOST}:${port}`;
117
123
  process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;
124
+ process.env[PAGE_VIEWPORTS_ENV] = JSON.stringify(settings.pageViewports);
118
125
  if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;
119
126
  return defineConfig({
120
127
  testDir: options.testDir ?? CONTRACT_TEST_DIR,
@@ -128,6 +135,7 @@ async function createPlaywrightConfig(options = {}) {
128
135
  // command line.
129
136
  workers: 1,
130
137
  timeout: 3e4,
138
+ globalTimeout: options.globalTimeout ?? DEFAULT_GLOBAL_TIMEOUT_MS,
131
139
  expect: { timeout: 5e3 },
132
140
  // A shared-server suite times out under CI load in ways it never does
133
141
  // locally, and without a retry budget one wobble aborts a tagged release.
@@ -158,12 +166,25 @@ async function createPlaywrightConfig(options = {}) {
158
166
  // `.ts` in this repo, `.js` once tsup compiles the shipped build into
159
167
  // `src/testing-js`; matching both here needs no build-time swap.
160
168
  testMatch: "**/component-*.contract.{ts,js}",
169
+ // The behavior suite shares the prefix and runs under Vitest. Left in,
170
+ // Playwright collects it, meets its Svelte imports and reports the
171
+ // whole project as collecting nothing.
172
+ testIgnore: "**/component-behavior.contract.{ts,js}",
161
173
  // `.tabs-preview` now caps its sticky band at 50vh, which is enough for
162
174
  // image, panel, card and sidenavigation to pass alone at 1280x720. A
163
175
  // full parallel run still fails panel's gradient radio there, so the
164
176
  // band can cover a control at some scroll positions. Until that is
165
177
  // fixed the suite runs taller. See docs/contract-test-defects.md.
166
178
  use: { ...devices["Desktop Chrome"], viewport: { width: 1280, height: 900 } }
179
+ },
180
+ {
181
+ name: "page",
182
+ testDir: CONTRACT_TEST_DIR,
183
+ testMatch: "**/page-*.contract.{ts,js}",
184
+ // The suite sizes the window itself, once per viewport in
185
+ // `pageViewports`, so the sizes stay one list rather than a project
186
+ // per viewport whose name the reporter would have to decode.
187
+ use: { ...devices["Desktop Chrome"] }
167
188
  }
168
189
  ],
169
190
  webServer: {
@@ -192,6 +213,9 @@ export {
192
213
  CONTRACTS_MODULE_ENV,
193
214
  ContractViolation,
194
215
  DATA_DIR_ENV,
216
+ DEFAULT_PAGE_VIEWPORTS,
217
+ PAGES_ENV,
218
+ PAGE_VIEWPORTS_ENV,
195
219
  PORT_ENV,
196
220
  TESTING_CONFIG_FILE,
197
221
  TEST_DATA_DIR_ENV,
@@ -1 +1 @@
1
- {"version":3,"sources":["../testing/playwright.ts","../testing/isolation.ts","../testing/port.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n defineConfig,\n devices,\n type PlaywrightTestConfig,\n type PlaywrightTestProject,\n} from '@playwright/test';\nimport {\n COMPONENT_ENV,\n COMPONENTS_PATH_ENV,\n devServerCommand,\n resolveTestingConfig,\n type LiveTokensTestingConfig,\n} from './config';\nimport { CONTRACTS_MODULE_ENV } from './contracts';\nimport { DATA_DIR_ENV, TEST_DATA_DIR_ENV, isolateDataDir } from './isolation';\nimport { resolvePort } from './port';\n\nconst HOST = '127.0.0.1';\n\n/** The shipped suites, wherever the package is installed. */\nconst CONTRACT_TEST_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface PlaywrightConfigOptions extends LiveTokensTestingConfig {\n /** Project root the settings resolve against. Default `process.cwd()`. */\n root?: string;\n /** Projects that run beside the contract project. */\n extraProjects?: PlaywrightTestProject[];\n /** Where projects that declare no `testDir` of their own look. */\n testDir?: string;\n}\n\n/**\n * The contract project, its dev server, and the data isolation the two share.\n *\n * Isolation runs here rather than in a global setup because the config is the\n * first thing every process in the run evaluates: the environment it leaves\n * behind reaches the workers and the dev server, and nothing in the run can\n * observe the state before it.\n */\nexport async function createPlaywrightConfig(\n options: PlaywrightConfigOptions = {},\n): Promise<PlaywrightTestConfig> {\n const settings = resolveTestingConfig(options, options.root);\n const { dataDir } = isolateDataDir(settings.dataDir);\n const port = resolvePort(settings.port);\n const baseURL = `http://${HOST}:${port}`;\n\n process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;\n if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;\n\n return defineConfig({\n testDir: options.testDir ?? CONTRACT_TEST_DIR,\n // The component suites carry their serial and parallel intent per file:\n // `component-editor.contract.ts` runs each component's save and reset\n // cycles in order against one data tree. Turning this on would interleave\n // them.\n fullyParallel: false,\n // One worker is the safe default: the specs share a dev server and a data\n // directory. A run that can afford more passes a worker count on the\n // command line.\n workers: 1,\n timeout: 30_000,\n expect: { timeout: 5_000 },\n // A shared-server suite times out under CI load in ways it never does\n // locally, and without a retry budget one wobble aborts a tagged release.\n retries: process.env.CI ? 2 : 0,\n // Absolute and rooted at the consumer project, not the config file's own\n // directory: `check-component --tests`'s generated config lives in a\n // temporary directory that gets removed on completion, and a relative\n // `outputDir` would put every trace and screenshot in there too.\n outputDir: path.join(settings.root, 'test-results/playwright'),\n reporter: process.env.CI ? [['line'], ['html', { open: 'never' }]] : 'list',\n use: {\n baseURL,\n // Unset, both of these are unbounded: a locator that never resolves waits\n // out the whole test timeout and reports nothing about where it stopped.\n actionTimeout: 10_000,\n navigationTimeout: 30_000,\n trace: 'on-first-retry',\n screenshot: 'only-on-failure',\n // `retain-on-failure` still records every passing test and throws the\n // file away, which costs ~28% CPU. Match the trace policy instead.\n video: 'on-first-retry',\n },\n projects: [\n ...(options.extraProjects ?? []),\n {\n name: 'contract',\n testDir: CONTRACT_TEST_DIR,\n // `.ts` in this repo, `.js` once tsup compiles the shipped build into\n // `src/testing-js`; matching both here needs no build-time swap.\n testMatch: '**/component-*.contract.{ts,js}',\n // `.tabs-preview` now caps its sticky band at 50vh, which is enough for\n // image, panel, card and sidenavigation to pass alone at 1280x720. A\n // full parallel run still fails panel's gradient radio there, so the\n // band can cover a control at some scroll positions. Until that is\n // fixed the suite runs taller. See docs/contract-test-defects.md.\n use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 900 } },\n },\n ],\n webServer: {\n command: devServerCommand(settings.devCommand, HOST, port),\n // Otherwise defaults to the config file's own directory. A generated\n // config that lives outside the consumer root (`check-component\n // --tests`'s temporary config) would run `npm run dev` from wherever\n // that happens to be instead.\n cwd: settings.root,\n url: baseURL,\n // A server this run did not start carries none of these variables, so it\n // would write the project's own data tree.\n reuseExistingServer: false,\n timeout: 120_000,\n env: {\n ...process.env,\n [TEST_DATA_DIR_ENV]: dataDir,\n [DATA_DIR_ENV]: dataDir,\n },\n },\n });\n}\n","import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\n/**\n * The plugin reads this name ahead of its own options and\n * `live-tokens.config.json`, so setting it redirects every server-side write —\n * the data tree, `tokens.generated.css`, and `fonts.css` — into the copy.\n */\nexport const TEST_DATA_DIR_ENV = 'LIVE_TOKENS_TEST_DATA_DIR';\n\n/** What the suites and the harness read component configs from in the runner's\n * own process. It names the same directory and is a separate variable because\n * it answers a different question: where a reader looks, not where the server\n * is confined. */\nexport const DATA_DIR_ENV = 'LIVE_TOKENS_DATA_DIR';\n\n/**\n * A developer's current session rather than the document under test. Each one\n * is gitignored or dev-written, so leaving it in the copy would make the run\n * pass or fail on whichever theme the maintainer has open.\n *\n * _working.json an unsaved buffer, which reads as a dirty document and\n * can raise a destructive confirmation dialog\n * _active.json the theme the editor has open. One carrying a sketchstyle\n * boots the suite with the sketch layer on, which paints\n * every fill onto a pseudo-element and leaves the real\n * background transparent\n * _production.json the theme baked into tokens.generated.css\n *\n * A missing pointer resolves to \"default\" at runtime, so removing them is the\n * whole reset.\n */\nconst SESSION_FILES = new Set(['_working.json', '_active.json', '_production.json']);\n\nexport interface IsolatedData {\n dataDir: string;\n /** True when this process made the copy and owns removing it. */\n created: boolean;\n}\n\nlet removed = false;\n\nfunction registerCleanup(dataDir: string): void {\n const remove = () => {\n if (removed) return;\n removed = true;\n fs.rmSync(dataDir, { recursive: true, force: true });\n };\n process.once('exit', remove);\n // Playwright owns the exit path on a signal: it stops the workers and kills\n // the dev server's process group, then exits, which reaches `exit` above.\n // These two only make sure the copy is gone before that teardown starts.\n process.once('SIGINT', remove);\n process.once('SIGTERM', remove);\n}\n\n/**\n * Copy `sourceDataDir` into a unique temporary directory and point both the\n * server and the runner at it. Idempotent across processes: Playwright loads\n * the config again in every worker, and each inherits the parent's environment,\n * so only the first call copies anything.\n */\nexport function isolateDataDir(sourceDataDir: string): IsolatedData {\n const existing = process.env[TEST_DATA_DIR_ENV];\n if (existing) {\n const dataDir = path.resolve(existing);\n if (!fs.existsSync(dataDir)) {\n throw new Error(`${TEST_DATA_DIR_ENV} names ${dataDir}, which does not exist`);\n }\n process.env[DATA_DIR_ENV] = dataDir;\n return { dataDir, created: false };\n }\n\n const source = path.resolve(sourceDataDir);\n if (!fs.existsSync(source)) {\n throw new Error(\n `No data directory at ${source}. Set \\`dataDir\\` in live-tokens.testing.ts `\n + 'when the project keeps its live-tokens data somewhere else.',\n );\n }\n\n // realpath: macOS resolves os.tmpdir() through a symlink, and the plugin\n // compares resolved paths when it decides whether a write is in scope.\n const dataDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'live-tokens-contract-')));\n fs.cpSync(source, dataDir, { recursive: true });\n for (const entry of fs.readdirSync(dataDir, { recursive: true }) as string[]) {\n if (SESSION_FILES.has(path.basename(entry))) {\n fs.rmSync(path.join(dataDir, entry), { force: true });\n }\n }\n\n process.env[TEST_DATA_DIR_ENV] = dataDir;\n process.env[DATA_DIR_ENV] = dataDir;\n registerCleanup(dataDir);\n return { dataDir, created: true };\n}\n","import { execFileSync } from 'node:child_process';\n\nexport const PORT_ENV = 'LIVE_TOKENS_TEST_PORT';\n\nconst PREFERRED_PORT = 4173;\n\n/** Bind the preferred port, fall back to whatever the OS hands out, print the\n * answer. A Playwright config is evaluated synchronously, so the check runs in\n * a child rather than on a listener callback. */\nconst PROBE = `\nconst net = require('net');\nconst listen = (port) => new Promise((resolve, reject) => {\n const server = net.createServer();\n server.once('error', reject);\n server.listen(port, '127.0.0.1', () => {\n const { port: bound } = server.address();\n server.close(() => resolve(bound));\n });\n});\n// process.stdout.write, not console.log: the parent's FORCE_COLOR makes\n// console.log wrap a number in ANSI escapes.\nlisten(Number(process.argv[1])).catch(() => listen(0)).then((port) => process.stdout.write(String(port)));\n`;\n\n/**\n * The port the dev server and `baseURL` share. Cached in the environment so\n * every Playwright worker, which loads the config again in its own process,\n * reads the port the main process settled on.\n */\nexport function resolvePort(preferred?: number): number {\n const cached = process.env[PORT_ENV];\n if (cached) return Number(cached);\n\n const port = preferred\n ?? Number(execFileSync(process.execPath, ['-e', PROBE, String(PREFERRED_PORT)], {\n encoding: 'utf-8',\n }).trim());\n if (!Number.isInteger(port) || port <= 0) {\n throw new Error(`Could not settle on a dev-server port (read ${port})`);\n }\n process.env[PORT_ENV] = String(port);\n return port;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;;;ACPP,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAOV,IAAM,oBAAoB;AAM1B,IAAM,eAAe;AAkB5B,IAAM,gBAAgB,oBAAI,IAAI,CAAC,iBAAiB,gBAAgB,kBAAkB,CAAC;AAQnF,IAAI,UAAU;AAEd,SAAS,gBAAgB,SAAuB;AAC9C,QAAM,SAAS,MAAM;AACnB,QAAI,QAAS;AACb,cAAU;AACV,OAAG,OAAO,SAAS,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACrD;AACA,UAAQ,KAAK,QAAQ,MAAM;AAI3B,UAAQ,KAAK,UAAU,MAAM;AAC7B,UAAQ,KAAK,WAAW,MAAM;AAChC;AAQO,SAAS,eAAe,eAAqC;AAClE,QAAM,WAAW,QAAQ,IAAI,iBAAiB;AAC9C,MAAI,UAAU;AACZ,UAAMC,WAAU,KAAK,QAAQ,QAAQ;AACrC,QAAI,CAAC,GAAG,WAAWA,QAAO,GAAG;AAC3B,YAAM,IAAI,MAAM,GAAG,iBAAiB,UAAUA,QAAO,wBAAwB;AA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;AAAA;AAAA,QAMX,KAAK,EAAE,GAAG,QAAQ,gBAAgB,GAAG,UAAU,EAAE,OAAO,MAAM,QAAQ,IAAI,EAAE;AAAA,MAC9E;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,SAAS,iBAAiB,SAAS,YAAY,MAAM,IAAI;AAAA;AAAA;AAAA;AAAA;AAAA,MAKzD,KAAK,SAAS;AAAA,MACd,KAAK;AAAA;AAAA;AAAA,MAGL,qBAAqB;AAAA,MACrB,SAAS;AAAA,MACT,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,CAAC,iBAAiB,GAAG;AAAA,QACrB,CAAC,YAAY,GAAG;AAAA,MAClB;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":["path","dataDir","path"]}
1
+ {"version":3,"sources":["../testing/playwright.ts","../testing/isolation.ts","../testing/port.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport {\n defineConfig,\n devices,\n type PlaywrightTestConfig,\n type PlaywrightTestProject,\n} from '@playwright/test';\nimport {\n COMPONENT_ENV,\n COMPONENTS_PATH_ENV,\n PAGE_VIEWPORTS_ENV,\n devServerCommand,\n resolveTestingConfig,\n type LiveTokensTestingConfig,\n} from './config';\nimport { CONTRACTS_MODULE_ENV } from './contracts';\nimport { DATA_DIR_ENV, TEST_DATA_DIR_ENV, isolateDataDir } from './isolation';\nimport { resolvePort } from './port';\n\nconst HOST = '127.0.0.1';\n\n/** The shipped suites, wherever the package is installed. */\nconst CONTRACT_TEST_DIR = path.dirname(fileURLToPath(import.meta.url));\n\nexport interface PlaywrightConfigOptions extends LiveTokensTestingConfig {\n /** Project root the settings resolve against. Default `process.cwd()`. */\n root?: string;\n /** Projects that run beside the contract project. */\n extraProjects?: PlaywrightTestProject[];\n /** Where projects that declare no `testDir` of their own look. */\n testDir?: string;\n /** Bounds the whole run. Default fifteen minutes, the same bound\n * `check-component --tests` and `check-page --tests` hold their spawned\n * child to (`LIVE_TOKENS_TESTS_TIMEOUT` in `bin/contractRunner.mjs`), so a\n * hung run stops here too, for a caller that invokes this factory\n * directly rather than through the CLI. */\n globalTimeout?: number;\n}\n\n/** Mirrors `bin/contractRunner.mjs`'s own `DEFAULT_TESTS_TIMEOUT_MS`,\n * duplicated because that file is plain JS and cannot import this module\n * before `build:testing` compiles it (see `bin/engineLoadsLazily.test.ts`). */\nconst DEFAULT_GLOBAL_TIMEOUT_MS = 15 * 60_000;\n\n/**\n * The contract project, its dev server, and the data isolation the two share.\n *\n * Isolation runs here rather than in a global setup because the config is the\n * first thing every process in the run evaluates: the environment it leaves\n * behind reaches the workers and the dev server, and nothing in the run can\n * observe the state before it.\n */\nexport async function createPlaywrightConfig(\n options: PlaywrightConfigOptions = {},\n): Promise<PlaywrightTestConfig> {\n const settings = resolveTestingConfig(options, options.root);\n const { dataDir } = isolateDataDir(settings.dataDir);\n const port = resolvePort(settings.port);\n const baseURL = `http://${HOST}:${port}`;\n\n process.env[COMPONENTS_PATH_ENV] = settings.componentsPath;\n process.env[PAGE_VIEWPORTS_ENV] = JSON.stringify(settings.pageViewports);\n if (settings.contractsModule) process.env[CONTRACTS_MODULE_ENV] = settings.contractsModule;\n\n return defineConfig({\n testDir: options.testDir ?? CONTRACT_TEST_DIR,\n // The component suites carry their serial and parallel intent per file:\n // `component-editor.contract.ts` runs each component's save and reset\n // cycles in order against one data tree. Turning this on would interleave\n // them.\n fullyParallel: false,\n // One worker is the safe default: the specs share a dev server and a data\n // directory. A run that can afford more passes a worker count on the\n // command line.\n workers: 1,\n timeout: 30_000,\n globalTimeout: options.globalTimeout ?? DEFAULT_GLOBAL_TIMEOUT_MS,\n expect: { timeout: 5_000 },\n // A shared-server suite times out under CI load in ways it never does\n // locally, and without a retry budget one wobble aborts a tagged release.\n retries: process.env.CI ? 2 : 0,\n // Absolute and rooted at the consumer project, not the config file's own\n // directory: `check-component --tests`'s generated config lives in a\n // temporary directory that gets removed on completion, and a relative\n // `outputDir` would put every trace and screenshot in there too.\n outputDir: path.join(settings.root, 'test-results/playwright'),\n reporter: process.env.CI ? [['line'], ['html', { open: 'never' }]] : 'list',\n use: {\n baseURL,\n // Unset, both of these are unbounded: a locator that never resolves waits\n // out the whole test timeout and reports nothing about where it stopped.\n actionTimeout: 10_000,\n navigationTimeout: 30_000,\n trace: 'on-first-retry',\n screenshot: 'only-on-failure',\n // `retain-on-failure` still records every passing test and throws the\n // file away, which costs ~28% CPU. Match the trace policy instead.\n video: 'on-first-retry',\n },\n projects: [\n ...(options.extraProjects ?? []),\n {\n name: 'contract',\n testDir: CONTRACT_TEST_DIR,\n // `.ts` in this repo, `.js` once tsup compiles the shipped build into\n // `src/testing-js`; matching both here needs no build-time swap.\n testMatch: '**/component-*.contract.{ts,js}',\n // The behavior suite shares the prefix and runs under Vitest. Left in,\n // Playwright collects it, meets its Svelte imports and reports the\n // whole project as collecting nothing.\n testIgnore: '**/component-behavior.contract.{ts,js}',\n // `.tabs-preview` now caps its sticky band at 50vh, which is enough for\n // image, panel, card and sidenavigation to pass alone at 1280x720. A\n // full parallel run still fails panel's gradient radio there, so the\n // band can cover a control at some scroll positions. Until that is\n // fixed the suite runs taller. See docs/contract-test-defects.md.\n use: { ...devices['Desktop Chrome'], viewport: { width: 1280, height: 900 } },\n },\n {\n name: 'page',\n testDir: CONTRACT_TEST_DIR,\n testMatch: '**/page-*.contract.{ts,js}',\n // The suite sizes the window itself, once per viewport in\n // `pageViewports`, so the sizes stay one list rather than a project\n // per viewport whose name the reporter would have to decode.\n use: { ...devices['Desktop Chrome'] },\n },\n ],\n webServer: {\n command: devServerCommand(settings.devCommand, HOST, port),\n // Otherwise defaults to the config file's own directory. A generated\n // config that lives outside the consumer root (`check-component\n // --tests`'s temporary config) would run `npm run dev` from wherever\n // that happens to be instead.\n cwd: settings.root,\n url: baseURL,\n // A server this run did not start carries none of these variables, so it\n // would write the project's own data tree.\n reuseExistingServer: false,\n timeout: 120_000,\n env: {\n ...process.env,\n [TEST_DATA_DIR_ENV]: dataDir,\n [DATA_DIR_ENV]: dataDir,\n },\n },\n });\n}\n","import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\n\n/**\n * The plugin reads this name ahead of its own options and\n * `live-tokens.config.json`, so setting it redirects every server-side write —\n * the data tree, `tokens.generated.css`, and `fonts.css` — into the copy.\n */\nexport const TEST_DATA_DIR_ENV = 'LIVE_TOKENS_TEST_DATA_DIR';\n\n/** What the suites and the harness read component configs from in the runner's\n * own process. It names the same directory and is a separate variable because\n * it answers a different question: where a reader looks, not where the server\n * is confined. */\nexport const DATA_DIR_ENV = 'LIVE_TOKENS_DATA_DIR';\n\n/**\n * A developer's current session rather than the document under test. Each one\n * is gitignored or dev-written, so leaving it in the copy would make the run\n * pass or fail on whichever theme the maintainer has open.\n *\n * _working.json an unsaved buffer, which reads as a dirty document and\n * can raise a destructive confirmation dialog\n * _active.json the theme the editor has open. One carrying a sketchstyle\n * boots the suite with the sketch layer on, which paints\n * every fill onto a pseudo-element and leaves the real\n * background transparent\n * _production.json the theme baked into tokens.generated.css\n *\n * A missing pointer resolves to \"default\" at runtime, so removing them is the\n * whole reset.\n */\nconst SESSION_FILES = new Set(['_working.json', '_active.json', '_production.json']);\n\nexport interface IsolatedData {\n dataDir: string;\n /** True when this process made the copy and owns removing it. */\n created: boolean;\n}\n\nlet removed = false;\n\nfunction registerCleanup(dataDir: string): void {\n const remove = () => {\n if (removed) return;\n removed = true;\n fs.rmSync(dataDir, { recursive: true, force: true });\n };\n process.once('exit', remove);\n // Playwright owns the exit path on a signal: it stops the workers and kills\n // the dev server's process group, then exits, which reaches `exit` above.\n // These two only make sure the copy is gone before that teardown starts.\n process.once('SIGINT', remove);\n process.once('SIGTERM', remove);\n}\n\n/**\n * Copy `sourceDataDir` into a unique temporary directory and point both the\n * server and the runner at it. Idempotent across processes: Playwright loads\n * the config again in every worker, and each inherits the parent's environment,\n * so only the first call copies anything.\n */\nexport function isolateDataDir(sourceDataDir: string): IsolatedData {\n const existing = process.env[TEST_DATA_DIR_ENV];\n if (existing) {\n const dataDir = path.resolve(existing);\n if (!fs.existsSync(dataDir)) {\n throw new Error(`${TEST_DATA_DIR_ENV} names ${dataDir}, which does not exist`);\n }\n process.env[DATA_DIR_ENV] = dataDir;\n return { dataDir, created: false };\n }\n\n const source = path.resolve(sourceDataDir);\n if (!fs.existsSync(source)) {\n throw new Error(\n `No data directory at ${source}. Set \\`dataDir\\` in live-tokens.testing.ts `\n + 'when the project keeps its live-tokens data somewhere else.',\n );\n }\n\n // realpath: macOS resolves os.tmpdir() through a symlink, and the plugin\n // compares resolved paths when it decides whether a write is in scope.\n const dataDir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'live-tokens-contract-')));\n fs.cpSync(source, dataDir, { recursive: true });\n for (const entry of fs.readdirSync(dataDir, { recursive: true }) as string[]) {\n if (SESSION_FILES.has(path.basename(entry))) {\n fs.rmSync(path.join(dataDir, entry), { force: true });\n }\n }\n\n process.env[TEST_DATA_DIR_ENV] = dataDir;\n process.env[DATA_DIR_ENV] = dataDir;\n registerCleanup(dataDir);\n return { dataDir, created: true };\n}\n","import { execFileSync } from 'node:child_process';\n\nexport const PORT_ENV = 'LIVE_TOKENS_TEST_PORT';\n\nconst PREFERRED_PORT = 4173;\n\n/** Bind the preferred port, fall back to whatever the OS hands out, print the\n * answer. A Playwright config is evaluated synchronously, so the check runs in\n * a child rather than on a listener callback. */\nconst PROBE = `\nconst net = require('net');\nconst listen = (port) => new Promise((resolve, reject) => {\n const server = net.createServer();\n server.once('error', reject);\n server.listen(port, '127.0.0.1', () => {\n const { port: bound } = server.address();\n server.close(() => resolve(bound));\n });\n});\n// process.stdout.write, not console.log: the parent's FORCE_COLOR makes\n// console.log wrap a number in ANSI escapes.\nlisten(Number(process.argv[1])).catch(() => listen(0)).then((port) => process.stdout.write(String(port)));\n`;\n\n/**\n * The port the dev server and `baseURL` share. Cached in the environment so\n * every Playwright worker, which loads the config again in its own process,\n * reads the port the main process settled on.\n */\nexport function resolvePort(preferred?: number): number {\n const cached = process.env[PORT_ENV];\n if (cached) return Number(cached);\n\n const port = preferred\n ?? Number(execFileSync(process.execPath, ['-e', PROBE, String(PREFERRED_PORT)], {\n encoding: 'utf-8',\n }).trim());\n if (!Number.isInteger(port) || port <= 0) {\n throw new Error(`Could not settle on a dev-server port (read ${port})`);\n }\n process.env[PORT_ENV] = String(port);\n return port;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,WAAU;AACjB,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,OAGK;;;ACPP,OAAO,QAAQ;AACf,OAAO,QAAQ;AACf,OAAO,UAAU;AAOV,IAAM,oBAAoB;AAM1B,IAAM,eAAe;AAkB5B,IAAM,gBAAgB,oBAAI,IAAI,CAAC,iBAAiB,gBAAgB,kBAAkB,CAAC;AAQnF,IAAI,UAAU;AAEd,SAAS,gBAAgB,SAAuB;AAC9C,QAAM,SAAS,MAAM;AACnB,QAAI,QAAS;AACb,cAAU;AACV,OAAG,OAAO,SAAS,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EACrD;AACA,UAAQ,KAAK,QAAQ,MAAM;AAI3B,UAAQ,KAAK,UAAU,MAAM;AAC7B,UAAQ,KAAK,WAAW,MAAM;AAChC;AAQO,SAAS,eAAe,eAAqC;AAClE,QAAM,WAAW,QAAQ,IAAI,iBAAiB;AAC9C,MAAI,UAAU;AACZ,UAAMC,WAAU,KAAK,QAAQ,QAAQ;AACrC,QAAI,CAAC,GAAG,WAAWA,QAAO,GAAG;AAC3B,YAAM,IAAI,MAAM,GAAG,iBAAiB,UAAUA,QAAO,wBAAwB;AAAA,IAC/E;AACA,YAAQ,IAAI,YAAY,IAAIA;AAC5B,WAAO,EAAE,SAAAA,UAAS,SAAS,MAAM;AAAA,EACnC;AAEA,QAAM,SAAS,KAAK,QAAQ,aAAa;AACzC,MAAI,CAAC,GAAG,WAAW,MAAM,GAAG;AAC1B,UAAM,I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