@astryxdesign/cli 0.7.1 → 0.7.2-canary.020e1fe

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 (247) hide show
  1. package/README.md +15 -14
  2. package/api/build/help/help.mjs +1 -1
  3. package/api/component/_adapter.d.mts +41 -1
  4. package/api/component/_adapter.mjs +93 -7
  5. package/api/component/component.mjs +22 -5
  6. package/api/component/component.test.mjs +420 -167
  7. package/api/component/integration-export-name.test.mjs +644 -0
  8. package/api/component/list/list.mjs +42 -4
  9. package/api/docs/_adapter.d.mts +11 -0
  10. package/api/docs/_adapter.mjs +244 -1
  11. package/api/docs/integrationDocs.test.mjs +124 -0
  12. package/api/doctor/doctor.mjs +27 -3
  13. package/api/doctor/doctor.test.mjs +43 -0
  14. package/api/doctor/theme-checks.mjs +1 -1
  15. package/api/gap-report/gap-report.mjs +67 -4
  16. package/api/index.d.mts +2 -0
  17. package/api/index.mjs +2 -0
  18. package/api/init/run/run.mjs +2 -2
  19. package/api/integration/_adapter.d.mts +12 -0
  20. package/api/integration/_adapter.mjs +54 -0
  21. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  22. package/api/integration/add-contribution.mjs +8 -4
  23. package/api/integration/add-contribution.test.mjs +4 -2
  24. package/api/integration/authoring-checks.mjs +11 -2
  25. package/api/integration/authoring-checks.test.mjs +39 -0
  26. package/api/integration/authoring-checks.type.d.mts +9 -0
  27. package/api/integration/authoring-checks.type.mjs +14 -1
  28. package/api/integration/check/check.d.mts +96 -0
  29. package/api/integration/check/check.mjs +357 -0
  30. package/api/integration/check/check.test.mjs +489 -0
  31. package/api/integration/integration-check.type.d.mts +118 -0
  32. package/api/integration/integration-check.type.mjs +84 -0
  33. package/api/integration/integrationCheck.doc.d.mts +10 -0
  34. package/api/integration/integrationCheck.doc.mjs +73 -0
  35. package/api/integration/integrationComponentConflicts.doc.mjs +43 -6
  36. package/api/integration/pack-check.mjs +61 -107
  37. package/api/integration/pack-check.test.mjs +359 -0
  38. package/api/integration/validate-integration.mjs +8 -0
  39. package/api/integration/validate-integration.test.mjs +11 -0
  40. package/api/integration/validate-integration.type.d.mts +8 -0
  41. package/api/integration/validate-integration.type.mjs +12 -1
  42. package/api/integration/validateIntegration.doc.mjs +19 -3
  43. package/api/search/search.d.mts +81 -12
  44. package/api/search/search.domain-priority.test.mjs +108 -18
  45. package/api/search/search.integration-check.test.mjs +24 -0
  46. package/api/search/search.mjs +609 -53
  47. package/api/search/search.test.mjs +175 -0
  48. package/api/swizzle/copy/copy.mjs +28 -14
  49. package/api/template/table-filter-view-tabs.test.mjs +45 -0
  50. package/api/template/template.test.mjs +120 -3
  51. package/api/theme/build/build.core-on-demand.test.mjs +113 -0
  52. package/api/theme/build/build.d.mts +13 -13
  53. package/api/theme/build/build.family.test.mjs +64 -0
  54. package/api/theme/build/build.mjs +252 -61
  55. package/api/theme/themeBuild.doc.mjs +4 -4
  56. package/assets/codemods/transforms/next/__tests__/migrate-list-edge-compensation-to-edge.test.mjs +120 -0
  57. package/assets/codemods/transforms/next/index.mjs +11 -1
  58. package/assets/codemods/transforms/next/migrate-list-edge-compensation-to-edge.mjs +198 -0
  59. package/assets/docs/README.md +10 -0
  60. package/assets/docs/author-a-theme.doc.mjs +1 -1
  61. package/assets/docs/getting-started.doc.mjs +3 -3
  62. package/assets/docs/styling-overview.doc.mjs +1 -1
  63. package/assets/docs/theme.doc.dense.mjs +1 -1
  64. package/assets/docs/theme.doc.mjs +1 -1
  65. package/assets/docs/theme.doc.zh.mjs +1 -1
  66. package/assets/docs/tree/add-a-component.doc.mjs +11 -1
  67. package/assets/docs/tree/add-a-theme.doc.mjs +1 -1
  68. package/assets/docs/tree/add-a-topic.doc.mjs +10 -7
  69. package/assets/docs/tree/agent-guidance.doc.mjs +2 -2
  70. package/assets/docs/tree/block-template.doc.mjs +8 -20
  71. package/assets/docs/tree/build-the-template.doc.mjs +1 -1
  72. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  73. package/assets/docs/tree/check-your-docs.doc.mjs +51 -5
  74. package/assets/docs/tree/checks.doc.mjs +24 -16
  75. package/assets/docs/tree/codemods.doc.mjs +4 -4
  76. package/assets/docs/tree/component-family.doc.mjs +8 -6
  77. package/assets/docs/tree/component-imports.doc.mjs +10 -2
  78. package/assets/docs/tree/components.doc.mjs +1 -1
  79. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +7 -18
  80. package/assets/docs/tree/define-the-theme.doc.mjs +6 -5
  81. package/assets/docs/tree/describe-the-component.doc.mjs +2 -2
  82. package/assets/docs/tree/docs.doc.mjs +3 -3
  83. package/assets/docs/tree/document-the-template.doc.mjs +1 -1
  84. package/assets/docs/tree/document-the-theme.doc.mjs +1 -1
  85. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  86. package/assets/docs/tree/extend-or-replace.doc.mjs +6 -6
  87. package/assets/docs/tree/fonts-and-assets.doc.mjs +2 -2
  88. package/assets/docs/tree/generate-a-palette.doc.mjs +5 -3
  89. package/assets/docs/tree/grade-template-with-agent.doc.mjs +1 -1
  90. package/assets/docs/tree/integrations.doc.mjs +8 -0
  91. package/assets/docs/tree/links.doc.mjs +6 -5
  92. package/assets/docs/tree/migration-setup.doc.mjs +1 -0
  93. package/assets/docs/tree/migration-verification.doc.mjs +0 -1
  94. package/assets/docs/tree/migration.doc.mjs +0 -1
  95. package/assets/docs/tree/package-and-test.doc.mjs +1 -1
  96. package/assets/docs/tree/page-template.doc.mjs +4 -8
  97. package/assets/docs/tree/publishing.doc.mjs +1 -1
  98. package/assets/docs/tree/quick-start.doc.mjs +37 -21
  99. package/assets/docs/tree/replace-a-core-component.doc.mjs +4 -6
  100. package/assets/docs/tree/replace-a-core-template.doc.mjs +6 -8
  101. package/assets/docs/tree/sections-and-placement.doc.mjs +4 -6
  102. package/assets/docs/tree/see-it-in-an-app.doc.mjs +4 -2
  103. package/assets/docs/tree/short-and-findable.doc.mjs +6 -5
  104. package/assets/docs/tree/single-component.doc.mjs +15 -6
  105. package/assets/docs/tree/start-a-template.doc.mjs +3 -3
  106. package/assets/docs/tree/subcomponent.doc.mjs +6 -6
  107. package/assets/docs/tree/template-assets.doc.mjs +2 -2
  108. package/assets/docs/tree/template-doc-overview.doc.mjs +4 -15
  109. package/assets/docs/tree/template-fonts.doc.mjs +1 -1
  110. package/assets/docs/tree/template-icons.doc.mjs +1 -1
  111. package/assets/docs/tree/template-images-media.doc.mjs +1 -1
  112. package/assets/docs/tree/template-styles.doc.mjs +2 -2
  113. package/assets/docs/tree/templates.doc.mjs +1 -1
  114. package/assets/docs/tree/test-in-an-app.doc.mjs +3 -3
  115. package/assets/docs/tree/test-template-in-app.doc.mjs +1 -1
  116. package/assets/docs/tree/tokens-and-setup.doc.mjs +19 -15
  117. package/assets/docs/tree/troubleshooting.doc.mjs +13 -5
  118. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  119. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  120. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +3 -1
  121. package/assets/docs/tree/verify-packed-template.doc.mjs +1 -1
  122. package/assets/docs/tree/versioning.doc.mjs +7 -6
  123. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -3
  124. package/assets/docs/use-a-theme.doc.mjs +2 -2
  125. package/assets/docs/working-with-ai.doc.mjs +43 -4
  126. package/assets/templates/blocks/components/Drawer/DrawerForm.doc.mjs +24 -0
  127. package/assets/templates/blocks/components/Drawer/DrawerForm.tsx +62 -0
  128. package/assets/templates/blocks/components/Drawer/DrawerScrim.doc.mjs +22 -0
  129. package/assets/templates/blocks/components/Drawer/DrawerScrim.tsx +68 -0
  130. package/assets/templates/blocks/components/Drawer/DrawerShowcase.doc.mjs +22 -0
  131. package/assets/templates/blocks/components/Drawer/DrawerShowcase.tsx +41 -0
  132. package/assets/templates/blocks/components/Drawer/DrawerStart.doc.mjs +21 -0
  133. package/assets/templates/blocks/components/Drawer/DrawerStart.tsx +41 -0
  134. package/assets/templates/blocks/components/Drawer/DrawerWidths.doc.mjs +22 -0
  135. package/assets/templates/blocks/components/Drawer/DrawerWidths.tsx +54 -0
  136. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.doc.mjs +15 -0
  137. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderShowcase.tsx +73 -0
  138. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.doc.mjs +22 -0
  139. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderSubtitleEndContent.tsx +49 -0
  140. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.doc.mjs +21 -0
  141. package/assets/templates/blocks/components/DrawerHeader/DrawerHeaderWithCloseButton.tsx +42 -0
  142. package/assets/templates/pages/detail-page/page.tsx +3 -3
  143. package/assets/templates/pages/table-filter/page.tsx +3 -2
  144. package/assets/templates/pages/table-inbox/page.tsx +10 -8
  145. package/assets/theme.template.ts +1 -1
  146. package/authoring/codemod/codemod.doc.mjs +7 -3
  147. package/authoring/config/config.doc.mjs +9 -6
  148. package/authoring/config/type.ts +4 -2
  149. package/authoring/discover/discover.doc.mjs +1 -1
  150. package/authoring/doctypes/base/graph-fields.doc.mjs +6 -4
  151. package/authoring/doctypes/base/type.ts +6 -0
  152. package/authoring/doctypes/command/command.doc.mjs +14 -12
  153. package/authoring/doctypes/component/component.doc.mjs +31 -28
  154. package/authoring/doctypes/component/type.ts +13 -8
  155. package/authoring/doctypes/enum/enum.doc.mjs +7 -4
  156. package/authoring/doctypes/function/function.doc.mjs +9 -8
  157. package/authoring/doctypes/hook/hook.doc.mjs +5 -4
  158. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -6
  159. package/authoring/doctypes/reference/reference.doc.mjs +11 -10
  160. package/authoring/doctypes/schema/schema.doc.mjs +9 -9
  161. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  162. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  163. package/authoring/doctypes/template/parse.d.mts +6 -2
  164. package/authoring/doctypes/template/parse.mjs +3 -1
  165. package/authoring/doctypes/template/template.doc.mjs +3 -3
  166. package/authoring/doctypes/template/type.ts +22 -0
  167. package/authoring/doctypes/theme/theme.doc.mjs +2 -2
  168. package/authoring/gap-report/gap-report.doc.mjs +2 -2
  169. package/authoring/identity/identity.doc.mjs +3 -3
  170. package/authoring/index.d.ts +1 -0
  171. package/authoring/integration/integration.doc.mjs +12 -4
  172. package/authoring/integration/parse.test.mjs +10 -0
  173. package/authoring/integration/schema.d.mts +2 -0
  174. package/authoring/integration/schema.mjs +1 -0
  175. package/authoring/integration/type.ts +4 -0
  176. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  177. package/clients/cli/commands/build-theme.mjs +1 -1
  178. package/clients/cli/commands/build-theme.path-safety.test.mjs +224 -6
  179. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  180. package/clients/cli/commands/cli-postinstall.test.mjs +49 -1
  181. package/clients/cli/commands/doctor-integration-components.doc.mjs +17 -4
  182. package/clients/cli/commands/doctor-integration-validate.doc.mjs +13 -2
  183. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  184. package/clients/cli/commands/doctor.mjs +190 -0
  185. package/clients/cli/commands/integration-check.doc.mjs +85 -0
  186. package/clients/cli/commands/integration-check.test.mjs +267 -0
  187. package/clients/cli/commands/integration.doc.mjs +6 -2
  188. package/clients/cli/commands/integration.mjs +107 -1
  189. package/clients/cli/commands/setup-nudge.test.mjs +79 -1
  190. package/clients/cli/commands/swizzle.mjs +5 -3
  191. package/clients/cli/commands/swizzle.routing.test.mjs +18 -1
  192. package/clients/cli/commands/text-json-parity.test.mjs +5 -0
  193. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  194. package/clients/cli/index.mjs +30 -5
  195. package/clients/cli/lib/component-format.mjs +5 -1
  196. package/foundation/agent-docs/agent-doc-state.d.mts +14 -0
  197. package/foundation/agent-docs/agent-doc-state.mjs +38 -0
  198. package/foundation/agent-docs/agent-docs.d.mts +2 -1
  199. package/foundation/agent-docs/agent-docs.mjs +8 -6
  200. package/foundation/config/project.mjs +82 -0
  201. package/foundation/discovery/authoring-self-docs.mjs +2 -1
  202. package/foundation/discovery/component-discovery.d.mts +190 -10
  203. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  204. package/foundation/discovery/component-discovery.mjs +864 -56
  205. package/foundation/discovery/component-discovery.test.mjs +96 -0
  206. package/foundation/discovery/component-replacement.mjs +18 -0
  207. package/foundation/discovery/component-replacement.test.mjs +40 -0
  208. package/foundation/discovery/doc-types.d.mts +157 -0
  209. package/foundation/discovery/doc-types.mjs +1224 -0
  210. package/foundation/discovery/doc-types.test.mjs +700 -0
  211. package/foundation/discovery/docs-discovery.d.mts +81 -0
  212. package/foundation/discovery/docs-discovery.mjs +57 -0
  213. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  214. package/foundation/discovery/integration-doc-files.mjs +231 -0
  215. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  216. package/foundation/discovery/module-exports.d.mts +27 -0
  217. package/foundation/discovery/module-exports.mjs +356 -31
  218. package/foundation/discovery/module-exports.test.mjs +172 -0
  219. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  220. package/foundation/discovery/package-tsconfig.mjs +228 -0
  221. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  222. package/foundation/discovery/project-typescript.d.mts +32 -0
  223. package/foundation/discovery/project-typescript.mjs +89 -0
  224. package/foundation/discovery/prop-drift.d.mts +278 -0
  225. package/foundation/discovery/prop-drift.mjs +2263 -0
  226. package/foundation/discovery/prop-drift.test.mjs +2272 -0
  227. package/foundation/discovery/template-adapter.mjs +74 -5
  228. package/foundation/discovery/type-match.d.mts +53 -0
  229. package/foundation/discovery/type-match.mjs +660 -0
  230. package/foundation/discovery/type-match.test.mjs +169 -0
  231. package/foundation/discovery/type-text.d.mts +68 -0
  232. package/foundation/discovery/type-text.mjs +658 -0
  233. package/foundation/discovery/type-text.test.mjs +196 -0
  234. package/foundation/discovery/unresolved-references.d.mts +62 -0
  235. package/foundation/discovery/unresolved-references.mjs +790 -0
  236. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  237. package/foundation/doc-compiler/doc-loads.test.mjs +15 -1
  238. package/foundation/doc-compiler/inputs.mjs +23 -0
  239. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  240. package/foundation/doc-compiler/links.d.mts +9 -5
  241. package/foundation/doc-compiler/links.mjs +4 -2
  242. package/foundation/integrations/contribution-inventory.mjs +6 -1
  243. package/foundation/response/response-types.doc.mjs +7 -2
  244. package/foundation/xle/registry.mjs +4 -0
  245. package/foundation/xle/registry.test.mjs +28 -0
  246. package/package.json +10 -10
  247. package/scripts/postinstall.mjs +3 -3
