@astryxdesign/cli 0.6.6-canary.c4df65c → 0.6.6-canary.cc0df20

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 (32) hide show
  1. package/api/theme/build/build.d.mts +70 -0
  2. package/api/theme/build/build.mjs +205 -43
  3. package/api/theme/build/font-warning.d.mts +11 -0
  4. package/api/theme/build/font-warning.mjs +28 -3
  5. package/assets/docs/author-a-theme.doc.mjs +12 -7
  6. package/assets/docs/theme.doc.zh.mjs +1 -1
  7. package/assets/docs/tree/layout.doc.mjs +20 -0
  8. package/assets/docs/use-a-theme.doc.mjs +6 -3
  9. package/assets/templates/pages/incident-console/page.tsx +1 -1
  10. package/clients/cli/commands/blog.mjs +3 -3
  11. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  12. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  13. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  14. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  15. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  16. package/clients/cli/commands/build-theme.mjs +64 -16
  17. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  18. package/clients/cli/commands/docs.test.mjs +2 -1
  19. package/clients/cli/commands/doctor.test.mjs +17 -1
  20. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  21. package/clients/cli/commands/search.test.mjs +6 -2
  22. package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
  23. package/clients/cli/commands/template.mjs +2 -2
  24. package/clients/cli/commands/theme-add-lifecycle.test.mjs +9 -6
  25. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  26. package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
  27. package/clients/cli/index.mjs +1 -1
  28. package/clients/cli/lib/component-format.test.mjs +1 -1
  29. package/foundation/env/package-manager.d.mts +28 -8
  30. package/foundation/env/package-manager.mjs +49 -10
  31. package/foundation/env/package-manager.test.mjs +93 -1
  32. package/package.json +9 -9
@@ -113,7 +113,8 @@ describe('progressive reads', () => {
113
113
  expect(status).toBe(0);
114
114
  expect(stdout).toMatch(/^principles +\S/m);
115
115
  expect(widest(stdout)).toBeLessThanOrEqual(120);
116
- expect(stdout).toContain('Usage: pnpm exec astryx docs <topic>');
116
+ // The repo root has no `astryx` bin, so the CLI names the scoped package.
117
+ expect(stdout).toMatch(/Usage: \S+(?: dlx)? (?:astryx|@astryxdesign\/cli) docs <topic>/);
117
118
  }, SLOW);
118
119
 
