@astryxdesign/cli 0.7.2-canary.ba80461 → 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 (118) 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/integration-export-name.test.mjs +644 -0
  7. package/api/docs/_adapter.d.mts +11 -0
  8. package/api/docs/_adapter.mjs +244 -1
  9. package/api/docs/integrationDocs.test.mjs +124 -0
  10. package/api/doctor/theme-checks.mjs +1 -1
  11. package/api/gap-report/gap-report.mjs +67 -4
  12. package/api/init/run/run.mjs +2 -2
  13. package/api/integration/_adapter.d.mts +12 -0
  14. package/api/integration/_adapter.mjs +54 -0
  15. package/api/integration/add-contribution.component-names.test.mjs +66 -0
  16. package/api/integration/add-contribution.mjs +8 -4
  17. package/api/integration/add-contribution.test.mjs +4 -2
  18. package/api/integration/authoring-checks.mjs +11 -2
  19. package/api/integration/authoring-checks.test.mjs +39 -0
  20. package/api/integration/authoring-checks.type.d.mts +9 -0
  21. package/api/integration/authoring-checks.type.mjs +14 -1
  22. package/api/integration/integrationComponentConflicts.doc.mjs +36 -5
  23. package/api/integration/pack-check.mjs +51 -97
  24. package/api/integration/pack-check.test.mjs +359 -0
  25. package/api/integration/validate-integration.mjs +8 -0
  26. package/api/integration/validate-integration.test.mjs +11 -0
  27. package/api/integration/validate-integration.type.d.mts +8 -0
  28. package/api/integration/validate-integration.type.mjs +12 -1
  29. package/api/integration/validateIntegration.doc.mjs +17 -3
  30. package/api/search/search.d.mts +9 -0
  31. package/api/search/search.mjs +100 -13
  32. package/api/swizzle/copy/copy.mjs +28 -14
  33. package/api/theme/build/build.mjs +4 -4
  34. package/assets/docs/README.md +10 -0
  35. package/assets/docs/author-a-theme.doc.mjs +1 -1
  36. package/assets/docs/getting-started.doc.mjs +3 -3
  37. package/assets/docs/theme.doc.dense.mjs +1 -1
  38. package/assets/docs/theme.doc.mjs +1 -1
  39. package/assets/docs/theme.doc.zh.mjs +1 -1
  40. package/assets/docs/tree/add-a-component.doc.mjs +10 -0
  41. package/assets/docs/tree/block-template.doc.mjs +2 -2
  42. package/assets/docs/tree/check-the-props.doc.mjs +196 -0
  43. package/assets/docs/tree/check-your-docs.doc.mjs +44 -3
  44. package/assets/docs/tree/checks.doc.mjs +6 -6
  45. package/assets/docs/tree/component-family.doc.mjs +5 -1
  46. package/assets/docs/tree/component-imports.doc.mjs +8 -0
  47. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  48. package/assets/docs/tree/links.doc.mjs +2 -2
  49. package/assets/docs/tree/page-template.doc.mjs +1 -1
  50. package/assets/docs/tree/replace-a-core-template.doc.mjs +1 -1
  51. package/assets/docs/tree/single-component.doc.mjs +3 -2
  52. package/assets/docs/tree/troubleshooting.doc.mjs +9 -1
  53. package/assets/docs/tree/type-scale.doc.mjs +3 -3
  54. package/assets/docs/tree/versioning.doc.mjs +1 -0
  55. package/assets/docs/tree/write-the-template-file.doc.mjs +2 -1
  56. package/assets/docs/use-a-theme.doc.mjs +2 -2
  57. package/assets/theme.template.ts +1 -1
  58. package/authoring/doctypes/component/component.doc.mjs +2 -2
  59. package/authoring/doctypes/component/type.ts +6 -3
  60. package/authoring/doctypes/template/integration-template.doc.d.mts +11 -0
  61. package/authoring/doctypes/template/integration-template.doc.mjs +49 -0
  62. package/authoring/doctypes/template/parse.d.mts +6 -2
  63. package/authoring/doctypes/template/parse.mjs +3 -1
  64. package/authoring/doctypes/template/template.doc.mjs +1 -1
  65. package/authoring/doctypes/template/type.ts +22 -0
  66. package/authoring/index.d.ts +1 -0
  67. package/authoring/integration/integration.doc.mjs +8 -1
  68. package/authoring/integration/parse.test.mjs +10 -0
  69. package/authoring/integration/schema.d.mts +2 -0
  70. package/authoring/integration/schema.mjs +1 -0
  71. package/authoring/integration/type.ts +4 -0
  72. package/clients/cli/commands/build-theme.batch-report.test.mjs +3 -1
  73. package/clients/cli/commands/build-theme.mjs +1 -1
  74. package/clients/cli/commands/doctor-integration-components.doc.mjs +15 -4
  75. package/clients/cli/commands/doctor-integration-validate.doc.mjs +11 -2
  76. package/clients/cli/commands/doctor-integration.test.mjs +837 -0
  77. package/clients/cli/commands/doctor.mjs +173 -0
  78. package/foundation/config/project.mjs +82 -0
  79. package/foundation/discovery/authoring-self-docs.mjs +1 -0
  80. package/foundation/discovery/component-discovery.d.mts +178 -10
  81. package/foundation/discovery/component-discovery.export-names.test.mjs +760 -0
  82. package/foundation/discovery/component-discovery.mjs +659 -62
  83. package/foundation/discovery/component-replacement.mjs +18 -0
  84. package/foundation/discovery/component-replacement.test.mjs +40 -0
  85. package/foundation/discovery/doc-types.d.mts +157 -0
  86. package/foundation/discovery/doc-types.mjs +1224 -0
  87. package/foundation/discovery/doc-types.test.mjs +652 -0
  88. package/foundation/discovery/docs-discovery.d.mts +81 -0
  89. package/foundation/discovery/docs-discovery.mjs +57 -0
  90. package/foundation/discovery/integration-doc-files.d.mts +22 -0
  91. package/foundation/discovery/integration-doc-files.mjs +231 -0
  92. package/foundation/discovery/integration-doc-files.test.mjs +246 -0
  93. package/foundation/discovery/module-exports.d.mts +27 -0
  94. package/foundation/discovery/module-exports.mjs +356 -31
  95. package/foundation/discovery/module-exports.test.mjs +172 -0
  96. package/foundation/discovery/package-tsconfig.d.mts +14 -0
  97. package/foundation/discovery/package-tsconfig.mjs +228 -0
  98. package/foundation/discovery/package-tsconfig.test.mjs +210 -0
  99. package/foundation/discovery/project-typescript.d.mts +23 -0
  100. package/foundation/discovery/project-typescript.mjs +61 -0
  101. package/foundation/discovery/prop-drift.d.mts +278 -0
  102. package/foundation/discovery/prop-drift.mjs +2263 -0
  103. package/foundation/discovery/prop-drift.test.mjs +2219 -0
  104. package/foundation/discovery/type-match.d.mts +53 -0
  105. package/foundation/discovery/type-match.mjs +660 -0
  106. package/foundation/discovery/type-match.test.mjs +169 -0
  107. package/foundation/discovery/type-text.d.mts +68 -0
  108. package/foundation/discovery/type-text.mjs +658 -0
  109. package/foundation/discovery/type-text.test.mjs +196 -0
  110. package/foundation/discovery/unresolved-references.d.mts +62 -0
  111. package/foundation/discovery/unresolved-references.mjs +790 -0
  112. package/foundation/discovery/unresolved-references.test.mjs +567 -0
  113. package/foundation/doc-compiler/doc-loads.test.mjs +4 -0
  114. package/foundation/doc-compiler/links.d.mts +9 -5
  115. package/foundation/doc-compiler/links.mjs +4 -2
  116. package/foundation/integrations/contribution-inventory.mjs +6 -1
  117. package/foundation/response/response-types.doc.mjs +2 -2
  118. package/package.json +9 -9