@@ -13,6 +13,7 @@ import {themeBuild, themeBuildFamily} from './build.mjs';
13
13
  import {interceptCore} from './core-interception.mjs';
14
14
  import {ensureCoreBuilt} from '../../../clients/cli/commands/ensure-core-built.mjs';
15
15
  import {runCli} from '../../../test-utils/run-cli.mjs';
16
+ import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
16
17
  vi.setConfig({testTimeout: 120_000});
17
18
  const CLI_ROOT = path.resolve(import.meta.dirname, '../../..');
18
19
  const FAMILY_KEY = 'ocean-family';
@@ -252,6 +253,69 @@ describe('themeBuildFamily()', () => {
252
253
  expect(fs.existsSync(dtsPath)).toBe(false);
253
254
  });
254
255
 
256
+ it('refuses to write family outputs outside cwd, and checks them read-only', async () => {
257
+ const dir = makeDir();
258
+ const files = writeFamily(dir).map(file => path.join(dir, file));
259
+ const app = path.join(dir, 'app');
260
+ fs.mkdirSync(app);
261
+
262
+ await expect(
263
+ themeBuildFamily(files, {familyKey: FAMILY_KEY}, {cwd: app}),
264
+ ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
265
+ const checked = await themeBuildFamily(
266
+ files,
267
+ {familyKey: FAMILY_KEY, check: true},
268
+ {cwd: app},
269
+ );
270
+ expect(checked?.type).toBe('theme.build.check');
271
+ expect(checked?.data.upToDate).toBe(false);
272
+ // The `.css.d.ts` import stub may be absent in check mode.
273
+ expect(checked?.data.stale).toEqual(
274
+ OUTPUTS.filter(file => !file.endsWith('.css.d.ts')).map(file => ({
275
+ path: `../themes/${file}`,
276
+ reason: 'missing',
277
+ })),
278
+ );
279
+ for (const output of OUTPUTS) {
280
+ expect(fs.existsSync(path.join(dir, 'themes', output))).toBe(false);
281
+ }
282
+ });
283
+
284
+ it('ends a stale family report for outputs outside cwd with a remedy that works', async () => {
285
+ const dir = makeDir();
286
+ const files = writeFamily(dir).map(file => path.join(dir, file));
287
+ const app = path.join(dir, 'app');
288
+ fs.mkdirSync(app);
289
+ const family = ['--family', ...files, '--family-key', FAMILY_KEY];
290
+
291
+ const stale = await runCli(['theme', 'build', ...family, '--check'], app);
292
+ expect(stale.code).toBe(1);
293
+ // The old remedy ran the build from cwd, which refuses these outputs.
294
+ expect(stale.stderr).not.toContain('Rebuild with:');
295
+
296
+ const lines = stale.stderr.split('\n').map(line => line.trim());
297
+ const runDir = lines.find(line => line.startsWith('cd '))?.slice(3);
298
+ expect(runDir).toBe(fs.realpathSync(path.join(dir, 'themes')));
299
+ const stem = `${getCliInvocation(runDir)} theme build `;
300
+ const [buildArgs, checkArgs] = lines
301
+ .filter(line => line.startsWith(stem))
302
+ .map(line => line.slice(stem.length).split(' '));
303
+ expect(checkArgs).toEqual([...buildArgs, '--check']);
304
+
305
+ // Following the remedy builds, and the check from there passes.
306
+ const built = await runCli(['theme', 'build', ...buildArgs], runDir);
307
+ expect(built.code).toBe(0);
308
+ for (const output of OUTPUTS) {
309
+ expect(fs.existsSync(path.join(dir, 'themes', output))).toBe(true);
310
+ }
311
+ const checked = await runCli(
312
+ ['--json', 'theme', 'build', ...checkArgs],
313
+ runDir,
314
+ );
315
+ expect(checked.code).toBe(0);
316
+ expect(JSON.parse(checked.stdout).data.upToDate).toBe(true);
317
+ });
318
+
255
319
  it('fails without publishing a mixed trio when staging a write fails', async () => {
256
320
  const dir = makeDir();
257
321
  const files = writeFamily(dir);
@@ -27,6 +27,10 @@
27
27
  * files; an internal callback lets the CLI make only the process status fail.
28
28
  * Human progress is emitted through the shared `logger` (silent by default), so
29
29
  * the CLI keeps its exact output while a programmatic caller stays quiet.
30
+ * Every output a build writes, explicit or beside the theme file, stays inside
31
+ * `cwd` (`ERR_PATH_TRAVERSAL` otherwise). Check mode writes nothing, so it
32
+ * compares outputs outside `cwd` read-only; only a relative `out` path that
33
+ * escapes `cwd` is refused there too.
30
34
  *
31
35
  * The installed `@astryxdesign/core` is an independently versioned optional
32
36
  * peer, so it can be older than the CLI. A theme that uses only baseline
@@ -37,6 +41,10 @@
37
41
  * general compatibility scheme for every export an arbitrary older core might
38
42
  * lack.
39
43
  *
44
+ * Core is imported on first use, never when this module loads: the CLI loads
45
+ * this module for every command, and Core's root entry pulls in all of Core
46
+ * and React.
47
+ *
40
48
  * With `{check: true}`, it compiles the same outputs in memory but writes
41
49
  * nothing: it compares each generated file against what is on disk (ignoring
42
50
  * only the volatile `@generated` `Command:` line) and returns a
@@ -54,7 +62,10 @@ import {isBuiltin} from 'node:module';
54
62
  import {fileURLToPath, pathToFileURL} from 'node:url';
55
63
  import {parse} from '@babel/parser';
56
64
  import {createJiti} from 'jiti';
57
- import {getCliInvocation} from '../../../foundation/env/package-manager.mjs';
65
+ import {
66
+ formatCliCommand,
67
+ getCliInvocation,
68
+ } from '../../../foundation/env/package-manager.mjs';
58
69
  import {
59
70
  CLI_ROOT,
60
71
  findCoreDir,
@@ -91,6 +102,8 @@ import {resolveIconImports} from './icon-imports.mjs';
91
102
  // action). A built, resolvable `@astryxdesign/core` is a hard requirement.
92
103
  // A built, resolvable `@astryxdesign/core` is a hard requirement. These are
93
104
  // populated from a dynamic import (a runtime boundary), so `any` is intentional.
105
+ // That import runs the first time a build needs Core (see `loadCliCore`), not
106
+ // when this module loads.
94
107
  //
95
108
  // The CLI and core are independently versioned optional peers, so this import
96
109
  // can succeed against a core OLDER than the CLI. Only the exports every theme
@@ -120,27 +133,6 @@ import {resolveIconImports} from './icon-imports.mjs';
120
133
  */
121
134
  /** @type {any} */ let _coreRootModule = null;
122
135
  /** @type {any} */ let _coreImportError = null;
123
- try {
124
- const coreTheme = await import('@astryxdesign/core/theme');
125
- _coreThemeModule = coreTheme;
126
- _defineTheme = coreTheme.defineTheme;
127
- _generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
128
- _generateOnMediaCSS = coreTheme.generateOnMediaCSS;
129
- _generateAdaptationCSS = coreTheme.generateAdaptationCSS;
130
- try {
131
- _coreRootModule = await import('@astryxdesign/core');
132
- } catch {
133
- // A core without a usable root entry still builds themes; interception
134
- // falls back to the theme namespace for the root specifier.
135
- }
136
- } catch (e) {
137
- // Capture the reason so the theme action can surface a precise, actionable
138
- // error. We don't throw here: this module is imported eagerly by the CLI
139
- // entrypoint for every command, and a throw at load time would break
140
- // unrelated commands (the entry wraps loads in try/catch and degrades the
141
- // command to a stub). The hard failure happens when `theme build` runs.
142
- _coreImportError = e;
143
- }
144
136
 
145
137
  /**
146
138
  * The bindings one Core provides: the namespaces interception spreads, the
@@ -157,19 +149,65 @@ try {
157
149
  */
158
150
 
159
151
  /**
160
- * The bindings exactly as the CLI's own import left them, kept so each build
161
- * can choose between them and the project's installed Core.
162
- * @type {CoreBindings}
152
+ * Import the CLI's own Core: the `@astryxdesign/core` this module resolves.
153
+ * Never throws. A failed import is kept as `importError`, so the build can
154
+ * surface a precise, actionable error when it runs.
155
+ * @returns {Promise<CoreBindings>}
163
156
  */
164
- const _cliCore = {
165
- themeModule: _coreThemeModule,
166
- rootModule: _coreRootModule,
167
- importError: _coreImportError,
168
- defineTheme: _defineTheme,
169
- generateThemeRulesSplit: _generateThemeRulesSplit,
170
- generateOnMediaCSS: _generateOnMediaCSS,
171
- generateAdaptationCSS: _generateAdaptationCSS,
172
- };
157
+ async function importCliCore() {
158
+ /** @type {CoreBindings} */
159
+ const core = {
160
+ themeModule: null,
161
+ rootModule: null,
162
+ importError: null,
163
+ defineTheme: null,
164
+ generateThemeRulesSplit: null,
165
+ generateOnMediaCSS: null,
166
+ generateAdaptationCSS: null,
167
+ };
168
+ try {
169
+ const coreTheme = await import('@astryxdesign/core/theme');
170
+ core.themeModule = coreTheme;
171
+ core.defineTheme = coreTheme.defineTheme;
172
+ core.generateThemeRulesSplit = coreTheme.generateThemeRulesSplit;
173
+ core.generateOnMediaCSS = coreTheme.generateOnMediaCSS;
174
+ core.generateAdaptationCSS = coreTheme.generateAdaptationCSS;
175
+ try {
176
+ core.rootModule = await import('@astryxdesign/core');
177
+ } catch {
178
+ // A core without a usable root entry still builds themes; interception
179
+ // falls back to the theme namespace for the root specifier.
180
+ }
181
+ } catch (e) {
182
+ // Capture the reason so the theme action can surface a precise, actionable
183
+ // error. The hard failure happens when `theme build` runs.
184
+ core.importError = e;
185
+ }
186
+ return core;
187
+ }
188
+
189
+ /**
190
+ * The CLI's own Core, imported once, the first time a build needs it. The CLI
191
+ * loads this module for every command, and Core's root entry loads all of Core
192
+ * and React, so an import at module load would make every command
193
+ * (`--version` included) pay for that whenever a Core resolves.
194
+ * @type {Promise<CoreBindings> | null}
195
+ */
196
+ let _cliCorePromise = null;
197
+
198
+ /**
199
+ * The CLI's own Core, kept so each build can choose between it and the
200
+ * project's installed Core. The first call also points the build at it, so a
201
+ * step that runs before any build has chosen a Core reads the CLI's own.
202
+ * @returns {Promise<CoreBindings>}
203
+ */
204
+ function loadCliCore() {
205
+ _cliCorePromise ??= importCliCore().then(core => {
206
+ setCore(core);
207
+ return core;
208
+ });
209
+ return _cliCorePromise;
210
+ }
173
211
 
174
212
  /**
175
213
  * Point the build at one Core: the module-level bindings every step reads.
@@ -239,6 +277,25 @@ function realOrSelf(file) {
239
277
  }
240
278
  }
241
279
 
280
+ /**
281
+ * `target` spelled through real directories: the deepest ancestor that exists
282
+ * is resolved through its symlinks, and the missing rest is appended as given.
283
+ * @param {string} target absolute path
284
+ * @returns {string}
285
+ */
286
+ function realLocation(target) {
287
+ /** @type {string[]} */
288
+ const missing = [];
289
+ let existing = target;
290
+ while (!fs.existsSync(existing)) {
291
+ const parent = path.dirname(existing);
292
+ if (parent === existing) break;
293
+ missing.unshift(path.basename(existing));
294
+ existing = parent;
295
+ }
296
+ return path.join(realOrSelf(existing), ...missing);
297
+ }
298
+
242
299
  /**
243
300
  * The Core the project at `cwd` installed, when it differs from the one the
244
301
  * CLI's own import found and loads. The app's `<Theme>` runs on the app's
@@ -248,13 +305,14 @@ function realOrSelf(file) {
248
305
  * repository, a bare directory), the same Core, or one that does not load.
249
306
  *
250
307
  * @param {string} cwd
308
+ * @param {CoreBindings} cliCore - The CLI's own Core, from {@link loadCliCore}.
251
309
  * @returns {Promise<CoreBindings | null>}
252
310
  */
253
- async function loadProjectCore(cwd) {
311
+ async function loadProjectCore(cwd, cliCore) {
254
312
  const dir = findInstalledPackage(cwd, '@astryxdesign/core');
255
313
  const themeFile = dir ? importTarget(dir, './theme') : null;
256
314
  if (!dir || !themeFile) return null;
257
- if (_cliCore.themeModule) {
315
+ if (cliCore.themeModule) {
258
316
  try {
259
317
  const own = fileURLToPath(
260
318
  import.meta.resolve('@astryxdesign/core/theme'),
@@ -301,9 +359,10 @@ const _projectCores = new Map();
301
359
  * @param {string} cwd
302
360
  */
303
361
  async function selectCore(cwd) {
362
+ const cliCore = await loadCliCore();
304
363
  if (!_projectCores.has(cwd))
305
- _projectCores.set(cwd, await loadProjectCore(cwd));
306
- setCore(_projectCores.get(cwd) ?? _cliCore);
364
+ _projectCores.set(cwd, await loadProjectCore(cwd, cliCore));
365
+ setCore(_projectCores.get(cwd) ?? cliCore);
307
366
  }
308
367
 
309
368
  /**
@@ -473,6 +532,127 @@ function checkedBuildOutputs(writes, cwd) {
473
532
  .map(write => path.relative(cwd, write.dest));
474
533
  }
475
534
 
535
+ /** Remedies that end a confinement error, by where the output path came from. */
536
+ const OUT_REMEDY = 'Pass an --out path inside it.';
537
+ const SOURCE_REMEDY =
538
+ 'Without --out the outputs go beside the theme file, so run the build from a directory that contains the theme file, or pass an --out path inside the working directory.';
539
+ const FAMILY_REMEDY =
540
+ "Family outputs go beside the family's root theme file, so run the build from a directory that contains it.";
541
+
542
+ /**
543
+ * Refuse an output outside `root`: every write is confined, whether `out` names
544
+ * the path or it defaults to the theme file's directory (architecture:cli-surface
545
+ * INV10). Both sides are compared by real location, so an absolute path that
546
+ * reaches the working directory through a symlink is inside it, and a symlink
547
+ * inside it that leads elsewhere is not.
548
+ * @param {string} dest absolute output path
549
+ * @param {string} root the directory writes stay inside: the working directory
550
+ * @param {string} remedy what to do instead; ends the error message
551
+ * @param {string} [shown] the path as the caller wrote it, for the message
552
+ */
553
+ function confineOutput(dest, root, remedy, shown = dest) {
554
+ try {
555
+ assertWithin(realLocation(dest), realOrSelf(path.resolve(root)), {
556
+ allowAbsolute: true,
557
+ label: 'output path',
558
+ });
559
+ } catch (err) {
560
+ if (!(err instanceof PathSafetyError)) throw err;
561
+ throw new AstryxError(
562
+ err.code === ERROR_CODES.ERR_PATH_TRAVERSAL
563
+ ? `Output path "${shown}" is outside the working directory (${root}). ${remedy}`
564
+ : err.message,
565
+ undefined,
566
+ ERROR_CODES.ERR_PATH_TRAVERSAL,
567
+ );
568
+ }
569
+ }
570
+
571
+ /** @param {Array<{dest: string}>} writes @param {string} root @param {string} remedy */
572
+ function confineOutputs(writes, root, remedy) {
573
+ for (const write of writes) confineOutput(write.dest, root, remedy);
574
+ }
575
+
576
+ /** @param {string} dest absolute output path @param {string} root @returns {boolean} whether a build at `root` refuses to write `dest` */
577
+ function refusedOutput(dest, root) {
578
+ try {
579
+ confineOutput(dest, root, '');
580
+ return false;
581
+ } catch (err) {
582
+ if (
583
+ err instanceof AstryxError &&
584
+ err.code === ERROR_CODES.ERR_PATH_TRAVERSAL
585
+ )
586
+ return true;
587
+ throw err;
588
+ }
589
+ }
590
+
591
+ /** @param {string[]} dirs absolute directories @returns {string | null} the deepest directory containing all of them, or null across roots */
592
+ function commonDirectory(dirs) {
593
+ let common = dirs[0];
594
+ for (const dir of dirs.slice(1)) {
595
+ while (
596
+ path.relative(common, dir).startsWith('..') ||
597
+ path.isAbsolute(path.relative(common, dir))
598
+ ) {
599
+ const parent = path.dirname(common);
600
+ if (parent === common) return null;
601
+ common = parent;
602
+ }
603
+ }
604
+ return common;
605
+ }
606
+
607
+ /** @param {string} value @returns {string} `value` as one shell word */
608
+ function shellWord(value) {
609
+ if (/^[A-Za-z0-9@%+=:,./_-]+$/.test(value)) return value;
610
+ return `'${value.replace(/'/g, `'\\''`)}'`;
611
+ }
612
+
613
+ /**
614
+ * How a stale check report ends when outputs sit outside the write root. A
615
+ * build there refuses them, and each output's `Source:` header records the
616
+ * directory its build ran from, so the build and the check both run from the
617
+ * nearest directory that contains every theme file and output.
618
+ * @param {Array<{dest: string}>} writes
619
+ * @param {string[]} sources absolute theme files the build reads
620
+ * @param {string} root the directory a build here keeps its writes inside
621
+ * @param {(relative: (file: string) => string) => string[]} args the arguments after `theme build`, given each path relative to the directory to run from
622
+ * @returns {string[] | null} report lines, or null when every output is inside `root`
623
+ */
624
+ function outsideCheckRemedy(writes, sources, root, args) {
625
+ if (!writes.some(write => refusedOutput(write.dest, root))) return null;
626
+ const real = (/** @type {string} */ file) => realLocation(path.resolve(file));
627
+ const dir = commonDirectory([
628
+ ...sources.map(file => path.dirname(real(file))),
629
+ ...writes.map(write => path.dirname(real(write.dest))),
630
+ ]);
631
+ if (!dir) {
632
+ return [
633
+ 'These outputs are outside the working directory, so a build here refuses them. Build and check them from one directory that contains the theme files and the outputs.',
634
+ ];
635
+ }
636
+ const command = (/** @type {string[]} */ extra) =>
637
+ formatCliCommand(
638
+ [
639
+ 'theme',
640
+ 'build',
641
+ ...args(file => path.relative(dir, real(file))),
642
+ ...extra,
643
+ ]
644
+ .map(shellWord)
645
+ .join(' '),
646
+ dir,
647
+ );
648
+ return [
649
+ 'These outputs are outside the working directory, so a build here refuses them, and each output records the directory it was built from. Build and check them from a directory that contains them:',
650
+ ` cd ${shellWord(dir)}`,
651
+ ` ${command([])}`,
652
+ ` ${command(['--check'])}`,
653
+ ];
654
+ }
655
+
476
656
  /** @param {Array<{dest: string, content: string}>} writes */
477
657
  function writeBuildOutputs(writes) {
478
658
  if (writes.length === 0) return;
@@ -1694,6 +1874,8 @@ export async function validateThemePrivateInputs(
1694
1874
  );
1695
1875
  }
1696
1876
 
1877
+ // The CLI's own Core, unless a build in this process already chose one.
1878
+ await loadCliCore();
1697
1879
  const interception = interceptCore(_coreThemeModule, _coreRootModule);
1698
1880
  let theme;
1699
1881
  try {
@@ -2309,9 +2491,10 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
2309
2491
  * `logger` (silent by default).
2310
2492
  *
2311
2493
  * @param {string} file - Theme file path, resolved against `cwd`.
2312
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void}} [options] -
2494
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string}} [options] -
2313
2495
  * `out` overrides the output CSS path; `check` compares against on-disk outputs
2314
- * instead of writing. `iconsSpecifier` overrides the icon registry import
2496
+ * instead of writing. `__writeRoot` replaces `cwd` as the directory every
2497
+ * output must stay inside, for a CLI-internal scratch build. `iconsSpecifier` overrides the icon registry import
2315
2498
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
2316
2499
  * direct registry specifiers from the theme source are emitted unchanged.
2317
2500
  * @param {{cwd?: string}} [ctx]
@@ -2756,24 +2939,17 @@ async function themeBuildInternal(
2756
2939
  // Derive the default CSS name from the theme name so .css/.js/.d.ts
2757
2940
  // share one scheme; an explicit --out still wins.
2758
2941
  const baseName = themeDef.name;
2942
+ // Every write stays inside cwd. A CLI-internal caller that renders into a
2943
+ // scratch directory it creates and removes names that directory instead.
2944
+ const writeRoot = options.__writeRoot ?? cwd;
2759
2945
  let outPath;
2760
2946
  if (options.out) {
2761
2947
  outPath = path.resolve(cwd, options.out);
2762
- // Guard: relative paths must not escape cwd via `../`. Absolute paths are
2763
- // trusted (the user explicitly controls where output goes, like gcc -o).
2764
- if (!path.isAbsolute(options.out)) {
2765
- try {
2766
- assertWithin(options.out, cwd, {label: 'output path'});
2767
- } catch (err) {
2768
- if (err instanceof PathSafetyError) {
2769
- throw new AstryxError(
2770
- err.message,
2771
- undefined,
2772
- ERROR_CODES.ERR_PATH_TRAVERSAL,
2773
- );
2774
- }
2775
- throw err;
2776
- }
2948
+ // A build keeps the explicit output inside the write root, relative or
2949
+ // absolute. Check mode writes nothing, so it refuses only a relative path
2950
+ // that escapes cwd.
2951
+ if (!options.check || !path.isAbsolute(options.out)) {
2952
+ confineOutput(outPath, writeRoot, OUT_REMEDY, options.out);
2777
2953
  }
2778
2954
  } else {
2779
2955
  outPath = path.join(path.dirname(filePath), `${baseName}.css`);
@@ -2870,6 +3046,13 @@ async function themeBuildInternal(
2870
3046
  writes.push({dest: variantDtsPath, content: variantContent});
2871
3047
  }
2872
3048
 
3049
+ // Every output a build writes stays inside cwd, including the defaults
3050
+ // beside the theme file. Check mode writes nothing, so it compares outputs
3051
+ // outside cwd read-only.
3052
+ if (!options.check) {
3053
+ confineOutputs(writes, writeRoot, options.out ? OUT_REMEDY : SOURCE_REMEDY);
3054
+ }
3055
+
2873
3056
  // Check mode: compare generated content against what's on disk instead of
2874
3057
  // writing. A file is "stale" if it's missing or its content differs once the
2875
3058
  // volatile @generated `Command:` line is ignored. Returns a
@@ -2888,7 +3071,10 @@ async function themeBuildInternal(
2888
3071
  ` ${s.reason === 'missing' ? 'missing' : 'stale'}: ${s.path}`,
2889
3072
  );
2890
3073
  }
2891
- logger.error(`\n Rebuild with: ${buildCommand}`);
3074
+ // prettier-ignore
3075
+ const remedy = outsideCheckRemedy(writes, [filePath], writeRoot, relative => [relative(filePath), ...(options.out ? ['--out', relative(outPath)] : []), ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
3076
+ if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
3077
+ else logger.error(`\n Rebuild with: ${buildCommand}`);
2892
3078
  }
2893
3079
  return {
2894
3080
  type: 'theme.build.check',
@@ -3001,7 +3187,7 @@ function printBuildTrailer(trailer) {
3001
3187
  logger.log(`
3002
3188
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3003
3189
 
3004
- import { Theme } from '@astryxdesign/core';
3190
+ import { Theme } from '@astryxdesign/core/theme';
3005
3191
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3006
3192
  import '${trailer.cssImport}';
3007
3193
 
@@ -3011,7 +3197,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3011
3197
 
3012
3198
  Or with a <link> tag:
3013
3199
 
3014
- import { Theme } from '@astryxdesign/core';
3200
+ import { Theme } from '@astryxdesign/core/theme';
3015
3201
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3016
3202
 
3017
3203
  <link rel="stylesheet" href="${trailer.cssImport}" />
@@ -3037,7 +3223,7 @@ export function printBatchTrailer(trailers) {
3037
3223
  logger.log(`
3038
3224
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3039
3225
 
3040
- import { Theme } from '@astryxdesign/core';
3226
+ import { Theme } from '@astryxdesign/core/theme';
3041
3227
  import { ${first.exportName} } from '${first.jsImport}';
3042
3228
  import '${first.cssImport}';
3043
3229
 
@@ -3047,7 +3233,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3047
3233
 
3048
3234
  Or with a <link> tag:
3049
3235
 
3050
- import { Theme } from '@astryxdesign/core';
3236
+ import { Theme } from '@astryxdesign/core/theme';
3051
3237
  import { ${first.exportName} } from '${first.jsImport}';
3052
3238
 
3053
3239
  <link rel="stylesheet" href="${first.cssImport}" />
@@ -3414,6 +3600,8 @@ export async function themeBuildFamily(
3414
3600
  js: path.relative(cwd, jsPath),
3415
3601
  dts: path.relative(cwd, dtsPath),
3416
3602
  };
3603
+ // A family build's outputs stay inside cwd too; check mode only reads them.
3604
+ if (!options.check) confineOutputs(writes, cwd, FAMILY_REMEDY);
3417
3605
  if (options.check) {
3418
3606
  const stale = staleBuildOutputs(writes, cwd);
3419
3607
  const upToDate = stale.length === 0;
@@ -3430,7 +3618,10 @@ export async function themeBuildFamily(
3430
3618
  ` ${entry.reason === 'missing' ? 'missing' : 'stale'}: ${entry.path}`,
3431
3619
  );
3432
3620
  }
3433
- logger.error(`\n Rebuild with: ${buildCommand}`);
3621
+ // prettier-ignore
3622
+ const remedy = outsideCheckRemedy(writes, members.map(member => member.filePath), cwd, relative => ['--family', ...members.map(member => relative(member.filePath)), '--family-key', baseName, ...(options.iconsSpecifier ? ['--icons-specifier', options.iconsSpecifier] : [])]);
3623
+ if (remedy) logger.error(`\n ${remedy.join('\n ')}`);
3624
+ else logger.error(`\n Rebuild with: ${buildCommand}`);
3434
3625
  }
3435
3626
  return {
3436
3627
  type: 'theme.build.check',
@@ -58,13 +58,13 @@ export const doc = {
58
58
  name: 'options.out',
59
59
  type: 'string',
60
60
  description:
61
- 'Override the output CSS path. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file. A relative path must stay within cwd.',
61
+ 'Override the output CSS path, relative or absolute; a build refuses a path outside cwd, and check mode refuses only a relative path that escapes cwd. The .js, .d.ts and any .variants.d.ts are written in the same directory, named after the theme (<name>.js), not after the CSS file.',
62
62
  },
63
63
  {
64
64
  name: 'options.check',
65
65
  type: 'boolean',
66
66
  description:
67
- 'Compile in memory and compare each output against what is on disk instead of writing: the CI drift guard.',
67
+ 'Compile in memory and compare each output against what is on disk instead of writing: the CI drift guard. Because it writes nothing, it also compares outputs outside cwd; when those are stale, the report names the directory that contains them and the build and check commands to run from there, since a build refuses them and each output records the directory it was built from.',
68
68
  default: 'false',
69
69
  },
70
70
  {
@@ -77,7 +77,7 @@ export const doc = {
77
77
  name: 'ctx.cwd',
78
78
  type: 'string',
79
79
  description:
80
- 'Directory the theme file, a relative out path, and the returned output paths resolve against.',
80
+ 'Directory the theme file, a relative out path, and the returned output paths resolve against. Every output a build writes is inside it, including the default outputs beside the theme file.',
81
81
  default: 'process.cwd()',
82
82
  },
83
83
  ],
@@ -105,7 +105,7 @@ export const doc = {
105
105
  },
106
106
  {
107
107
  code: 'ERR_PATH_TRAVERSAL',
108
- when: 'the theme name contains a path separator or traversal marker, or a relative `out` path resolves outside cwd (including through a symlink)',
108
+ when: 'the theme name contains a path separator or traversal marker, or a written output resolves outside cwd (including through a symlink): an `out` path, relative or absolute, or the default outputs beside a theme file outside cwd. Check mode writes nothing, so it refuses only a relative `out` path that escapes cwd',
109
109
  },
110
110
  {
111
111
  code: 'ERR_CORE_NOT_FOUND',