@astryxdesign/cli 0.6.6-canary.6ea1fb7 → 0.6.6-canary.7c8ddf2

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 (176) hide show
  1. package/README.md +83 -83
  2. package/api/build/_adapter.d.mts +15 -0
  3. package/api/build/_adapter.mjs +22 -0
  4. package/api/build/build.doc.mjs +1 -1
  5. package/api/build/build.type.d.mts +4 -0
  6. package/api/build/build.type.mjs +1 -0
  7. package/api/build/help/help.mjs +1 -1
  8. package/api/build/kit/kit.mjs +12 -1
  9. package/api/component/component-replacement.test.mjs +12 -0
  10. package/api/component/component.doc.mjs +5 -2
  11. package/api/docs/_adapter.mjs +48 -1
  12. package/api/docs/compiled-topics.test.mjs +1 -1
  13. package/api/docs/detail/section/section.d.mts +44 -0
  14. package/api/docs/detail/section/section.mjs +164 -13
  15. package/api/docs/detail/section/section.test.mjs +4 -4
  16. package/api/docs/docOverlays.test.mjs +28 -17
  17. package/api/docs/docs.doc.mjs +3 -3
  18. package/api/docs/docs.mjs +11 -16
  19. package/api/docs/docs.test.mjs +9 -10
  20. package/api/docs/integration-tree.test.mjs +26 -26
  21. package/api/docs/integrationDocs.test.mjs +2 -2
  22. package/api/docs/namespace-section.test.mjs +260 -0
  23. package/api/docs/token-tables.test.mjs +93 -0
  24. package/api/doctor/doctor.d.mts +6 -0
  25. package/api/doctor/doctor.mjs +149 -40
  26. package/api/doctor/doctor.test.mjs +104 -0
  27. package/api/doctor/theme-checks.mjs +1 -1
  28. package/api/gap-report/gap-report.doc.mjs +2 -1
  29. package/api/init/run/run.mjs +1 -0
  30. package/api/integration/validate-integration.mjs +20 -4
  31. package/api/integration/validate-integration.test.mjs +73 -0
  32. package/api/layout/check/check.d.mts +1 -0
  33. package/api/layout/check/check.mjs +1 -0
  34. package/api/layout/expand/expand.d.mts +1 -0
  35. package/api/layout/expand/expand.mjs +1 -0
  36. package/api/layout/grammar/grammar.d.mts +1 -0
  37. package/api/layout/grammar/grammar.mjs +1 -0
  38. package/api/layout/layoutCheck.doc.mjs +1 -1
  39. package/api/layout/layoutExpand.doc.mjs +1 -1
  40. package/api/layout/layoutGrammar.doc.mjs +1 -1
  41. package/api/search/search.d.mts +44 -0
  42. package/api/search/search.domain-priority.test.mjs +261 -0
  43. package/api/search/search.mjs +191 -29
  44. package/api/swizzle/swizzle.doc.mjs +5 -2
  45. package/api/template/copy/copy.mjs +12 -0
  46. package/api/template/template.doc.mjs +1 -1
  47. package/api/template/template.type.d.mts +3 -0
  48. package/api/template/template.type.mjs +3 -0
  49. package/api/theme/build/build.d.mts +70 -0
  50. package/api/theme/build/build.mjs +205 -41
  51. package/api/theme/build/font-warning.d.mts +11 -0
  52. package/api/theme/build/font-warning.mjs +28 -3
  53. package/assets/docs/author-a-theme.doc.mjs +16 -11
  54. package/assets/docs/getting-started.doc.mjs +2 -2
  55. package/assets/docs/principles.doc.dense.mjs +3 -3
  56. package/assets/docs/principles.doc.mjs +4 -4
  57. package/assets/docs/principles.doc.zh.mjs +3 -3
  58. package/assets/docs/styling-overview.doc.mjs +6 -6
  59. package/assets/docs/theme.doc.dense.mjs +1 -1
  60. package/assets/docs/theme.doc.zh.mjs +1 -1
  61. package/assets/docs/tree/component-migration.doc.mjs +107 -0
  62. package/assets/docs/tree/css-and-stylex.doc.mjs +150 -0
  63. package/assets/docs/tree/font-setup.doc.mjs +122 -0
  64. package/assets/docs/tree/headers-and-footers.doc.mjs +0 -1
  65. package/assets/docs/tree/i18n-library-integration.doc.mjs +167 -0
  66. package/assets/docs/tree/i18n-quick-start.doc.mjs +101 -0
  67. package/assets/docs/{internationalization.doc.mjs → tree/i18n-rtl-and-testing.doc.mjs} +17 -223
  68. package/assets/docs/tree/internationalization.doc.mjs +29 -0
  69. package/assets/docs/tree/layout.doc.mjs +23 -0
  70. package/assets/docs/{migration.doc.mjs → tree/migration-setup.doc.mjs} +24 -129
  71. package/assets/docs/tree/migration-verification.doc.mjs +67 -0
  72. package/assets/docs/tree/migration.doc.mjs +28 -0
  73. package/assets/docs/tree/non-css-processing.doc.mjs +112 -0
  74. package/assets/docs/tree/other-libraries.doc.mjs +218 -0
  75. package/assets/docs/tree/responsive.doc.mjs +0 -4
  76. package/assets/docs/tree/scaffold.doc.mjs +0 -5
  77. package/assets/docs/tree/side-panels.doc.mjs +0 -1
  78. package/assets/docs/tree/structure.doc.mjs +0 -4
  79. package/assets/docs/tree/styling-advanced.doc.mjs +159 -0
  80. package/assets/docs/tree/styling-basics.doc.mjs +181 -0
  81. package/assets/docs/tree/styling-libraries.doc.mjs +30 -0
  82. package/assets/docs/tree/styling.doc.mjs +29 -0
  83. package/assets/docs/tree/tailwind.doc.mjs +65 -0
  84. package/assets/docs/tree/tokens-and-setup.doc.mjs +128 -0
  85. package/assets/docs/tree/tokens-border.doc.mjs +46 -0
  86. package/assets/docs/tree/tokens-color.doc.dense.mjs +10 -0
  87. package/assets/docs/tree/tokens-color.doc.mjs +438 -0
  88. package/assets/docs/tree/tokens-color.doc.zh.mjs +10 -0
  89. package/assets/docs/tree/tokens-data.doc.mjs +323 -0
  90. package/assets/docs/tree/tokens-duration.doc.mjs +78 -0
  91. package/assets/docs/tree/tokens-ease.doc.mjs +46 -0
  92. package/assets/docs/tree/tokens-focus.doc.mjs +57 -0
  93. package/assets/docs/tree/tokens-font-weight.doc.mjs +58 -0
  94. package/assets/docs/tree/tokens-radius.doc.dense.mjs +10 -0
  95. package/assets/docs/tree/tokens-radius.doc.mjs +70 -0
  96. package/assets/docs/tree/tokens-radius.doc.zh.mjs +10 -0
  97. package/assets/docs/tree/tokens-shadow.doc.dense.mjs +10 -0
  98. package/assets/docs/tree/tokens-shadow.doc.mjs +74 -0
  99. package/assets/docs/tree/tokens-shadow.doc.zh.mjs +10 -0
  100. package/assets/docs/tree/tokens-size.doc.dense.mjs +10 -0
  101. package/assets/docs/tree/tokens-size.doc.mjs +54 -0
  102. package/assets/docs/tree/tokens-size.doc.zh.mjs +10 -0
  103. package/assets/docs/tree/tokens-spacing.doc.dense.mjs +10 -0
  104. package/assets/docs/tree/tokens-spacing.doc.mjs +102 -0
  105. package/assets/docs/tree/tokens-spacing.doc.zh.mjs +10 -0
  106. package/assets/docs/tree/tokens-syntax.doc.mjs +98 -0
  107. package/assets/docs/tree/tokens-text-size.doc.mjs +90 -0
  108. package/assets/docs/tree/tokens-type-scale.doc.mjs +210 -0
  109. package/assets/docs/tree/tokens-typography.doc.mjs +54 -0
  110. package/assets/docs/tree/tokens-usage.doc.dense.mjs +10 -0
  111. package/assets/docs/tree/tokens-usage.doc.mjs +36 -0
  112. package/assets/docs/tree/tokens-usage.doc.zh.mjs +10 -0
  113. package/assets/docs/tree/tokens.doc.mjs +28 -0
  114. package/assets/docs/tree/type-scale.doc.mjs +147 -0
  115. package/assets/docs/tree/typography-best-practices.doc.mjs +55 -0
  116. package/assets/docs/tree/typography.doc.mjs +29 -0
  117. package/assets/docs/use-a-theme.doc.mjs +6 -3
  118. package/assets/templates/pages/incident-console/page.tsx +1 -1
  119. package/assets/theme.template.ts +4 -3
  120. package/clients/cli/commands/blog.mjs +3 -3
  121. package/clients/cli/commands/build-theme.adaptations.test.mjs +1 -1
  122. package/clients/cli/commands/build-theme.ascii-output.test.mjs +11 -1
  123. package/clients/cli/commands/build-theme.batch-report.test.mjs +335 -0
  124. package/clients/cli/commands/build-theme.font-warning.test.mjs +36 -7
  125. package/clients/cli/commands/build-theme.import-path.test.mjs +3 -3
  126. package/clients/cli/commands/build-theme.mjs +68 -18
  127. package/clients/cli/commands/build-theme.watch.test.mjs +33 -0
  128. package/clients/cli/commands/build.mjs +1 -0
  129. package/clients/cli/commands/component/index.mjs +4 -1
  130. package/clients/cli/commands/component-replacement.text.test.mjs +45 -0
  131. package/clients/cli/commands/docs.doc.mjs +2 -1
  132. package/clients/cli/commands/docs.test.mjs +15 -12
  133. package/clients/cli/commands/doctor-integration-components.doc.mjs +1 -1
  134. package/clients/cli/commands/doctor.test.mjs +50 -1
  135. package/clients/cli/commands/import-hint-correctness.test.mjs +23 -0
  136. package/clients/cli/commands/layout-check.doc.mjs +1 -0
  137. package/clients/cli/commands/layout-expand.doc.mjs +1 -0
  138. package/clients/cli/commands/layout-grammar.doc.mjs +1 -0
  139. package/clients/cli/commands/layout.deprecation-lifecycle.test.mjs +140 -0
  140. package/clients/cli/commands/layout.doc.mjs +1 -0
  141. package/clients/cli/commands/layout.mjs +6 -11
  142. package/clients/cli/commands/search.test.mjs +6 -2
  143. package/clients/cli/commands/swizzle.routing.test.mjs +2 -1
  144. package/clients/cli/commands/template.mjs +4 -3
  145. package/clients/cli/commands/theme-add-lifecycle.test.mjs +9 -6
  146. package/clients/cli/commands/theme-build.doc.mjs +3 -1
  147. package/clients/cli/commands/upgrade.config-ordering.test.mjs +2 -1
  148. package/clients/cli/index.mjs +1 -1
  149. package/clients/cli/lib/component-format.mjs +13 -3
  150. package/clients/cli/lib/component-format.test.mjs +1 -1
  151. package/clients/cli/lib/define-command.mjs +4 -0
  152. package/foundation/agent-docs/agent-docs.mjs +18 -2
  153. package/foundation/agent-docs/agent-docs.test.mjs +18 -0
  154. package/foundation/config/project.test.mjs +1 -1
  155. package/foundation/discovery/docs-discovery.test.mjs +1 -1
  156. package/foundation/discovery/template-needs.d.mts +31 -0
  157. package/foundation/discovery/template-needs.mjs +156 -0
  158. package/foundation/discovery/template-needs.test.mjs +203 -0
  159. package/foundation/doc-compiler/bundle.mjs +52 -1
  160. package/foundation/doc-compiler/split-topic-keywords.test.mjs +73 -0
  161. package/foundation/doc-compiler/tree.d.mts +10 -0
  162. package/foundation/doc-compiler/tree.mjs +22 -0
  163. package/foundation/doc-compiler/tree.test.mjs +3 -2
  164. package/foundation/env/package-manager.d.mts +31 -8
  165. package/foundation/env/package-manager.mjs +120 -13
  166. package/foundation/env/package-manager.test.mjs +174 -1
  167. package/foundation/integrations/validate-contributions.d.mts +16 -0
  168. package/foundation/integrations/validate-contributions.mjs +56 -8
  169. package/foundation/response/response-types.doc.mjs +4 -4
  170. package/package.json +9 -9
  171. package/assets/docs/styling-libraries.doc.mjs +0 -469
  172. package/assets/docs/styling.doc.mjs +0 -412
  173. package/assets/docs/tokens.doc.dense.mjs +0 -15
  174. package/assets/docs/tokens.doc.mjs +0 -1491
  175. package/assets/docs/tokens.doc.zh.mjs +0 -15
  176. package/assets/docs/typography.doc.mjs +0 -286
