@astryxdesign/cli 0.7.1 → 0.7.2-canary.01eab6a

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 (101) hide show
  1. package/README.md +7 -7
  2. package/api/component/_adapter.d.mts +41 -1
  3. package/api/component/_adapter.mjs +93 -7
  4. package/api/component/component.mjs +22 -5
  5. package/api/component/component.test.mjs +420 -167
  6. package/api/component/integration-export-name.test.mjs +644 -0
  7. package/api/component/list/list.mjs +42 -4
  8. package/api/gap-report/gap-report.mjs +67 -4
  9. package/api/integration/_adapter.d.mts +12 -0
  10. package/api/integration/_adapter.mjs +54 -0
  11. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  12. package/api/integration/add-contribution.mjs +7 -3
  13. package/api/integration/authoring-checks.mjs +11 -2
  14. package/api/integration/authoring-checks.test.mjs +39 -0
  15. package/api/integration/authoring-checks.type.d.mts +9 -0
  16. package/api/integration/authoring-checks.type.mjs +14 -1
  17. package/api/integration/integrationComponentConflicts.doc.mjs +21 -5
  18. package/api/integration/pack-check.mjs +61 -107
  19. package/api/integration/pack-check.test.mjs +359 -0
  20. package/api/search/search.d.mts +9 -0
  21. package/api/search/search.mjs +108 -16
  22. package/api/search/search.test.mjs +36 -0
  23. package/api/swizzle/copy/copy.mjs +28 -14
  24. package/api/template/table-filter-view-tabs.test.mjs +45 -0
  25. package/api/template/template.test.mjs +120 -3
  26. package/api/theme/build/build.core-on-demand.test.mjs +113 -0
  27. package/api/theme/build/build.d.mts +13 -13
  28. package/api/theme/build/build.family.test.mjs +16 -0
  29. package/api/theme/build/build.mjs +149 -55
  30. package/api/theme/themeBuild.doc.mjs +3 -3
  31. package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
  32. package/assets/codemods/transforms/next/index.mjs +11 -1
  33. package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
  34. package/assets/docs/tree/add-a-component.doc.mjs +10 -0
  35. package/assets/docs/tree/check-the-props.doc.mjs +145 -0
  36. package/assets/docs/tree/checks.doc.mjs +4 -4
  37. package/assets/docs/tree/component-family.doc.mjs +5 -1
  38. package/assets/docs/tree/component-imports.doc.mjs +8 -0
  39. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  40. package/assets/docs/tree/single-component.doc.mjs +3 -2
  41. package/assets/docs/tree/troubleshooting.doc.mjs +9 -1
  42. package/assets/docs/tree/versioning.doc.mjs +1 -0
  43. package/assets/docs/working-with-ai.doc.mjs +43 -4
  44. package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
  45. package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
  46. package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
  47. package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
  48. package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
  49. package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
  50. package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
  51. package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
  52. package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
  53. package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
  54. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
  55. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
  56. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
  57. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
  58. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
  59. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
  60. package/assets/templates/pages/detail-page/page.tsx +3 -3
  61. package/assets/templates/pages/table-filter/page.tsx +3 -2
  62. package/assets/templates/pages/table-inbox/page.tsx +10 -8
  63. package/authoring/doctypes/base/type.ts +6 -0
  64. package/authoring/doctypes/component/component.doc.mjs +4 -4
  65. package/authoring/doctypes/component/type.ts +6 -3
  66. package/clients/cli/commands/build-theme.path-safety.test.mjs +84 -0
  67. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  68. package/clients/cli/commands/doctor-integration-components.doc.mjs +9 -3
  69. package/clients/cli/commands/doctor-integration.test.mjs +327 -0
  70. package/clients/cli/commands/doctor.mjs +74 -0
  71. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  72. package/clients/cli/lib/component-format.mjs +5 -1
  73. package/foundation/discovery/component-discovery.d.mts +190 -10
  74. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  75. package/foundation/discovery/component-discovery.mjs +864 -56
  76. package/foundation/discovery/component-discovery.test.mjs +96 -0
  77. package/foundation/discovery/component-replacement.mjs +18 -0
  78. package/foundation/discovery/component-replacement.test.mjs +40 -0
  79. package/foundation/discovery/module-exports.d.mts +27 -0
  80. package/foundation/discovery/module-exports.mjs +356 -31
  81. package/foundation/discovery/module-exports.test.mjs +172 -0
  82. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  83. package/foundation/discovery/package-tsconfig.mjs +228 -0
  84. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  85. package/foundation/discovery/project-typescript.d.mts +23 -0
  86. package/foundation/discovery/project-typescript.mjs +61 -0
  87. package/foundation/discovery/prop-drift.d.mts +220 -0
  88. package/foundation/discovery/prop-drift.mjs +1765 -0
  89. package/foundation/discovery/prop-drift.test.mjs +1197 -0
  90. package/foundation/discovery/template-adapter.mjs +74 -5
  91. package/foundation/discovery/unresolved-references.d.mts +62 -0
  92. package/foundation/discovery/unresolved-references.mjs +790 -0
  93. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  94. package/foundation/doc-compiler/doc-loads.test.mjs +9 -1
  95. package/foundation/doc-compiler/inputs.mjs +23 -0
  96. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  97. package/foundation/integrations/contribution-inventory.mjs +6 -1
  98. package/foundation/response/response-types.doc.mjs +1 -1
  99. package/foundation/xle/registry.mjs +4 -0
  100. package/foundation/xle/registry.test.mjs +28 -0
  101. package/package.json +10 -10
