@astryxdesign/cli 0.7.2-canary.621784f → 0.7.2-canary.6a3ff0f

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 (143) hide show
  1. package/README.md +10 -10
  2. package/api/doctor/doctor.mjs +27 -3
  3. package/api/doctor/doctor.test.mjs +43 -0
  4. package/api/gap-report/gap-report.d.mts +3 -0
  5. package/api/gap-report/gap-report.doc.mjs +11 -3
  6. package/api/gap-report/gap-report.mjs +152 -48
  7. package/api/gap-report/gap-report.test.mjs +233 -0
  8. package/api/gap-report/gap-report.type.d.mts +41 -0
  9. package/api/gap-report/gap-report.type.mjs +18 -0
  10. package/api/integration/integrationComponentConflicts.doc.mjs +9 -3
  11. package/api/integration/validateIntegration.doc.mjs +3 -1
  12. package/api/search/search.d.mts +72 -12
  13. package/api/search/search.domain-priority.test.mjs +108 -18
  14. package/api/search/search.mjs +501 -37
  15. package/api/search/search.test.mjs +139 -0
  16. package/api/theme/build/build.family.test.mjs +54 -6
  17. package/api/theme/build/build.mjs +110 -13
  18. package/api/theme/themeBuild.doc.mjs +4 -4
  19. package/api/upgrade/_adapter.d.mts +40 -2
  20. package/api/upgrade/_adapter.mjs +117 -4
  21. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  22. package/api/upgrade/run/run.mjs +30 -1
  23. package/api/upgrade/status/status.d.mts +21 -5
  24. package/api/upgrade/status/status.mjs +45 -8
  25. package/api/upgrade/upgrade.doc.mjs +5 -3
  26. package/api/upgrade/upgrade.type.d.mts +23 -0
  27. package/api/upgrade/upgrade.type.mjs +16 -1
  28. package/assets/codemods/runner.mjs +7 -1
  29. package/assets/docs/styling-overview.doc.mjs +1 -1
  30. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  31. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  32. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  33. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  34. package/assets/docs/tree/block-template.doc.mjs +6 -18
  35. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  36. package/assets/docs/tree/check-the-props.doc.mjs +1 -1
  37. package/assets/docs/tree/check-your-docs.doc.mjs +10 -5
  38. package/assets/docs/tree/checks.doc.mjs +5 -5
  39. package/assets/docs/tree/codemods.doc.mjs +4 -4
  40. package/assets/docs/tree/component-family.doc.mjs +3 -5
  41. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  42. package/assets/docs/tree/components.doc.mjs +1 -1
  43. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +25 -16
  44. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  45. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  46. package/assets/docs/tree/docs.doc.mjs +3 -3
  47. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  48. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  49. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  50. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  51. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  52. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  53. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  54. package/assets/docs/tree/integrations.doc.mjs +8 -0
  55. package/assets/docs/tree/links.doc.mjs +5 -4
  56. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  57. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  58. package/assets/docs/tree/migration.doc.mjs +0 -1
  59. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  60. package/assets/docs/tree/page-template.doc.mjs +3 -7
  61. package/assets/docs/tree/publishing.doc.mjs +1 -1
  62. package/assets/docs/tree/quick-start.doc.mjs +36 -20
  63. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  64. package/assets/docs/tree/replace-a-core-template.doc.mjs +5 -7
  65. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  66. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  67. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  68. package/assets/docs/tree/single-component.doc.mjs +12 -4
  69. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  70. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  71. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  72. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  73. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  74. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  75. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  76. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  77. package/assets/docs/tree/templates.doc.mjs +1 -1
  78. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  79. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  80. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  81. package/assets/docs/tree/troubleshooting.doc.mjs +4 -4
  82. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  83. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  84. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  85. package/assets/docs/tree/versioning.doc.mjs +6 -6
  86. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -2
  87. package/authoring/codemod/codemod.doc.mjs +7 -3
  88. package/authoring/config/config.doc.mjs +9 -6
  89. package/authoring/config/type.ts +4 -2
  90. package/authoring/discover/discover.doc.mjs +1 -1
  91. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  92. package/authoring/doctypes/command/command.doc.mjs +14 -12
  93. package/authoring/doctypes/component/component.doc.mjs +28 -25
  94. package/authoring/doctypes/component/type.ts +7 -5
  95. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  96. package/authoring/doctypes/function/function.doc.mjs +9 -8
  97. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  98. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  99. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  100. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  101. package/authoring/doctypes/template/template.doc.mjs +2 -2
  102. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  103. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  104. package/authoring/identity/identity.doc.mjs +3 -3
  105. package/authoring/integration/integration.doc.mjs +4 -3
  106. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  107. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  108. package/clients/cli/commands/doctor-integration-components.doc.mjs +3 -1
  109. package/clients/cli/commands/doctor-integration-validate.doc.mjs +3 -1
  110. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  111. package/clients/cli/commands/gap-report.mjs +24 -2
  112. package/clients/cli/commands/gap-report.test.mjs +79 -0
  113. package/clients/cli/commands/integration-check.test.mjs +17 -0
  114. package/clients/cli/commands/integration.mjs +2 -3
  115. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  116. package/clients/cli/commands/swizzle.mjs +5 -3
  117. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  118. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  119. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  120. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  121. package/clients/cli/index.mjs +29 -5
  122. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  123. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  124. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  125. package/foundation/agent-docs/agent-docs.mjs +8 -6
  126. package/foundation/discovery/authoring-self-docs.mjs +1 -1
  127. package/foundation/discovery/doc-types.d.mts +1 -1
  128. package/foundation/discovery/doc-types.mjs +3 -3
  129. package/foundation/discovery/doc-types.test.mjs +48 -0
  130. package/foundation/discovery/project-typescript.d.mts +11 -2
  131. package/foundation/discovery/project-typescript.mjs +32 -4
  132. package/foundation/discovery/prop-drift.d.mts +1 -1
  133. package/foundation/discovery/prop-drift.mjs +2 -2
  134. package/foundation/discovery/prop-drift.test.mjs +55 -2
  135. package/foundation/discovery/type-text.mjs +1 -1
  136. package/foundation/discovery/type-text.test.mjs +1 -1
  137. package/foundation/doc-compiler/doc-loads.test.mjs +6 -2
  138. package/foundation/env/package-manager.d.mts +32 -0
  139. package/foundation/env/package-manager.mjs +47 -0
  140. package/foundation/env/package-manager.test.mjs +194 -7
  141. package/foundation/response/response-types.doc.mjs +5 -4
  142. package/package.json +9 -9
  143. package/scripts/postinstall.mjs +3 -3