@@ -495,7 +495,7 @@ describe("the CLI's own docs tree", () => {
495
495
  async () => {
496
496
  const tree = await loadDocsTree({fresh: true});
497
497
  expect(tree.diagnostics).toEqual([]);
498
- expect(tree.roots().map(node => node.route)).toEqual(['cli', 'layout']);
498
+ expect(tree.roots().map(node => node.route)).toEqual(['cli', 'internationalization', 'layout', 'migration', 'styling', 'styling-libraries', 'tokens', 'typography']);
499
499
  // Every slot child is a node one level below the namespace that places
500
500
  // it, and every node but the root is placed. Read from the tree, so a
501
501
  // restructure of the guides does not need this test edited.
@@ -518,10 +518,11 @@ describe("the CLI's own docs tree", () => {
518
518
  }
519
519
  }
520
520
  expect(misplaced).toEqual([]);
521
+ const roots = new Set(tree.roots().map(node => node.route));
521
522
  expect(
522
523
  nodes
523
524
  .map(node => node.route)
524
- .filter(route => route !== 'cli' && route !== 'layout' && !placed.has(route)),
525
+ .filter(route => !roots.has(route) && !placed.has(route)),
525
526
  ).toEqual([]);
526
527
  // The reference groups the CLI generates from its own typed docs.
527
528
  expect(
@@ -80,6 +80,9 @@ export function getRunPrefix(targetDir?: string): string;
80
80
  * {@link CLI_PACKAGE}, never the bare `astryx` bin. Running bare `npx astryx`
81
81
  * without the CLI installed resolves to an unrelated package on the registry.
82
82
  *
83
+ * Classic Yarn (1.x) has no `dlx`, so its projects get `npx`, which every
84
+ * Node install carries.
85
+ *
83
86
  * @param {string} [targetDir]
84
87
  * @returns {string} e.g. 'npx', 'pnpm dlx', 'yarn dlx', 'bunx'
85
88
  */
@@ -90,22 +93,42 @@ export function getDlxPrefix(targetDir?: string): string;
90
93
  *
91
94
  * We sniff the entry path (`process.argv[1]`) for well-known runner-cache
92
95
  * 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`).
96
+ * {@link getCliInvocation}'s on-disk check, and a false positive emits the
97
+ * always-valid scoped form (`<dlx> @astryxdesign/cli`).
95
98
  *
96
99
  * @returns {boolean}
97
100
  */
98
101
  export function isCliOneOff(): boolean;
102
+ /**
103
+ * Does the bare `astryx` bin resolve from `targetDir`?
104
+ *
105
+ * A package runner finds an installed bin in `node_modules/.bin`, in the
106
+ * project or in a folder above it (a workspace root). When no such link
107
+ * exists, `npx astryx` and `bunx astryx` fetch the unrelated registry package
108
+ * named `astryx` instead of running this CLI, and `pnpm exec astryx` or
109
+ * `yarn astryx` fail. A global install, or a workspace install running in a
110
+ * fresh package, is exactly that case.
111
+ *
112
+ * A false negative (a layout without `node_modules/.bin`, such as Yarn Plug'n'Play)
113
+ * is safe: the caller suggests the scoped package, which always resolves.
114
+ *
115
+ * @param {string} [targetDir=process.cwd()]
116
+ * @returns {boolean}
117
+ */
118
+ export function cliBinResolves(targetDir?: string): boolean;
99
119
  /**
100
120
  * The safe, install-aware CLI invocation stem to suggest to users.
101
121
  *
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.
122
+ * - The `astryx` bin resolves from `targetDir`: `<run-prefix> astryx`
123
+ * (e.g. `pnpm exec astryx`).
124
+ * - Launched one-off (npx/dlx cache), or the bin does not resolve from
125
+ * `targetDir` (a global install, a fresh package in a workspace):
126
+ * `<dlx-prefix> @astryxdesign/cli`. The bare `astryx` name would make npm
127
+ * fetch an unrelated registry package; the scoped package always resolves
128
+ * to this CLI.
107
129
  *
108
- * @param {string} [targetDir]
130
+ * @param {string} [targetDir] the project the printed command runs in;
131
+ * defaults to the working directory
109
132
  * @returns {string}
110
133
  */
111
134
  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';
@@ -299,13 +301,16 @@ export const CLI_BIN = 'astryx';
299
301
  * {@link CLI_PACKAGE}, never the bare `astryx` bin. Running bare `npx astryx`
300
302
  * without the CLI installed resolves to an unrelated package on the registry.
301
303
  *
304
+ * Classic Yarn (1.x) has no `dlx`, so its projects get `npx`, which every
305
+ * Node install carries.
306
+ *
302
307
  * @param {string} [targetDir]
303
308
  * @returns {string} e.g. 'npx', 'pnpm dlx', 'yarn dlx', 'bunx'
304
309
  */
305
310
  export function getDlxPrefix(targetDir) {
306
- const pm = detectPackageManager(targetDir);
307
- switch (pm) {
308
- case 'yarn': return 'yarn dlx';
311
+ const resolution = explainPackageManager(targetDir);
312
+ switch (resolution.pm) {
313
+ case 'yarn': return isYarnClassic(resolution) ? 'npx' : 'yarn dlx';
309
314
  case 'pnpm': return 'pnpm dlx';
310
315
  case 'bun': return 'bunx';
311
316
  case 'npm':
@@ -313,14 +318,79 @@ export function getDlxPrefix(targetDir) {
313
318
  }
314
319
  }
315
320
 
321
+ /**
322
+ * Is the project's Yarn the classic line (1.x), which has no `dlx`?
323
+ *
324
+ * Read from the signals detection trusts, in the same order: the declared
325
+ * `packageManager` version, then the lockfile header (`# yarn lockfile v1`
326
+ * is classic; Berry's lockfile carries `__metadata:`), then a committed
327
+ * config (`.yarnrc.yml` is Berry, a lone `.yarnrc` classic), then the
328
+ * runner's user agent (`yarn/1.22.21 …`). With none of them it is Berry.
329
+ *
330
+ * @param {PackageManagerResolution} resolution
331
+ * @returns {boolean}
332
+ */
333
+ function isYarnClassic({dir}) {
334
+ if (dir) {
335
+ const declared = declaredYarnMajor(dir);
336
+ if (declared !== null) return declared === 1;
337
+ const lockfile = path.join(dir, 'yarn.lock');
338
+ if (fs.existsSync(lockfile)) {
339
+ const head = readHead(lockfile);
340
+ if (/^# yarn lockfile v1\b/m.test(head)) return true;
341
+ if (/^__metadata:/m.test(head)) return false;
342
+ }
343
+ if (fs.existsSync(path.join(dir, '.yarnrc.yml'))) return false;
344
+ if (fs.existsSync(path.join(dir, '.yarnrc'))) return true;
345
+ }
346
+ const agent = /^yarn\/(\d+)\./.exec(String(process.env.npm_config_user_agent ?? ''));
347
+ return agent ? agent[1] === '1' : false;
348
+ }
349
+
350
+ /**
351
+ * The major version in a directory's `packageManager: "yarn@<version>"`.
352
+ * @param {string} dir
353
+ * @returns {number | null}
354
+ */
355
+ function declaredYarnMajor(dir) {
356
+ try {
357
+ const pkg = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'));
358
+ const match = /^yarn@(\d+)(?:[.+]|$)/.exec(String(pkg.packageManager ?? ''));
359
+ return match ? Number(match[1]) : null;
360
+ } catch {
361
+ // Best-effort: no package.json, or an unreadable one.
362
+ return null;
363
+ }
364
+ }
365
+
366
+ /**
367
+ * The first bytes of a file — enough for a lockfile's header.
368
+ * @param {string} file
369
+ * @returns {string}
370
+ */
371
+ function readHead(file) {
372
+ try {
373
+ const fd = fs.openSync(file, 'r');
374
+ try {
375
+ const buffer = Buffer.alloc(512);
376
+ const bytes = fs.readSync(fd, buffer, 0, buffer.length, 0);
377
+ return buffer.toString('utf-8', 0, bytes);
378
+ } finally {
379
+ fs.closeSync(fd);
380
+ }
381
+ } catch {
382
+ return '';
383
+ }
384
+ }
385
+
316
386
  /**
317
387
  * Heuristic: was the running CLI launched one-off via a package runner
318
388
  * (npx / pnpm dlx / yarn dlx / bunx) rather than from an installed dependency?
319
389
  *
320
390
  * We sniff the entry path (`process.argv[1]`) for well-known runner-cache
321
391
  * 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`).
392
+ * {@link getCliInvocation}'s on-disk check, and a false positive emits the
393
+ * always-valid scoped form (`<dlx> @astryxdesign/cli`).
324
394
  *
325
395
  * @returns {boolean}
326
396
  */
@@ -329,20 +399,57 @@ export function isCliOneOff() {
329
399
  return /\/_npx\/|\/dlx[-/]|\/\.bun\/install\/cache\/|\/bunx-/.test(entry);
330
400
  }
331
401
 
402
+ /** The `astryx` bin as package managers link it, including the Windows shims. */
403
+ const CLI_BIN_LINKS = [CLI_BIN, `${CLI_BIN}.cmd`, `${CLI_BIN}.ps1`];
404
+
405
+ /**
406
+ * Does the bare `astryx` bin resolve from `targetDir`?
407
+ *
408
+ * A package runner finds an installed bin in `node_modules/.bin`, in the
409
+ * project or in a folder above it (a workspace root). When no such link
410
+ * exists, `npx astryx` and `bunx astryx` fetch the unrelated registry package
411
+ * named `astryx` instead of running this CLI, and `pnpm exec astryx` or
412
+ * `yarn astryx` fail. A global install, or a workspace install running in a
413
+ * fresh package, is exactly that case.
414
+ *
415
+ * A false negative (a layout without `node_modules/.bin`, such as Yarn Plug'n'Play)
416
+ * is safe: the caller suggests the scoped package, which always resolves.
417
+ *
418
+ * @param {string} [targetDir=process.cwd()]
419
+ * @returns {boolean}
420
+ */
421
+ export function cliBinResolves(targetDir = process.cwd()) {
422
+ let dir = path.resolve(targetDir);
423
+ for (;;) {
424
+ const binDir = path.join(dir, 'node_modules', '.bin');
425
+ if (CLI_BIN_LINKS.some(name => fs.existsSync(path.join(binDir, name)))) {
426
+ return true;
427
+ }
428
+ const parent = path.dirname(dir);
429
+ if (parent === dir) return false;
430
+ dir = parent;
431
+ }
432
+ }
433
+
332
434
  /**
333
435
  * The safe, install-aware CLI invocation stem to suggest to users.
334
436
  *
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.
437
+ * - The `astryx` bin resolves from `targetDir`: `<run-prefix> astryx`
438
+ * (e.g. `pnpm exec astryx`).
439
+ * - Launched one-off (npx/dlx cache), or the bin does not resolve from
440
+ * `targetDir` (a global install, a fresh package in a workspace):
441
+ * `<dlx-prefix> @astryxdesign/cli`. The bare `astryx` name would make npm
442
+ * fetch an unrelated registry package; the scoped package always resolves
443
+ * to this CLI.
340
444
  *
341
- * @param {string} [targetDir]
445
+ * @param {string} [targetDir] the project the printed command runs in;
446
+ * defaults to the working directory
342
447
  * @returns {string}
343
448
  */
344
449
  export function getCliInvocation(targetDir) {
345
- if (isCliOneOff()) return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
450
+ if (isCliOneOff() || !cliBinResolves(targetDir)) {
451
+ return `${getDlxPrefix(targetDir)} ${CLI_PACKAGE}`;
452
+ }
346
453
  return `${getRunPrefix(targetDir)} ${CLI_BIN}`;
347
454
  }
348
455
 
@@ -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,24 @@ 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
+ /** The header a classic Yarn (1.x) lockfile starts with. */
43
+ const YARN_V1_LOCK =
44
+ '# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n# yarn lockfile v1\n\n';
45
+
46
+ /** The header a Berry (Yarn 2+) lockfile starts with. */
47
+ const YARN_BERRY_LOCK =
48
+ '# This file is generated by running "yarn install" inside your project.\n# Manual changes might be lost - proceed with caution!\n\n__metadata:\n version: 8\n';
49
+
50
+ /** An installed CLI's entry, outside any runner cache (a global or workspace install). */
51
+ const INSTALLED_ENTRY = '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
52
+
34
53
  describe('detectPackageManager', () => {
35
54
  it('detects yarn from yarn.lock', () => {
36
55
  const dir = makeTmpDir();
@@ -79,6 +98,7 @@ describe('detectPackageManager', () => {
79
98
  const dir = makeTmpDir();
80
99
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
81
100
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
101
+ linkCliBin(dir);
82
102
  process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
83
103
  expect(detectPackageManager(dir)).not.toBe('yarn');
84
104
  expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -90,6 +110,7 @@ describe('detectPackageManager', () => {
90
110
  try {
91
111
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
92
112
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
113
+ linkCliBin(dir);
93
114
  process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
94
115
  process.argv[1] = path.join(dir, 'node_modules/.bin/astryx');
95
116
  expect(getCliInvocation(dir)).toBe('npx astryx');
@@ -198,6 +219,7 @@ describe('detectPackageManager', () => {
198
219
  path.join(dir, 'package.json'),
199
220
  JSON.stringify({packageManager: 'pnpm@8.0.0'}),
200
221
  );
222
+ linkCliBin(dir);
201
223
  expect(detectPackageManager(dir)).toBe('pnpm');
202
224
  expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
203
225
  });
@@ -311,6 +333,78 @@ describe('getDlxPrefix', () => {
311
333
  expect(getDlxPrefix(dir)).toBe('yarn dlx');
312
334
  });
313
335
 
336
+ // Classic Yarn (1.x) has no `dlx`; `yarn dlx …` fails there, so its one-off
337
+ // form is `npx`. Berry (2+) keeps `yarn dlx`.
338
+ it('returns "npx" for a classic Yarn lockfile', () => {
339
+ const dir = makeTmpDir();
340
+ fs.writeFileSync(path.join(dir, 'yarn.lock'), YARN_V1_LOCK);
341
+ expect(getDlxPrefix(dir)).toBe('npx');
342
+ });
343
+
344
+ it('returns "yarn dlx" for a Berry lockfile', () => {
345
+ const dir = makeTmpDir();
346
+ fs.writeFileSync(path.join(dir, 'yarn.lock'), YARN_BERRY_LOCK);
347
+ expect(getDlxPrefix(dir)).toBe('yarn dlx');
348
+ });
349
+
350
+ it('reads the declared packageManager version first', () => {
351
+ const classic = makeTmpDir();
352
+ fs.writeFileSync(
353
+ path.join(classic, 'package.json'),
354
+ JSON.stringify({packageManager: 'yarn@1.22.19'}),
355
+ );
356
+ // A Berry-looking lockfile does not outrank the declaration.
357
+ fs.writeFileSync(path.join(classic, 'yarn.lock'), YARN_BERRY_LOCK);
358
+ expect(getDlxPrefix(classic)).toBe('npx');
359
+ fs.rmSync(classic, {recursive: true, force: true});
360
+
361
+ const berry = makeTmpDir();
362
+ fs.writeFileSync(
363
+ path.join(berry, 'package.json'),
364
+ JSON.stringify({packageManager: 'yarn@4.5.0'}),
365
+ );
366
+ fs.writeFileSync(path.join(berry, 'yarn.lock'), YARN_V1_LOCK);
367
+ expect(getDlxPrefix(berry)).toBe('yarn dlx');
368
+ });
369
+
370
+ it('reads a bare major version in the declaration', () => {
371
+ const classic = makeTmpDir();
372
+ fs.writeFileSync(
373
+ path.join(classic, 'package.json'),
374
+ JSON.stringify({packageManager: 'yarn@1'}),
375
+ );
376
+ expect(getDlxPrefix(classic)).toBe('npx');
377
+ fs.rmSync(classic, {recursive: true, force: true});
378
+
379
+ const berry = makeTmpDir();
380
+ fs.writeFileSync(
381
+ path.join(berry, 'package.json'),
382
+ JSON.stringify({packageManager: 'yarn@4'}),
383
+ );
384
+ expect(getDlxPrefix(berry)).toBe('yarn dlx');
385
+ });
386
+
387
+ it('reads a committed Yarn config when the lockfile has no header', () => {
388
+ const classic = makeTmpDir();
389
+ fs.writeFileSync(path.join(classic, 'yarn.lock'), '');
390
+ fs.writeFileSync(path.join(classic, '.yarnrc'), '');
391
+ expect(getDlxPrefix(classic)).toBe('npx');
392
+ fs.rmSync(classic, {recursive: true, force: true});
393
+
394
+ const berry = makeTmpDir();
395
+ fs.writeFileSync(path.join(berry, 'yarn.lock'), '');
396
+ fs.writeFileSync(path.join(berry, '.yarnrc.yml'), '');
397
+ expect(getDlxPrefix(berry)).toBe('yarn dlx');
398
+ });
399
+
400
+ it('reads the runner version when nothing on disk names Yarn', () => {
401
+ makeTmpDir();
402
+ process.env.npm_config_user_agent = 'yarn/1.22.21 npm/? node/v22.0.0';
403
+ expect(getDlxPrefix(tmpDir)).toBe('npx');
404
+ process.env.npm_config_user_agent = 'yarn/4.5.0 npm/? node/v22.0.0';
405
+ expect(getDlxPrefix(tmpDir)).toBe('yarn dlx');
406
+ });
407
+
314
408
  it('returns "bunx" for bun projects', () => {
315
409
  const dir = makeTmpDir();
316
410
  fs.writeFileSync(path.join(dir, 'bun.lockb'), '');
@@ -351,14 +445,91 @@ describe('isCliOneOff', () => {
351
445
  });
352
446
  });
353
447
 
448
+ describe('cliBinResolves', () => {
449
+ it('finds the bin link in the project', () => {
450
+ const dir = makeTmpDir();
451
+ linkCliBin(dir);
452
+ expect(cliBinResolves(dir)).toBe(true);
453
+ });
454
+
455
+ it('finds it in a folder above the project (a workspace root)', () => {
456
+ const root = makeTmpDir();
457
+ linkCliBin(root);
458
+ const pkg = path.join(root, 'packages', 'app');
459
+ fs.mkdirSync(pkg, {recursive: true});
460
+ expect(cliBinResolves(pkg)).toBe(true);
461
+ });
462
+
463
+ it('finds a Windows shim', () => {
464
+ const dir = makeTmpDir();
465
+ linkCliBin(dir, 'astryx.cmd');
466
+ expect(cliBinResolves(dir)).toBe(true);
467
+ });
468
+
469
+ it('is false when no bin link exists up the tree', () => {
470
+ const dir = makeTmpDir();
471
+ fs.mkdirSync(path.join(dir, 'node_modules', '.bin'), {recursive: true});
472
+ expect(cliBinResolves(dir)).toBe(false);
473
+ });
474
+ });
475
+
354
476
  describe('getCliInvocation', () => {
355
- it('uses the run-prefix + bare bin when installed (not one-off)', () => {
477
+ it('uses the run-prefix + bare bin when the bin resolves from the project', () => {
356
478
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
357
479
  const dir = makeTmpDir();
358
480
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
481
+ linkCliBin(dir);
359
482
  expect(getCliInvocation(dir)).toBe('pnpm exec astryx');
360
483
  });
361
484
 
485
+ it('keeps `npx astryx` for a project with a local CLI', () => {
486
+ process.argv[1] = INSTALLED_ENTRY;
487
+ const dir = makeTmpDir();
488
+ fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
489
+ linkCliBin(dir);
490
+ expect(getCliInvocation(dir)).toBe('npx astryx');
491
+ });
492
+
493
+ it('keeps the installed form in a workspace package when the root has the bin', () => {
494
+ process.argv[1] = INSTALLED_ENTRY;
495
+ const root = makeTmpDir();
496
+ fs.writeFileSync(path.join(root, 'pnpm-lock.yaml'), '');
497
+ linkCliBin(root);
498
+ const pkg = path.join(root, 'packages', 'app');
499
+ fs.mkdirSync(pkg, {recursive: true});
500
+ fs.writeFileSync(path.join(pkg, 'package.json'), '{"name":"app"}');
501
+ expect(getCliInvocation(pkg)).toBe('pnpm exec astryx');
502
+ });
503
+
504
+ // The hazard: the npm package named `astryx` is not this CLI. Launched from
505
+ // an installed path (a global install, or a workspace install running in a
506
+ // fresh package), the CLI used to print `npx astryx` for a project where that
507
+ // bin does not resolve, so following the hint fetched someone else's package.
508
+ it.each([
509
+ ['package-lock.json', '{}', 'npx @astryxdesign/cli'],
510
+ ['pnpm-lock.yaml', '', 'pnpm dlx @astryxdesign/cli'],
511
+ ['yarn.lock', YARN_BERRY_LOCK, 'yarn dlx @astryxdesign/cli'],
512
+ ['yarn.lock', YARN_V1_LOCK, 'npx @astryxdesign/cli'],
513
+ ['bun.lockb', '', 'bunx @astryxdesign/cli'],
514
+ ])(
515
+ 'prints the scoped package for a project with no local CLI (%s), launched from an installed path',
516
+ (lockfile, contents, expected) => {
517
+ process.argv[1] = INSTALLED_ENTRY;
518
+ const dir = makeTmpDir();
519
+ fs.writeFileSync(path.join(dir, lockfile), contents);
520
+ expect(isCliOneOff()).toBe(false);
521
+ expect(getCliInvocation(dir)).toBe(expected);
522
+ },
523
+ );
524
+
525
+ it('prints the scoped package for a fresh package with no lockfile or install', () => {
526
+ process.argv[1] = INSTALLED_ENTRY;
527
+ const dir = makeTmpDir();
528
+ delete process.env.npm_config_user_agent;
529
+ fs.writeFileSync(path.join(dir, 'package.json'), '{"name":"fresh"}');
530
+ expect(getCliInvocation(dir)).toBe('npx @astryxdesign/cli');
531
+ });
532
+
362
533
  it('uses the dlx runner + scoped package when run one-off', () => {
363
534
  process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
364
535
  const dir = makeTmpDir();
@@ -379,6 +550,7 @@ describe('formatCliCommand', () => {
379
550
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
380
551
  const dir = makeTmpDir();
381
552
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
553
+ linkCliBin(dir);
382
554
  expect(formatCliCommand('astryx component Button', dir)).toBe('pnpm exec astryx component Button');
383
555
  });
384
556
 
@@ -386,6 +558,7 @@ describe('formatCliCommand', () => {
386
558
  process.argv[1] = '/proj/node_modules/@astryxdesign/cli/bin/astryx.mjs';
387
559
  const dir = makeTmpDir();
388
560
  fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
561
+ linkCliBin(dir);
389
562
  expect(formatCliCommand('docs tokens', dir)).toBe('npx astryx docs tokens');
390
563
  });
391
564
 
@@ -5,6 +5,22 @@
5
5
  export function issueError(code: string, message: string): Issue;
6
6
  /** @param {string} code @param {string} message @returns {Issue} */
7
7
  export function issueWarning(code: string, message: string): Issue;
8
+ /**
9
+ * Why a declared root cannot be read as a folder, or null when it can.
10
+ * A missing root keeps its own issue; a root that is a file or that the
11
+ * user running astryx cannot read used to surface as a raw errno from
12
+ * whichever check touched it first, or end validation outright.
13
+ * @param {string} root
14
+ * @returns {{kind: 'missing'} | {kind: 'not-a-folder'} | {kind: 'unreadable', code: string} | null}
15
+ */
16
+ export function rootProblem(root: string): {
17
+ kind: "missing";
18
+ } | {
19
+ kind: "not-a-folder";
20
+ } | {
21
+ kind: "unreadable";
22
+ code: string;
23
+ } | null;
8
24
  /**
9
25
  * Validate an already-LOADED integration (as produced by `loadIntegrations` —
10
26
  * absolute contribution roots plus identity) and return its issues. This is the
@@ -99,8 +99,40 @@ function checkUnknownKeys(integration, issues) {
99
99
  }
100
100
 
101
101
  /**
102
- * Verify each declared contribution root exists on disk. A declared-but-missing
103
- * root is a `missing_root` error.
102
+ * Why a declared root cannot be read as a folder, or null when it can.
103
+ * A missing root keeps its own issue; a root that is a file or that the
104
+ * user running astryx cannot read used to surface as a raw errno from
105
+ * whichever check touched it first, or end validation outright.
106
+ * @param {string} root
107
+ * @returns {{kind: 'missing'} | {kind: 'not-a-folder'} | {kind: 'unreadable', code: string} | null}
108
+ */
109
+ export function rootProblem(root) {
110
+ let stat;
111
+ try {
112
+ stat = fs.statSync(root);
113
+ } catch (err) {
114
+ const code = /** @type {any} */ (err)?.code;
115
+ return code === 'ENOENT' || code === 'ENOTDIR'
116
+ ? {kind: 'missing'}
117
+ : {kind: 'unreadable', code: String(code ?? 'unknown error')};
118
+ }
119
+ if (!stat.isDirectory()) return {kind: 'not-a-folder'};
120
+ try {
121
+ fs.accessSync(root, fs.constants.R_OK | fs.constants.X_OK);
122
+ } catch (err) {
123
+ return {
124
+ kind: 'unreadable',
125
+ code: String(/** @type {any} */ (err)?.code ?? 'unknown error'),
126
+ };
127
+ }
128
+ return null;
129
+ }
130
+
131
+ /**
132
+ * Verify each declared contribution root is a folder Astryx can read. A
133
+ * declared-but-missing root is a `missing_root` error, a file is an
134
+ * `invalid_root` error, and a folder that cannot be read is an
135
+ * `unreadable_root` error. The contribution checks skip all three.
104
136
  * @param {{components?: string, templates?: string, codemods?: string, docs?: string, themes?: string}} resolved
105
137
  * absolute resolved roots (undefined when not declared)
106
138
  * @param {Issue[]} issues
@@ -116,13 +148,29 @@ function checkRoots(resolved, issues) {
116
148
  for (const kind of kinds) {
117
149
  const root = resolved[kind];
118
150
  if (root == null) continue;
119
- if (!fs.existsSync(root)) {
151
+ const problem = rootProblem(root);
152
+ if (problem == null) continue;
153
+ if (problem.kind === 'missing') {
120
154
  issues.push(
121
155
  issueError(
122
156
  'missing_root',
123
157
  `Declared ${kind} root does not exist on disk: ${root}`,
124
158
  ),
125
159
  );
160
+ } else if (problem.kind === 'not-a-folder') {
161
+ issues.push(
162
+ issueError(
163
+ 'invalid_root',
164
+ `Declared ${kind} root is a file, not a folder: ${root}. Fix: point "${kind}" in the manifest at the folder that holds them.`,
165
+ ),
166
+ );
167
+ } else {
168
+ issues.push(
169
+ issueError(
170
+ 'unreadable_root',
171
+ `Declared ${kind} root cannot be read (${problem.code}): ${root}. Fix: make it readable by the user running astryx.`,
172
+ ),
173
+ );
126
174
  }
127
175
  }
128
176
  }
@@ -135,7 +183,7 @@ function checkRoots(resolved, issues) {
135
183
  * @param {Issue[]} issues
136
184
  */
137
185
  async function checkCodemods(integration, issues) {
138
- if (!integration.codemods || !fs.existsSync(integration.codemods)) return;
186
+ if (!integration.codemods || rootProblem(integration.codemods)) return;
139
187
  const context = integration.__packageDir
140
188
  ? createFixContext(integration.__packageDir, integration)
141
189
  : null;
@@ -232,7 +280,7 @@ async function checkCodemods(integration, issues) {
232
280
  * @param {Issue[]} issues
233
281
  */
234
282
  async function checkTemplates(integration, issues) {
235
- if (!integration.templates || !fs.existsSync(integration.templates)) return;
283
+ if (!integration.templates || rootProblem(integration.templates)) return;
236
284
  try {
237
285
  const {errors} = await discoverIntegrationTemplatesForOne(integration);
238
286
  for (const e of errors) {
@@ -257,7 +305,7 @@ async function checkTemplates(integration, issues) {
257
305
  * @param {Issue[]} issues
258
306
  */
259
307
  async function checkComponents(integration, issues) {
260
- if (!integration.components || !fs.existsSync(integration.components)) return;
308
+ if (!integration.components || rootProblem(integration.components)) return;
261
309
  const discover = componentDiscovery.discoverValidIntegrationComponents;
262
310
  if (typeof discover !== 'function') return; // feature not present yet
263
311
  try {
@@ -330,7 +378,7 @@ async function checkComponents(integration, issues) {
330
378
  * @param {Issue[]} issues
331
379
  */
332
380
  async function checkDocs(integration, issues) {
333
- if (!integration.docs || !fs.existsSync(integration.docs)) return;
381
+ if (!integration.docs || rootProblem(integration.docs)) return;
334
382
  try {
335
383
  const {errors} = await discoverIntegrationDocs(integration);
336
384
  for (const e of errors) {
@@ -349,7 +397,7 @@ async function checkDocs(integration, issues) {
349
397
  * @param {Issue[]} issues
350
398
  */
351
399
  async function checkThemes(integration, issues) {
352
- if (!integration.themes || !fs.existsSync(integration.themes)) return;
400
+ if (!integration.themes || rootProblem(integration.themes)) return;
353
401
  try {
354
402
  await discoverIntegrationThemes(integration);
355
403
  } catch (err) {