@astryxdesign/cli 0.7.0-canary.81dc9bb → 0.7.0-canary.94bdc8e

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 (53) hide show
  1. package/README.md +61 -61
  2. package/api/integration/pack-check.test.mjs +8 -0
  3. package/api/template/template.doc.mjs +1 -1
  4. package/api/template/template.type.mjs +1 -1
  5. package/api/theme/build/build.d.mts +0 -1
  6. package/api/theme/build/build.mjs +4 -29
  7. package/api/theme/build/family.mjs +1 -1
  8. package/assets/codemods/transforms/next/__tests__/migrate-field-input-styling.test.mjs +108 -0
  9. package/assets/codemods/transforms/next/__tests__/validate-data-token-ownership.test.mjs +84 -0
  10. package/assets/codemods/transforms/next/index.mjs +16 -0
  11. package/assets/codemods/transforms/next/migrate-field-input-styling.mjs +198 -0
  12. package/assets/codemods/transforms/next/validate-data-token-ownership.mjs +102 -0
  13. package/assets/docs/author-a-theme.doc.mjs +1 -1
  14. package/assets/docs/tree/tokens-data.doc.mjs +2 -2
  15. package/assets/docs/tree/tokens-usage.doc.mjs +1 -1
  16. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorDeadlinePicker.tsx +1 -1
  17. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorShowcase.tsx +1 -1
  18. package/assets/templates/blocks/components/ComplexSelector/ComplexSelectorTreeSearch.tsx +1 -1
  19. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider01ShippedLocale.tsx +1 -1
  20. package/assets/templates/blocks/components/InternationalizationProvider/InternationalizationProvider02Overrides.tsx +1 -1
  21. package/assets/templates/blocks/components/Selector/SelectorClearable.tsx +1 -1
  22. package/assets/templates/blocks/components/Selector/SelectorOptionDescriptions.tsx +2 -2
  23. package/assets/templates/blocks/components/Selector/SelectorShowcase.tsx +1 -1
  24. package/assets/templates/blocks/components/Selector/SelectorWithSections.tsx +1 -1
  25. package/assets/templates/blocks/components/SelectorOption/SelectorOptionBasic.tsx +1 -1
  26. package/assets/templates/blocks/components/SelectorOption/SelectorOptionShowcase.tsx +1 -1
  27. package/assets/templates/blocks/components/Slider/SliderFormattedValue.tsx +1 -1
  28. package/assets/templates/blocks/components/Slider/SliderRangeSlider.tsx +1 -1
  29. package/assets/templates/blocks/components/Slider/SliderShowcase.tsx +1 -1
  30. package/assets/templates/blocks/components/Slider/SliderWithMarks.tsx +1 -1
  31. package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +1 -1
  32. package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +2 -2
  33. package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +1 -1
  34. package/assets/templates/blocks/components/Tokenizer/TokenizerIcon.tsx +1 -1
  35. package/assets/templates/blocks/components/Tokenizer/TokenizerMaxEntries.tsx +1 -1
  36. package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +2 -2
  37. package/assets/templates/blocks/components/Tokenizer/TokenizerShowcase.tsx +1 -1
  38. package/assets/templates/blocks/components/Tokenizer/TokenizerStates.tsx +4 -4
  39. package/assets/templates/blocks/components/Toolbar/ToolbarTableFilter.tsx +1 -1
  40. package/assets/templates/pages/canvas-editor/page.tsx +2 -2
  41. package/assets/templates/pages/form-wizard-vertical/page.tsx +1 -1
  42. package/assets/templates/pages/payment-form/page.tsx +1 -1
  43. package/assets/templates/pages/table-filter/page.tsx +3 -3
  44. package/assets/templates/pages/theme-showcase/page.tsx +2 -2
  45. package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +10 -9
  46. package/clients/cli/commands/build-theme.color-scheme.test.mjs +10 -6
  47. package/clients/cli/commands/build-theme.data-tokens.test.mjs +23 -75
  48. package/foundation/discovery/template-needs.mjs +93 -11
  49. package/foundation/discovery/template-needs.test.mjs +106 -3
  50. package/foundation/env/package-manager.d.mts +13 -0
  51. package/foundation/env/package-manager.mjs +106 -63
  52. package/foundation/response/response-types.doc.mjs +1 -2
  53. package/package.json +9 -9