@@ -163,6 +163,19 @@ export function themeBuildFamily(files: string[], options: {
163
163
  checked?: undefined;
164
164
  };
165
165
  }>;
166
+ /**
167
+ * The bindings one Core provides: the namespaces interception spreads, the
168
+ * functions the build calls, and why the import failed, if it did.
169
+ */
170
+ export type CoreBindings = {
171
+ themeModule: any;
172
+ rootModule: any;
173
+ importError: any;
174
+ defineTheme: any;
175
+ generateThemeRulesSplit: any;
176
+ generateOnMediaCSS: any;
177
+ generateAdaptationCSS: any;
178
+ };
166
179
  /**
167
180
  * How one `prop:value` pair on a component target is classified — the single
168
181
  * vocabulary both the root and adaptation paths reason in.
@@ -210,16 +223,3 @@ export type ThemeBuildTrailer = {
210
223
  */
211
224
  fontNotices: string[];
212
225
  };
213
- /**
214
- * The bindings one Core provides: the namespaces interception spreads, the
215
- * functions the build calls, and why the import failed, if it did.
216
- */
217
- export type CoreBindings = {
218
- themeModule: any;
219
- rootModule: any;
220
- importError: any;
221
- defineTheme: any;
222
- generateThemeRulesSplit: any;
223
- generateOnMediaCSS: any;
224
- generateAdaptationCSS: any;
225
- };
@@ -252,6 +252,22 @@ describe('themeBuildFamily()', () => {
252
252
  expect(fs.existsSync(dtsPath)).toBe(false);
253
253
  });
254
254
 