@@ -81,12 +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,
88
92
  familyMember,
89
93
  findComponentReadme,
94
+ forEachIntegrationDoc,
95
+ integrationMemberEntry,
96
+ integrationRecordHold,
97
+ isIntegrationMember,
90
98
  resolveImportPath,
91
99
  resolveIntegrationImportPath,
92
100
  CORE_PACKAGE,
@@ -98,6 +106,7 @@ import {
98
106
  import {
99
107
  loadComponentReplacements,
100
108
  loadIntegrationsSafely,
109
+ resolveLegacyExternalDoc,
101
110
  } from '../component/_adapter.mjs';
102
111
  import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
103
112
  import {discoverTemplates, extractComponents} from '../template/template.mjs';
@@ -150,6 +159,9 @@ import {setResultCoverage} from './coverage.mjs';
150
159
  * @property {'page'|'block'} [_kind]
151
160
  * @property {string} [_resultName]
152
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.
153
165
  */
154
166
 
155
167
  /**
@@ -1110,20 +1122,57 @@ async function gatherCoreComponents(coreDir) {
1110
1122
  * usage/description from each component's .doc.mjs, same as core. Without
1111
1123
  * this, an integration component is invisible to `search`/`build` even
1112
1124
  * though `component --list`/`component <Name>` already resolve it — the two
1113
- * 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.
1114
1127
  * @param {import('../../foundation/integrations/integrations.mjs').LoadedIntegration[]} loadedIntegrations
1115
- * @returns {Promise<Candidate[]>}
1128
+ * @returns {Promise<{candidates: Candidate[], fileNamed: Map<string, Set<string>>, documented: Map<string, Set<string>>}>}
1116
1129
  */
1117
1130
  async function gatherIntegrationComponents(loadedIntegrations) {
1118
1131
  /** @type {Candidate[]} */
1119
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));
1120
1143
  for (const integration of loadedIntegrations) {
1121
- 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
+ });
1122
1155
  for (const rec of components) {
1123
- 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
+ }
1124
1170
  candidates.push({
1125
1171
  domain: 'component',
1126
1172
  name: rec.name,
1173
+ aliases: !member && fileName !== rec.name ? [fileName] : [],
1174
+ _hold: integrationRecordHold(rec),
1175
+ _docPath: rec.docPath,
1127
1176
  keywords: doc && Array.isArray(doc.keywords) ? doc.keywords : [],
1128
1177
  description: doc ? doc.usage?.description || doc.description || '' : '',
1129
1178
  guidance: guidanceFrom(doc),
@@ -1143,12 +1192,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1143
1192
  packageName: rec.package,
1144
1193
  },
1145
1194
  rec.name,
1146
- doc?.import,
1195
+ loaded?.import,
1147
1196
  ),