@@ -93,15 +93,23 @@ describe('extractImportedPackages', () => {
93
93
 
94
94
  describe('analyzeTemplateNeeds', () => {
95
95
  let dir;
96
+ let userAgent;
96
97
  beforeEach(() => {
97
98
  dir = fs.mkdtempSync(path.join(os.tmpdir(), 'tmpl-needs-'));
99
+ userAgent = process.env.npm_config_user_agent;
100
+ });
101
+ afterEach(() => {
102
+ fs.rmSync(dir, {recursive: true, force: true});
103
+ if (userAgent === undefined) delete process.env.npm_config_user_agent;
104
+ else process.env.npm_config_user_agent = userAgent;
98
105
  });
99
- afterEach(() => fs.rmSync(dir, {recursive: true, force: true}));
100
106
 
101
107
  it('reports missing external packages with an install command', () => {
102
108
  fs.writeFileSync(
103
109
  path.join(dir, 'package.json'),
104
- JSON.stringify({dependencies: {'react': '^19.0.0', '@astryxdesign/core': '^0.6.0'}}),
110
+ JSON.stringify({
111
+ dependencies: {react: '^19.0.0', '@astryxdesign/core': '^0.6.0'},
112
+ }),
105
113
  );
106
114
  const source = `
107
115
  import {Button} from '@astryxdesign/core';
@@ -120,7 +128,7 @@ describe('analyzeTemplateNeeds', () => {
120
128
  path.join(dir, 'package.json'),
121
129
  JSON.stringify({
122
130
  dependencies: {
123
- 'react': '^19.0.0',
131
+ react: '^19.0.0',
124
132
  '@astryxdesign/core': '^0.6.0',
125
133
  '@heroicons/react': '^2.2.0',
126
134
  },
@@ -183,6 +191,101 @@ describe('analyzeTemplateNeeds', () => {
183
191
  expect(result.installCommand).toMatch(/^yarn add /);
184
192
  });
185
193
 
194
+ describe('package manager for the install command (AST-048 FR17, FR19)', () => {
195
+ const source = `import {Chart} from 'recharts';`;
196
+ const write = (rel, body = '') => {
197
+ fs.mkdirSync(path.dirname(path.join(dir, rel)), {recursive: true});
198
+ fs.writeFileSync(path.join(dir, rel), body);
199
+ };
200
+
201
+ it('uses npm when no directory up to the workspace root has a field or lockfile, whatever runs the CLI', () => {
202
+ write('package.json', '{}');
203
+ process.env.npm_config_user_agent = 'pnpm/11.10.0 npm/? node/v22.0.0';
204
+ expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
205
+ /^npm install recharts/,
206
+ );
207
+ });
208
+
209
+ it('reads a lockfile that sits only at the workspace root', () => {
210
+ write('package.json', JSON.stringify({workspaces: ['apps/*']}));
211
+ write('yarn.lock');
212
+ write('apps/web/package.json', '{}');
213
+ const result = analyzeTemplateNeeds(source, path.join(dir, 'apps/web'));
214
+ expect(result.installCommand).toMatch(/^yarn add recharts/);
215
+ });
216
+
217
+ it('ignores a lockfile above the workspace root of a standalone project', () => {
218
+ write('yarn.lock');
219
+ write('app/package.json', '{}');
220
+ const result = analyzeTemplateNeeds(source, path.join(dir, 'app'));
221
+ expect(result.installCommand).toMatch(/^npm install recharts/);
222
+ });
223
+
224
+ it('follows a declared packageManager over another lockfile', () => {
225
+ write('package.json', JSON.stringify({packageManager: 'pnpm@11.10.0'}));
226
+ write('pnpm-lock.yaml');
227
+ write('yarn.lock');
228
+ expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
229
+ /^pnpm add recharts/,
230
+ );
231
+ });
232
+
233
+ it('lets a file only one package manager reads decide between tied lockfiles', () => {
234
+ write('package.json', '{}');
235
+ write('pnpm-lock.yaml');
236
+ write('yarn.lock');
237
+ write('pnpm-workspace.yaml', "packages: ['.']\n");
238
+ expect(analyzeTemplateNeeds(source, dir).installCommand).toMatch(
239
+ /^pnpm add recharts/,
240
+ );
241
+ });
242
+
243
+ it.each([
244
+ ['no other file', []],
245
+ [
246
+ 'config files for two package managers',
247
+ ['pnpm-workspace.yaml', '.yarnrc.yml'],
248
+ ],
249
+ ])(
250
+ 'omits the command and names the directory and lockfiles when lockfiles tie with %s',
251
+ (_label, extras) => {
252
+ write('package.json', '{}');
253
+ write('pnpm-lock.yaml');
254
+ write('yarn.lock');
255
+ for (const file of extras) write(file);
256
+ const result = analyzeTemplateNeeds(source, dir);
257
+ expect(result.missingPackages).toEqual(['recharts']);
258
+ expect(result.installCommand).toBeNull();
259
+ const note = result.notes[0];
260
+ expect(note).toContain('recharts');
261
+ expect(note).toContain('No install command: . has');
262
+ expect(note).toMatch(
263
+ /yarn\.lock and pnpm-lock\.yaml|pnpm-lock\.yaml and yarn\.lock/,
264
+ );
265
+ expect(note).not.toMatch(/npm install|pnpm add|yarn add/);
266
+ },
267
+ );
268
+
269
+ it('names the deciding directory relative to the target, not the process', () => {
270
+ write('package.json', JSON.stringify({workspaces: ['apps/*']}));
271
+ write('package-lock.json');
272
+ write('yarn.lock');
273
+ write('apps/web/package.json', '{}');
274
+ const result = analyzeTemplateNeeds(source, path.join(dir, 'apps/web'));
275
+ expect(result.installCommand).toBeNull();
276
+ expect(result.notes[0]).toContain(
277
+ `No install command: ${path.join('..', '..')} has`,
278
+ );
279
+ });
280
+
281
+ it('stays ambiguous with only a package.json workspaces field beside tied lockfiles', () => {
282
+ write('package.json', JSON.stringify({workspaces: ['apps/*']}));
283
+ write('package-lock.json');
284
+ write('yarn.lock');
285
+ expect(analyzeTemplateNeeds(source, dir).installCommand).toBeNull();
286
+ });
287
+ });
288
+
186
289
  it('excludes @stylexjs/stylex from missing packages (it is a Core peer)', () => {
187
290
  fs.writeFileSync(path.join(dir, 'package.json'), '{}');
188
291
  const source = `import * as stylex from '@stylexjs/stylex';`;
@@ -19,6 +19,19 @@
19
19
  * declared field contradicts. Detection ignores them; `astryx doctor` reports
20
20
  * them, because a tool that trusts the lockfile instead will disagree with us.
21
21
  */
22
+ /**
23
+ * What one directory's own files say about its package manager, by the rules
24
+ * {@link explainPackageManager} applies within a directory (declared field,
25
+ * then a single lockfile, then committed config when lockfiles tie). Returns
26
+ * null when the directory has neither a declaration nor a lockfile, so a caller
27
+ * walking up keeps looking. An ambiguous directory reports `ambiguous: true`
28
+ * with the lockfiles that disagree, so a caller can name them.
29
+ * @param {string} dir
30
+ * @returns {(Omit<PackageManagerResolution, 'dir'> & {lockfiles: FoundLockfile[]}) | null}
31
+ */
32
+ export function decidePackageManagerIn(dir: string): (Omit<PackageManagerResolution, "dir"> & {
33
+ lockfiles: FoundLockfile[];
34
+ }) | null;
22
35
  /**
23
36
  * Detect the project's package manager, with the reasoning attached.
24
37
  * Walks up from targetDir, taking the first directory that answers.
@@ -144,6 +144,76 @@ function evidenceIn(dir) {
144
144
  * them, because a tool that trusts the lockfile instead will disagree with us.
145
145
  */
146
146
 
147
+ /**
148
+ * What one directory's own files say about its package manager, by the rules
149
+ * {@link explainPackageManager} applies within a directory (declared field,
150
+ * then a single lockfile, then committed config when lockfiles tie). Returns
151
+ * null when the directory has neither a declaration nor a lockfile, so a caller
152
+ * walking up keeps looking. An ambiguous directory reports `ambiguous: true`
153
+ * with the lockfiles that disagree, so a caller can name them.
154
+ * @param {string} dir
155
+ * @returns {(Omit<PackageManagerResolution, 'dir'> & {lockfiles: FoundLockfile[]}) | null}
156
+ */
157
+ export function decidePackageManagerIn(dir) {
158
+ const locks = lockfilesIn(dir);
159
+ const candidates = locks.map(lock => lock.pm);
160
+ const declared = declaredPackageManager(dir);
161
+
162
+ // The project declared one. Nothing on the filesystem outranks that.
163
+ if (declared) {
164
+ return {
165
+ pm: declared,
166
+ ambiguous: false,
167
+ candidates,
168
+ declared,
169
+ source: 'declared',
170
+ lockfiles: locks,
171
+ strayLockfiles: locks.filter(lock => lock.pm !== declared),
172
+ };
173
+ }
174
+
175
+ // One lockfile is unambiguous.
176
+ if (locks.length === 1) {
177
+ return {
178
+ pm: locks[0].pm,
179
+ ambiguous: false,
180
+ candidates,
181
+ declared: null,
182
+ source: 'lockfile',
183
+ lockfiles: locks,
184
+ strayLockfiles: [],
185
+ };
186
+ }
187
+
188
+ // Several lockfiles and no declaration: the filesystem cannot say. Only a
189
+ // file the project committed on purpose can.
190
+ if (locks.length > 1) {
191
+ const evidence = evidenceIn(dir).filter(pm => candidates.includes(pm));
192
+ if (evidence.length === 1) {
193
+ return {
194
+ pm: evidence[0],
195
+ ambiguous: false,
196
+ candidates,
197
+ declared: null,
198
+ source: 'evidence',
199
+ lockfiles: locks,
200
+ strayLockfiles: [],
201
+ };
202
+ }
203
+ return {
204
+ pm: 'npx',
205
+ ambiguous: true,
206
+ candidates,
207
+ declared: null,
208
+ source: 'none',
209
+ lockfiles: locks,
210
+ strayLockfiles: [],
211
+ };
212
+ }
213
+
214
+ return null;
215
+ }
216
+
147
217
  /**
148
218
  * Detect the project's package manager, with the reasoning attached.
149
219
  * Walks up from targetDir, taking the first directory that answers.
@@ -182,59 +252,16 @@ export function explainPackageManager(targetDir = process.cwd()) {
182
252
  const root = path.parse(dir).root;
183
253
 
184
254
  while (dir !== root) {
185
- const locks = lockfilesIn(dir);
186
- const candidates = locks.map(lock => lock.pm);
187
- const declared = declaredPackageManager(dir);
188
-
189
- // 1. The project declared one. Nothing on the filesystem outranks that.
190
- if (declared) {
255
+ const decision = decidePackageManagerIn(dir);
256
+ if (decision) {
191
257
  return {
192
- pm: declared,
193
- ambiguous: false,
194
- dir,
195
- candidates,
196
- declared,
197
- source: 'declared',
198
- strayLockfiles: locks.filter(lock => lock.pm !== declared),
199
- };
200
- }
201
-
202
- // 2. One lockfile is unambiguous.
203
- if (locks.length === 1) {
204
- return {
205
- pm: locks[0].pm,
206
- ambiguous: false,
258
+ pm: decision.pm,
259
+ ambiguous: decision.ambiguous,
207
260
  dir,
208
- candidates,
209
- declared: null,
210
- source: 'lockfile',
211
- strayLockfiles: [],
212
- };
213
- }
214
-
215
- // 3. Several lockfiles and no declaration: the filesystem cannot say.
216
- // Only a file the project committed on purpose can.
217
- if (locks.length > 1) {
218
- const evidence = evidenceIn(dir).filter(pm => candidates.includes(pm));
219
- if (evidence.length === 1) {
220
- return {
221
- pm: evidence[0],
222
- ambiguous: false,
223
- dir,
224
- candidates,
225
- declared: null,
226
- source: 'evidence',
227
- strayLockfiles: [],
228
- };
229
- }
230
- return {
231
- pm: 'npx',
232
- ambiguous: true,
233
- dir,
234
- candidates,
235
- declared: null,
236
- source: 'none',
237
- strayLockfiles: [],
261
+ candidates: decision.candidates,
262
+ declared: decision.declared,
263
+ source: decision.source,
264
+ strayLockfiles: decision.strayLockfiles,
238
265
  };
239
266
  }
240
267
 
@@ -279,11 +306,15 @@ export function detectPackageManager(targetDir = process.cwd()) {
279
306
  export function getRunPrefix(targetDir) {
280
307
  const pm = detectPackageManager(targetDir);
281
308
  switch (pm) {
282
- case 'yarn': return 'yarn';
283
- case 'pnpm': return 'pnpm exec';
284
- case 'bun': return 'bunx';
309
+ case 'yarn':
310
+ return 'yarn';
311
+ case 'pnpm':
312
+ return 'pnpm exec';
313
+ case 'bun':
314
+ return 'bunx';
285
315
  case 'npm':
286
- default: return 'npx';
316
+ default:
317
+ return 'npx';
287
318
  }
288
319
  }
289
320
 
@@ -310,11 +341,15 @@ export const CLI_BIN = 'astryx';
310
341
  export function getDlxPrefix(targetDir) {
311
342
  const resolution = explainPackageManager(targetDir);
312
343
  switch (resolution.pm) {
313
- case 'yarn': return isYarnClassic(resolution) ? 'npx' : 'yarn dlx';
314
- case 'pnpm': return 'pnpm dlx';
315
- case 'bun': return 'bunx';
344
+ case 'yarn':
345
+ return isYarnClassic(resolution) ? 'npx' : 'yarn dlx';
346
+ case 'pnpm':
347
+ return 'pnpm dlx';
348
+ case 'bun':
349
+ return 'bunx';
316
350
  case 'npm':
317
- default: return 'npx';
351
+ default:
352
+ return 'npx';
318
353
  }
319
354
  }
320
355
 
@@ -343,7 +378,9 @@ function isYarnClassic({dir}) {
343
378
  if (fs.existsSync(path.join(dir, '.yarnrc.yml'))) return false;
344
379
  if (fs.existsSync(path.join(dir, '.yarnrc'))) return true;
345
380
  }
346
- const agent = /^yarn\/(\d+)\./.exec(String(process.env.npm_config_user_agent ?? ''));
381
+ const agent = /^yarn\/(\d+)\./.exec(
382
+ String(process.env.npm_config_user_agent ?? ''),
383
+ );
347
384
  return agent ? agent[1] === '1' : false;
348
385
  }
349
386
 
@@ -354,8 +391,12 @@ function isYarnClassic({dir}) {
354
391
  */
355
392
  function declaredYarnMajor(dir) {
356
393
  try {
357
- const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
358
- const match = /^yarn@(\d+)(?:[.+]|$)/.exec(String(pkg.packageManager ?? ''));
394
+ const pkg = JSON.parse(
395
+ fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'),
396
+ );
397
+ const match = /^yarn@(\d+)(?:[.+]|$)/.exec(
398
+ String(pkg.packageManager ?? ''),
399
+ );
359
400
  return match ? Number(match[1]) : null;
360
401
  } catch {
361
402
  // Best-effort: no package.json, or an unreadable one.
@@ -465,7 +506,9 @@ export function getCliInvocation(targetDir) {
465
506
  * @returns {string}
466
507
  */
467
508
  export function formatCliCommand(command, targetDir) {
468
- const sub = String(command).replace(/^\s*astryx\b\s*/, '').trim();
509
+ const sub = String(command)
510
+ .replace(/^\s*astryx\b\s*/, '')
511
+ .trim();
469
512
  const stem = getCliInvocation(targetDir);
470
513
  return sub ? `${stem} ${sub}` : stem;
471
514
  }
@@ -196,7 +196,7 @@ export const doc = {
196
196
  {
197
197
  value: 'template.copy',
198
198
  description:
199
- "A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing). The envelope's package names the npm package that owns the template.",
199
+ "A scaffold receipt: template id, output directory, written file name, file count, demoMediaReplaced (how many Astryx demo media references were replaced with placeholders), notes (setup notes naming what the template needs that the project lacks — missing packages, missing StyleX compiler; empty when satisfied), missingPackages (external package names the template imports that are not in the project), and installCommand (a ready-to-run install command with the detected package manager and workspace version ranges; null when nothing is missing, or when several lockfiles leave the package manager undetermined). The envelope's package names the npm package that owns the template.",
200
200
  },
201
201
 
202
202
  {
@@ -349,6 +349,5 @@ export const doc = {
349
349
  description:
350
350
  'validated (false when no integration manifest was found, so nothing was inspected), the integration identity, structural issues, and Core doc overlaps. Each finding includes `severity` (`info` | `error`) and `relationship` (`replaces` | `extends` | `accidental`).',
351
351
  },
352
-
353
352
  ],
354
353
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.7.0-canary.81dc9bb",
3
+ "version": "0.7.0-canary.94bdc8e",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -101,10 +101,10 @@
101
101
  "zod": "^4.4.3"
102
102
  },
103
103
  "peerDependencies": {
104
- "@astryxdesign/charts": "0.7.0-canary.81dc9bb",
105
- "@astryxdesign/core": "0.7.0-canary.81dc9bb",
106
- "@astryxdesign/lab": "0.7.0-canary.81dc9bb",
107
- "@astryxdesign/theme-neutral": "0.7.0-canary.81dc9bb"
104
+ "@astryxdesign/charts": "0.7.0-canary.94bdc8e",
105
+ "@astryxdesign/core": "0.7.0-canary.94bdc8e",
106
+ "@astryxdesign/lab": "0.7.0-canary.94bdc8e",
107
+ "@astryxdesign/theme-neutral": "0.7.0-canary.94bdc8e"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.7.0-canary.81dc9bb",
125
- "@astryxdesign/core": "0.7.0-canary.81dc9bb",
126
- "@astryxdesign/lab": "0.7.0-canary.81dc9bb",
127
- "@astryxdesign/theme-neutral": "0.7.0-canary.81dc9bb",
124
+ "@astryxdesign/charts": "0.7.0-canary.94bdc8e",
125
+ "@astryxdesign/core": "0.7.0-canary.94bdc8e",
126
+ "@astryxdesign/lab": "0.7.0-canary.94bdc8e",
127
+ "@astryxdesign/theme-neutral": "0.7.0-canary.94bdc8e",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",