255
+ it('refuses family outputs outside cwd before checking or writing', async () => {
256
+ const dir = makeDir();
257
+ const files = writeFamily(dir).map(file => path.join(dir, file));
258
+ const app = path.join(dir, 'app');
259
+ fs.mkdirSync(app);
260
+
261
+ for (const check of [false, true]) {
262
+ await expect(
263
+ themeBuildFamily(files, {familyKey: FAMILY_KEY, check}, {cwd: app}),
264
+ ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
265
+ }
266
+ for (const output of OUTPUTS) {
267
+ expect(fs.existsSync(path.join(dir, 'themes', output))).toBe(false);
268
+ }
269
+ });
270
+
255
271
  it('fails without publishing a mixed trio when staging a write fails', async () => {
256
272
  const dir = makeDir();
257
273
  const files = writeFamily(dir);
@@ -27,6 +27,8 @@
27
27
  * files; an internal callback lets the CLI make only the process status fail.
28
28
  * Human progress is emitted through the shared `logger` (silent by default), so
29
29
  * the CLI keeps its exact output while a programmatic caller stays quiet.
30
+ * Every output, explicit or beside the theme file, stays inside `cwd`
31
+ * (`ERR_PATH_TRAVERSAL` otherwise), in check mode too.
30
32
  *
31
33
  * The installed `@astryxdesign/core` is an independently versioned optional
32
34
  * peer, so it can be older than the CLI. A theme that uses only baseline
@@ -37,6 +39,10 @@
37
39
  * general compatibility scheme for every export an arbitrary older core might
38
40
  * lack.
39
41
  *
42
+ * Core is imported on first use, never when this module loads: the CLI loads
43
+ * this module for every command, and Core's root entry pulls in all of Core
44
+ * and React.
45
+ *
40
46
  * With `{check: true}`, it compiles the same outputs in memory but writes
41
47
  * nothing: it compares each generated file against what is on disk (ignoring
42
48
  * only the volatile `@generated` `Command:` line) and returns a
@@ -91,6 +97,8 @@ import {resolveIconImports} from './icon-imports.mjs';
91
97
  // action). A built, resolvable `@astryxdesign/core` is a hard requirement.
92
98
  // A built, resolvable `@astryxdesign/core` is a hard requirement. These are
93
99
  // populated from a dynamic import (a runtime boundary), so `any` is intentional.
100
+ // That import runs the first time a build needs Core (see `loadCliCore`), not
101
+ // when this module loads.
94
102
  //
95
103
  // The CLI and core are independently versioned optional peers, so this import
96
104
  // can succeed against a core OLDER than the CLI. Only the exports every theme
@@ -120,27 +128,6 @@ import {resolveIconImports} from './icon-imports.mjs';
120
128
  */
121
129
  /** @type {any} */ let _coreRootModule = null;
122
130
  /** @type {any} */ let _coreImportError = null;
123
- try {
124
- const coreTheme = await import('@astryxdesign/core/theme');
125
- _coreThemeModule = coreTheme;
126
- _defineTheme = coreTheme.defineTheme;
127
- _generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
128
- _generateOnMediaCSS = coreTheme.generateOnMediaCSS;
129
- _generateAdaptationCSS = coreTheme.generateAdaptationCSS;
130
- try {
131
- _coreRootModule = await import('@astryxdesign/core');
132
- } catch {
133
- // A core without a usable root entry still builds themes; interception
134
- // falls back to the theme namespace for the root specifier.
135
- }
136
- } catch (e) {
137
- // Capture the reason so the theme action can surface a precise, actionable
138
- // error. We don't throw here: this module is imported eagerly by the CLI
139
- // entrypoint for every command, and a throw at load time would break
140
- // unrelated commands (the entry wraps loads in try/catch and degrades the
141
- // command to a stub). The hard failure happens when `theme build` runs.
142
- _coreImportError = e;
143
- }
144
131
 
145
132
  /**
146
133
  * The bindings one Core provides: the namespaces interception spreads, the
@@ -157,19 +144,65 @@ try {
157
144
  */
158
145
 
159
146
  /**
160
- * The bindings exactly as the CLI's own import left them, kept so each build
161
- * can choose between them and the project's installed Core.
162
- * @type {CoreBindings}
147
+ * Import the CLI's own Core: the `@astryxdesign/core` this module resolves.
148
+ * Never throws. A failed import is kept as `importError`, so the build can
149
+ * surface a precise, actionable error when it runs.
150
+ * @returns {Promise<CoreBindings>}
163
151
  */
164
- const _cliCore = {
165
- themeModule: _coreThemeModule,
166
- rootModule: _coreRootModule,
167
- importError: _coreImportError,
168
- defineTheme: _defineTheme,
169
- generateThemeRulesSplit: _generateThemeRulesSplit,
170
- generateOnMediaCSS: _generateOnMediaCSS,
171
- generateAdaptationCSS: _generateAdaptationCSS,
172
- };
152
+ async function importCliCore() {
153
+ /** @type {CoreBindings} */
154
+ const core = {
155
+ themeModule: null,
156
+ rootModule: null,
157
+ importError: null,
158
+ defineTheme: null,
159
+ generateThemeRulesSplit: null,
160
+ generateOnMediaCSS: null,
161
+ generateAdaptationCSS: null,
162
+ };
163
+ try {
164
+ const coreTheme = await import('@astryxdesign/core/theme');
165
+ core.themeModule = coreTheme;
166
+ core.defineTheme = coreTheme.defineTheme;
167
+ core.generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
168
+ core.generateOnMediaCSS = coreTheme.generateOnMediaCSS;
169
+ core.generateAdaptationCSS = coreTheme.generateAdaptationCSS;
170
+ try {
171
+ core.rootModule = await import('@astryxdesign/core');
172
+ } catch {
173
+ // A core without a usable root entry still builds themes; interception
174
+ // falls back to the theme namespace for the root specifier.
175
+ }
176
+ } catch (e) {
177
+ // Capture the reason so the theme action can surface a precise, actionable
178
+ // error. The hard failure happens when `theme build` runs.
179
+ core.importError = e;
180
+ }
181
+ return core;
182
+ }
183
+
184
+ /**
185
+ * The CLI's own Core, imported once, the first time a build needs it. The CLI
186
+ * loads this module for every command, and Core's root entry loads all of Core
187
+ * and React, so an import at module load would make every command
188
+ * (`--version` included) pay for that whenever a Core resolves.
189
+ * @type {Promise<CoreBindings> | null}
190
+ */
191
+ let _cliCorePromise = null;
192
+
193
+ /**
194
+ * The CLI's own Core, kept so each build can choose between it and the
195
+ * project's installed Core. The first call also points the build at it, so a
196
+ * step that runs before any build has chosen a Core reads the CLI's own.
197
+ * @returns {Promise<CoreBindings>}
198
+ */
199
+ function loadCliCore() {
200
+ _cliCorePromise ??= importCliCore().then(core => {
201
+ setCore(core);
202
+ return core;
203
+ });
204
+ return _cliCorePromise;
205
+ }
173
206
 
174
207
  /**
175
208
  * Point the build at one Core: the module-level bindings every step reads.
@@ -239,6 +272,25 @@ function realOrSelf(file) {
239
272
  }
240
273
  }
241
274
 
275
+ /**
276
+ * `target` spelled through real directories: the deepest ancestor that exists
277
+ * is resolved through its symlinks, and the missing rest is appended as given.
278
+ * @param {string} target absolute path
279
+ * @returns {string}
280
+ */
281
+ function realLocation(target) {
282
+ /** @type {string[]} */
283
+ const missing = [];
284
+ let existing = target;
285
+ while (!fs.existsSync(existing)) {
286
+ const parent = path.dirname(existing);
287
+ if (parent === existing) break;
288
+ missing.unshift(path.basename(existing));
289
+ existing = parent;
290
+ }
291
+ return path.join(realOrSelf(existing), ...missing);
292
+ }
293
+
242
294
  /**
243
295
  * The Core the project at `cwd` installed, when it differs from the one the
244
296
  * CLI's own import found and loads. The app's `<Theme>` runs on the app's
@@ -248,13 +300,14 @@ function realOrSelf(file) {
248
300
  * repository, a bare directory), the same Core, or one that does not load.
249
301
  *
250
302
  * @param {string} cwd
303
+ * @param {CoreBindings} cliCore - The CLI's own Core, from {@link loadCliCore}.
251
304
  * @returns {Promise<CoreBindings | null>}
252
305
  */
253
- async function loadProjectCore(cwd) {
306
+ async function loadProjectCore(cwd, cliCore) {
254
307
  const dir = findInstalledPackage(cwd, '@astryxdesign/core');
255
308
  const themeFile = dir ? importTarget(dir, './theme') : null;
256
309
  if (!dir || !themeFile) return null;
257
- if (_cliCore.themeModule) {
310
+ if (cliCore.themeModule) {
258
311
  try {
259
312
  const own = fileURLToPath(
260
313
  import.meta.resolve('@astryxdesign/core/theme'),
@@ -301,9 +354,10 @@ const _projectCores = new Map();
301
354
  * @param {string} cwd
302
355
  */
303
356
  async function selectCore(cwd) {
357
+ const cliCore = await loadCliCore();
304
358
  if (!_projectCores.has(cwd))
305
- _projectCores.set(cwd, await loadProjectCore(cwd));
306
- setCore(_projectCores.get(cwd) ?? _cliCore);
359
+ _projectCores.set(cwd, await loadProjectCore(cwd, cliCore));
360
+ setCore(_projectCores.get(cwd) ?? cliCore);
307
361
  }
308
362
 
309
363
  /**
@@ -473,6 +527,47 @@ function checkedBuildOutputs(writes, cwd) {
473
527
  .map(write => path.relative(cwd, write.dest));
474
528
  }
475
529
 
530
+ /** Remedies that end a confinement error, by where the output path came from. */
531
+ const OUT_REMEDY = 'Pass an --out path inside it.';
532
+ const SOURCE_REMEDY =
533
+ 'Without --out the outputs go beside the theme file, so run the build from a directory that contains the theme file, or pass an --out path inside the working directory.';
534
+ const FAMILY_REMEDY =
535
+ "Family outputs go beside the family's root theme file, so run the build from a directory that contains it.";
536
+
537
+ /**
538
+ * Refuse an output outside `root`: every write is confined, whether `out` names
539
+ * the path or it defaults to the theme file's directory (architecture:cli-surface
540
+ * INV10). Both sides are compared by real location, so an absolute path that
541
+ * reaches the working directory through a symlink is inside it, and a symlink
542
+ * inside it that leads elsewhere is not.
543
+ * @param {string} dest absolute output path
544
+ * @param {string} root the directory writes stay inside: the working directory
545
+ * @param {string} remedy what to do instead; ends the error message
546
+ * @param {string} [shown] the path as the caller wrote it, for the message
547
+ */
548
+ function confineOutput(dest, root, remedy, shown = dest) {
549
+ try {
550
+ assertWithin(realLocation(dest), realOrSelf(path.resolve(root)), {
551
+ allowAbsolute: true,
552
+ label: 'output path',
553
+ });
554
+ } catch (err) {
555
+ if (!(err instanceof PathSafetyError)) throw err;
556
+ throw new AstryxError(
557
+ err.code === ERROR_CODES.ERR_PATH_TRAVERSAL
558
+ ? `Output path "${shown}" is outside the working directory (${root}). ${remedy}`
559
+ : err.message,
560
+ undefined,
561
+ ERROR_CODES.ERR_PATH_TRAVERSAL,
562
+ );
563
+ }
564
+ }
565
+
566
+ /** @param {Array<{dest: string}>} writes @param {string} root @param {string} remedy */
567
+ function confineOutputs(writes, root, remedy) {
568
+ for (const write of writes) confineOutput(write.dest, root, remedy);
569
+ }
570
+
476
571
  /** @param {Array<{dest: string, content: string}>} writes */
477
572
  function writeBuildOutputs(writes) {
478
573
  if (writes.length === 0) return;
@@ -1694,6 +1789,8 @@ export async function validateThemePrivateInputs(
1694
1789
  );
1695
1790
  }
1696
1791
 
1792
+ // The CLI's own Core, unless a build in this process already chose one.
1793
+ await loadCliCore();
1697
1794
  const interception = interceptCore(_coreThemeModule, _coreRootModule);
1698
1795
  let theme;
1699
1796
  try {
@@ -2309,9 +2406,10 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
2309
2406
  * `logger` (silent by default).
2310
2407
  *
2311
2408
  * @param {string} file - Theme file path, resolved against `cwd`.
2312
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void}} [options] -
2409
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string}} [options] -
2313
2410
  * `out` overrides the output CSS path; `check` compares against on-disk outputs
2314
- * instead of writing. `iconsSpecifier` overrides the icon registry import
2411
+ * instead of writing. `__writeRoot` replaces `cwd` as the directory every
2412
+ * output must stay inside, for a CLI-internal scratch build. `iconsSpecifier` overrides the icon registry import
2315
2413
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
2316
2414
  * direct registry specifiers from the theme source are emitted unchanged.
2317
2415
  * @param {{cwd?: string}} [ctx]
@@ -2756,25 +2854,14 @@ async function themeBuildInternal(
2756
2854
  // Derive the default CSS name from the theme name so .css/.js/.d.ts
2757
2855
  // share one scheme; an explicit --out still wins.
2758
2856
  const baseName = themeDef.name;
2857
+ // Every write stays inside cwd. A CLI-internal caller that renders into a
2858
+ // scratch directory it creates and removes names that directory instead.
2859
+ const writeRoot = options.__writeRoot ?? cwd;
2759
2860
  let outPath;
2760
2861
  if (options.out) {
2862
+ // Relative or absolute, the explicit output stays inside the write root.
2761
2863
  outPath = path.resolve(cwd, options.out);
2762
- // Guard: relative paths must not escape cwd via `../`. Absolute paths are
2763
- // trusted (the user explicitly controls where output goes, like gcc -o).
2764
- if (!path.isAbsolute(options.out)) {
2765
- try {
2766
- assertWithin(options.out, cwd, {label: 'output path'});
2767
- } catch (err) {
2768
- if (err instanceof PathSafetyError) {
2769
- throw new AstryxError(
2770
- err.message,
2771
- undefined,
2772
- ERROR_CODES.ERR_PATH_TRAVERSAL,
2773
- );
2774
- }
2775
- throw err;
2776
- }
2777
- }
2864
+ confineOutput(outPath, writeRoot, OUT_REMEDY, options.out);
2778
2865
  } else {
2779
2866
  outPath = path.join(path.dirname(filePath), `${baseName}.css`);
2780
2867
  }
@@ -2870,6 +2957,11 @@ async function themeBuildInternal(
2870
2957
  writes.push({dest: variantDtsPath, content: variantContent});
2871
2958
  }
2872
2959
 
2960
+ // Every output stays inside cwd, including the defaults beside the theme
2961
+ // file. Check mode refuses the same paths, so it never passes outputs that a
2962
+ // build would refuse to write.
2963
+ confineOutputs(writes, writeRoot, options.out ? OUT_REMEDY : SOURCE_REMEDY);
2964
+
2873
2965
  // Check mode: compare generated content against what's on disk instead of
2874
2966
  // writing. A file is "stale" if it's missing or its content differs once the
2875
2967
  // volatile @generated `Command:` line is ignored. Returns a
@@ -3414,6 +3506,8 @@ export async function themeBuildFamily(
3414
3506
  js: path.relative(cwd, jsPath),
3415
3507
  dts: path.relative(cwd, dtsPath),
3416
3508
  };
3509
+ // The family's outputs stay inside cwd too, in check mode as well.
3510
+ confineOutputs(writes, cwd, FAMILY_REMEDY);
3417
3511
  if (options.check) {
3418
3512
  const stale = staleBuildOutputs(writes, cwd);
3419
3513
  const upToDate = stale.length === 0;
@@ -58,7 +58,7 @@ export const doc = {
58
58
  name: 'options.out',
59
59
  type: 'string',
60
60
  description:
61
- 'Override the output CSS path. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file. A relative path must stay within cwd.',
61
+ 'Override the output CSS path, relative or absolute; it must resolve inside cwd. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file.',
62
62
  },
63
63
  {
64
64
  name: 'options.check',
@@ -77,7 +77,7 @@ export const doc = {
77
77
  name: 'ctx.cwd',
78
78
  type: 'string',
79
79
  description:
80
- 'Directory the theme file, a relative out path, and the returned output paths resolve against.',
80
+ 'Directory the theme file, a relative out path, and the returned output paths resolve against. Every output is written inside it, including the default outputs beside the theme file.',
81
81
  default: 'process.cwd()',
82
82
  },
83
83
  ],
@@ -105,7 +105,7 @@ export const doc = {
105
105
  },
106
106
  {
107
107
  code: 'ERR_PATH_TRAVERSAL',
108
- when: 'the theme name contains a path separator or traversal marker, or a relative `out` path resolves outside cwd (including through a symlink)',
108
+ when: 'the theme name contains a path separator or traversal marker, or an output resolves outside cwd (including through a symlink): an `out` path, relative or absolute, or the default outputs beside a theme file outside cwd (also rejected in check mode)',
109
109
  },
110
110
  {
111
111
  code: 'ERR_CORE_NOT_FOUND',
@@ -0,0 +1,120 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import {describe, expect, it} from 'vitest';
4
+ import transform from '../migrate-list-edge-compensation-to-edge.mjs';
5
+
6
+ async function applyTransform(source) {
7
+ const jscodeshift = (await import('jscodeshift')).default;
8
+ const j = jscodeshift.withParser('tsx');
9
+ const api = {jscodeshift: j, stats: () => {}, report: () => {}};
10
+ return transform({source, path: 'test.tsx'}, api) ?? source;
11
+ }
12
+
13
+ describe('migrate-list-edge-compensation-to-edge', () => {
14
+ it("renames edgeCompensation='inline' to edge='outset'", async () => {
15
+ const output =
16
+ await applyTransform(`import {List, ListItem} from '@astryxdesign/core/List';
17
+ const a = <List edgeCompensation="inline"><ListItem label="a" /></List>;
18
+ const b = <List hasDividers edgeCompensation={'inline'} />;`);
19
+
20
+ expect(output).not.toContain('edgeCompensation');
21
+ expect(output.match(/edge='outset'/g)).toHaveLength(2);
22
+ expect(output).toContain('hasDividers');
23
+ });
24
+
25
+ it('follows aliases and the package root import', async () => {
26
+ const output =
27
+ await applyTransform(`import {List as Rows} from '@astryxdesign/core';
28
+ const a = <Rows edgeCompensation="inline" />;`);
29
+
30
+ expect(output).toContain("<Rows edge='outset' />");
31
+ });
32
+
33
+ it('drops edgeCompensation beside an edge string, whatever its value', async () => {
34
+ const output =
35
+ await applyTransform(`import {List} from '@astryxdesign/core/List';
36
+ const a = <List edge="bleed" edgeCompensation="inline" />;
37
+ const b = <List edge={'flush'} edgeCompensation={mode} />;
38
+ const c = <List {...rest} edge="padded" edgeCompensation="inline" />;`);
39
+
40
+ // c: the spread comes before edge, so it cannot override it.
41
+ expect(output).toContain('edge="bleed"');
42
+ expect(output).toContain("edge={'flush'}");
43
+ expect(output).toContain('edge="padded"');
44
+ expect(output).not.toContain('edgeCompensation');
45
+ expect(output).not.toContain('TODO');
46
+ });
47
+
48
+ it('leaves a TODO where edge may be undefined at runtime', async () => {
49
+ const output =
50
+ await applyTransform(`import {List} from '@astryxdesign/core/List';
51
+ const a = <List edge={edge} edgeCompensation="inline" />;
52
+ const b = <List edge="flush" {...rest} edgeCompensation="inline" />;
53
+ const c = <List edge={props.edge} edgeCompensation={mode} />;`);
54
+
55
+ // a and c: a computed edge falls back to the old prop when undefined.
56
+ // b: the spread after edge may set it to undefined.
57
+ expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(3);
58
+ expect(output.match(/edgeCompensation=/g)).toHaveLength(3);
59
+ expect(output).toContain('edge={edge}');
60
+ expect(output).toContain('edge={props.edge}');
61
+ });
62
+
63
+ it('leaves a TODO on a dynamic value and keeps it working', async () => {
64
+ const output =
65
+ await applyTransform(`import {List} from '@astryxdesign/core/List';
66
+ const a = <List edgeCompensation={mode} />;
67
+ const b = <List edgeCompensation={flag ? 'inline' : undefined} />;`);
68
+
69
+ expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(2);
70
+ expect(output).toContain('edgeCompensation={mode}');
71
+ expect(output).toContain("edgeCompensation={flag ? 'inline' : undefined}");
72
+ });
73
+
74
+ it('keeps edgeCompensation with a TODO when the List also spreads props', async () => {
75
+ const output =
76
+ await applyTransform(`import {List} from '@astryxdesign/core/List';
77
+ const a = <List {...rest} edgeCompensation="inline" />;
78
+ const b = <List edgeCompensation="inline" {...rest} />;
79
+ const c = <List {...rest} edgeCompensation={mode} />;
80
+ const d = <List {...props} />;
81
+ const e = <List {...rest} edge="padded" />;`);
82
+
83
+ // a: an edge in the spread wins today, and a new edge would override
84
+ // it. b: the spread may override either prop. c: dynamic value and a
85
+ // spread, one TODO. d: no evidence of the old prop, so unchanged; its
86
+ // @deprecated type reports a typed use where the props are written.
87
+ // e: no old prop.
88
+ expect(output.match(/TODO\(astryx upgrade\)/g)).toHaveLength(3);
89
+ const code = output.replace(/\/\*[\s\S]*?\*\//g, '');
90
+ expect(code).not.toContain("edge='outset'");
91
+ expect(code.match(/edgeCompensation="inline"/g)).toHaveLength(2);
92
+ expect(output).toContain('edgeCompensation={mode}');
93
+ expect(output).toContain('const d = <List {...props} />;');
94
+ expect(output).toContain('edge="padded"');
95
+ });
96
+
97
+ it('leaves other components, other packages, and unrelated spreads alone', async () => {
98
+ const source = `import {List} from '@astryxdesign/core/List';
99
+ import {TabList} from '@astryxdesign/core/TabList';
100
+ import {List as Other} from 'some-other-package';
101
+ const a = <TabList edgeCompensation="inline" {...props} />;
102
+ const b = <Other edgeCompensation="inline" {...props} />;
103
+ const c = <div {...props} />;`;
104
+ expect(await applyTransform(source)).toBe(source);
105
+ });
106
+
107
+ it('changes nothing on a second run', async () => {
108
+ const once =
109
+ await applyTransform(`import {List} from '@astryxdesign/core/List';
110
+ const a = <List edgeCompensation="inline" />;
111
+ const b = <List edgeCompensation={mode} />;
112
+ const c = <List {...props} edgeCompensation="inline" />;
113
+ const d = <List edge="flush" edgeCompensation="inline" />;
114
+ const e = <List edge={edge} edgeCompensation="inline" />;`);
115
+ const twice = await applyTransform(once);
116
+
117
+ expect(twice).toBe(once);
118
+ expect(twice.match(/TODO\(astryx upgrade\)/g)).toHaveLength(3);
119
+ });
120
+ });
@@ -7,4 +7,14 @@
7
7
  * this file into the resolved version folder.
8
8
  */
9
9
 
10
- export default [];
10
+ import migrateListEdgeCompensationToEdge, {
11
+ meta as migrateListEdgeCompensationToEdgeMeta,
12
+ } from './migrate-list-edge-compensation-to-edge.mjs';
13
+
14
+ export default [
15
+ {
16
+ name: 'migrate-list-edge-compensation-to-edge',
17
+ transform: migrateListEdgeCompensationToEdge,
18
+ meta: migrateListEdgeCompensationToEdgeMeta,
19
+ },
20
+ ];