@astryxdesign/cli 0.7.2-canary.a7d26b7 → 0.7.2-canary.acfd1ff

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 (251) hide show
  1. package/README.md +74 -73
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/discover/_adapter.d.mts +119 -12
  4. package/api/discover/_adapter.mjs +449 -10
  5. package/api/discover/_adapter.test.mjs +599 -17
  6. package/api/discover/_catalog-view.d.mts +16 -5
  7. package/api/discover/_catalog-view.mjs +32 -8
  8. package/api/discover/discover.d.mts +11 -0
  9. package/api/discover/discover.doc.mjs +7 -6
  10. package/api/discover/discover.mjs +107 -19
  11. package/api/discover/discover.type.d.mts +18 -7
  12. package/api/discover/discover.type.mjs +15 -7
  13. package/api/discover/list/list.d.mts +4 -3
  14. package/api/discover/list/list.mjs +17 -10
  15. package/api/docs/_adapter.d.mts +11 -0
  16. package/api/docs/_adapter.mjs +244 -1
  17. package/api/docs/integrationDocs.test.mjs +124 -0
  18. package/api/doctor/doctor.mjs +27 -3
  19. package/api/doctor/doctor.test.mjs +43 -0
  20. package/api/doctor/theme-checks.mjs +1 -1
  21. package/api/doctor/theme-checks.test.mjs +136 -0
  22. package/api/gap-report/gap-report.d.mts +3 -0
  23. package/api/gap-report/gap-report.doc.mjs +11 -3
  24. package/api/gap-report/gap-report.mjs +152 -48
  25. package/api/gap-report/gap-report.test.mjs +233 -0
  26. package/api/gap-report/gap-report.type.d.mts +41 -0
  27. package/api/gap-report/gap-report.type.mjs +18 -0
  28. package/api/index.d.mts +2 -0
  29. package/api/index.mjs +2 -0
  30. package/api/init/run/run.mjs +2 -2
  31. package/api/integration/_adapter.d.mts +32 -0
  32. package/api/integration/_adapter.mjs +80 -0
  33. package/api/integration/add-contribution.mjs +1 -1
  34. package/api/integration/add-contribution.test.mjs +4 -2
  35. package/api/integration/authoring-checks.mjs +44 -4
  36. package/api/integration/authoring-checks.test.mjs +515 -0
  37. package/api/integration/authoring-checks.type.d.mts +95 -0
  38. package/api/integration/authoring-checks.type.mjs +53 -2
  39. package/api/integration/check/check.d.mts +96 -0
  40. package/api/integration/check/check.mjs +357 -0
  41. package/api/integration/check/check.test.mjs +489 -0
  42. package/api/integration/integration-check.type.d.mts +118 -0
  43. package/api/integration/integration-check.type.mjs +84 -0
  44. package/api/integration/integrationCheck.doc.d.mts +10 -0
  45. package/api/integration/integrationCheck.doc.mjs +73 -0
  46. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  47. package/api/integration/integrationDocConflicts.doc.mjs +19 -5
  48. package/api/integration/pack-check.mjs +292 -7
  49. package/api/integration/pack-check.test.mjs +367 -0
  50. package/api/integration/validate-integration-fixes.test.mjs +67 -0
  51. package/api/integration/validate-integration.mjs +8 -0
  52. package/api/integration/validate-integration.test.mjs +41 -0
  53. package/api/integration/validate-integration.type.d.mts +8 -0
  54. package/api/integration/validate-integration.type.mjs +12 -1
  55. package/api/integration/validateIntegration.doc.mjs +19 -3
  56. package/api/search/search.d.mts +72 -12
  57. package/api/search/search.domain-priority.test.mjs +108 -18
  58. package/api/search/search.integration-check.test.mjs +24 -0
  59. package/api/search/search.mjs +501 -37
  60. package/api/search/search.test.mjs +139 -0
  61. package/api/theme/build/build.family.test.mjs +54 -6
  62. package/api/theme/build/build.mjs +114 -17
  63. package/api/theme/themeBuild.doc.mjs +4 -4
  64. package/api/upgrade/_adapter.d.mts +40 -2
  65. package/api/upgrade/_adapter.mjs +117 -4
  66. package/api/upgrade/run/cli-behind-core.test.mjs +438 -0
  67. package/api/upgrade/run/run.mjs +30 -1
  68. package/api/upgrade/status/status.d.mts +21 -5
  69. package/api/upgrade/status/status.mjs +45 -8
  70. package/api/upgrade/upgrade.doc.mjs +5 -3
  71. package/api/upgrade/upgrade.type.d.mts +23 -0
  72. package/api/upgrade/upgrade.type.mjs +16 -1
  73. package/assets/codemods/runner.mjs +7 -1
  74. package/assets/discover/official-packages.json +367 -0
  75. package/assets/docs/README.md +10 -0
  76. package/assets/docs/author-a-theme.doc.mjs +3 -3
  77. package/assets/docs/browser-support.doc.mjs +1 -1
  78. package/assets/docs/getting-started.doc.mjs +3 -3
  79. package/assets/docs/styling-overview.doc.mjs +1 -1
  80. package/assets/docs/theme.doc.dense.mjs +1 -1
  81. package/assets/docs/theme.doc.mjs +2 -2
  82. package/assets/docs/theme.doc.zh.mjs +1 -1
  83. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  84. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  85. package/assets/docs/tree/add-a-topic.doc.mjs +11 -8
  86. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  87. package/assets/docs/tree/block-template.doc.mjs +8 -20
  88. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  89. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  90. package/assets/docs/tree/check-your-docs.doc.mjs +61 -7
  91. package/assets/docs/tree/checks.doc.mjs +25 -17
  92. package/assets/docs/tree/codemods.doc.mjs +4 -4
  93. package/assets/docs/tree/component-family.doc.mjs +3 -5
  94. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  95. package/assets/docs/tree/components.doc.mjs +1 -1
  96. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +30 -21
  97. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  98. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  99. package/assets/docs/tree/docs.doc.mjs +3 -3
  100. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  101. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  102. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  103. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  104. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  105. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  106. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  107. package/assets/docs/tree/integrations.doc.mjs +8 -0
  108. package/assets/docs/tree/layout-spacing.doc.mjs +2 -3
  109. package/assets/docs/tree/layout.doc.mjs +6 -6
  110. package/assets/docs/tree/links.doc.mjs +6 -5
  111. package/assets/docs/tree/migration-setup.doc.mjs +3 -2
  112. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  113. package/assets/docs/tree/migration.doc.mjs +0 -1
  114. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  115. package/assets/docs/tree/page-template.doc.mjs +4 -8
  116. package/assets/docs/tree/publishing.doc.mjs +4 -4
  117. package/assets/docs/tree/quick-start.doc.mjs +38 -22
  118. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  119. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  120. package/assets/docs/tree/sections-and-placement.doc.mjs +6 -8
  121. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  122. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  123. package/assets/docs/tree/single-component.doc.mjs +14 -5
  124. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  125. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  126. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  127. package/assets/docs/tree/template-doc-overview.doc.mjs +5 -16
  128. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  129. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  130. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  131. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  132. package/assets/docs/tree/templates.doc.mjs +1 -1
  133. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  134. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  135. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  136. package/assets/docs/tree/troubleshooting.doc.mjs +8 -8
  137. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  138. package/assets/docs/tree/upgrading.doc.mjs +4 -4
  139. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  140. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  141. package/assets/docs/tree/versioning.doc.mjs +6 -6
  142. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  143. package/assets/docs/use-a-theme.doc.mjs +2 -2
  144. package/assets/theme.template.ts +1 -1
  145. package/authoring/codemod/codemod.doc.mjs +7 -3
  146. package/authoring/config/config.doc.mjs +9 -6
  147. package/authoring/config/type.ts +4 -2
  148. package/authoring/discover/discover.doc.mjs +1 -1
  149. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  150. package/authoring/doctypes/command/command.doc.mjs +14 -12
  151. package/authoring/doctypes/component/component.doc.mjs +29 -26
  152. package/authoring/doctypes/component/type.ts +7 -5
  153. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  154. package/authoring/doctypes/function/function.doc.mjs +9 -8
  155. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  156. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  157. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  158. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  159. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  160. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  161. package/authoring/doctypes/template/parse.d.mts +6 -2
  162. package/authoring/doctypes/template/parse.mjs +3 -1
  163. package/authoring/doctypes/template/template.doc.mjs +3 -3
  164. package/authoring/doctypes/template/type.ts +22 -0
  165. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  166. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  167. package/authoring/identity/identity.doc.mjs +3 -3
  168. package/authoring/index.d.ts +1 -0
  169. package/authoring/integration/integration.doc.mjs +12 -4
  170. package/authoring/integration/parse.test.mjs +10 -0
  171. package/authoring/integration/schema.d.mts +2 -0
  172. package/authoring/integration/schema.mjs +1 -0
  173. package/authoring/integration/type.ts +4 -0
  174. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  175. package/clients/cli/commands/build-theme.mjs +1 -1
  176. package/clients/cli/commands/build-theme.path-safety.test.mjs +155 -21
  177. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  178. package/clients/cli/commands/discover.broken-integration.test.mjs +4 -1
  179. package/clients/cli/commands/discover.doc.mjs +1 -1
  180. package/clients/cli/commands/discover.mjs +144 -93
  181. package/clients/cli/commands/discover.no-source.test.mjs +447 -33
  182. package/clients/cli/commands/discover.sources.test.mjs +20 -1
  183. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  184. package/clients/cli/commands/doctor-integration-docs.doc.mjs +18 -5
  185. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  186. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  187. package/clients/cli/commands/doctor.mjs +250 -3
  188. package/clients/cli/commands/gap-report.doc.mjs +14 -2
  189. package/clients/cli/commands/gap-report.mjs +24 -2
  190. package/clients/cli/commands/gap-report.test.mjs +79 -0
  191. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  192. package/clients/cli/commands/integration-check.test.mjs +370 -0
  193. package/clients/cli/commands/integration.doc.mjs +6 -2
  194. package/clients/cli/commands/integration.mjs +106 -1
  195. package/clients/cli/commands/json-contract.test.mjs +5 -1
  196. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  197. package/clients/cli/commands/swizzle.mjs +5 -3
  198. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  199. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  200. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  201. package/clients/cli/commands/upgrade.doc.mjs +14 -0
  202. package/clients/cli/commands/upgrade.older-cli.test.mjs +160 -0
  203. package/clients/cli/index.mjs +30 -5
  204. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  205. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  206. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  207. package/foundation/agent-docs/agent-docs.mjs +8 -6
  208. package/foundation/config/project.mjs +82 -0
  209. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  210. package/foundation/discovery/component-discovery.d.mts +18 -0
  211. package/foundation/discovery/component-discovery.mjs +2 -2
  212. package/foundation/discovery/copied-passages.d.mts +216 -0
  213. package/foundation/discovery/copied-passages.mjs +720 -0
  214. package/foundation/discovery/copied-passages.test.mjs +124 -0
  215. package/foundation/discovery/doc-fluff.d.mts +112 -0
  216. package/foundation/discovery/doc-fluff.mjs +328 -0
  217. package/foundation/discovery/doc-fluff.test.mjs +142 -0
  218. package/foundation/discovery/doc-types.d.mts +157 -0
  219. package/foundation/discovery/doc-types.mjs +1224 -0
  220. package/foundation/discovery/doc-types.test.mjs +700 -0
  221. package/foundation/discovery/docs-discovery.d.mts +88 -0
  222. package/foundation/discovery/docs-discovery.mjs +83 -2
  223. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  224. package/foundation/discovery/integration-doc-files.mjs +231 -0
  225. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  226. package/foundation/discovery/project-typescript.d.mts +11 -2
  227. package/foundation/discovery/project-typescript.mjs +32 -4
  228. package/foundation/discovery/prop-drift.d.mts +278 -0
  229. package/foundation/discovery/prop-drift.mjs +2263 -0
  230. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  231. package/foundation/discovery/type-match.d.mts +53 -0
  232. package/foundation/discovery/type-match.mjs +660 -0
  233. package/foundation/discovery/type-match.test.mjs +169 -0
  234. package/foundation/discovery/type-text.d.mts +68 -0
  235. package/foundation/discovery/type-text.mjs +658 -0
  236. package/foundation/discovery/type-text.test.mjs +196 -0
  237. package/foundation/doc-compiler/doc-loads.test.mjs +16 -2
  238. package/foundation/doc-compiler/links.d.mts +9 -5
  239. package/foundation/doc-compiler/links.mjs +4 -2
  240. package/foundation/env/package-manager.d.mts +32 -0
  241. package/foundation/env/package-manager.mjs +47 -0
  242. package/foundation/env/package-manager.test.mjs +194 -7
  243. package/foundation/fs/module-loader.d.mts +2 -1
  244. package/foundation/fs/module-loader.mjs +60 -4
  245. package/foundation/fs/module-loader.test.mjs +194 -0
  246. package/foundation/integrations/contribution-inventory.d.mts +11 -0
  247. package/foundation/integrations/contribution-inventory.mjs +50 -2
  248. package/foundation/integrations/validate-contributions.mjs +30 -1
  249. package/foundation/response/response-types.doc.mjs +14 -8
  250. package/package.json +11 -11
  251. package/scripts/postinstall.mjs +3 -3