119
120
  it("prints a topic's section index with the keys to read by", async () => {
@@ -168,7 +168,23 @@ describe('doctor — individual checks', () => {
168
168
  it('agent-docs: INFO when no docs present', () => {
169
169
  const res = checkAgentDocs({cwd: tmpDir});
170
170
  expect(res.status).toBe('info');
171
- expect(res.fix).toContain('astryx init');
171
+ expect(res.fix).toContain('init --features agents');
172
+ });
173
+
174
+ // The npm package named `astryx` is not this CLI: a project without the
175
+ // `astryx` bin gets the scoped package in the fix, one with it keeps the bin.
176
+ it('agent-docs: the fix names the scoped package when the project has no local CLI', () => {
177
+ fs.writeFileSync(path.join(tmpDir, 'package-lock.json'), '{}');
178
+ const res = checkAgentDocs({cwd: tmpDir});
179
+ expect(res.fix).toContain('`npx @astryxdesign/cli init --features agents`');
180
+ });
181
+
182
+ it('agent-docs: the fix keeps `npx astryx` when the project has a local CLI', () => {
183
+ fs.writeFileSync(path.join(tmpDir, 'package-lock.json'), '{}');
184
+ fs.mkdirSync(path.join(tmpDir, 'node_modules', '.bin'), {recursive: true});
185
+ fs.writeFileSync(path.join(tmpDir, 'node_modules', '.bin', 'astryx'), '');
186
+ const res = checkAgentDocs({cwd: tmpDir});
187
+ expect(res.fix).toContain('`npx astryx init --features agents`');
172
188
  });
173
189
 
174
190
  it('agent-docs: WARN when docs exist without XDS markers', () => {
@@ -248,4 +248,27 @@ describe('import hint correctness', () => {
248
248
  });
249
249
  }
250
250
  });
251
+
252
+ describe('CLI --detail brief text output for a single component', () => {
253
+ it('brief text output names the component and its package', async () => {
254
+ const result = await runCli(['component', 'Button', '--detail', 'brief'], REPO_ROOT);
255
+ expect(result.code).toBe(0);
256
+ expect(result.stdout).toContain('Button');
257
+ expect(result.stdout).toContain('@astryxdesign/core');
258
+ });
259
+
260
+ it('brief text is shorter than compact text', async () => {
261
+ const brief = await runCli(['component', 'Button', '--detail', 'brief'], REPO_ROOT);
262
+ const compact = await runCli(['component', 'Button', '--detail', 'compact'], REPO_ROOT);
263
+ expect(brief.code).toBe(0);
264
+ expect(compact.code).toBe(0);
265
+ expect(brief.stdout.length).toBeLessThan(compact.stdout.length);
266
+ });
267
+
268
+ it('brief text shows the import path in the signature line', async () => {
269
+ const result = await runCli(['component', 'Button', '--detail', 'brief'], REPO_ROOT);
270
+ expect(result.code).toBe(0);
271
+ expect(result.stdout).toContain('@astryxdesign/core/Button');
272
+ });
273
+ });
251
274
  });
@@ -53,7 +53,11 @@ function asText(value) {
53
53
  * @param {unknown} value
54
54
  */
55
55
  function printsField(lines, key, value) {
56
- const shown = asText(value).split('\n')[0].trimEnd();
56
+ // The text prefixes a command (`command`, `parent`) with the project's
57
+ // invocation (`pnpm exec astryx`, or `pnpm dlx @astryxdesign/cli` where no
58
+ // `astryx` bin is installed), so compare the part after `astryx`.
59
+ const text = asText(value).split('\n')[0].trimEnd();
60
+ const shown = text.replace(/^astryx /, '');
57
61
  return lines.some(line => line.startsWith(`${key}:`) && line.trimEnd().endsWith(shown));
58
62
  }
59
63
 
@@ -282,7 +286,7 @@ describe('search CLI — exit codes + JSON contract', () => {
282
286
 
283
287
  it('renders each result as a greppable key: value record', async () => {
284
288
  const r = await runCli(['search', 'button'], REPO_ROOT);
285
- expect(r.stdout).toContain('astryx component Button');
289
+ expect(r.stdout).toMatch(/^command:\s+\S.*(?:astryx|@astryxdesign\/cli) component Button$/m);
286
290
  // Fields mirror the JSON object and are line-greppable.
287
291
  expect(r.stdout).toMatch(/^name:\s+Button$/m);
288
292
  expect(r.stdout).toMatch(/^domain:\s+component$/m);
@@ -305,7 +305,8 @@ describe('swizzle — StyleX build setup note (#3373)', () => {
305
305
  expect(humanResult.stdout).toMatch(/StyleX compiler/i);
306
306
  expect(humanResult.stdout).toMatch(/unstyled/i);
307
307
  expect(humanResult.stdout).toMatch(/next\/font/i);
308
- expect(humanResult.stdout).toMatch(/astryx docs styling/);
308
+ // The fixture has no `astryx` bin installed, so the note names the scoped package.
309
+ expect(humanResult.stdout).toMatch(/@astryxdesign\/cli docs styling/);
309
310
  });
310
311
 
311
312
  it('does not print the StyleX note for components without StyleX', async () => {
@@ -137,9 +137,9 @@ export function registerTemplate(program) {
137
137
  return lines.join('\n');
138
138
  };
139
139
  emit(
140
- section(`Page Templates (${pages.length})`),
140
+ pages.length > 0 && section(`Page Templates (${pages.length})`),
141
141
  pages.length > 0 && text(grouped(pages)),
142
- section(`Block Templates (${blocks.length})`),
142
+ blocks.length > 0 && section(`Block Templates (${blocks.length})`),
143
143
  blocks.length > 0 && text(grouped(blocks)),
144
144
  section('Usage'),
145
145
  text(
@@ -7,6 +7,7 @@ import * as fs from 'node:fs';
7
7
  import * as os from 'node:os';
8
8
  import * as path from 'node:path';
9
9
  import {runCli} from '../../../test-utils/run-cli.mjs';
10
+ import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
10
11
 
11
12
  let tmpDir;
12
13
 
@@ -35,10 +36,11 @@ describe('theme add compatibility lifecycle', () => {
35
36
  expect(result.stderr.match(/source copying is deprecated/g)).toHaveLength(
36
37
  1,
37
38
  );
38
- expect(result.stderr).toContain('pnpm exec astryx theme eject neutral');
39
- expect(result.stderr).toContain(
40
- 'pnpm exec astryx theme add neutral --import',
41
- );
39
+ // The app has no CLI installed, so the commands name the scoped package.
40
+ const run = getCliInvocation(tmpDir);
41
+ expect(run).toMatch(/ @astryxdesign\/cli$/);
42
+ expect(result.stderr).toContain(`${run} theme eject neutral`);
43
+ expect(result.stderr).toContain(`${run} theme add neutral --import`);
42
44
  expect(fs.existsSync(path.join(tmpDir, 'src/themes/neutral'))).toBe(true);
43
45
  expect(fs.existsSync(path.join(tmpDir, 'src/astryx-themes.ts'))).toBe(
44
46
  false,
@@ -77,11 +79,12 @@ describe('theme add compatibility lifecycle', () => {
77
79
 
78
80
  const textResult = await runCli(['theme', 'add', '--list'], tmpDir);
79
81
  expect(textResult.status, textResult.stderr).toBe(0);
82
+ const run = getCliInvocation(tmpDir);
80
83
  expect(textResult.stdout).toContain(
81
- 'Import one: pnpm exec astryx theme add <slug> --import [--package <package>]',
84
+ `Import one: ${run} theme add <slug> --import [--package <package>]`,
82
85
  );
83
86
  expect(textResult.stdout).toContain(
84
- 'Fork source: pnpm exec astryx theme eject <slug> [target-path]',
87
+ `Fork source: ${run} theme eject <slug> [target-path]`,
85
88
  );
86
89
  expect(textResult.stdout).not.toContain('theme add <slug> [target-path]');
87
90
  expect(textResult.stderr).not.toContain('deprecated');
@@ -21,7 +21,9 @@ export const doc = {
21
21
  'theme. --family combines one selected extension tree into the three files named by ' +
22
22
  'the required --family-key, ready for one CSS load and identity-only switching. ' +
23
23
  'With --check it writes nothing and reports source drift. --icons-specifier keeps ' +
24
- 'its existing generated-module behavior.',
24
+ 'its existing generated-module behavior. It prints one line per built theme and ' +
25
+ 'one line naming fonts the themes do not load; --detail full adds the install ' +
26
+ 'example and the font recipe, once for a batch.',
25
27
  fn: 'themeBuild',
26
28
  args: [{name: 'files', param: 'file', required: true, variadic: true}],
27
29
  options: [
@@ -187,8 +187,9 @@ describe('upgrade — core codemods run before config load', () => {
187
187
 
188
188
  const out = await runHuman(['upgrade', '--from', '0.1.2', '--path', 'src']);
189
189
  expect(out).toMatch(/fails strict validation/i);
190
+ // The fixture has no `astryx` bin installed, so the command names the scoped package.
190
191
  expect(out).toContain(
191
- 'astryx upgrade --from 0.1.2 --codemod migrate-layout-components-to-experimental --apply',
192
+ '@astryxdesign/cli upgrade --from 0.1.2 --codemod migrate-layout-components-to-experimental --apply',
192
193
  );
193
194
  expect(exitCode).not.toBe(1);
194
195
  });
@@ -362,7 +362,7 @@ export async function createProgram() {
362
362
  .addOption(
363
363
  new Option(
364
364
  '--detail <level>',
365
- 'Detail level for component, hook, and docs tree reads (e.g. docs cli/commands/build). Lists default to brief',
365
+ 'Detail level for component, hook, and docs tree reads (e.g. docs cli/commands/build), and for theme build reports. Lists default to brief; theme build prints one line per built theme unless full, which adds the install example and font recipe',
366
366
  )
367
367
  .choices(['full', 'compact', 'brief'])
368
368
  .default('full'),
@@ -56,7 +56,7 @@ describe('formatFull sub-component rendering', () => {
56
56
  expect(out).toContain('### XDSRadioListItem');
57
57
  expect(out).not.toContain('undefined');
58
58
  // Points the reader at the sub-component's own docs instead of a blank.
59
- expect(out).toContain('astryx component XDSRadioListItem');
59
+ expect(out).toMatch(/(?:astryx|@astryxdesign\/cli) component XDSRadioListItem/);
60
60
  });
61
61
 
62
62
  it('renders a full props table for a sub-component that has inline props', () => {
@@ -90,22 +90,42 @@ export function getDlxPrefix(targetDir?: string): string;
90
90
  *
91
91
  * We sniff the entry path (`process.argv[1]`) for well-known runner-cache
92
92
  * markers. This errs safe in both directions: a false negative falls back to
93
- * the installed form (`<prefix> astryx`, the historical behavior), and a false
94
- * positive emits the always-valid scoped form (`<dlx> @astryxdesign/cli`).
93
+ * {@link getCliInvocation}'s on-disk check, and a false positive emits the
94
+ * always-valid scoped form (`<dlx> @astryxdesign/cli`).
95
95
  *
96
96
  * @returns {boolean}
97
97
  */
98
98
  export function isCliOneOff(): boolean;
99
+ /**
100
+ * Does the bare `astryx` bin resolve from `targetDir`?
101
+ *
102
+ * A package runner finds an installed bin in `node_modules/.bin`, in the
103
+ * project or in a folder above it (a workspace root). When no such link
104
+ * exists, `npx astryx` and `bunx astryx` fetch the unrelated registry package
105
+ * named `astryx` instead of running this CLI, and `pnpm exec astryx` or
106
+ * `yarn astryx` fail. A global install, or a workspace install running in a
107
+ * fresh package, is exactly that case.
108
+ *
109
+ * A false negative (a layout without `node_modules/.bin`, such as Yarn Plug'n'Play)
110
+ * is safe: the caller suggests the scoped package, which always resolves.
111
+ *
112
+ * @param {string} [targetDir=process.cwd()]
113
+ * @returns {boolean}
114
+ */
115
+ export function cliBinResolves(targetDir?: string): boolean;
99
116
  /**
100
117
  * The safe, install-aware CLI invocation stem to suggest to users.
101
118
  *
102
- * - Installed / global / dev: `<run-prefix> astryx` (e.g. `pnpm exec astryx`).
103
- * Bare `astryx` resolves to the local (or global) binary.
104
- * - One-off (npx/dlx cache): `<dlx-prefix> @astryxdesign/cli` — the bare
105
- * `astryx` name isn't on disk, so npm would fetch an unrelated registry
106
- * package; the scoped package always resolves to us.
119
+ * - The `astryx` bin resolves from `targetDir`: `<run-prefix> astryx`
120
+ * (e.g. `pnpm exec astryx`).
121
+ * - Launched one-off (npx/dlx cache), or the bin does not resolve from
122
+ * `targetDir` (a global install, a fresh package in a workspace):
123
+ * `<dlx-prefix> @astryxdesign/cli`. The bare `astryx` name would make npm
124
+ * fetch an unrelated registry package; the scoped package always resolves
125
+ * to this CLI.
107
126
  *
108
- * @param {string} [targetDir]
127
+ * @param {string} [targetDir] the project the printed command runs in;
128
+ * defaults to the working directory
109
129
  * @returns {string}
110
130
  */
111
131
  export function getCliInvocation(targetDir?: string): string;
@@ -6,7 +6,9 @@
6
6
  * The order is: the `packageManager` field a project DECLARES, then the
7
7
  * lockfiles it happens to have, then a committed package-manager config, then
8
8
  * the runner that launched us. Returns the correct command prefix for running
9
- * package binaries (e.g. 'npx astryx', 'yarn astryx', 'pnpm exec astryx').
9
+ * package binaries (e.g. 'npx astryx', 'yarn astryx', 'pnpm exec astryx'), and
10
+ * the scoped one-off form ('npx @astryxdesign/cli') when the `astryx` bin does
11
+ * not resolve from the project.
10
12
  */
11
13
 
12
14
  import * as fs from 'node:fs';
@@ -319,8 +321,8 @@ export function getDlxPrefix(targetDir) {
319
321
  *
320
322
  * We sniff the entry path (`process.argv[1]`) for well-known runner-cache
321
323
  * markers. This errs safe in both directions: a false negative falls back to
322
- * the installed form (`<prefix> astryx`, the historical behavior), and a false
323
- * positive emits the always-valid scoped form (`<dlx> @astryxdesign/cli`).
324
+ * {@link getCliInvocation}'s on-disk check, and a false positive emits the
325
+ * always-valid scoped form (`<dlx> @astryxdesign/cli`).
324
326
  *
325
327
  * @returns {boolean}
326
328
  */
@@ -329,20 +331,57 @@ export function isCliOneOff() {
329
331
  return /\/_npx\/|\/dlx[-/]|\/\.bun\/install\/cache\/|\/bunx-/.test(entry);
330
332
  }
331
333
 
334
+ /** The `astryx` bin as package managers link it, including the Windows shims. */
335
+ const CLI_BIN_LINKS = [CLI_BIN, `${CLI_BIN}.cmd`, `${CLI_BIN}.ps1`];
336
+
337
+ /**
338
+ * Does the bare `astryx` bin resolve from `targetDir`?
339
+ *
340
+ * A package runner finds an installed bin in `node_modules/.bin`, in the
341
+ * project or in a folder above it (a workspace root). When no such link
342
+ * exists, `npx astryx` and `bunx astryx` fetch the unrelated registry package
343
+ * named `astryx` instead of running this CLI, and `pnpm exec astryx` or
344
+ * `yarn astryx` fail. A global install, or a workspace install running in a
345
+ * fresh package, is exactly that case.
346
+ *
347
+ * A false negative (a layout without `node_modules/.bin`, such as Yarn Plug'n'Play)
348
+ * is safe: the caller suggests the scoped package, which always resolves.
349
+ *
350
+ * @param {string} [targetDir=process.cwd()]
351
+ * @returns {boolean}
352
+ */
353
+ export function cliBinResolves(targetDir = process.cwd()) {
354
+ let dir = path.resolve(targetDir);
355
+ for (;;) {
356
+ const binDir = path.join(dir, 'node_modules', '.bin');
357
+ if (CLI_BIN_LINKS.some(name => fs.existsSync(path.join(binDir, name)))) {
358
+ return true;
359
+ }
360
+ const parent = path.dirname(dir);
361
+ if (parent === dir) return false;
362
+ dir = parent;
363
+ }
364
+ }
365
+
332
366
  /**
333
367
  * The safe, install-aware CLI invocation stem to suggest to users.
334
368
  *
335
- * - Installed / global / dev: `<run-prefix> astryx` (e.g. `pnpm exec astryx`).
336
- * Bare `astryx` resolves to the local (or global) binary.
337
- * - One-off (npx/dlx cache): `<dlx-prefix> @astryxdesign/cli` — the bare
338
- * `astryx` name isn't on disk, so npm would fetch an unrelated registry
339
- * package; the scoped package always resolves to us.
369
+ * - The `astryx` bin resolves from `targetDir`: `<run-prefix> astryx`
370
+ * (e.g. `pnpm exec astryx`).
371
+ * - Launched one-off (npx/dlx cache), or the bin does not resolve from
372
+ * `targetDir` (a global install, a fresh package in a workspace):
373
+ * `<dlx-prefix> @astryxdesign/cli`. The bare `astryx` name would make npm
374
+ * fetch an unrelated registry package; the scoped package always resolves
375
+ * to this CLI.
340
376
  *
341
- * @param {string} [targetDir]
377
+ * @param {string} [targetDir] the project the printed command runs in;
378
+ * defaults to the working directory
342
379
  * @returns {string}
343
380
  */
344
381
  export function getCliInvocation(targetDir) {
345
- if (isCliOneOff()) return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
382
+ if (isCliOneOff() || !cliBinResolves(targetDir)) {
383
+ return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
384
+ }
346
385
  return `${getRunPrefix(targetDir)} ${CLI_BIN}`;
347
386
  }
348
387
 
@@ -9,6 +9,7 @@ import {
9
9
  explainPackageManager,
10
10
  getDlxPrefix,
11
11
  isCliOneOff,
12
+ cliBinResolves,
12
13
  getCliInvocation,
13
14
  formatCliCommand,
14
15
  } from './package-manager.mjs';
@@ -31,6 +32,16 @@ function makeTmpDir() {
31
32
  return tmpDir;
32
33
  }
33
34
 
35
+ /** Install the CLI's bin link in `dir`, the way a package manager does. */
36
+ function linkCliBin(dir, name = 'astryx') {
37
+ const binDir = path.join(dir, 'node_modules', '.bin');
38
+ fs.mkdirSync(binDir, {recursive: true});
39
+ fs.writeFileSync(path.join(binDir, name), '');
40
+ }
41
+
42
+ /** An installed CLI's entry, outside any runner cache (a global or workspace install). */
43
+ const INSTALLED_ENTRY = '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
44
+
34
45
  describe('detectPackageManager', () => {
35
46
  it('detects yarn from yarn.lock', () => {
36
47
  const dir = makeTmpDir();
@@ -79,6 +90,7 @@ describe('detectPackageManager', () => {
79
90
  const dir = makeTmpDir();
80
91
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
81
92
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
93
+ linkCliBin(dir);
82
94
  process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
83
95
  expect(detectPackageManager(dir)).not.toBe('yarn');
84
96
  expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -90,6 +102,7 @@ describe('detectPackageManager', () => {
90
102
  try {
91
103
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
92
104
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
105
+ linkCliBin(dir);
93
106
  process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
94
107
  process.argv[1] = path.join(dir, 'node_modules/.bin/astryx');
95
108
  expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -198,6 +211,7 @@ describe('detectPackageManager', () => {
198
211
  path.join(dir, 'package.json'),
199
212
  JSON.stringify({packageManager: 'pnpm@8.0.0'}),
200
213
  );
214
+ linkCliBin(dir);
201
215
  expect(detectPackageManager(dir)).toBe('pnpm');
202
216
  expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
203
217
  });
@@ -351,14 +365,90 @@ describe('isCliOneOff', () => {
351
365
  });
352
366
  });
353
367
 
368
+ describe('cliBinResolves', () => {
369
+ it('finds the bin link in the project', () => {
370
+ const dir = makeTmpDir();
371
+ linkCliBin(dir);
372
+ expect(cliBinResolves(dir)).toBe(true);
373
+ });
374
+
375
+ it('finds it in a folder above the project (a workspace root)', () => {
376
+ const root = makeTmpDir();
377
+ linkCliBin(root);
378
+ const pkg = path.join(root, 'packages', 'app');
379
+ fs.mkdirSync(pkg, {recursive: true});
380
+ expect(cliBinResolves(pkg)).toBe(true);
381
+ });
382
+
383
+ it('finds a Windows shim', () => {
384
+ const dir = makeTmpDir();
385
+ linkCliBin(dir, 'astryx.cmd');
386
+ expect(cliBinResolves(dir)).toBe(true);
387
+ });
388
+
389
+ it('is false when no bin link exists up the tree', () => {
390
+ const dir = makeTmpDir();
391
+ fs.mkdirSync(path.join(dir, 'node_modules', '.bin'), {recursive: true});
392
+ expect(cliBinResolves(dir)).toBe(false);
393
+ });
394
+ });
395
+
354
396
  describe('getCliInvocation', () => {
355
- it('uses the run-prefix + bare bin when installed (not one-off)', () => {
397
+ it('uses the run-prefix + bare bin when the bin resolves from the project', () => {
356
398
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
357
399
  const dir = makeTmpDir();
358
400
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
401
+ linkCliBin(dir);
359
402
  expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
360
403
  });
361
404
 
405
+ it('keeps `npx astryx` for a project with a local CLI', () => {
406
+ process.argv[1] = INSTALLED_ENTRY;
407
+ const dir = makeTmpDir();
408
+ fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
409
+ linkCliBin(dir);
410
+ expect(getCliInvocation(dir)).toBe('npx astryx');
411
+ });
412
+
413
+ it('keeps the installed form in a workspace package when the root has the bin', () => {
414
+ process.argv[1] = INSTALLED_ENTRY;
415
+ const root = makeTmpDir();
416
+ fs.writeFileSync(path.join(root, 'pnpm-lock.yaml'), '');
417
+ linkCliBin(root);
418
+ const pkg = path.join(root, 'packages', 'app');
419
+ fs.mkdirSync(pkg, {recursive: true});
420
+ fs.writeFileSync(path.join(pkg, 'package.json'), '{"name":"app"}');
421
+ expect(getCliInvocation(pkg)).toBe('pnpm exec astryx');
422
+ });
423
+
424
+ // The hazard: the npm package named `astryx` is not this CLI. Launched from
425
+ // an installed path (a global install, or a workspace install running in a
426
+ // fresh package), the CLI used to print `npx astryx` for a project where that
427
+ // bin does not resolve, so following the hint fetched someone else's package.
428
+ it.each([
429
+ ['package-lock.json', '{}', 'npx @astryxdesign/cli'],
430
+ ['pnpm-lock.yaml', '', 'pnpm dlx @astryxdesign/cli'],
431
+ ['yarn.lock', '', 'yarn dlx @astryxdesign/cli'],
432
+ ['bun.lockb', '', 'bunx @astryxdesign/cli'],
433
+ ])(
434
+ 'prints the scoped package for a project with no local CLI (%s), launched from an installed path',
435
+ (lockfile, contents, expected) => {
436
+ process.argv[1] = INSTALLED_ENTRY;
437
+ const dir = makeTmpDir();
438
+ fs.writeFileSync(path.join(dir, lockfile), contents);
439
+ expect(isCliOneOff()).toBe(false);
440
+ expect(getCliInvocation(dir)).toBe(expected);
441
+ },
442
+ );
443
+
444
+ it('prints the scoped package for a fresh package with no lockfile or install', () => {
445
+ process.argv[1] = INSTALLED_ENTRY;
446
+ const dir = makeTmpDir();
447
+ delete process.env.npm_config_user_agent;
448
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"fresh"}');
449
+ expect(getCliInvocation(dir)).toBe('npx @astryxdesign/cli');
450
+ });
451
+
362
452
  it('uses the dlx runner + scoped package when run one-off', () => {
363
453
  process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
364
454
  const dir = makeTmpDir();
@@ -379,6 +469,7 @@ describe('formatCliCommand', () => {
379
469
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
380
470
  const dir = makeTmpDir();
381
471
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
472
+ linkCliBin(dir);
382
473
  expect(formatCliCommand('astryx component Button', dir)).toBe('pnpm exec astryx component Button');
383
474
  });
384
475
 
@@ -386,6 +477,7 @@ describe('formatCliCommand', () => {
386
477
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
387
478
  const dir = makeTmpDir();
388
479
  fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
480
+ linkCliBin(dir);
389
481
  expect(formatCliCommand('docs tokens', dir)).toBe('npx astryx docs tokens');
390
482
  });
391
483
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.6.6-canary.c4df65c",
3
+ "version": "0.6.6-canary.cc0df20",
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.6.6-canary.c4df65c",
105
- "@astryxdesign/core": "0.6.6-canary.c4df65c",
106
- "@astryxdesign/lab": "0.6.6-canary.c4df65c",
107
- "@astryxdesign/theme-neutral": "0.6.6-canary.c4df65c"
104
+ "@astryxdesign/charts": "0.6.6-canary.cc0df20",
105
+ "@astryxdesign/core": "0.6.6-canary.cc0df20",
106
+ "@astryxdesign/lab": "0.6.6-canary.cc0df20",
107
+ "@astryxdesign/theme-neutral": "0.6.6-canary.cc0df20"
108
108
  },
109
109
  "peerDependenciesMeta": {
110
110
  "@astryxdesign/charts": {
@@ -121,10 +121,10 @@
121
121
  }
122
122
  },
123
123
  "devDependencies": {
124
- "@astryxdesign/charts": "0.6.6-canary.c4df65c",
125
- "@astryxdesign/core": "0.6.6-canary.c4df65c",
126
- "@astryxdesign/lab": "0.6.6-canary.c4df65c",
127
- "@astryxdesign/theme-neutral": "0.6.6-canary.c4df65c",
124
+ "@astryxdesign/charts": "0.6.6-canary.cc0df20",
125
+ "@astryxdesign/core": "0.6.6-canary.cc0df20",
126
+ "@astryxdesign/lab": "0.6.6-canary.cc0df20",
127
+ "@astryxdesign/theme-neutral": "0.6.6-canary.cc0df20",
128
128
  "@heroicons/react": "^2.2.0",
129
129
  "@stylexjs/stylex": "^0.19.0",
130
130
  "@types/babel__core": "^7.20.5",