@@ -2,7 +2,9 @@
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
4
  /**
5
- * Resolve the project's own `typescript`, trying each directory in order.
5
+ * Resolve the project's own `typescript`, trying each directory in order;
6
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
7
+ * API package installed beside it.
6
8
  * @param {Array<string | null | undefined>} dirs
7
9
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
8
10
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -16,8 +18,15 @@ export function resolveProjectTypeScript(dirs: Array<string | null | undefined>)
16
18
  } | null;
17
19
  /**
18
20
  * Why a check that needs the compiler did not run, when the TypeScript
19
- * installed has no JavaScript compiler API.
21
+ * installed has no JavaScript compiler API, and what to do.
20
22
  * @param {string} version
21
23
  * @param {string} outcome what was not done, such as `docs were not checked`
22
24
  */
23
25
  export function unusableTypeScriptReason(version: string, outcome: string): string;
26
+ /**
27
+ * What to do when the project's TypeScript is missing or cannot be used:
28
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
29
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
30
+ * JavaScript doc) through 6.
31
+ */
32
+ export const TYPESCRIPT_FIX: "On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
@@ -15,7 +15,16 @@ import * as path from 'node:path';
15
15
  import {createRequire} from 'node:module';
16
16
 
17
17
  /**
18
- * Resolve the project's own `typescript`, trying each directory in order.
18
+ * The package TypeScript publishes beside TypeScript 7 for tools that need a
19
+ * JavaScript compiler API: TypeScript 6's. Kept in a constant so the type
20
+ * check does not treat the load as a static import of an uninstalled package.
21
+ */
22
+ const TYPESCRIPT_6_API = '@typescript/typescript6';
23
+
24
+ /**
25
+ * Resolve the project's own `typescript`, trying each directory in order;
26
+ * where it has no JavaScript compiler API (TypeScript 7), the TypeScript 6
27
+ * API package installed beside it.
19
28
  * @param {Array<string | null | undefined>} dirs
20
29
  * @returns {{ts: any, version: string} | {ts: null, version: string} | null}
21
30
  * `ts: null` when a TypeScript is installed but has no `createProgram`
@@ -43,19 +52,38 @@ export function resolveProjectTypeScript(dirs) {
43
52
  unusable ??= installed();
44
53
  } catch {
45
54
  // Not installed from here, or installed without an entry this CLI can
46
- // load; try the next directory.
55
+ // load.
47
56
  unusable ??= installed();
48
57
  }
58
+ // TypeScript 7 has no JavaScript compiler API; the package TypeScript
59
+ // ships beside it for tools that need one carries TypeScript 6's.
60
+ try {
61
+ const ts = require(TYPESCRIPT_6_API);
62
+ if (ts && typeof ts.createProgram === 'function') {
63
+ return {ts, version: String(ts.version)};
64
+ }
65
+ } catch {
66
+ // Not installed from here; try the next directory.
67
+ }
49
68
  }
50
69
  return unusable ? {ts: null, version: unusable} : null;
51
70
  }
52
71
 
72
+ /**
73
+ * What to do when the project's TypeScript is missing or cannot be used:
74
+ * beside TypeScript 7, the TypeScript 6 API package it ships for tools;
75
+ * otherwise a version every check here reads, 5.0 (the oldest that checks a
76
+ * JavaScript doc) through 6.
77
+ */
78
+ export const TYPESCRIPT_FIX =
79
+ 'On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.';
80
+
53
81
  /**
54
82
  * Why a check that needs the compiler did not run, when the TypeScript
55
- * installed has no JavaScript compiler API.
83
+ * installed has no JavaScript compiler API, and what to do.
56
84
  * @param {string} version
57
85
  * @param {string} outcome what was not done, such as `docs were not checked`
58
86
  */