@@ -0,0 +1,196 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /** @file The type-text normalization the prop type judgment compares by. */
4
+
5
+ import {createRequire} from 'node:module';
6
+ import {describe, expect, it} from 'vitest';
7
+ import {
8
+ normalizeTypeText as normalize,
9
+ typeTextTooOld,
10
+ UNPARSED,
11
+ } from './type-text.mjs';
12
+
13
+ const ts = createRequire(import.meta.url)('typescript');
14
+ /** @type {(text: string, options?: {optional?: boolean}) => readonly string[]} */
15
+ const normalizeTypeText = (text, options = {}) =>
16
+ normalize(text, {...options, ts});
17
+
18
+ describe('normalizeTypeText', () => {
19
+ it.each([
20
+ ["'b' | 'a'", '"a" | "b"'],
21
+ ['React.ReactNode', 'ReactNode'],
22
+ ['Array<string>', 'string[]'],
23
+ ['ReadonlyArray<"a" | "b">', "('a' | 'b')[]"],
24
+ ['readonly string[]', 'string[]'],
25
+ ['Readonly<Status>', 'Status'],
26
+ ['true | false', 'boolean'],
27
+ ["'sm' | string", 'string'],
28
+ ['(e: MouseEvent) => void', '(event: MouseEvent) => void'],
29
+ ['{b: number; a?: string}', '{ a?: string, b: number }'],
30
+ ['{ /** doc */ a: string; }', '{a: string}'],
31
+ ['{get /*c*/ a(): string}', '{get a(): string}'],
32
+ ['{get a(): string; b: number}', '{b: number, get a(): string}'],
33
+ ['{set a(v: string), b: number}', '{set a(v: string); b: number}'],
34
+ ['{a: string, b: number}', '{a: string; b: number}'],
35
+ ['"a"|"b"', "'a' | 'b'"],
36
+ ['string | never', 'string'],
37
+ ['Array<() => void>', '(() => void)[]'],
38
+ [
39
+ 'Array<(value: string) => string | undefined>',
40
+ '((v: string) => string | undefined)[]',
41
+ ],
42
+ ['readonly ("a" | "b")[]', "ReadonlyArray<'a' | 'b'>"],
43
+ ['readonly [string, number]', '[string, number]'],
44
+ ['(() => void) | null', 'null | (() => void)'],
45
+ ['() => (string | null)', '() => null | string'],
46
+ ['(this: Window) => void', '(this: Window) => void'],
47
+ ['(a: X, b: X) => a is T', '(c: X, d: X) => c is T'],
48
+ ['Readonly<A & B>[]', '(A & B)[]'],
49
+ ['Readonly<{a: string; b: number}>', '{b: number; a: string}'],
50
+ ['Readonly<Record<string, string>>', 'Record<string, string>'],
51
+ ["(v: unknown) => v is 'x'", "(value: unknown) => value is 'x'"],
52
+ ['(a: A, b?: B) => void', '(x: A, y?: B) => void'],
53
+ ['[a: string, b?: number]', '[string, number?]'],
54
+ ["{'a': string}", '{a: string}'],
55
+ ['1e3 | 1000', '1000'],
56
+ ['T extends string ? (() => B) : C', 'T extends string ? () => B : C'],
57
+ ['(A | B) | C', 'C | B | A'],
58
+ ])('reads %s as %s', (a, b) => {
59
+ expect(normalizeTypeText(a)).toEqual(normalizeTypeText(b));
60
+ });
61
+
62
+ it('returns a result no caller can change for the next', () => {
63
+ const first = normalizeTypeText("'b' | 'a'");
64
+ expect(() => /** @type {string[]} */ (first).push('c')).toThrow();
65
+ expect(normalizeTypeText("'b' | 'a'")).toEqual(["'a'", "'b'"]);
66
+ });
67
+
68
+ it('drops undefined only on an optional prop', () => {
69
+ expect(normalizeTypeText('string | undefined', {optional: true})).toEqual([
70
+ 'string',
71
+ ]);
72
+ expect(normalizeTypeText('string | undefined')).toEqual([
73
+ 'string',
74
+ 'undefined',
75
+ ]);
76
+ });
77
+
78
+ it.each([
79
+ ["'a' | 'b'", "'a'"],
80
+ ['(a: string) => void', '(a: number) => void'],
81
+ // An array of callbacks, and a callback that returns an array.
82
+ ['(() => void)[]', '() => void[]'],
83
+ [
84
+ '((value: string) => string | undefined)[]',
85
+ '(value: string) => string | undefined[]',
86
+ ],
87
+ ['Array<() => void>', '() => void[]'],
88
+ // An array of an intersection, and an intersection with an array.
89
+ ['(A & B)[]', 'A & B[]'],
90
+ ['Array<A & B>', 'A & B[]'],
91
+ ['(keyof T)[]', 'keyof T[]'],
92
+ ['keyof (A & B)', 'keyof A & B'],
93
+ // `never` that is a whole type, not a union member.
94
+ ['(x: never) => void', '() => void'],
95
+ ['[never]', '[]'],
96
+ ['Array<never>', '[]'],
97
+ // String literals as written.
98
+ ["{a: 'x;y'}", "{a: 'x,y'}"],
99
+ ["'readonly x'", "'x'"],
100
+ ["'React.Node'", "'Node'"],
101
+ // A union around a function, and one in its return.
102
+ ['(() => ReactNode) | null', '() => ReactNode | null'],
103
+ ['(() => string) | undefined', '() => string | undefined'],
104
+ ['Array<(() => ReactNode) | null>', 'Array<() => ReactNode | null>'],
105
+ ['{f: (() => ReactNode) | null}', '{f: () => ReactNode | null}'],
106
+ // `this` is no ordinary parameter.
107
+ ['(this: Window, e: Event) => void', '(w: Window, e: Event) => void'],
108
+ // A conditional's false branch takes the rest of a union.
109
+ ['T extends string ? A : B | C', '(T extends string ? A : B) | C'],
110
+ // An array of `Readonly<A & B>` is no intersection with an array.
111
+ ['Readonly<A & B>[]', 'A & B[]'],
112
+ // `keyof` keeps its operand apart from the name after it.
113
+ ['Array<keyof (B)>', 'keyof (Array<B>)'],
114
+ // A type predicate names a parameter by its place.
115
+ ['(a: X, b: X) => a is T', '(b: X, a: X) => a is T'],
116
+ [
117
+ "(a: unknown, b: unknown) => a is 'x'",
118
+ "(b: unknown, a: unknown) => a is 'x'",
119
+ ],
120
+ // A function in a conditional's true branch returns only its own type.
121
+ [
122
+ 'T extends string ? () => B : C | A',
123
+ 'T extends string ? () => A | B : C',
124
+ ],
125
+ // `Readonly<…>` keeps its argument grouped.
126
+ ['Readonly<A | B> & C', 'A | (B & C)'],
127
+ ['keyof Readonly<A & B>', '(keyof A) & B'],
128
+ // Overloads keep their order; an intersection's members keep theirs.
129
+ ['{(a: string): A; (a: number): B}', '{(a: number): B; (a: string): A}'],
130
+ // Text that does not parse is kept as written.
131
+ ['string?', 'string'],
132
+ // Text spelled as the printer prints a type, but that does not parse.
133
+ ['((Item[]) => void)[]', '((items: Item[]) => void)[]'],
134
+ // A computed property name, and an index signature.
135
+ ['{[K]: number}', '{[k: K]: number}'],
136
+ // A method named `'new'`, and a construct signature.
137
+ ["{'new'(): X}", '{new(): X}'],
138
+ // A comment between two words separates them, as a space does.
139
+ ['{get/*c*/a(): string}', '{geta(): string}'],
140
+ // Import attributes change which file a module resolves to.
141
+ [
142
+ "import('dual', {with: {'resolution-mode': 'import'}}).T",
143
+ "import('dual', {with: {'resolution-mode': 'require'}}).T",
144
+ ],
145
+ ])('keeps %s and %s different', (a, b) => {
146
+ expect(normalizeTypeText(a)).not.toEqual(normalizeTypeText(b));
147
+ });
148
+
149
+ it('marks text that does not parse, and names a TypeScript too old to read types with', () => {
150
+ expect(normalizeTypeText('((Item[]) => void)[]')).toEqual([
151
+ `${UNPARSED}((Item[])=>void)[]`,
152
+ ]);
153
+ // Forms only the checker rejects.
154
+ for (const text of [
155
+ 'Foo<>',
156
+ 'Array.<string>',
157
+ '{a: Map<>}',
158
+ 'typeof Foo<>',
159
+ '?string',
160
+ 'string?',
161
+ '*',
162
+ 'function(string): void',
163
+ '{[K in keyof P]: P[K]; extra: string}',
164
+ '{public a: string}',
165
+ '(public a: string) => void',
166
+ '(a: string = "x") => void',
167
+ '<in T>(x: T) => void',
168
+ '{[k?: string]: number}',
169
+ '{[a: string, b: string]: number}',
170
+ "{a: string = 'x'}",
171
+ 'Foo<A,>',
172
+ ]) {
173
+ expect(normalizeTypeText(text)[0].startsWith(UNPARSED)).toBe(true);
174
+ }
175
+ expect(normalizeTypeText('Array /* v1.2 */ <string>')).toEqual([
176
+ 'string[]',
177
+ ]);
178
+ expect(typeTextTooOld({version: '4.7.4'})).toBe(
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
+ );
181
+ for (const version of ['4.8.4', '5.0.4', '6.0.3', ts.version]) {
182
+ expect(typeTextTooOld({version})).toBeNull();
183
+ }
184
+ });
185
+
186
+ it('keeps a union around a function apart from one in its return, joined as the members are', () => {
187
+ for (const [a, b] of [
188
+ ['(() => ReactNode) | null', '() => ReactNode | null'],
189
+ ['(T extends string ? A : B) | C', 'T extends string ? A : B | C'],
190
+ ]) {
191
+ expect(normalizeTypeText(a).join('|')).not.toBe(
192
+ normalizeTypeText(b).join('|'),
193
+ );
194
+ }
195
+ });
196
+ });
@@ -195,8 +195,10 @@ const RUNNERS = {
195
195
  runs: SELF_DOCS,
196
196
  sites: [
197
197
  'import ../../../api/integration/integrationAdd.doc.mjs',
198
+ 'import ../../../api/integration/integrationCheck.doc.mjs',
198
199
  'import ../../../api/integration/integrationPackCheck.doc.mjs',
199
200
  'import ./integration-add.doc.mjs',
201
+ 'import ./integration-check.doc.mjs',
200
202
  'import ./integration-pack.doc.mjs',
201
203
  'import ./integration-verify.doc.mjs',
202
204
  'import ./integration.doc.mjs',
@@ -250,13 +252,25 @@ const RUNNERS = {
250
252
  runs: '@babel/parser, on first use, to read the members a family doc lists in its components without running the doc',
251
253
  sites: ['require(@babel/parser)'],
252
254
  },
255
+ 'foundation/discovery/copied-passages.mjs': {
256
+ runs: "the CLI's own guides and the package's topics, to compare their prose for passages two topics repeat",
257
+ sites: ['builtinGuideFiles', 'loadTopicModule'],
258
+ },
259
+ 'foundation/discovery/doc-fluff.mjs': {
260
+ runs: "the CLI's own guides, to measure the median share of content words a topic's density is compared with",
261
+ sites: ['builtinGuideFiles'],
262
+ },
253
263
  'foundation/discovery/docs-discovery.mjs': {
254
264
  runs: 'a contributed topic, for its catalog fields: name, title, description, category, and relationships',
255
265
  sites: ['importDocModule'],
256
266
  },
257
267
  'foundation/discovery/project-typescript.mjs': {
258
- 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",
259
- sites: ['require(typescript)', 'require(typescript/package.json)'],
268
+ 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",
269
+ sites: [
270
+ 'require(<computed>)',
271
+ 'require(typescript)',
272
+ 'require(typescript/package.json)',
273
+ ],
260
274
  },
261
275
  'foundation/discovery/template-adapter.mjs': {
262
276
  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',
@@ -13,10 +13,12 @@
13
13
  * @typedef {object} DocLink
14
14
  * @property {string} target the target as written: `[<provider>:]<kind>:<name>`
15
15
  * @property {string} id the doc's identity (a DocId)
16
- * @property {string} route what `astryx docs <route>` opens
16
+ * @property {string | null} route what `astryx docs <route>` opens; null for a
17
+ * component, page, or block doc, which no docs route opens
17
18
  * @property {string} title
18
19
  * @property {string} summary
19
- * @property {string} command the command that opens it, `astryx docs <route>`
20
+ * @property {string} command the command that opens it: `astryx docs <route>`,
21
+ * or `astryx component` or `astryx template` for a component, page, or block
20
22
  */
21
23
  /**
22
24
  * Finds the doc a target names, or says why none matches.
@@ -118,13 +120,15 @@ export type DocLink = {
118
120
  */
119
121
  id: string;
120
122
  /**
121
- * what `astryx docs <route>` opens
123
+ * what `astryx docs <route>` opens; null for a
124
+ * component, page, or block doc, which no docs route opens
122
125
  */
123
- route: string;
126
+ route: string | null;
124
127
  title: string;
125
128
  summary: string;
126
129
  /**
127
- * the command that opens it, `astryx docs <route>`
130
+ * the command that opens it: `astryx docs <route>`,
131
+ * or `astryx component` or `astryx template` for a component, page, or block
128
132
  */
129
133
  command: string;
130
134
  };
@@ -47,10 +47,12 @@ const CODE_SPAN = /(`[^`]*`)/;
47
47
  * @typedef {object} DocLink
48
48
  * @property {string} target the target as written: `[<provider>:]<kind>:<name>`
49
49
  * @property {string} id the doc's identity (a DocId)
50
- * @property {string} route what `astryx docs <route>` opens
50
+ * @property {string | null} route what `astryx docs <route>` opens; null for a
51
+ * component, page, or block doc, which no docs route opens
51
52
  * @property {string} title
52
53
  * @property {string} summary
53
- * @property {string} command the command that opens it, `astryx docs <route>`
54
+ * @property {string} command the command that opens it: `astryx docs <route>`,
55
+ * or `astryx component` or `astryx template` for a component, page, or block
54
56
  */
55
57
 
56
58
  /**
@@ -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
  });
@@ -21,7 +21,8 @@ export function importUserModule(file: string, { fresh }?: {
21
21
  /**
22
22
  * Load a generated theme artifact and its extensionless JS/JSX/TS/TSX graph.
23
23
  * Package specifiers resolve from the consumer project, while relative paths
24
- * resolve from that same project root.
24
+ * resolve from that same project root. An import of an existing `.css` file
25
+ * loads as an empty module.
25
26
  * @param {string} specifier
26
27
  * @param {string} cwd
27
28
  * @returns {Promise<Record<string, unknown>>}