@astryxdesign/cli 0.7.2-canary.ba6a6e2 → 0.7.2-canary.c2e0a59

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 (132) hide show
  1. package/README.md +8 -8
  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 +80 -0
  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/theme-checks.mjs +1 -1
  13. package/api/gap-report/gap-report.mjs +67 -4
  14. package/api/init/run/run.mjs +2 -2
  15. package/api/integration/_adapter.d.mts +12 -0
  16. package/api/integration/_adapter.mjs +54 -0
  17. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  18. package/api/integration/add-contribution.mjs +8 -4
  19. package/api/integration/add-contribution.test.mjs +4 -2
  20. package/api/integration/authoring-checks.mjs +11 -2
  21. package/api/integration/authoring-checks.test.mjs +39 -0
  22. package/api/integration/authoring-checks.type.d.mts +9 -0
  23. package/api/integration/authoring-checks.type.mjs +14 -1
  24. package/api/integration/integrationComponentConflicts.doc.mjs +36 -5
  25. package/api/integration/pack-check.mjs +61 -107
  26. package/api/integration/pack-check.test.mjs +359 -0
  27. package/api/integration/validate-integration.mjs +8 -0
  28. package/api/integration/validate-integration.test.mjs +11 -0
  29. package/api/integration/validate-integration.type.d.mts +8 -0
  30. package/api/integration/validate-integration.type.mjs +12 -1
  31. package/api/integration/validateIntegration.doc.mjs +17 -3
  32. package/api/search/search.d.mts +9 -0
  33. package/api/search/search.mjs +108 -16
  34. package/api/search/search.test.mjs +36 -0
  35. package/api/swizzle/copy/copy.mjs +28 -14
  36. package/api/theme/build/build.family.test.mjs +16 -0
  37. package/api/theme/build/build.mjs +81 -22
  38. package/api/theme/themeBuild.doc.mjs +3 -3
  39. package/assets/docs/README.md +10 -0
  40. package/assets/docs/author-a-theme.doc.mjs +1 -1
  41. package/assets/docs/getting-started.doc.mjs +3 -3
  42. package/assets/docs/theme.doc.dense.mjs +1 -1
  43. package/assets/docs/theme.doc.mjs +1 -1
  44. package/assets/docs/theme.doc.zh.mjs +1 -1
  45. package/assets/docs/tree/add-a-component.doc.mjs +10 -0
  46. package/assets/docs/tree/block-template.doc.mjs +2 -2
  47. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  48. package/assets/docs/tree/check-your-docs.doc.mjs +44 -3
  49. package/assets/docs/tree/checks.doc.mjs +6 -6
  50. package/assets/docs/tree/component-family.doc.mjs +5 -1
  51. package/assets/docs/tree/component-imports.doc.mjs +8 -0
  52. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  53. package/assets/docs/tree/links.doc.mjs +2 -2
  54. package/assets/docs/tree/page-template.doc.mjs +1 -1
  55. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  56. package/assets/docs/tree/single-component.doc.mjs +3 -2
  57. package/assets/docs/tree/troubleshooting.doc.mjs +9 -1
  58. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  59. package/assets/docs/tree/versioning.doc.mjs +1 -0
  60. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -1
  61. package/assets/docs/use-a-theme.doc.mjs +2 -2
  62. package/assets/docs/working-with-ai.doc.mjs +43 -4
  63. package/assets/theme.template.ts +1 -1
  64. package/authoring/doctypes/component/component.doc.mjs +2 -2
  65. package/authoring/doctypes/component/type.ts +6 -3
  66. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  67. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  68. package/authoring/doctypes/template/parse.d.mts +6 -2
  69. package/authoring/doctypes/template/parse.mjs +3 -1
  70. package/authoring/doctypes/template/template.doc.mjs +1 -1
  71. package/authoring/doctypes/template/type.ts +22 -0
  72. package/authoring/index.d.ts +1 -0
  73. package/authoring/integration/integration.doc.mjs +8 -1
  74. package/authoring/integration/parse.test.mjs +10 -0
  75. package/authoring/integration/schema.d.mts +2 -0
  76. package/authoring/integration/schema.mjs +1 -0
  77. package/authoring/integration/type.ts +4 -0
  78. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  79. package/clients/cli/commands/build-theme.mjs +1 -1
  80. package/clients/cli/commands/build-theme.path-safety.test.mjs +84 -0
  81. package/clients/cli/commands/build-theme.registry.test.mjs +5 -2
  82. package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
  83. package/clients/cli/commands/doctor-integration-validate.doc.mjs +11 -2
  84. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  85. package/clients/cli/commands/doctor.mjs +173 -0
  86. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  87. package/foundation/config/project.mjs +82 -0
  88. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  89. package/foundation/discovery/component-discovery.d.mts +190 -10
  90. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  91. package/foundation/discovery/component-discovery.mjs +864 -56
  92. package/foundation/discovery/component-discovery.test.mjs +96 -0
  93. package/foundation/discovery/component-replacement.mjs +18 -0
  94. package/foundation/discovery/component-replacement.test.mjs +40 -0
  95. package/foundation/discovery/doc-types.d.mts +157 -0
  96. package/foundation/discovery/doc-types.mjs +1224 -0
  97. package/foundation/discovery/doc-types.test.mjs +652 -0
  98. package/foundation/discovery/docs-discovery.d.mts +81 -0
  99. package/foundation/discovery/docs-discovery.mjs +57 -0
  100. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  101. package/foundation/discovery/integration-doc-files.mjs +231 -0
  102. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  103. package/foundation/discovery/module-exports.d.mts +27 -0
  104. package/foundation/discovery/module-exports.mjs +356 -31
  105. package/foundation/discovery/module-exports.test.mjs +172 -0
  106. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  107. package/foundation/discovery/package-tsconfig.mjs +228 -0
  108. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  109. package/foundation/discovery/project-typescript.d.mts +23 -0
  110. package/foundation/discovery/project-typescript.mjs +61 -0
  111. package/foundation/discovery/prop-drift.d.mts +278 -0
  112. package/foundation/discovery/prop-drift.mjs +2263 -0
  113. package/foundation/discovery/prop-drift.test.mjs +2219 -0
  114. package/foundation/discovery/type-match.d.mts +53 -0
  115. package/foundation/discovery/type-match.mjs +660 -0
  116. package/foundation/discovery/type-match.test.mjs +169 -0
  117. package/foundation/discovery/type-text.d.mts +68 -0
  118. package/foundation/discovery/type-text.mjs +658 -0
  119. package/foundation/discovery/type-text.test.mjs +196 -0
  120. package/foundation/discovery/unresolved-references.d.mts +62 -0
  121. package/foundation/discovery/unresolved-references.mjs +790 -0
  122. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  123. package/foundation/doc-compiler/doc-loads.test.mjs +8 -0
  124. package/foundation/doc-compiler/inputs.mjs +23 -0
  125. package/foundation/doc-compiler/inputs.test.mjs +0 -1
  126. package/foundation/doc-compiler/links.d.mts +9 -5
  127. package/foundation/doc-compiler/links.mjs +4 -2
  128. package/foundation/integrations/contribution-inventory.mjs +6 -1
  129. package/foundation/response/response-types.doc.mjs +2 -2
  130. package/foundation/xle/registry.mjs +4 -0
  131. package/foundation/xle/registry.test.mjs +28 -0
  132. package/package.json +9 -9