59
87
  export function unusableTypeScriptReason(version, outcome) {
60
- return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with, so ${outcome}.`;
88
+ return `TypeScript ${version} is installed in this project, but it has no JavaScript compiler API (\`createProgram\`) to read types with (TypeScript 7 ships none), so ${outcome}. ${TYPESCRIPT_FIX}`;
61
89
  }
@@ -96,7 +96,7 @@ export function comparePropDocs(components: PropDriftComponent[], options: {
96
96
  */
97
97
  export const PROPS_NOT_DOCUMENTED: readonly string[];
98
98
  /** The line both surfaces print when the compiler is missing. */
99
- export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. Install typescript and run this check again.";
99
+ export const TYPESCRIPT_MISSING_REASON: "TypeScript is not installed in this project, so documented props were not compared with the code. On TypeScript 7, add its TypeScript 6 API package (`npm install -D @typescript/typescript6`); otherwise install TypeScript 5.0 through 6 (`npm install -D typescript@6`). Then run this check again.";
100
100
  export type CodeProp = {
101
101
  name: string;
102
102
  /**
@@ -47,6 +47,7 @@ import {loadComponentDoc} from './component-loader.mjs';
47
47
  import {readPackageTsconfig} from './package-tsconfig.mjs';
48
48
  import {
49
49
  resolveProjectTypeScript,
50
+ TYPESCRIPT_FIX,
50
51
  unusableTypeScriptReason,
51
52
  } from './project-typescript.mjs';
52
53
  import {judgeType} from './type-match.mjs';
@@ -158,8 +159,7 @@ const outside = (name, code) =>
158
159
  const HOOK_NAME = /^use[A-Z0-9]/;
159
160
 
160
161
  /** The line both surfaces print when the compiler is missing. */
161
- export const TYPESCRIPT_MISSING_REASON =
162
- 'TypeScript is not installed in this project, so documented props were not compared with the code. Install typescript and run this check again.';
162
+ export const TYPESCRIPT_MISSING_REASON = `TypeScript is not installed in this project, so documented props were not compared with the code. ${TYPESCRIPT_FIX}`;
163
163
 
164
164
  /**
165
165
  * @template T
@@ -58,6 +58,37 @@ function withTypeScript() {
58
58
  );
59
59
  }
60
60
 
61
+ /**
62
+ * TypeScript 7 (no JavaScript compiler API) with the TypeScript 6 API package
63
+ * beside it, which re-exports a real TypeScript.
64
+ */
65
+ function withTypeScript7AndItsTypeScript6Api() {
66
+ const ts7 = path.join(pkg, 'node_modules', 'typescript');
67
+ fs.mkdirSync(ts7, {recursive: true});
68
+ fs.writeFileSync(
69
+ path.join(ts7, 'package.json'),
70
+ JSON.stringify({
71
+ name: 'typescript',
72
+ version: '7.0.2',
73
+ exports: {'./package.json': './package.json'},
74
+ }),
75
+ );
76
+ const ts6 = path.join(pkg, 'node_modules', '@typescript', 'typescript6');
77
+ fs.mkdirSync(ts6, {recursive: true});
78
+ fs.writeFileSync(
79
+ path.join(ts6, 'package.json'),
80
+ JSON.stringify({
81
+ name: '@typescript/typescript6',
82
+ version: '6.0.2',
83
+ main: 'index.js',
84
+ }),
85
+ );
86
+ fs.writeFileSync(
87
+ path.join(ts6, 'index.js'),
88
+ `module.exports = require(${JSON.stringify(TYPESCRIPT_DIR)});\n`,
89
+ );
90
+ }
91
+
61
92
  /**
62
93
  * Write `components/<name>.tsx` and its doc; returns its prop table, which
63
94
  * also carries the component record (name, docPath, sourcePath).
@@ -176,7 +207,8 @@ describe('comparePropTables', () => {
176
207
  expect(await compare([component('Badge', source, doc)])).toMatchObject({
177
208
  findings: [],
178
209
  typesCompared: 0,
179
- typesSkipped: `TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads`,
210
+ typesSkipped:
211
+ 'TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads; install TypeScript 5.0 through 6 (`npm install -D typescript@6`), or on TypeScript 7 add `@typescript/typescript6`, to judge them',
180
212
  });
181
213
  });
182
214
 
@@ -2179,6 +2211,23 @@ export const Hoc = withName((props: {label?: string}) => null);`;
2179
2211
  ]);
2180
2212
  });
2181
2213
 
2214
+ it("compares with TypeScript 7's TypeScript 6 API package when the project has one", async () => {
2215
+ const badge = component(
2216
+ 'Badge',
2217
+ 'export function Badge(props: {label: string}) { return null; }\n',
2218
+ {props: [prop('label', 'number')]},
2219
+ );
2220
+ withTypeScript7AndItsTypeScript6Api();
2221
+
2222
+ const report = await compare([badge]);
2223
+
2224
+ expect(report.status).toBe('checked');
2225
+ // The comparison ran: the documented `number` is judged against `string`.
2226
+ expect(
2227
+ report.findings.map(f => `${f.component}.${f.prop} ${f.kind}`),
2228
+ ).toContain('Badge.label type_mismatch');
2229
+ });
2230
+
2182
2231
  it('skips with a reason, and compares nothing, without a TypeScript it can use', async () => {
2183
2232
  const badge = component(
2184
2233
  'Badge',
@@ -2196,6 +2245,7 @@ export const Hoc = withName((props: {label?: string}) => null);`;
2196
2245
  });
2197
2246
 
2198
2247
  expect(await compare([badge])).toEqual(skipped(TYPESCRIPT_MISSING_REASON));
2248
+ expect(TYPESCRIPT_MISSING_REASON).toContain('npm install -D typescript@6');
2199
2249
  // TypeScript 7 has no JavaScript compiler API to load.
2200
2250
  const dir = path.join(pkg, 'node_modules', 'typescript');
2201
2251
  fs.mkdirSync(dir, {recursive: true});
@@ -2207,7 +2257,10 @@ export const Hoc = withName((props: {label?: string}) => null);`;
2207
2257
  exports: {'./package.json': './package.json'},
2208
2258
  }),
2209
2259
  );
2210
- expect(await compare([badge])).toEqual(
2260
+ const report = await compare([badge]);
2261
+ expect(report.reason).toContain('TypeScript 7.0.0');
2262
+ expect(report.reason).toContain('npm install -D @typescript/typescript6');
2263
+ expect(report).toEqual(
2211
2264
  skipped(
2212
2265
  unusableTypeScriptReason(
2213
2266
  '7.0.0',
@@ -46,7 +46,7 @@ export function typeTextTooOld(ts) {
46
46
  const [major, minor] = String(ts.version).split('.').map(Number);
47
47
  return major > 4 || (major === 4 && minor >= 8)
48
48
  ? null
49
- : `TypeScript ${ts.version} is older than 4.8, the oldest the type comparison reads`;
49
+ : `TypeScript ${ts.version} is older than 4.8, the oldest the type comparison reads; install TypeScript 5.0 through 6 (\`npm install -D typescript@6\`), or on TypeScript 7 add \`@typescript/typescript6\`, to judge them`;
50
50
  }
51
51
 
52
52
  /** How tightly a printed type binds: a slot needs at least its level. */
@@ -176,7 +176,7 @@ describe('normalizeTypeText', () => {
176
176
  'string[]',
177
177
  ]);
178
178
  expect(typeTextTooOld({version: '4.7.4'})).toBe(
179
- 'TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads',
179
+ 'TypeScript 4.7.4 is older than 4.8, the oldest the type comparison reads; install TypeScript 5.0 through 6 (`npm install -D typescript@6`), or on TypeScript 7 add `@typescript/typescript6`, to judge them',
180
180
  );
181
181
  for (const version of ['4.8.4', '5.0.4', '6.0.3', ts.version]) {
182
182
  expect(typeTextTooOld({version})).toBeNull();
@@ -257,8 +257,12 @@ const RUNNERS = {
257
257
  sites: ['importDocModule'],
258
258
  },
259
259
  'foundation/discovery/project-typescript.mjs': {
260
- runs: "the project's own typescript, for the author checks that read source and docs with it, and its package.json for the version of one they cannot use",
261
- sites: ['require(typescript)', 'require(typescript/package.json)'],
260
+ runs: "the project's own typescript, for the author checks that read source and docs with it, and its package.json for the version of one they cannot use; beside TypeScript 7, which has no compiler API, the TypeScript 6 API package @typescript/typescript6",
261
+ sites: [
262
+ 'require(<computed>)',
263
+ 'require(typescript)',
264
+ 'require(typescript/package.json)',
265
+ ],
262
266
  },
263
267
  'foundation/discovery/template-adapter.mjs': {
264
268
  runs: '@babel/parser, to find the fixture references and page-local bindings in template source; and a template doc that does not validate, to read the replacement it declares',
@@ -157,6 +157,38 @@ export function getCliInvocation(targetDir?: string): string;
157
157
  * @returns {string}
158
158
  */
159
159
  export function formatCliCommand(command: string, targetDir?: string): string;
160
+ /**
161
+ * Quote one argument of a printed command so the shell it is pasted into
162
+ * passes it on unchanged. Printed commands target a POSIX shell (sh, bash,
163
+ * zsh), and PowerShell on Windows; cmd.exe is not a target. A value made only
164
+ * of letters, digits and `@ / . _ -` (and, on Windows, a drive path's `:` and
165
+ * `\`) stays bare. Any other value gets single quotes, inside which both
166
+ * shells read `$`, backticks, `%`, `!`, spaces and double quotes literally. An
167
+ * embedded single quote is written `'\''` for a POSIX shell and doubled for
168
+ * PowerShell, which also ends a single-quoted string at the typographic
169
+ * quotes `‘ ’ ‚ ‛`, so those are doubled too (`Macy’s` → `'Macy’’s'`).
170
+ *
171
+ * @param {string} value
172
+ * @param {string} [platform] the `process.platform` the command is printed for
173
+ * @returns {string}
174
+ */
175
+ export function quoteCommandArgument(value: string, platform?: string): string;
176
+ /**
177
+ * A printed command that changes to `dir`, then runs `command` there, so it
178
+ * does the same work pasted from any folder. It runs `command` only when the
179
+ * change worked. For a POSIX shell: `cd <dir> && <command>`. For PowerShell
180
+ * on Windows: `cd -LiteralPath <dir> -ErrorAction Stop; <command>`, because
181
+ * `-LiteralPath` reads `[` and `]` in a folder name literally, and a failed
182
+ * change stops the line in Windows PowerShell 5.1, which has no `&&`, as in
183
+ * PowerShell 7.
184
+ *
185
+ * @param {string} dir an absolute folder
186
+ * @param {string} command the command to run there, its arguments already
187
+ * quoted with {@link quoteCommandArgument}
188
+ * @param {string} [platform] the `process.platform` the command is printed for
189
+ * @returns {string}
190
+ */
191
+ export function commandInFolder(dir: string, command: string, platform?: string): string;
160
192
  /** The published CLI package name — used for one-off (uninstalled) invocations. */
161
193
  export const CLI_PACKAGE: "@astryxdesign/cli";
162
194
  /** The CLI binary name — only resolves once the CLI is installed (or run via CLI_PACKAGE). */
@@ -512,3 +512,50 @@ export function formatCliCommand(command, targetDir) {
512
512
  const stem = getCliInvocation(targetDir);
513
513
  return sub ? `${stem} ${sub}` : stem;
514
514
  }
515
+
516
+ /**
517
+ * Quote one argument of a printed command so the shell it is pasted into
518
+ * passes it on unchanged. Printed commands target a POSIX shell (sh, bash,
519
+ * zsh), and PowerShell on Windows; cmd.exe is not a target. A value made only
520
+ * of letters, digits and `@ / . _ -` (and, on Windows, a drive path's `:` and
521
+ * `\`) stays bare. Any other value gets single quotes, inside which both
522
+ * shells read `$`, backticks, `%`, `!`, spaces and double quotes literally. An
523
+ * embedded single quote is written `'\''` for a POSIX shell and doubled for
524
+ * PowerShell, which also ends a single-quoted string at the typographic
525
+ * quotes `‘ ’ ‚ ‛`, so those are doubled too (`Macy’s` → `'Macy’’s'`).
526
+ *
527
+ * @param {string} value
528
+ * @param {string} [platform] the `process.platform` the command is printed for
529
+ * @returns {string}
530
+ */
531
+ export function quoteCommandArgument(value, platform = process.platform) {
532
+ const text = String(value);
533
+ if (platform === 'win32') {
534
+ if (/^[A-Za-z0-9@/._:\\-]+$/u.test(text)) return text;
535
+ return `'${text.replace(/['\u2018\u2019\u201A\u201B]/gu, quote => quote + quote)}'`;
536
+ }
537
+ if (/^[A-Za-z0-9@/._-]+$/u.test(text)) return text;
538
+ return `'${text.replace(/'/gu, `'\\''`)}'`;
539
+ }
540
+
541
+ /**
542
+ * A printed command that changes to `dir`, then runs `command` there, so it
543
+ * does the same work pasted from any folder. It runs `command` only when the
544
+ * change worked. For a POSIX shell: `cd <dir> && <command>`. For PowerShell
545
+ * on Windows: `cd -LiteralPath <dir> -ErrorAction Stop; <command>`, because
546
+ * `-LiteralPath` reads `[` and `]` in a folder name literally, and a failed
547
+ * change stops the line in Windows PowerShell 5.1, which has no `&&`, as in
548
+ * PowerShell 7.
549
+ *
550
+ * @param {string} dir an absolute folder
551
+ * @param {string} command the command to run there, its arguments already
552
+ * quoted with {@link quoteCommandArgument}
553
+ * @param {string} [platform] the `process.platform` the command is printed for
554
+ * @returns {string}
555
+ */
556
+ export function commandInFolder(dir, command, platform = process.platform) {
557
+ const folder = quoteCommandArgument(dir, platform);
558
+ return platform === 'win32'
559
+ ? `cd -LiteralPath ${folder} -ErrorAction Stop; ${command}`
560
+ : `cd ${folder} && ${command}`;
561
+ }
@@ -1,6 +1,7 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  import {describe, it, expect, afterEach, vi} from 'vitest';
4
+ import {spawnSync} from 'node:child_process';
4
5
  import * as fs from 'node:fs';
5
6
  import * as path from 'node:path';
6
7
  import * as os from 'node:os';
@@ -12,11 +13,32 @@ import {
12
13
  cliBinResolves,
13
14
  getCliInvocation,
14
15
  formatCliCommand,
16
+ quoteCommandArgument,
17
+ commandInFolder,
15
18
  } from './package-manager.mjs';
16
19
 
17
20
  let tmpDir;
18
21
  const ORIGINAL_ARGV1 = process.argv[1];
19
22
 
23
+ /** Prints, as JSON, the folder a command ran in and the arguments it got. */
24
+ const PRINT_RUN =
25
+ 'process.stdout.write(JSON.stringify({cwd: process.cwd(), argv: process.argv.slice(1)}))';
26
+
27
+ /** PowerShell, when it is on the PATH: printed commands target it on Windows. */
28
+ const PWSH = (process.env.PATH ?? '')
29
+ .split(path.delimiter)
30
+ .flatMap(dir => ['pwsh', 'pwsh.exe'].map(name => path.join(dir, name)))
31
+ .find(file => isFile(file));
32
+
33
+ /** @param {string} file */
34
+ function isFile(file) {
35
+ try {
36
+ return fs.statSync(file).isFile();
37
+ } catch {
38
+ return false;
39
+ }
40
+ }
41
+
20
42
  afterEach(() => {
21
43
  if (tmpDir) {
22
44
  fs.rmSync(tmpDir, {recursive: true, force: true});
@@ -48,7 +70,8 @@ const YARN_BERRY_LOCK =
48
70
  '# 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
71
 
50
72
  /** 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';
73
+ const INSTALLED_ENTRY =
74
+ '/usr/local/lib/node_modules/@astryxdesign/cli/clients/cli/bin/astryx.mjs';
52
75
 
53
76
  describe('detectPackageManager', () => {
54
77
  it('detects yarn from yarn.lock', () => {
@@ -132,7 +155,10 @@ describe('detectPackageManager', () => {
132
155
  const dir = makeTmpDir();
133
156
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
134
157
  fs.writeFileSync(path.join(dir, 'yarn.lock'), '');
135
- fs.writeFileSync(path.join(dir, '.yarnrc.yml'), 'nodeLinker: node-modules\n');
158
+ fs.writeFileSync(
159
+ path.join(dir, '.yarnrc.yml'),
160
+ 'nodeLinker: node-modules\n',
161
+ );
136
162
  expect(detectPackageManager(dir)).toBe('yarn');
137
163
  });
138
164
 
@@ -425,12 +451,14 @@ describe('isCliOneOff', () => {
425
451
  });
426
452
 
427
453
  it('detects a pnpm dlx cache entry', () => {
428
- process.argv[1] = '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
454
+ process.argv[1] =
455
+ '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
429
456
  expect(isCliOneOff()).toBe(true);
430
457
  });
431
458
 
432
459
  it('detects a bunx cache entry', () => {
433
- process.argv[1] = '/home/u/.bun/install/cache/@astryxdesign/cli/bin/astryx.mjs';
460
+ process.argv[1] =
461
+ '/home/u/.bun/install/cache/@astryxdesign/cli/bin/astryx.mjs';
434
462
  expect(isCliOneOff()).toBe(true);
435
463
  });
436
464
 
@@ -538,7 +566,8 @@ describe('getCliInvocation', () => {
538
566
  });
539
567
 
540
568
  it('pairs the dlx runner with the scoped package for pnpm one-off', () => {
541
- process.argv[1] = '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
569
+ process.argv[1] =
570
+ '/home/u/.cache/pnpm/dlx/9f/node_modules/@astryxdesign/cli/bin/astryx.mjs';
542
571
  const dir = makeTmpDir();
543
572
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
544
573
  expect(getCliInvocation(dir)).toBe('pnpm dlx @astryxdesign/cli');
@@ -551,7 +580,9 @@ describe('formatCliCommand', () => {
551
580
  const dir = makeTmpDir();
552
581
  fs.writeFileSync(path.join(dir, 'pnpm-lock.yaml'), '');
553
582
  linkCliBin(dir);
554
- expect(formatCliCommand('astryx component Button', dir)).toBe('pnpm exec astryx component Button');
583
+ expect(formatCliCommand('astryx component Button', dir)).toBe(
584
+ 'pnpm exec astryx component Button',
585
+ );
555
586
  });
556
587
 
557
588
  it('accepts a bare subcommand (no leading astryx)', () => {
@@ -566,6 +597,162 @@ describe('formatCliCommand', () => {
566
597
  process.argv[1] = '/home/u/.npm/_npx/a1b2/node_modules/.bin/astryx';
567
598
  const dir = makeTmpDir();
568
599
  fs.writeFileSync(path.join(dir, 'package-lock.json'), '{}');
569
- expect(formatCliCommand('astryx component Button', dir)).toBe('npx @astryxdesign/cli component Button');
600
+ expect(formatCliCommand('astryx component Button', dir)).toBe(
601
+ 'npx @astryxdesign/cli component Button',
602
+ );
603
+ });
604
+ });
605
+
606
+ describe('quoteCommandArgument', () => {
607
+ it('leaves a plain value bare', () => {
608
+ for (const platform of ['linux', 'darwin', 'win32']) {
609
+ expect(quoteCommandArgument('0.7.1', platform)).toBe('0.7.1');
610
+ expect(quoteCommandArgument('@acme/widgets', platform)).toBe(
611
+ '@acme/widgets',
612
+ );
613
+ expect(quoteCommandArgument('/home/me/app/src', platform)).toBe(
614
+ '/home/me/app/src',
615
+ );
616
+ }
617
+ });
618
+
619
+ it('single-quotes for a POSIX shell, so $, backticks and double quotes stay literal', () => {
620
+ expect(quoteCommandArgument('/tmp/my app/src', 'linux')).toBe(
621
+ "'/tmp/my app/src'",
622
+ );
623
+ expect(quoteCommandArgument('/tmp/cost $5/src', 'darwin')).toBe(
624
+ "'/tmp/cost $5/src'",
625
+ );
626
+ expect(quoteCommandArgument('a`id`"b"!', 'linux')).toBe('\'a`id`"b"!\'');
627
+ expect(quoteCommandArgument("it's", 'linux')).toBe("'it'\\''s'");
628
+ expect(quoteCommandArgument('C:\\app', 'linux')).toBe("'C:\\app'");
629
+ expect(quoteCommandArgument('', 'linux')).toBe("''");
630
+ });
631
+
632
+ it('keeps a Windows drive path bare', () => {
633
+ expect(quoteCommandArgument('C:\\Users\\me\\app\\src', 'win32')).toBe(
634
+ 'C:\\Users\\me\\app\\src',
635
+ );
636
+ });
637
+
638
+ // Windows output targets PowerShell, not cmd.exe: PowerShell reads a
639
+ // single-quoted value literally, `$`, backticks, `%` and `!` included.
640
+ it('single-quotes for PowerShell on Windows, doubling an embedded quote', () => {
641
+ expect(quoteCommandArgument('C:\\Users\\Jo Smith\\app\\src', 'win32')).toBe(
642
+ "'C:\\Users\\Jo Smith\\app\\src'",
643
+ );
644
+ expect(quoteCommandArgument('C:\\cost $5 %x% !y\\src', 'win32')).toBe(
645
+ "'C:\\cost $5 %x% !y\\src'",
646
+ );
647
+ expect(quoteCommandArgument('C:\\it\'s `x` "q"', 'win32')).toBe(
648
+ "'C:\\it''s `x` \"q\"'",
649
+ );
650
+ // PowerShell also ends a single-quoted string at ‘ ’ ‚ and ‛.
651
+ expect(
652
+ quoteCommandArgument('C:\\Users\\jo\\OneDrive - Macy’s\\app', 'win32'),
653
+ ).toBe("'C:\\Users\\jo\\OneDrive - Macy’’s\\app'");
654
+ expect(quoteCommandArgument('‘a’ ‚b‛', 'win32')).toBe("'‘‘a’’ ‚‚b‛‛'");
655
+ // A POSIX shell reads them literally inside single quotes.
656
+ expect(quoteCommandArgument('/home/jo/Macy’s app', 'linux')).toBe(
657
+ "'/home/jo/Macy’s app'",
658
+ );
659
+ });
660
+ });
661
+
662
+ describe('commandInFolder', () => {
663
+ it('enters the folder, then runs the command only if that worked, in a POSIX shell', () => {
664
+ expect(commandInFolder('/tmp/my app', 'npx x', 'linux')).toBe(
665
+ "cd '/tmp/my app' && npx x",
666
+ );
667
+ expect(commandInFolder('/srv/app', 'npx x', 'darwin')).toBe(
668
+ 'cd /srv/app && npx x',
669
+ );
670
+ });
671
+
672
+ it('enters the folder literally and stops if it cannot, in PowerShell', () => {
673
+ expect(commandInFolder('C:\\a[1] b', 'npx x', 'win32')).toBe(
674
+ "cd -LiteralPath 'C:\\a[1] b' -ErrorAction Stop; npx x",
675
+ );
676
+ });
677
+
678
+ it.skipIf(process.platform === 'win32')(
679
+ 'runs in the folder with every argument unchanged, pasted into /bin/sh elsewhere',
680
+ () => {
681
+ const root = makeTmpDir();
682
+ const project = path.join(root, 'it\'s Macy’s ‘q’ $5 %x% !y `z` "q" [1]');
683
+ fs.mkdirSync(project);
684
+ const args = [path.join(project, 'src'), 'a$b c', "it's", '@scope/pkg@1'];
685
+ const command = commandInFolder(
686
+ project,
687
+ ['npx', ...args.map(arg => quoteCommandArgument(arg, 'linux'))].join(
688
+ ' ',
689
+ ),
690
+ 'linux',
691
+ );
692
+ const ran = spawnSync(
693
+ '/bin/sh',
694
+ [
695
+ '-c',
696
+ `npx() { "$0" -e '${PRINT_RUN}' -- "$@"; }; ${command}`,
697
+ process.execPath,
698
+ ],
699
+ {cwd: root, encoding: 'utf8'},
700
+ );
701
+
702
+ expect(ran.status, ran.stderr).toBe(0);
703
+ expect(JSON.parse(ran.stdout)).toEqual({
704
+ cwd: fs.realpathSync(project),
705
+ argv: args,
706
+ });
707
+ },
708
+ );
709
+
710
+ describe.runIf(PWSH)('in PowerShell, where it is installed', () => {
711
+ it('runs in the folder with every argument unchanged', () => {
712
+ const root = makeTmpDir();
713
+ const project = path.join(root, 'it\'s Macy’s ‘q’ $5 %x% !y `z` "q" [1]');
714
+ fs.mkdirSync(project);
715
+ const args = [path.join(project, 'src'), 'a$b c', "it's", '@scope/pkg@1'];
716
+ const command = commandInFolder(
717
+ project,
718
+ ['npx', ...args.map(arg => quoteCommandArgument(arg, 'win32'))].join(
719
+ ' ',
720
+ ),
721
+ 'win32',
722
+ );
723
+ const npx = `function npx { & ${quoteCommandArgument(process.execPath, 'win32')} -e '${PRINT_RUN}' -- @args }`;
724
+ const ran = spawnSync(
725
+ /** @type {string} */ (PWSH),
726
+ ['-NoProfile', '-NonInteractive', '-Command', `${npx}; ${command}`],
727
+ {cwd: root, encoding: 'utf8'},
728
+ );
729
+
730
+ expect(ran.status, ran.stderr).toBe(0);
731
+ expect(JSON.parse(ran.stdout)).toEqual({
732
+ cwd: fs.realpathSync(project),
733
+ argv: args,
734
+ });
735
+ });
736
+
737
+ it('stops when the folder cannot be entered', () => {
738
+ const root = makeTmpDir();
739
+ const command = commandInFolder(
740
+ path.join(root, 'missing'),
741
+ 'npx',
742
+ 'win32',
743
+ );
744
+ const ran = spawnSync(
745
+ /** @type {string} */ (PWSH),
746
+ [
747
+ '-NoProfile',
748
+ '-NonInteractive',
749
+ '-Command',
750
+ `function npx { 'RAN' }; ${command}`,
751
+ ],
752
+ {cwd: root, encoding: 'utf8'},
753
+ );
754
+
755
+ expect(ran.stdout).not.toContain('RAN');
756
+ });
570
757
  });
571
758
  });
@@ -169,12 +169,13 @@ export const doc = {
169
169
  // gap reports
170
170
  {
171
171
  value: 'gap-report.categories',
172
- description: 'The fixed gap category values and human-readable labels.',
172
+ description:
173
+ 'The fixed gap category values and human-readable labels; when a loaded integration names its own issues URL, meta.destinations lists every destination ({to, default, issuesUrl}) and meta.ask tells an agent to ask the person.',
173
174
  },
174
175
  {
175
176
  value: 'gap-report.file',
176
177
  description:
177
- 'An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project | integration | fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals.',
178
+ 'An aggregate receipt: overall status, the selected package, issuesUrl (or null), deliveries in handler order, each {handlerType: project | integration | fallback, handler, audience, status, url, message}, and filedCount/routedOnlyCount totals; without --to, when a loaded integration names its own issues URL, destinations and ask as on gap-report.categories.',
178
179
  },
179
180
 
180
181
  // template
@@ -283,12 +284,12 @@ export const doc = {
283
284
  {
284
285
  value: 'upgrade.status',
285
286
  description:
286
- 'A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary.',
287
+ 'A short-circuit outcome with no codemods run (up_to_date, no_codemods, or config_fixable), each carrying the agent-docs summary. no_codemods and config_fixable carry cliBehindCore ({cliVersion, command}) when the installed Core is newer than the CLI, which then has no codemods for the releases after its own version.',
287
288
  },
288
289
  {
289
290
  value: 'upgrade.run',
290
291
  description:
291
- 'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors.',
292
+ 'The run receipt: from/to versions, codemod count, integrations processed, the agent-docs summary, sourcePathFound (false when the resolved source directory does not exist, so no source file was read), and (apply mode) filesChanged, transformsApplied, and per-codemod errors. When the installed Core is newer than the CLI, it also carries cliBehindCore ({cliVersion, command}): codemods for the releases after cliVersion did not run.',
292
293
  },
293
294
 
294
295
  // manifest