1148
1197
  });
1149
1198
  }
1150
1199
  }
1151
- return candidates;
1200
+ return {candidates, fileNamed, documented};
1152
1201
  }
1153
1202
 
1154
1203
  /**
@@ -1160,11 +1209,12 @@ async function gatherIntegrationComponents(loadedIntegrations) {
1160
1209
  */
1161
1210
  async function gatherComponents(coreDir, cwd) {
1162
1211
  const loadedIntegrations = await loadIntegrationsSafely(cwd);
1163
- const [core, integrations, replacements] = await Promise.all([
1212
+ const [core, gathered, replacements] = await Promise.all([
1164
1213
  gatherCoreComponents(coreDir),
1165
1214
  gatherIntegrationComponents(loadedIntegrations),
1166
1215
  loadComponentReplacements(coreDir, loadedIntegrations),
1167
1216
  ]);
1217
+ const {candidates: integrations, fileNamed, documented} = gathered;
1168
1218
  // An active replacement answers to the Core name it replaces, so a search
1169
1219
  // for that name finds the replacement and not the Core original
1170
1220
  // (spec:AST-035 FR11).
@@ -1175,9 +1225,43 @@ async function gatherComponents(coreDir, cwd) {
1175
1225
  active.target,
1176
1226
  ]),
1177
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
+ });
1178
1259
  return [
1179
1260
  ...core.filter(candidate => !replacements.forTarget(candidate.name)),
1180
- ...integrations.map(candidate => {
1261
+ ...[
1262
+ ...ruled.filter(candidate => !candidate._command),
1263
+ ...ruled.filter(candidate => candidate._command),
1264
+ ].map(candidate => {
1181
1265
  const target = targetOf.get(`${candidate._package}\0${candidate.name}`);
1182
1266
  if (target != null) {
1183
1267
  return {...candidate, aliases: [...(candidate.aliases ?? []), target]};
@@ -1244,10 +1328,13 @@ export async function componentKeywords(coreDir, cwd) {
1244
1328
  const integrations = loadedIntegrations.map(async integration => {
1245
1329
  const {components} = await discoverValidIntegrationComponents(integration);
1246
1330
  return Promise.all(
1247
- components.map(async rec => ({
1248
- name: rec.name,
1249
- keywords: keywordsOf(await loadModuleDoc(rec.docPath)),
1250
- })),
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
+ }),
1251
1338
  );
1252
1339
  });
1253
1340
  return [
@@ -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(
@@ -3093,7 +3093,7 @@ function printBuildTrailer(trailer) {
3093
3093
  logger.log(`
3094
3094
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3095
3095
 
3096
- import { Theme } from '@astryxdesign/core';
3096
+ import { Theme } from '@astryxdesign/core/theme';
3097
3097
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3098
3098
  import '${trailer.cssImport}';
3099
3099
 
@@ -3103,7 +3103,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3103
3103
 
3104
3104
  Or with a <link> tag:
3105
3105
 
3106
- import { Theme } from '@astryxdesign/core';
3106
+ import { Theme } from '@astryxdesign/core/theme';
3107
3107
  import { ${trailer.exportName} } from '${trailer.jsImport}';
3108
3108
 
3109
3109
  <link rel="stylesheet" href="${trailer.cssImport}" />
@@ -3129,7 +3129,7 @@ export function printBatchTrailer(trailers) {
3129
3129
  logger.log(`
3130
3130
  Install in your app (paths are relative to a file in src/; adjust if yours lives elsewhere):
3131
3131
 
3132
- import { Theme } from '@astryxdesign/core';
3132
+ import { Theme } from '@astryxdesign/core/theme';
3133
3133
  import { ${first.exportName} } from '${first.jsImport}';
3134
3134
  import '${first.cssImport}';
3135
3135
 
@@ -3139,7 +3139,7 @@ Install in your app (paths are relative to a file in src/; adjust if yours lives
3139
3139
 
3140
3140
  Or with a <link> tag:
3141
3141
 
3142
- import { Theme } from '@astryxdesign/core';
3142
+ import { Theme } from '@astryxdesign/core/theme';
3143
3143
  import { ${first.exportName} } from '${first.jsImport}';
3144
3144
 
3145
3145
  <link rel="stylesheet" href="${first.cssImport}" />
@@ -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
  {
@@ -23,7 +23,7 @@ export const docs = {
23
23
  type: 'code',
24
24
  lang: 'tsx',
25
25
  label: 'Wire the generated module once',
26
- code: "import {Theme} from '@astryxdesign/core';\nimport {themes, defaultThemeSlug} from './astryx-themes';\n\nfunction App() {\n return (\n <Theme theme={themes[defaultThemeSlug]}>\n <YourApp />\n </Theme>\n );\n}",
26
+ code: "import {Theme} from '@astryxdesign/core/theme';\nimport {themes, defaultThemeSlug} from './astryx-themes';\n\nfunction App() {\n return (\n <Theme theme={themes[defaultThemeSlug]}>\n <YourApp />\n </Theme>\n );\n}",
27
27
  },
28
28
  ],
29
29
  },
@@ -11,7 +11,7 @@ export const docsZh = {
11
11
  content: [
12
12
  {
13
13
  type: 'prose',
14
- text: "安装主题包,用 `<Theme>`(`import {Theme} from '@astryxdesign/core'`)包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。",
14
+ text: "安装主题包,用 `<Theme>`(`import {Theme} from '@astryxdesign/core/theme'`)包裹应用,选择浅色或深色模式。完整指南——可用主题、集成主题、深色模式、嵌套主题和生产构建——请参阅 {@link generic:use-a-theme}。",
15
15
  },
16
16
  ],
17
17
  },
@@ -71,5 +71,15 @@ Declare component root ./components in astryx.integration.mjs.
71
71
  },
72
72
  ],
73
73
  },
74
+ {
75
+ id: 'document-an-existing-component',
76
+ title: 'Document a component you already have',
77
+ content: [
78
+ {
79
+ type: 'prose',
80
+ text: "To document a component your package already has, write its doc beside the source file and name the doc after that file, such as `acme-gallery.doc.mjs` beside `acme-gallery.tsx`. Set `name` to the export apps import, such as `name: 'AcmeGallery'`, and keep both files inside the components root that `astryx.integration.mjs` declares. The file does not have to be named after the component; {@link generic:component-imports} shows how apps then find it.",
81
+ },
82
+ ],
83
+ },
74
84
  ],
75
85
  };
@@ -31,7 +31,7 @@ export const docs = {
31
31
  type: 'code',
32
32
  lang: 'javascript',
33
33
  label: 'templates/acme-stat-card.doc.mjs',
34
- code: `/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
34
+ code: `/** @type {import('@astryxdesign/cli/authoring').IntegrationTemplateDoc} */
35
35
  export default {
36
36
  type: 'block',
37
37
  name: 'acme-stat-card',
@@ -75,7 +75,7 @@ export default {
75
75
  type: 'code',
76
76
  lang: 'javascript',
77
77
  label: 'templates/acme-status-card-showcase.doc.mjs',
78
- code: `/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
78
+ code: `/** @type {import('@astryxdesign/cli/authoring').IntegrationTemplateDoc} */
79
79
  export default {
80
80
  type: 'block',
81
81
  name: 'acme-status-card-showcase',
@@ -0,0 +1,196 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file `astryx docs cli/integrations/building-blocks/components/describe-the-component/check-the-props`:
5
+ * compare each component doc's props table with the component's TypeScript
6
+ * props, read each finding, and fix the doc or the code.
7
+ */
8
+
9
+ /** @type {import('@astryxdesign/cli/authoring').ReferenceDoc} */
10
+ export const docs = {
11
+ type: 'generic',
12
+ name: 'check-the-props',
13
+ placement: {
14
+ parent: 'namespace:describe-the-component',
15
+ slot: 'guides',
16
+ order: 50,
17
+ },
18
+ title: 'Check the props table',
19
+ category: 'guide',
20
+ keywords: [
21
+ 'props table',
22
+ 'documented props',
23
+ 'prop drift',
24
+ 'props not compared',
25
+ ],
26
+ description:
27
+ "Compare each props table with the component's TypeScript props, then fix the doc or the code.",
28
+ sections: [
29
+ {
30
+ id: 'run-the-props-check',
31
+ title: 'Run the props check',
32
+ content: [
33
+ {
34
+ type: 'prose',
35
+ text: "`doctor integration components` compares every props table in your component docs, hidden docs and every family entry included, with the props the component's TypeScript declares. Run it in your package after you change a component or its doc.",
36
+ },
37
+ {
38
+ type: 'code',
39
+ lang: 'bash',
40
+ code: 'npx astryx doctor integration components',
41
+ },
42
+ {
43
+ type: 'code',
44
+ lang: 'text',
45
+ code: `severity: [warn]
46
+ component: AcmeCarousel
47
+ prop: loop
48
+ kind: not_in_code
49
+ message: "loop" is documented, but AcmeCarousel's props have no "loop".
50
+ doc: components/AcmeCarousel.doc.mjs
51
+ source: components/AcmeCarousel.tsx
52
+ docType: boolean
53
+
54
+ 1 prop(s) differ between the docs and the code in 1 of 1 component(s) compared (TypeScript 6.0.3). These are warnings: update the doc, or the code if the doc is right.`,
55
+ },
56
+ {
57
+ type: 'list',
58
+ style: 'unordered',
59
+ items: [
60
+ "A doc's own `props` describe the export its `name` names. In a family doc, each entry describes its own export. A hook entry documents parameters and returns, so it is not compared.",
61
+ "It reads props with the `typescript` your package installs, and reads your package's `tsconfig.json` the way `tsc -p` does. Without TypeScript it prints `[skip] Props not compared` and the reason.",
62
+ 'Every finding is a warning, so the exit code stays 0. Read them before you publish. With `--json`, they are in `data.propDrift.findings`.',
63
+ ],
64
+ },
65
+ ],
66
+ },
67
+ {
68
+ id: 'fix-each-finding',
69
+ title: 'Fix each finding',
70
+ content: [
71
+ {
72
+ type: 'prose',
73
+ text: "Each finding's `kind` says what differs. Fix the doc, or the code if the doc is right.",
74
+ },
75
+ {
76
+ type: 'table',
77
+ headers: ['Kind', 'Means', 'Fix'],
78
+ rows: [
79
+ [
80
+ '`not_in_code`',
81
+ "The doc lists a prop the component's props do not have",
82
+ 'Remove it from the doc, or add it to the code. A name an index signature takes, such as `data-*`, counts as present',
83
+ ],
84
+ [
85
+ '`not_in_doc`',
86
+ "Your package declares a prop the doc does not list, or builds one with a mapped type, such as `Partial<Record<'sm' | 'md', string>>`",
87
+ 'Document it. Props from React, the DOM, or another package are never asked for, and neither are props whose keys another package defines (`keyof CSSProperties`, behind an alias or not), `className`, `style`, `xstyle`, `data-testid`, `ref`, `key`, or a prop whose JSDoc has `@internal`. A deprecated prop is still a prop: document it until you remove it. A prop a mapped type builds from keys the check cannot trace (a template literal, say) is listed under `[info] Props not checked for a doc entry` instead',
88
+ ],
89
+ [
90
+ '`required_mismatch`',
91
+ '`required` disagrees with the code',
92
+ 'Set `required: true` exactly when every caller must pass the prop. One your `defaultProps` fills counts as optional, as it is to JSX callers, and so does one only some members of a union require, since a caller can leave it out: say in its description which variants need it. An entry that names several props (`value / onChange`) makes the same claim about each: give them separate entries when they differ',
93
+ ],
94
+ [
95
+ '`type_mismatch`',
96
+ "The documented `type` differs from the code's, where both read exactly",
97
+ 'Copy the type from the source, or fix the code. The next section says which types are judged',
98
+ ],
99
+ ],
100
+ },
101
+ ],
102
+ },
103
+ {
104
+ id: 'write-types-the-check-can-judge',
105
+ title: 'Write types the check can judge',
106
+ content: [
107
+ {
108
+ type: 'prose',
109
+ text: 'For a prop your package declares, the check also compares the documented `type`, but only where both sides read exactly. It never guesses, so a type it cannot judge is listed, not reported. It needs TypeScript 4.8 or later: with an older one it prints `[skip] Prop types not judged` and judges none.',
110
+ },
111
+ {
112
+ type: 'code',
113
+ lang: 'text',
114
+ code: `severity: [warn]
115
+ component: AcmeCarousel
116
+ prop: interval
117
+ kind: type_mismatch
118
+ message: "interval" is documented as string, but the code declares number.
119
+ doc: components/AcmeCarousel.doc.mjs
120
+ source: components/AcmeCarousel.tsx
121
+ docType: string
122
+ codeType: number`,
123
+ },
124
+ {
125
+ type: 'list',
126
+ style: 'unordered',
127
+ items: [
128
+ "Write the type as the source writes it, such as `ReactNode[]` or `(index: number) => void`. Parameter names, member order, quotes and whitespace may differ. Text that writes `readonly` must match exactly, parameter names included; only whitespace may differ. `React.X` names React's own `X` where the prop is declared, so it matches a bare `X` only where that name is React's: `React.KeyboardEvent` is not the DOM's `KeyboardEvent`.",
129
+ "Name a type as the file that declares the prop names it, so an import renamed there (`Item as BaseItem`) is written as that file writes it. A field (`cfg.level`) takes its prop's file, even when the field's own type is declared in another file.",
130
+ 'A type written another way is judged only when both sides are built from exact parts: primitives such as `string` and `number`, string, number and boolean literals, string enum members, arrays and unions of these, and type names that stand for them. Union members may come in any order, and a member another covers adds nothing, as TypeScript passes it there: `undefined` beside `void`, or `string[]` beside `(string | number)[]`.',
131
+ 'A mutable array type matches a readonly one, because callers can pass it. A readonly one documented for a mutable array is a mismatch.',
132
+ "When a prop's variants give a field different types, as `{value: string} | {value: number}` does, document every variant's type (`string | number`). The types of only some variants are listed: the prop's variants give this field different types. With more than six variant types, any other type is listed too.",
133
+ "To name an alias and show its values, write `AcmeSize = 'sm' | 'md'` or `AcmeSize ('sm' | 'md')`. Both parts must match.",
134
+ "An optional prop's `undefined` is set aside on both sides. With `exactOptionalPropertyTypes`, the doc shows `undefined` exactly when the code declares it.",
135
+ 'Anything else, such as an object, a tuple, a generic with arguments, `keyof`, an intersection, or a mapped or conditional type written another way, is not compared.',
136
+ ],
137
+ },
138
+ {
139
+ type: 'prose',
140
+ text: "The check prints how many documented types it judged, then lists the rest by reason: not a form the check judges exactly, a field the prop's variants give different types, a standard prop, or a prop declared outside the package. With `--json`, they are in `data.propDrift.typesNotCompared`.",
141
+ },
142
+ {
143
+ type: 'code',
144
+ lang: 'text',
145
+ code: '[info] Documented prop types judged: 2; not compared: 0. A type is judged when the doc writes it the same as the source (exactly, if it contains `readonly`), or when both are primitives, literals, arrays and unions of those, or names for them.',
146
+ },
147
+ ],
148
+ },
149
+ {
150
+ id: 'when-a-component-is-not-compared',
151
+ title: 'When a component is not compared',
152
+ content: [
153
+ {
154
+ type: 'prose',
155
+ text: "When the check cannot read a component's props exactly, it lists the component under `[info] Props not compared`, with the reason, instead of reporting findings that might be wrong.",
156
+ },
157
+ {
158
+ type: 'code',
159
+ lang: 'text',
160
+ code: `[info] Props not compared for 1 documented component(s):
161
+
162
+ component: AcmeCarousel
163
+ doc: components/AcmeCarousel.doc.mjs
164
+ reason: AcmeCarousel depends on \`@acme/motion\` (imported in AcmeCarousel.tsx), which the compiler could not resolve, usually a dependency that is not installed. Install the package's dependencies and run this check again`,
165
+ },
166
+ {
167
+ type: 'table',
168
+ headers: ['Reason', 'Fix'],
169
+ rows: [
170
+ [
171
+ 'It depends on a package or file the compiler could not resolve',
172
+ "Install the package's dependencies, then run the check again",
173
+ ],
174
+ [
175
+ "It depends on a type the compiler can't work out",
176
+ 'Make the types compile with `npx tsc --noEmit`, then run the check again',
177
+ ],
178
+ [
179
+ "The package's TypeScript config has an error",
180
+ 'Fix `tsconfig.json` until `npx tsc -p .` reads it',
181
+ ],
182
+ ['Its props are typed `any`', 'Give the component a props type'],
183
+ [
184
+ 'Some prop names come from a type parameter',
185
+ 'Nothing to fix: a component that renders an element the caller picks takes props known only where it is used',
186
+ ],
187
+ [
188
+ "The file has no export named by the doc's `name`",
189
+ 'Change `name` or the export so they agree',
190
+ ],
191
+ ],
192
+ },
193
+ ],
194
+ },
195
+ ],
196
+ };