@@ -81,11 +81,20 @@
81
81
 
82
82
  import {withListingCache} from '../../foundation/fs/listing-cache.mjs';
83
83
  import {readDocView} from '../../foundation/doc-compiler/read.mjs';
84
- import {findCoreDir} from '../../foundation/fs/paths.mjs';
84
+ import {
85
+ discoverExternalPackages,
86
+ findCoreDir,
87
+ } from '../../foundation/fs/paths.mjs';
85
88
  import {
86
89
  discoverComponents,
87
90
  discoverValidIntegrationComponents,
91
+ docStem,
92
+ familyMember,
88
93
  findComponentReadme,
94
+ forEachIntegrationDoc,
95
+ integrationMemberEntry,
96
+ integrationRecordHold,
97
+ isIntegrationMember,
89
98
  resolveImportPath,
90
99
  resolveIntegrationImportPath,
91
100
  CORE_PACKAGE,
@@ -97,6 +106,7 @@ import {
97
106
  import {
98
107
  loadComponentReplacements,
99
108
  loadIntegrationsSafely,
109
+ resolveLegacyExternalDoc,
100
110
  } from '../component/_adapter.mjs';
101
111
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
102
112
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
@@ -149,6 +159,9 @@ import {setResultCoverage} from './coverage.mjs';
149
159
  * @property {'page'|'block'} [_kind]
150
160
  * @property {string} [_resultName]
151
161
  * @property {string} [_commandName]
162
+ * @property {'file'|'doc'} [_hold] - How an integration component holds its
163
+ * name, for the owner rule.
164
+ * @property {string} [_docPath] - An integration component's doc.
152
165
  */
153
166
 
154
167
  /**
@@ -1079,7 +1092,11 @@ async function gatherCoreComponents(coreDir) {
1079
1092
  /** @type {string[]} */
1080
1093
  let guidance = [];
1081
1094
  if (readme && readme.endsWith('.doc.mjs')) {
1082
- const doc = await loadModuleDoc(readme);
1095
+ const loaded = await loadModuleDoc(readme);
1096
+ // A member documented in its family's doc (VStack in Stack's doc) is
1097
+ // indexed from its own entry: the family's keywords and guidance
1098
+ // describe the family, not the member.
1099
+ const doc = familyMember(loaded, comp) ?? loaded;
1083
1100
  if (doc) {
1084
1101
  keywords = Array.isArray(doc.keywords) ? doc.keywords : [];
1085
1102
  description = doc.usage?.description || doc.description || '';
@@ -1105,20 +1122,57 @@ async function gatherCoreComponents(coreDir) {
1105
1122
  * usage/description from each component's .doc.mjs, same as core. Without
1106
1123
  * this, an integration component is invisible to `search`/`build` even
1107
1124
  * though `component --list`/`component <Name>` already resolve it — the two
1108
- * discovery paths silently disagreed.
1125
+ * discovery paths silently disagreed. Also returns, per name, the docs that
1126
+ * hold it by their file name and the loadable docs that only record it.
1109
1127
  * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
1110
- * @returns {Promise<Candidate[]>}
1128
+ * @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
1111
1129
  */
1112
1130
  async function gatherIntegrationComponents(loadedIntegrations) {
1113
1131
  /** @type {Candidate[]} */
1114
1132
  const candidates = [];
1133
+ // What the owner rule reads: the docs that hold a name by their file name,
1134
+ // loadable or not and hidden ones too, and the loadable docs that only
1135
+ // record it.
1136
+ /** @type {Map<string, Set<string>>} */
1137
+ const fileNamed = new Map();
1138
+ /** @type {Map<string, Set<string>>} */
1139
+ const documented = new Map();
1140
+ /** @param {Map<string, Set<string>>} map @param {string} name @param {string} docPath */
1141
+ const hold = (map, name, docPath) =>
1142
+ map.set(name, (map.get(name) ?? new Set()).add(docPath));
1115
1143
  for (const integration of loadedIntegrations) {
1116
- const {components} = await discoverValidIntegrationComponents(integration);
1144
+ const {components, discovered} =
1145
+ await discoverValidIntegrationComponents(integration);
1146
+ const renamed = new Set(
1147
+ discovered
1148
+ .filter(rec => integrationRecordHold(rec) === 'doc')
1149
+ .filter(rec => !isIntegrationMember(rec))
1150
+ .map(rec => rec.docPath),
1151
+ );
1152
+ forEachIntegrationDoc(integration.components, (docPath, stem) => {
1153
+ if (!renamed.has(docPath)) hold(fileNamed, stem, docPath);
1154
+ });
1117
1155
  for (const rec of components) {
1118
- const doc = await loadModuleDoc(rec.docPath);
1156
+ const loaded = await loadModuleDoc(rec.docPath);
1157
+ // A family member is indexed from its own entry: the family's keywords
1158
+ // and guidance describe the family.
1159
+ const member = isIntegrationMember(rec);
1160
+ const doc = member ? integrationMemberEntry(loaded, rec) : loaded;
1161
+ // A doc that names another export of its file still answers to the
1162
+ // file's name, as `component <file name>` does.
1163
+ const fileName = docStem(rec.docPath);
1164
+ if (integrationRecordHold(rec) === 'doc') {
1165
+ hold(documented, rec.name, rec.docPath);
1166
+ }
1167
+ if (renamed.has(rec.docPath) && !member) {
1168
+ hold(documented, fileName, rec.docPath);
1169
+ }
1119
1170
  candidates.push({
1120
1171
  domain: 'component',
1121
1172
  name: rec.name,
1173
+ aliases: !member && fileName !== rec.name ? [fileName] : [],
1174
+ _hold: integrationRecordHold(rec),
1175
+ _docPath: rec.docPath,
1122
1176
  keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
1123
1177
  description: doc ? doc.usage?.description || doc.description || '' : '',
1124
1178
  guidance: guidanceFrom(doc),
@@ -1138,12 +1192,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1138
1192
  packageName: rec.package,
1139
1193
  },
1140
1194
  rec.name,
1141
- doc?.import,
1195
+ loaded?.import,
1142
1196
  ),
1143
1197
  });
1144
1198
  }
1145
1199
  }
1146
- return candidates;
1200
+ return {candidates, fileNamed, documented};
1147
1201
  }
1148
1202
 
1149
1203
  /**
@@ -1155,11 +1209,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1155
1209
  */
1156
1210
  async function gatherComponents(coreDir, cwd) {
1157
1211
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1158
- const [core, integrations, replacements] = await Promise.all([
1212
+ const [core, gathered, replacements] = await Promise.all([
1159
1213
  gatherCoreComponents(coreDir),
1160
1214
  gatherIntegrationComponents(loadedIntegrations),
1161
1215
  loadComponentReplacements(coreDir, loadedIntegrations),
1162
1216
  ]);
1217
+ const {candidates: integrations, fileNamed, documented} = gathered;
1163
1218
  // An active replacement answers to the Core name it replaces, so a search
1164
1219
  // for that name finds the replacement and not the Core original
1165
1220
  // (spec:AST-035 FR11).
@@ -1170,9 +1225,43 @@ async function gatherComponents(coreDir, cwd) {
1170
1225
  active.target,
1171
1226
  ]),
1172
1227
  );
1228
+ // The owner rule, as component detail applies it: a candidate `component
1229
+ // <name>` does not open names its package and follows the owner, and a
1230
+ // file-name alias that opens another owner is dropped.
1231
+ const coreNames = new Set(core.map(candidate => candidate.name));
1232
+ /** @param {string} name @param {Candidate} candidate */
1233
+ const opens = (name, candidate) =>
1234
+ !coreNames.has(name) &&
1235
+ findComponentReadme(coreDir, name) == null &&
1236
+ [...(fileNamed.get(name) ?? [])].every(doc => doc === candidate._docPath) &&
1237
+ [...(documented.get(name) ?? [])].every(doc => doc === candidate._docPath);
1238
+ // A legacy docs package keeps an exact name over an export name a doc records.
1239
+ /** @type {ReturnType<typeof discoverExternalPackages> | undefined} */
1240
+ let externals;
1241
+ /** @param {string} name */
1242
+ const legacyDocuments = name =>
1243
+ (externals ??= discoverExternalPackages(cwd)).some(
1244
+ ext => resolveLegacyExternalDoc(ext, name) != null,
1245
+ );
1246
+ const ruled = integrations.map(candidate => {
1247
+ const aliases = (candidate.aliases ?? []).filter(alias =>
1248
+ opens(alias, candidate),
1249
+ );
1250
+ return candidate._hold === 'doc' &&
1251
+ (!opens(candidate.name, candidate) || legacyDocuments(candidate.name))
1252
+ ? {
1253
+ ...candidate,
1254
+ aliases,
1255
+ _command: `astryx component ${candidate.name} --package ${candidate._package}`,
1256
+ }
1257
+ : {...candidate, aliases};
1258
+ });
1173
1259
  return [
1174
1260
  ...core.filter(candidate => !replacements.forTarget(candidate.name)),
1175
- ...integrations.map(candidate => {
1261
+ ...[
1262
+ ...ruled.filter(candidate => !candidate._command),
1263
+ ...ruled.filter(candidate => candidate._command),
1264
+ ].map(candidate => {
1176
1265
  const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
1177
1266
  if (target != null) {
1178
1267
  return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
@@ -1225,11 +1314,11 @@ export async function componentKeywords(coreDir, cwd) {
1225
1314
  .flat()
1226
1315
  .map(async name => {
1227
1316
  const readme = findComponentReadme(coreDir, name);
1228
- const doc =
1317
+ const loaded =
1229
1318
  readme && readme.endsWith('.doc.mjs')
1230
1319
  ? await loadModuleDoc(readme)
1231
1320
  : null;
1232
- return {name, keywords: keywordsOf(doc)};
1321
+ return {name, keywords: keywordsOf(familyMember(loaded, name) ?? loaded)};
1233
1322
  });
1234
1323
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1235
1324
  const replacements = await loadComponentReplacements(
@@ -1239,10 +1328,13 @@ export async function componentKeywords(coreDir, cwd) {
1239
1328
  const integrations = loadedIntegrations.map(async integration => {
1240
1329
  const {components} = await discoverValidIntegrationComponents(integration);
1241
1330
  return Promise.all(
1242
- components.map(async rec => ({
1243
- name: rec.name,
1244
- keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
1245
- })),
1331
+ components.map(async rec => {
1332
+ const loaded = await loadModuleDoc(rec.docPath);
1333
+ return {
1334
+ name: rec.name,
1335
+ keywords: keywordsOf(integrationMemberEntry(loaded, rec) ?? loaded),
1336
+ };
1337
+ }),
1246
1338
  );
1247
1339
  });
1248
1340
  return [
@@ -616,6 +616,42 @@ describe('search leaf — a theme is found by its names; its description is pros
616
616
  );
617
617
  });
618
618
 
619
+ describe('search leaf — components whose docs live in a family folder', () => {
620
+ it("indexes a family member from its own entry, not the family's keywords", async () => {
621
+ // HStack and VStack are documented in Stack's doc, whose keywords
622
+ // (horizontal, vertical, row, column, ...) describe Stack.
623
+ const reasons = async (/** @type {string} */ query) =>
624
+ Object.fromEntries(
625
+ (await search(query, {cwd, type: 'component'})).data.results.map(r => [
626
+ r.name,
627
+ r.reason,
628
+ ]),
629
+ );
630
+ const column = await reasons('column');
631
+ expect(column.HStack ?? '').not.toMatch(/keyword/);
632
+ expect(column.VStack ?? '').not.toMatch(/keyword/);
633
+ expect(column.Stack).toMatch(/keyword/);
634
+ const vertical = (await search('vertical', {cwd, type: 'component'})).data.results.map(
635
+ r => r.name,
636
+ );
637
+ expect(vertical.indexOf('VStack')).toBeGreaterThanOrEqual(0);
638
+ if (vertical.includes('HStack')) {
639
+ expect(vertical.indexOf('VStack')).toBeLessThan(vertical.indexOf('HStack'));
640
+ }
641
+ }, SLOW);
642
+
643
+ it('ranks VStack, HStack and Heading first for their own names, with their own import', async () => {
644
+ for (const name of ['VStack', 'HStack', 'Heading']) {
645
+ const r = await search(name.toLowerCase(), {cwd, type: 'component'});
646
+ expect(r.data.results[0]).toMatchObject({
647
+ domain: 'component',
648
+ name,
649
+ import: `@astryxdesign/core/${name}`,
650
+ });
651
+ }
652
+ }, SLOW);
653
+ });
654
+
619
655
  describe('search leaf — integration components', () => {
620
656
  /**
621
657
  * A minimal consumer project: a stub `@astryxdesign/core` (so `findCoreDir`
@@ -21,8 +21,10 @@ import {checkGhCli} from '../_github.mjs';
21
21
  import {Project} from '../../../foundation/config/project.mjs';
22
22
  import {
23
23
  CORE_PACKAGE,
24
- findIntegrationComponentDoc,
25
- findIntegrationComponentSource,
24
+ docStem,
25
+ findComponentReadme,
26
+ findIntegrationComponent,
27
+ unscopedComponentOwners,
26
28
  } from '../../../foundation/discovery/component-discovery.mjs';
27
29
  import {ERROR_CODES} from '../../../foundation/response/error-codes.mjs';
28
30
  import {AstryxError, writeFailed} from '../../error.mjs';
@@ -126,33 +128,38 @@ async function loadConfigSafely(cwd) {
126
128
 
127
129
  /**
128
130
  * Build the set of OWNER packages that provide a component named `name` across
129
- * core + every loaded integration.
131
+ * core + every loaded integration. Core holds every name it documents, but has
132
+ * source to copy (`sourceDir`) only for a name with its own folder.
130
133
  * @param {string} coreDir
131
134
  * @param {Array<{name: string, components?: string, issuesUrl?: string}>} loadedIntegrations
132
135
  * @param {string} name
133
136
  * @param {string|undefined} coreIssuesUrl
134
- * @returns {Array<{package: string, sourceDir: string|null, ownerPackage: string, issuesUrl: string|undefined}>}
137
+ * @returns {Array<{package: string, sourceDir: string|null, docPath: string|null, ownerPackage: string, issuesUrl: string|undefined, hold: string}>}
135
138
  */
136
139
  function resolveOwners(coreDir, loadedIntegrations, name, coreIssuesUrl) {
137
140
  const owners = [];
138
141
  const coreComponentDir = path.join(coreDir, 'src', name);
139
- if (fs.existsSync(coreComponentDir)) {
142
+ const coreFolder = fs.existsSync(coreComponentDir);
143
+ if (coreFolder || findComponentReadme(coreDir, name)) {
140
144
  owners.push({
141
145
  package: CORE_PACKAGE,
142
- sourceDir: coreComponentDir,
146
+ sourceDir: coreFolder ? coreComponentDir : null,
147
+ docPath: null,
143
148
  ownerPackage: CORE_PACKAGE,
144
149
  issuesUrl: coreIssuesUrl || DEFAULT_ISSUES_URL,
150
+ hold: 'core',
145
151
  });
146
152
  }
147
153
  for (const integration of loadedIntegrations) {
148
- const docPath = findIntegrationComponentDoc(integration, name);
149
- if (!docPath) continue;
150
- const sourcePath = findIntegrationComponentSource(integration, name);
154
+ const found = findIntegrationComponent(integration, name);
155
+ if (!found) continue;
151
156
  owners.push({
152
157
  package: integration.name,
153
- sourceDir: sourcePath ? path.dirname(sourcePath) : null,
158
+ sourceDir: found.sourcePath ? path.dirname(found.sourcePath) : null,
159
+ docPath: found.docPath,
154
160
  ownerPackage: integration.name,
155
161
  issuesUrl: integration.issuesUrl,
162
+ hold: found.hold,
156
163
  });
157
164
  }
158
165
  return owners;
@@ -222,25 +229,32 @@ export async function swizzleCopy(component, options = {}) {
222
229
  : undefined;
223
230
  // An active integration replacement answers to the Core name it replaces,
224
231
  // bare or qualified by its own package (spec:AST-035 FR11): copy it under its
225
- // own name. `--package @astryxdesign/core` still copies the Core original.
232
+ // doc's file name, the folder it has always gone to. `--package
233
+ // @astryxdesign/core` still copies the Core original.
226
234
  if (pkg !== CORE_PACKAGE) {
227
235
  const replacement = await resolveComponentReplacement(
228
236
  coreDir,
229
237
  loadedIntegrations,
230
238
  dirName,
231
239
  );
240
+ const copyName = replacement ? docStem(replacement.docPath) : null;
232
241
  if (
233
242
  replacement &&
234
- (!pkg || (pkg === replacement.package && replacement.name !== dirName))
243
+ copyName &&
244
+ (!pkg || (pkg === replacement.package && copyName !== dirName))
235
245
  ) {
236
- return swizzleCopy(replacement.name, {
246
+ return swizzleCopy(copyName, {
237
247
  ...options,
238
248
  package: replacement.package,
239
249
  });
240
250
  }
241
251
  }
242
252
 
243
- const allOwners = resolveOwners(coreDir, loadedIntegrations, dirName, coreIssuesUrl);
253
+ const found = resolveOwners(coreDir, loadedIntegrations, dirName, coreIssuesUrl);
254
+ // The owner rule, then a Core name without its own folder drops out.
255
+ const allOwners = (pkg ? found : unscopedComponentOwners(found)).filter(
256
+ owner => owner.package !== CORE_PACKAGE || owner.sourceDir != null,
257
+ );
244
258
 
245
259
  if (allOwners.length === 0) {
246
260
  throw new AstryxError(
@@ -252,6 +252,22 @@ describe('themeBuildFamily()', () => {
252
252
  expect(fs.existsSync(dtsPath)).toBe(false);
253
253
  });
254
254
 
255
+ it('refuses family outputs outside cwd before checking or writing', async () => {
256
+ const dir = makeDir();
257
+ const files = writeFamily(dir).map(file => path.join(dir, file));
258
+ const app = path.join(dir, 'app');
259
+ fs.mkdirSync(app);
260
+
261
+ for (const check of [false, true]) {
262
+ await expect(
263
+ themeBuildFamily(files, {familyKey: FAMILY_KEY, check}, {cwd: app}),
264
+ ).rejects.toMatchObject({code: 'ERR_PATH_TRAVERSAL'});
265
+ }
266
+ for (const output of OUTPUTS) {
267
+ expect(fs.existsSync(path.join(dir, 'themes', output))).toBe(false);
268
+ }
269
+ });
270
+
255
271
  it('fails without publishing a mixed trio when staging a write fails', async () => {
256
272
  const dir = makeDir();
257
273
  const files = writeFamily(dir);
@@ -27,6 +27,8 @@
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, explicit or beside the theme file, stays inside `cwd`
31
+ * (`ERR_PATH_TRAVERSAL` otherwise), in check mode too.
30
32
  *
31
33
  * The installed `@astryxdesign/core` is an independently versioned optional
32
34
  * peer, so it can be older than the CLI. A theme that uses only baseline
@@ -270,6 +272,25 @@ function realOrSelf(file) {
270
272
  }
271
273
  }
272
274
 
275
+ /**
276
+ * `target` spelled through real directories: the deepest ancestor that exists
277
+ * is resolved through its symlinks, and the missing rest is appended as given.
278
+ * @param {string} target absolute path
279
+ * @returns {string}
280
+ */
281
+ function realLocation(target) {
282
+ /** @type {string[]} */
283
+ const missing = [];
284
+ let existing = target;
285
+ while (!fs.existsSync(existing)) {
286
+ const parent = path.dirname(existing);
287
+ if (parent === existing) break;
288
+ missing.unshift(path.basename(existing));
289
+ existing = parent;
290
+ }
291
+ return path.join(realOrSelf(existing), ...missing);
292
+ }
293
+
273
294
  /**
274
295
  * The Core the project at `cwd` installed, when it differs from the one the
275
296
  * CLI's own import found and loads. The app's `<Theme>` runs on the app's
@@ -506,6 +527,47 @@ function checkedBuildOutputs(writes, cwd) {
506
527
  .map(write => path.relative(cwd, write.dest));
507
528
  }
508
529
 
530
+ /** Remedies that end a confinement error, by where the output path came from. */
531
+ const OUT_REMEDY = 'Pass an --out path inside it.';
532
+ const SOURCE_REMEDY =
533
+ '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.';
534
+ const FAMILY_REMEDY =
535
+ "Family outputs go beside the family's root theme file, so run the build from a directory that contains it.";
536
+
537
+ /**
538
+ * Refuse an output outside `root`: every write is confined, whether `out` names
539
+ * the path or it defaults to the theme file's directory (architecture:cli-surface
540
+ * INV10). Both sides are compared by real location, so an absolute path that
541
+ * reaches the working directory through a symlink is inside it, and a symlink
542
+ * inside it that leads elsewhere is not.
543
+ * @param {string} dest absolute output path
544
+ * @param {string} root the directory writes stay inside: the working directory
545
+ * @param {string} remedy what to do instead; ends the error message
546
+ * @param {string} [shown] the path as the caller wrote it, for the message
547
+ */
548
+ function confineOutput(dest, root, remedy, shown = dest) {
549
+ try {
550
+ assertWithin(realLocation(dest), realOrSelf(path.resolve(root)), {
551
+ allowAbsolute: true,
552
+ label: 'output path',
553
+ });
554
+ } catch (err) {
555
+ if (!(err instanceof PathSafetyError)) throw err;
556
+ throw new AstryxError(
557
+ err.code === ERROR_CODES.ERR_PATH_TRAVERSAL
558
+ ? `Output path "${shown}" is outside the working directory (${root}). ${remedy}`
559
+ : err.message,
560
+ undefined,
561
+ ERROR_CODES.ERR_PATH_TRAVERSAL,
562
+ );
563
+ }
564
+ }
565
+
566
+ /** @param {Array<{dest: string}>} writes @param {string} root @param {string} remedy */
567
+ function confineOutputs(writes, root, remedy) {
568
+ for (const write of writes) confineOutput(write.dest, root, remedy);
569
+ }
570
+
509
571
  /** @param {Array<{dest: string, content: string}>} writes */
510
572
  function writeBuildOutputs(writes) {
511
573
  if (writes.length === 0) return;
@@ -2344,9 +2406,10 @@ function validateHeadingTypeAugmentationSupport(themeDef) {
2344
2406
  * `logger` (silent by default).
2345
2407
  *
2346
2408
  * @param {string} file - Theme file path, resolved against `cwd`.
2347
- * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void}} [options] -
2409
+ * @param {{out?: string, check?: boolean, iconsSpecifier?: string, __prepareFamily?: boolean, __familyLoader?: any, __familyInterception?: any, __onPrivateVarError?: () => void, __writeRoot?: string}} [options] -
2348
2410
  * `out` overrides the output CSS path; `check` compares against on-disk outputs
2349
- * instead of writing. `iconsSpecifier` overrides the icon registry import
2411
+ * instead of writing. `__writeRoot` replaces `cwd` as the directory every
2412
+ * output must stay inside, for a CLI-internal scratch build. `iconsSpecifier` overrides the icon registry import
2350
2413
  * specifier in the generated module (e.g. `./icons.mjs`); when omitted, the
2351
2414
  * direct registry specifiers from the theme source are emitted unchanged.
2352
2415
  * @param {{cwd?: string}} [ctx]
@@ -2791,25 +2854,14 @@ async function themeBuildInternal(
2791
2854
  // Derive the default CSS name from the theme name so .css/.js/.d.ts
2792
2855
  // share one scheme; an explicit --out still wins.
2793
2856
  const baseName = themeDef.name;
2857
+ // Every write stays inside cwd. A CLI-internal caller that renders into a
2858
+ // scratch directory it creates and removes names that directory instead.
2859
+ const writeRoot = options.__writeRoot ?? cwd;
2794
2860
  let outPath;
2795
2861
  if (options.out) {
2862
+ // Relative or absolute, the explicit output stays inside the write root.
2796
2863
  outPath = path.resolve(cwd, options.out);
2797
- // Guard: relative paths must not escape cwd via `../`. Absolute paths are
2798
- // trusted (the user explicitly controls where output goes, like gcc -o).
2799
- if (!path.isAbsolute(options.out)) {
2800
- try {
2801
- assertWithin(options.out, cwd, {label: 'output path'});
2802
- } catch (err) {
2803
- if (err instanceof PathSafetyError) {
2804
- throw new AstryxError(
2805
- err.message,
2806
- undefined,
2807
- ERROR_CODES.ERR_PATH_TRAVERSAL,
2808
- );
2809
- }
2810
- throw err;
2811
- }
2812
- }
2864
+ confineOutput(outPath, writeRoot, OUT_REMEDY, options.out);
2813
2865
  } else {
2814
2866
  outPath = path.join(path.dirname(filePath), `${baseName}.css`);
2815
2867
  }
@@ -2905,6 +2957,11 @@ async function themeBuildInternal(
2905
2957
  writes.push({dest: variantDtsPath, content: variantContent});
2906
2958
  }
2907
2959
 
2960
+ // Every output stays inside cwd, including the defaults beside the theme
2961
+ // file. Check mode refuses the same paths, so it never passes outputs that a
2962
+ // build would refuse to write.
2963
+ confineOutputs(writes, writeRoot, options.out ? OUT_REMEDY : SOURCE_REMEDY);
2964
+
2908
2965
  // Check mode: compare generated content against what's on disk instead of
2909
2966
  // writing. A file is "stale" if it's missing or its content differs once the
2910
2967
  // volatile @generated `Command:` line is ignored. Returns a
@@ -3036,7 +3093,7 @@ function printBuildTrailer(trailer) {
3036
3093
  logger.log(`
3037
3094
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3038
3095
 
3039
- import { Theme } from '@astryxdesign/core';
3096
+ import { Theme } from '@astryxdesign/core/theme';
3040
3097
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3041
3098
  import '${trailer.cssImport}';
3042
3099
 
@@ -3046,7 +3103,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3046
3103
 
3047
3104
  Or with a <link> tag:
3048
3105
 
3049
- import { Theme } from '@astryxdesign/core';
3106
+ import { Theme } from '@astryxdesign/core/theme';
3050
3107
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3051
3108
 
3052
3109
  <link rel="stylesheet" href="${trailer.cssImport}" />
@@ -3072,7 +3129,7 @@ export function printBatchTrailer(trailers) {
3072
3129
  logger.log(`
3073
3130
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3074
3131
 
3075
- import { Theme } from '@astryxdesign/core';
3132
+ import { Theme } from '@astryxdesign/core/theme';
3076
3133
  import { ${first.exportName} } from '${first.jsImport}';
3077
3134
  import '${first.cssImport}';
3078
3135
 
@@ -3082,7 +3139,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3082
3139
 
3083
3140
  Or with a <link> tag:
3084
3141
 
3085
- import { Theme } from '@astryxdesign/core';
3142
+ import { Theme } from '@astryxdesign/core/theme';
3086
3143
  import { ${first.exportName} } from '${first.jsImport}';
3087
3144
 
3088
3145
  <link rel="stylesheet" href="${first.cssImport}" />
@@ -3449,6 +3506,8 @@ export async function themeBuildFamily(
3449
3506
  js: path.relative(cwd, jsPath),
3450
3507
  dts: path.relative(cwd, dtsPath),
3451
3508
  };
3509
+ // The family's outputs stay inside cwd too, in check mode as well.
3510
+ confineOutputs(writes, cwd, FAMILY_REMEDY);
3452
3511
  if (options.check) {
3453
3512
  const stale = staleBuildOutputs(writes, cwd);
3454
3513
  const upToDate = stale.length === 0;
@@ -58,7 +58,7 @@ 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; it must resolve inside 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',
@@ -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 is written 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 an output resolves outside cwd (including through a symlink): an `out` path, relative or absolute, or the default outputs beside a theme file outside cwd (also rejected in check mode)',
109
109
  },
110
110
  {
111
111
  code: 'ERR_CORE_NOT_FOUND',
@@ -51,6 +51,16 @@ The material is usually good; the finding is placement, not quality. It goes in
51
51
 
52
52
  Worked example: a responsive-and-interaction readiness rubric is grading criteria → **Component-Audit-Rubric**, or **Component-Lifecycle** if it is a promotion gate.
53
53
 
54
+ ## Imports in code samples
55
+
56
+ Import each Core export from the path `astryx component <Name>` prints: the
57
+ component's own entry when Core has one (`@astryxdesign/core/VStack`,
58
+ `@astryxdesign/core/Heading`), and `@astryxdesign/core/theme` for `Theme`,
59
+ `defineTheme` and the rest of the theme API. A reader copies one sample and then
60
+ reads `astryx component`, and two paths for one export read as two different
61
+ things. The no-build CDN page is the exception: its import map names only the
62
+ package root.
63
+
54
64
  ## Sections are read one at a time
55
65
 
56
66
  `astryx docs <topic> --index` lists a topic's sections, and readers then open
@@ -120,7 +120,7 @@ export const docs = {
120
120
  ['ocean.variants.d.ts', "(Optional) Module augmentations for custom component prop values"],
121
121
  ]},
122
122
  {type: 'prose', text: 'The `__built: true` flag tells Theme to skip runtime `<style>` injection; the CSS file handles it. Load the generated CSS wherever you load the module.'},
123
- {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {Theme} from '@astryxdesign/core';\nimport {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
123
+ {type: 'code', lang: 'tsx', label: 'Using a custom built theme', code: "import {Theme} from '@astryxdesign/core/theme';\nimport {oceanTheme} from './themes/ocean';\nimport './themes/ocean.css';\n\n<Theme theme={oceanTheme}>\n <App />\n</Theme>"},
124
124
  {type: 'prose', text: "After upgrading Astryx, rerun `astryx theme build` for every custom prebuilt theme. Deploy the regenerated files together. The runtime intentionally trusts `__built: true` and will not repair stale CSS from an older build. The build also warns when the theme names font families it does not load. See {@link generic:font-setup} for the full recipe."},
125
125
  {type: 'prose', text: 'For the runtime vs built tradeoff, see the Runtime vs Built section of {@link generic:use-a-theme}.'},
126
126
  ],
@@ -86,7 +86,7 @@ export const docs = {
86
86
  type: 'code',
87
87
  lang: 'tsx',
88
88
  label: 'App root',
89
- code: `import {Theme} from '@astryxdesign/core';
89
+ code: `import {Theme} from '@astryxdesign/core/theme';
90
90
  import {themes, defaultThemeSlug} from './astryx-themes';
91
91
 
92
92
  <Theme theme={themes[defaultThemeSlug]}><App /></Theme>`,
@@ -119,14 +119,14 @@ import {themes, defaultThemeSlug} from './astryx-themes';
119
119
  content: [
120
120
  {
121
121
  type: 'prose',
122
- text: 'Components are imported from per-category subpath entrypoints. This keeps bundles small and makes intent clear.',
122
+ text: 'Import each component from its own entry, the path `astryx component <Name>` prints. This keeps bundles small and makes intent clear.',
123
123
  },
124
124
  {
125
125
  type: 'code',
126
126
  lang: 'tsx',
127
127
  label: 'app/page.tsx',
128
128
  code: `import {Button} from '@astryxdesign/core/Button';
129
- import {VStack} from '@astryxdesign/core/Layout';
129
+ import {VStack} from '@astryxdesign/core/VStack';
130
130
 
131
131
  export default function Page() {
132
132
  return (
@@ -9,7 +9,7 @@ export const docsDense = {
9
9
  section: 'Wrap your app in a theme',
10
10
  title: 'Quick start',
11
11
  content: [
12
- {type: 'prose', text: "Install a theme, wrap in `<Theme>` (`import {Theme} from '@astryxdesign/core'`). {@link generic:use-a-theme} for full guide."},
12
+ {type: 'prose', text: "Install a theme, wrap in `<Theme>` (`import {Theme} from '@astryxdesign/core/theme'`). {@link generic:use-a-theme} for full guide."},
13
13
  ],
14
14
  },
15
15
  {