@astryxdesign/cli 0.7.4-canary.3f6ea7d → 0.7.4-canary.78641f8

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 (206) hide show
  1. package/README.md +63 -63
  2. package/api/component/_adapter.mjs +4 -3
  3. package/api/component/component.mjs +13 -6
  4. package/api/component/doc-links.test.mjs +33 -0
  5. package/api/docs/_adapter.d.mts +80 -0
  6. package/api/docs/_adapter.mjs +261 -11
  7. package/api/docs/detail/detail.mjs +8 -0
  8. package/api/docs/docOverlays.test.mjs +2 -1
  9. package/api/docs/docs.d.mts +16 -6
  10. package/api/docs/docs.doc.mjs +1 -1
  11. package/api/docs/docs.mjs +55 -6
  12. package/api/docs/docs.type.d.mts +28 -2
  13. package/api/docs/docs.type.mjs +13 -3
  14. package/api/docs/guide-route-targets.test.mjs +1002 -0
  15. package/api/docs/index/index.mjs +9 -0
  16. package/api/docs/integration-tree.test.mjs +22 -0
  17. package/api/docs/integrationDocs.test.mjs +85 -0
  18. package/api/docs/list/list.mjs +7 -1
  19. package/api/docs/node/node.mjs +9 -1
  20. package/api/docs/reference-blocks.test.mjs +1 -1
  21. package/api/doctor/built-checks.mjs +43 -13
  22. package/api/doctor/built-checks.test.mjs +29 -0
  23. package/api/doctor/doctor.doc.mjs +2 -2
  24. package/api/hook/list/list.d.mts +1 -1
  25. package/api/integration/_adapter.d.mts +11 -2
  26. package/api/integration/_adapter.mjs +30 -4
  27. package/api/integration/authoring-checks.mjs +29 -2
  28. package/api/integration/authoring-checks.test.mjs +131 -1
  29. package/api/integration/check/check.d.mts +4 -1
  30. package/api/integration/check/check.mjs +34 -4
  31. package/api/integration/check/check.test.mjs +49 -0
  32. package/api/integration/example-checks.no-npm.test.mjs +140 -0
  33. package/api/integration/example-checks.test.mjs +776 -0
  34. package/api/integration/integration-check.type.d.mts +8 -0
  35. package/api/integration/integration-check.type.mjs +4 -1
  36. package/api/integration/integrationCheck.doc.mjs +8 -1
  37. package/api/integration/integrationDocConflicts.doc.mjs +1 -1
  38. package/api/integration/pack-check.mjs +65 -1
  39. package/api/integration/pack-check.test.mjs +63 -0
  40. package/api/integration/validate-integration-case-disk.test.mjs +14 -2
  41. package/api/integration/validate-integration-gaps.test.mjs +43 -19
  42. package/api/integration/validate-integration.mjs +112 -14
  43. package/api/integration/validate-integration.type.d.mts +23 -4
  44. package/api/integration/validate-integration.type.mjs +14 -5
  45. package/api/integration/validateIntegration.doc.mjs +1 -1
  46. package/api/search/_candidate-score.d.mts +9 -3
  47. package/api/search/_candidate-score.mjs +90 -3
  48. package/api/search/_gather-components.mjs +48 -1
  49. package/api/search/_gather-docs.mjs +12 -2
  50. package/api/search/_lexical.d.mts +12 -0
  51. package/api/search/_lexical.mjs +3 -0
  52. package/api/search/_priority.mjs +5 -2
  53. package/api/search/_score.d.mts +2 -1
  54. package/api/search/_score.mjs +4 -3
  55. package/api/search/search.doc.mjs +1 -1
  56. package/api/search/search.family-members.test.mjs +124 -0
  57. package/api/search/search.family-word.test.mjs +146 -0
  58. package/api/search/search.mjs +28 -0
  59. package/api/template/template-suffix.test.mjs +26 -0
  60. package/api/theme/themeBuild.doc.mjs +1 -1
  61. package/api/theme/themeList.doc.mjs +1 -1
  62. package/api/theme/themeTargets.doc.mjs +1 -1
  63. package/assets/discover/official-packages.json +16 -0
  64. package/assets/docs/author-a-theme.doc.mjs +15 -15
  65. package/assets/docs/browser-support.doc.mjs +1 -1
  66. package/assets/docs/getting-started.doc.mjs +16 -16
  67. package/assets/docs/is-my-code-good.doc.mjs +6 -6
  68. package/assets/docs/styling-overview.doc.mjs +5 -5
  69. package/assets/docs/theme.doc.mjs +5 -5
  70. package/assets/docs/tree/add-a-component.doc.mjs +1 -1
  71. package/assets/docs/tree/add-a-theme.doc.mjs +2 -2
  72. package/assets/docs/tree/add-a-topic.doc.mjs +6 -6
  73. package/assets/docs/tree/agent-guidance.doc.mjs +5 -5
  74. package/assets/docs/tree/authoring.doc.mjs +2 -2
  75. package/assets/docs/tree/block-template.doc.mjs +1 -1
  76. package/assets/docs/tree/check-the-props.doc.mjs +3 -3
  77. package/assets/docs/tree/check-your-docs.doc.mjs +6 -6
  78. package/assets/docs/tree/checks.doc.mjs +11 -11
  79. package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
  80. package/assets/docs/tree/cli-command.doc.mjs +6 -6
  81. package/assets/docs/tree/codemods.doc.mjs +7 -7
  82. package/assets/docs/tree/component-family.doc.mjs +1 -1
  83. package/assets/docs/tree/component-imports.doc.mjs +2 -2
  84. package/assets/docs/tree/component-lookups.doc.mjs +6 -5
  85. package/assets/docs/tree/computer-agent-guide.doc.mjs +7 -7
  86. package/assets/docs/tree/computer-integrations.doc.mjs +5 -5
  87. package/assets/docs/tree/debug-and-gap-reports.doc.mjs +3 -3
  88. package/assets/docs/tree/define-the-theme.doc.mjs +1 -1
  89. package/assets/docs/tree/describe-the-component.doc.mjs +1 -1
  90. package/assets/docs/tree/doc-syntax.doc.mjs +219 -0
  91. package/assets/docs/tree/export-template-assets.doc.mjs +1 -1
  92. package/assets/docs/tree/extend-or-replace.doc.mjs +39 -7
  93. package/assets/docs/tree/font-setup.doc.mjs +1 -1
  94. package/assets/docs/tree/generate-a-palette.doc.mjs +1 -1
  95. package/assets/docs/tree/global-integrations.doc.mjs +11 -11
  96. package/assets/docs/tree/global.doc.mjs +2 -2
  97. package/assets/docs/tree/host-entry.doc.mjs +1 -1
  98. package/assets/docs/tree/install-once.doc.mjs +4 -4
  99. package/assets/docs/tree/layout.doc.mjs +1 -1
  100. package/assets/docs/tree/links.doc.mjs +2 -2
  101. package/assets/docs/tree/migration-setup.doc.mjs +15 -15
  102. package/assets/docs/tree/migration.doc.mjs +2 -1
  103. package/assets/docs/tree/other-libraries.doc.mjs +1 -1
  104. package/assets/docs/tree/page-template.doc.mjs +2 -2
  105. package/assets/docs/tree/problems.doc.mjs +8 -8
  106. package/assets/docs/tree/project-global-or-both.doc.mjs +2 -2
  107. package/assets/docs/tree/publishing.doc.mjs +7 -7
  108. package/assets/docs/tree/quick-start.doc.mjs +9 -9
  109. package/assets/docs/tree/reference.doc.mjs +2 -2
  110. package/assets/docs/tree/replace-a-core-component.doc.mjs +1 -1
  111. package/assets/docs/tree/replace-a-core-template.doc.mjs +4 -4
  112. package/assets/docs/tree/scaffold.doc.mjs +1 -1
  113. package/assets/docs/tree/sections-and-placement.doc.mjs +3 -3
  114. package/assets/docs/tree/see-it-in-an-app.doc.mjs +3 -3
  115. package/assets/docs/tree/short-and-findable.doc.mjs +3 -3
  116. package/assets/docs/tree/single-component.doc.mjs +4 -4
  117. package/assets/docs/tree/start-a-template.doc.mjs +5 -5
  118. package/assets/docs/tree/styling-advanced.doc.mjs +1 -1
  119. package/assets/docs/tree/styling-libraries.doc.mjs +2 -1
  120. package/assets/docs/tree/styling.doc.mjs +1 -1
  121. package/assets/docs/tree/tailwind.doc.mjs +1 -1
  122. package/assets/docs/tree/test-in-an-app.doc.mjs +5 -5
  123. package/assets/docs/tree/test-template-in-app.doc.mjs +6 -6
  124. package/assets/docs/tree/tokens-and-setup.doc.mjs +1 -1
  125. package/assets/docs/tree/troubleshooting.doc.mjs +24 -20
  126. package/assets/docs/tree/uninstall.doc.mjs +2 -2
  127. package/assets/docs/tree/updates.doc.mjs +1 -1
  128. package/assets/docs/tree/upgrading.doc.mjs +3 -3
  129. package/assets/docs/tree/use-a-theme-in-an-app.doc.mjs +1 -1
  130. package/assets/docs/tree/verify-packed-template.doc.mjs +3 -3
  131. package/assets/docs/tree/versioning.doc.mjs +4 -4
  132. package/assets/docs/tree/who-answers.doc.mjs +4 -4
  133. package/assets/docs/tree/write-the-template-file.doc.mjs +4 -4
  134. package/assets/docs/use-a-theme.doc.mjs +10 -10
  135. package/assets/docs/use-integrations.doc.mjs +1 -1
  136. package/assets/docs/working-with-ai.doc.mjs +15 -15
  137. package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +54 -0
  138. package/assets/templates/themes/butter/butterPalettes.generated.receipt.json +1499 -0
  139. package/assets/templates/themes/butter/butterPalettes.generated.ts +550 -0
  140. package/assets/templates/themes/butter/butterTheme.ts +274 -234
  141. package/assets/templates/themes/butter/palette.config.json +484 -0
  142. package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +51 -0
  143. package/assets/templates/themes/matcha/matchaPalettes.generated.receipt.json +1502 -0
  144. package/assets/templates/themes/matcha/matchaPalettes.generated.ts +501 -0
  145. package/assets/templates/themes/matcha/matchaPalettes.ts +21 -0
  146. package/assets/templates/themes/matcha/matchaTheme.ts +164 -103
  147. package/assets/templates/themes/matcha/palette.config.json +448 -0
  148. package/assets/templates/themes/y2k/palette.config.json +166 -0
  149. package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +54 -0
  150. package/assets/templates/themes/y2k/y2kPalettes.generated.receipt.json +872 -0
  151. package/assets/templates/themes/y2k/y2kPalettes.generated.ts +550 -0
  152. package/assets/templates/themes/y2k/y2kPalettes.ts +257 -0
  153. package/assets/templates/themes/y2k/y2kTheme.ts +164 -391
  154. package/authoring/codemod/codemod.doc.mjs +1 -1
  155. package/authoring/config/config.doc.mjs +4 -4
  156. package/authoring/debug/parse.d.mts +1 -1
  157. package/authoring/discover/discover.doc.mjs +1 -1
  158. package/authoring/doctypes/_schema.d.mts +4 -0
  159. package/authoring/doctypes/_schema.mjs +4 -0
  160. package/authoring/doctypes/reference/type.ts +14 -2
  161. package/authoring/gap-report/gap-report.doc.mjs +1 -1
  162. package/authoring/integration/integration.doc.mjs +6 -6
  163. package/clients/cli/commands/docs.doc.mjs +1 -1
  164. package/clients/cli/commands/docs.mjs +27 -2
  165. package/clients/cli/commands/docs.test.mjs +1 -1
  166. package/clients/cli/commands/doctor-integration-docs.doc.mjs +1 -1
  167. package/clients/cli/commands/doctor.doc.mjs +1 -1
  168. package/clients/cli/commands/doctor.mjs +12 -1
  169. package/clients/cli/commands/integration-check.doc.mjs +11 -0
  170. package/clients/cli/commands/integration-check.test.mjs +36 -3
  171. package/clients/cli/commands/integration-pack.doc.mjs +1 -1
  172. package/clients/cli/commands/integration-verify.doc.mjs +1 -1
  173. package/clients/cli/commands/integration.mjs +15 -3
  174. package/clients/cli/commands/theme-targets.doc.mjs +1 -1
  175. package/clients/cli/commands/upgrade.doc.mjs +2 -2
  176. package/clients/cli/lib/define-command.mjs +5 -3
  177. package/foundation/agent-docs/agent-docs.d.mts +14 -2
  178. package/foundation/agent-docs/agent-docs.mjs +65 -4
  179. package/foundation/agent-docs/agent-docs.test.mjs +107 -0
  180. package/foundation/discovery/docs-discovery.d.mts +93 -2
  181. package/foundation/discovery/docs-discovery.mjs +237 -8
  182. package/foundation/discovery/runner-allowlist.d.mts +2 -0
  183. package/foundation/discovery/runner-allowlist.mjs +4 -0
  184. package/foundation/discovery/runner-commands.d.mts +29 -13
  185. package/foundation/discovery/runner-commands.mjs +253 -17
  186. package/foundation/discovery/stray-pointers.mjs +11 -5
  187. package/foundation/discovery/stray-pointers.test.mjs +6 -0
  188. package/foundation/discovery/template-adapter.mjs +11 -0
  189. package/foundation/doc-compiler/compile.mjs +8 -1
  190. package/foundation/doc-compiler/doc-loads.test.mjs +7 -0
  191. package/foundation/doc-compiler/doc-syntax.d.mts +194 -0
  192. package/foundation/doc-compiler/doc-syntax.mjs +739 -0
  193. package/foundation/doc-compiler/doc-syntax.test.mjs +383 -0
  194. package/foundation/doc-compiler/links.d.mts +13 -16
  195. package/foundation/doc-compiler/links.mjs +40 -7
  196. package/foundation/doc-compiler/tree.d.mts +5 -0
  197. package/foundation/doc-compiler/tree.mjs +9 -0
  198. package/foundation/env/package-manager.d.mts +18 -0
  199. package/foundation/env/package-manager.mjs +40 -0
  200. package/foundation/integrations/cli-requirement.d.mts +29 -0
  201. package/foundation/integrations/cli-requirement.mjs +47 -0
  202. package/foundation/integrations/cli-requirement.test.mjs +23 -2
  203. package/foundation/integrations/validate-contributions.d.mts +53 -0
  204. package/foundation/integrations/validate-contributions.mjs +788 -0
  205. package/foundation/response/response-types.doc.mjs +6 -6
  206. package/package.json +9 -9
@@ -23,6 +23,8 @@
23
23
 
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
+ import {spawnSync} from 'node:child_process';
27
+ import {builtinModules} from 'node:module';
26
28
  import {parse as parseModule} from '@babel/parser';
27
29
  import {isValidSemver} from '../env/semver.mjs';
28
30
  import {findProjectCoreDir} from '../fs/paths.mjs';
@@ -49,6 +51,7 @@ import {
49
51
  TEMPLATE_CANDIDATE_RE,
50
52
  } from './contribution-fixes.mjs';
51
53
  import {MANIFEST_BASENAMES} from './integrations.mjs';
54
+ import {npmCommand} from '../release/cache.mjs';
52
55
  import {discoverIntegrationCodemods} from '../../assets/codemods/integration-discovery.mjs';
53
56
  import {discoverIntegrationTemplatesForOne} from '../discovery/template-adapter.mjs';
54
57
  import * as componentDiscovery from '../discovery/component-discovery.mjs';
@@ -1023,6 +1026,791 @@ export async function blockComponentsCheck(integration) {
1023
1026
  };
1024
1027
  }
1025
1028
 
1029
+ /** A package's own template category: `"<Group> - <Variant>"`. */
1030
+ /**
1031
+ * A category written as a path, such as `components/Button`: a slash with no
1032
+ * " - " between a group and a variant. Single words (`Settings`) and
1033
+ * `"<Group> - <Variant>"` (`Table - Index/Detail`) are fine.
1034
+ */
1035
+ // A category written as a path: lowercase first segment and no spaces
1036
+ // (`components/X`, `blocks/forms`), not a name with a slash in it (`UI/UX`,
1037
+ // `A/B Testing`).
1038
+ const PATH_CATEGORY = /^[a-z0-9][\w.-]*(?:\/[\w.-]+)+$/u;
1039
+
1040
+ /** Imports a browser cannot load, which a showcase must not make. */
1041
+ const SERVER_ONLY_IMPORTS =
1042
+ /^(?:server-only|next\/headers|next\/server|next\/cache|node:.+)$/u;
1043
+
1044
+ /**
1045
+ * Every spelling a glob's `{a,b}` braces stand for, nested braces included.
1046
+ * @param {string} pattern
1047
+ * @returns {string[]}
1048
+ */
1049
+ function expandBraces(pattern) {
1050
+ let depth = 0;
1051
+ let open = -1;
1052
+ for (let i = 0; i < pattern.length; i++) {
1053
+ const ch = pattern[i];
1054
+ if (ch === '\\') {
1055
+ i++;
1056
+ } else if (ch === '{') {
1057
+ if (depth++ === 0) open = i;
1058
+ } else if (ch === '}' && depth > 0 && --depth === 0) {
1059
+ const body = pattern.slice(open + 1, i);
1060
+ /** @type {string[]} */
1061
+ const parts = [];
1062
+ let level = 0;
1063
+ let from = 0;
1064
+ for (let j = 0; j < body.length; j++) {
1065
+ if (body[j] === '{') level++;
1066
+ else if (body[j] === '}') level--;
1067
+ else if (body[j] === ',' && level === 0) {
1068
+ parts.push(body.slice(from, j));
1069
+ from = j + 1;
1070
+ }
1071
+ }
1072
+ parts.push(body.slice(from));
1073
+ if (parts.length < 2) continue;
1074
+ const head = pattern.slice(0, open);
1075
+ const tail = pattern.slice(i + 1);
1076
+ return parts.flatMap(part => expandBraces(head + part + tail));
1077
+ }
1078
+ }
1079
+ return [pattern];
1080
+ }
1081
+
1082
+ /**
1083
+ * One brace-free glob as a regular expression source: `**`, `*`, `?` and
1084
+ * `[…]` classes (`[!…]` negated), as npm's `files` matching reads them.
1085
+ * @param {string} pattern
1086
+ */
1087
+ function globSource(pattern) {
1088
+ let out = '';
1089
+ for (let i = 0; i < pattern.length; i++) {
1090
+ const ch = pattern[i];
1091
+ if (ch === '*') {
1092
+ if (pattern[i + 1] === '*') {
1093
+ const slashAfter = pattern[i + 2] === '/';
1094
+ const atStart = i === 0 || pattern[i - 1] === '/';
1095
+ if (atStart && slashAfter) {
1096
+ out += '(?:.*/)?';
1097
+ i += 2;
1098
+ } else if (atStart && i + 2 === pattern.length) {
1099
+ out = out.replace(/\/$/u, '') + '(?:/.*)?';
1100
+ i += 1;
1101
+ } else {
1102
+ out += '.*';
1103
+ i += 1;
1104
+ }
1105
+ } else {
1106
+ out += '[^/]*';
1107
+ }
1108
+ } else if (ch === '?') {
1109
+ out += '[^/]';
1110
+ } else if (ch === '[') {
1111
+ const close = pattern.indexOf(']', i + 2);
1112
+ if (close === -1) {
1113
+ out += '\\[';
1114
+ } else {
1115
+ let body = pattern.slice(i + 1, close);
1116
+ const negated = body.startsWith('!') || body.startsWith('^');
1117
+ if (negated) body = body.slice(1);
1118
+ out += `[${negated ? '^' : ''}${body.replace(/[\\\]]/gu, '\\$&')}]`;
1119
+ i = close;
1120
+ }
1121
+ } else if (ch === '\\' && i + 1 < pattern.length) {
1122
+ out += pattern[++i].replace(/[.+^${}()|[\]\\*?/]/gu, '\\$&');
1123
+ } else {
1124
+ out += ch.replace(/[.+^${}()|[\]\\]/gu, '\\$&');
1125
+ }
1126
+ }
1127
+ return out;
1128
+ }
1129
+
1130
+ /**
1131
+ * The paths npm packs for the package in `base`, read from
1132
+ * `npm pack --dry-run --json --ignore-scripts` (nothing runs, nothing is
1133
+ * written), started the way the CLI starts npm everywhere else, or why npm
1134
+ * could not answer.
1135
+ * @param {string} base
1136
+ * @returns {{paths: Set<string>} | {error: string}}
1137
+ */
1138
+ function npmPackedPaths(base) {
1139
+ let npm;
1140
+ try {
1141
+ npm = npmCommand();
1142
+ } catch {
1143
+ return {error: 'npm was not found'};
1144
+ }
1145
+ const result = spawnSync(
1146
+ npm.command,
1147
+ [
1148
+ ...npm.prefix,
1149
+ 'pack',
1150
+ '--dry-run',
1151
+ '--json',
1152
+ '--ignore-scripts',
1153
+ '--silent',
1154
+ ],
1155
+ {
1156
+ cwd: base,
1157
+ encoding: 'utf-8',
1158
+ shell: false,
1159
+ timeout: 60_000,
1160
+ // One line per packed file: room for a very large package.
1161
+ maxBuffer: 256 * 1024 * 1024,
1162
+ },
1163
+ );
1164
+ if (result.error) return {error: `npm did not run (${result.error.message})`};
1165
+ if (result.status !== 0) {
1166
+ let code = '';
1167
+ try {
1168
+ code = JSON.parse(result.stdout)?.error?.code ?? '';
1169
+ } catch {
1170
+ // not JSON
1171
+ }
1172
+ return {
1173
+ error: `npm pack failed${code ? ` (${code})` : ` with exit ${result.status}`}`,
1174
+ };
1175
+ }
1176
+ try {
1177
+ const [info] = JSON.parse(result.stdout);
1178
+ if (Array.isArray(info?.files)) {
1179
+ return {
1180
+ paths: new Set(
1181
+ info.files.map((/** @type {{path: string}} */ f) => f.path),
1182
+ ),
1183
+ };
1184
+ }
1185
+ } catch {
1186
+ // fall through
1187
+ }
1188
+ return {error: 'npm pack printed no file list'};
1189
+ }
1190
+
1191
+ /**
1192
+ * The ignore files npm reads for one path in a package with no `files`
1193
+ * field: in the root and each folder down to the path's own, `.npmignore`,
1194
+ * or `.gitignore` where that folder has none. Root first, each relative to
1195
+ * the package root.
1196
+ * @param {string} base
1197
+ * @param {string} rel POSIX, relative to the package root
1198
+ * @returns {string[]}
1199
+ */
1200
+ function ignoreFilesFor(base, rel) {
1201
+ /** @type {string[]} */
1202
+ const found = [];
1203
+ const folders = rel.split('/').slice(0, -1);
1204
+ for (let depth = 0; depth <= folders.length; depth++) {
1205
+ const folder = folders.slice(0, depth).join('/');
1206
+ const file = ['.npmignore', '.gitignore'].find(name =>
1207
+ fs.existsSync(path.join(base, folder, name)),
1208
+ );
1209
+ if (file) found.push(folder ? `${folder}/${file}` : file);
1210
+ }
1211
+ return found;
1212
+ }
1213
+
1214
+ /**
1215
+ * The note for an asset a package with no `files` field leaves out through
1216
+ * an ignore file, naming the line that drops it, never a `files` field,
1217
+ * which would leave out everything else. The deepest file with a matching
1218
+ * line is named; an entry is read relative to its own folder.
1219
+ * @param {string} base
1220
+ * @param {string} template
1221
+ * @param {string} asset
1222
+ * @param {boolean} [nestedOnly] with a `files` field npm skips the root's
1223
+ * ignore file but still reads those in folders below it
1224
+ */
1225
+ function ignoreFix(base, template, asset, nestedOnly = false) {
1226
+ const files = ignoreFilesFor(base, asset).filter(
1227
+ file => !nestedOnly || file.includes('/'),
1228
+ );
1229
+ for (const file of [...files].reverse()) {
1230
+ const folder = path.posix.dirname(file);
1231
+ const within = folder === '.' ? asset : asset.slice(folder.length + 1);
1232
+ /** @type {string[]} */
1233
+ let lines;
1234
+ try {
1235
+ lines = fs.readFileSync(path.join(base, file), 'utf8').split(/\r?\n/);
1236
+ } catch {
1237
+ continue;
1238
+ }
1239
+ const line = lines.find(
1240
+ entry =>
1241
+ entry.trim() !== '' &&
1242
+ !entry.trim().startsWith('#') &&
1243
+ !entry.trim().startsWith('!') &&
1244
+ !outsideFiles(within, [entry.trim()]),
1245
+ );
1246
+ if (line) {
1247
+ return `${template}: loads ${asset}, which npm leaves out of the package because ${file} drops it, so the template breaks once installed. Fix: remove or narrow the line \`${line.trim()}\` in ${file}, and confirm with \`npm pack --dry-run\`.`;
1248
+ }
1249
+ }
1250
+ const file = files.at(-1) ?? '.npmignore';
1251
+ return `${template}: loads ${asset}, which npm leaves out of the package because an ignore file drops it, so the template breaks once installed. Fix: remove the line in ${file} (or another ignore file on its path) that matches ${asset}, and confirm with \`npm pack --dry-run\`.`;
1252
+ }
1253
+
1254
+ /**
1255
+ * Whether no `files` entry can reach a path, read case-insensitively and
1256
+ * generously (`{a,b}` braces, globs, a no-slash entry at any depth, an entry
1257
+ * for the path or any folder above it), for when npm cannot say what it
1258
+ * packs: a path this misses is out of the package however npm reads the list.
1259
+ * @param {string} rel POSIX, relative to the package root
1260
+ * @param {unknown} files
1261
+ */
1262
+ export function outsideFiles(rel, files) {
1263
+ if (!Array.isArray(files)) return false;
1264
+ const parts = rel.split('/');
1265
+ const paths = parts.map((_, i) => parts.slice(0, i + 1).join('/'));
1266
+ return !files.some(entry => {
1267
+ if (typeof entry !== 'string' || entry.startsWith('!')) return false;
1268
+ const trimmed = entry
1269
+ .replace(/^\.?\//u, '')
1270
+ .replace(/\/+$/u, '')
1271
+ .replace(/\/\*$/u, '/**');
1272
+ return expandBraces(trimmed).some(spelling => {
1273
+ const pattern = new RegExp(`^${globSource(spelling)}$`, 'iu');
1274
+ return spelling.includes('/') || /^\.?\//u.test(entry)
1275
+ ? paths.some(at => pattern.test(at))
1276
+ : parts.some(name => pattern.test(name));
1277
+ });
1278
+ });
1279
+ }
1280
+
1281
+ /**
1282
+ * The `!` entry of a `files` field that leaves out `rel` or a folder above
1283
+ * it, as written; null when none does.
1284
+ * @param {string} rel package-relative path
1285
+ * @param {unknown} files the `files` field
1286
+ * @returns {string | null}
1287
+ */
1288
+ export function negatedFilesEntry(rel, files) {
1289
+ if (!Array.isArray(files)) return null;
1290
+ const parts = rel.split('/');
1291
+ const paths = parts.map((_, i) => parts.slice(0, i + 1).join('/'));
1292
+ for (const entry of files) {
1293
+ if (typeof entry !== 'string' || !entry.startsWith('!')) continue;
1294
+ const trimmed = entry
1295
+ .slice(1)
1296
+ .replace(/^\.?\//u, '')
1297
+ .replace(/\/+$/u, '')
1298
+ .replace(/\/\*$/u, '/**');
1299
+ const hit = expandBraces(trimmed).some(spelling => {
1300
+ const pattern = new RegExp(`^${globSource(spelling)}$`, 'iu');
1301
+ return spelling.includes('/') || /^!\.?\//u.test(entry)
1302
+ ? paths.some(at => pattern.test(at))
1303
+ : parts.some(name => pattern.test(name));
1304
+ });
1305
+ if (hit) return entry;
1306
+ }
1307
+ return null;
1308
+ }
1309
+
1310
+ /**
1311
+ * The path a `new URL()` argument spells out: a string, or a template
1312
+ * literal with no expressions. Anything computed is not read.
1313
+ * @param {any} node
1314
+ * @returns {string | null}
1315
+ */
1316
+ function literalPath(node) {
1317
+ if (node?.type === 'StringLiteral') return node.value;
1318
+ if (node?.type === 'TemplateLiteral' && node.expressions.length === 0) {
1319
+ return node.quasis[0]?.value?.cooked ?? null;
1320
+ }
1321
+ return null;
1322
+ }
1323
+
1324
+ /**
1325
+ * A template module, parsed, so strings, JSX text, comments and type-only
1326
+ * imports and exports never count. `server` is what a browser cannot run: an
1327
+ * import, re-export or `require()` of a server-only module or an uninstalled
1328
+ * Node builtin, a read of `process.env` other than `process.env.NODE_ENV`
1329
+ * (which bundlers replace). `assets` are the relative paths it loads with `new URL('./x', import.meta.url)`. A module
1330
+ * that does not parse reports nothing; the template check owns that.
1331
+ * @param {string} source
1332
+ * @param {Set<string>} builtins
1333
+ * @returns {{server: string[], assets: string[]}}
1334
+ */
1335
+ function readModule(source, builtins) {
1336
+ /** @type {any} */
1337
+ let ast;
1338
+ try {
1339
+ ast = parseModule(source, {
1340
+ sourceType: 'module',
1341
+ plugins: ['jsx', 'typescript'],
1342
+ errorRecovery: true,
1343
+ });
1344
+ } catch {
1345
+ return {server: [], assets: []};
1346
+ }
1347
+ /** @type {string[]} */
1348
+ const assets = [];
1349
+ /** @type {string[]} */
1350
+ const found = [];
1351
+ /** @param {unknown} spec */
1352
+ const checkSpec = spec => {
1353
+ if (
1354
+ typeof spec === 'string' &&
1355
+ (SERVER_ONLY_IMPORTS.test(spec) || builtins.has(spec))
1356
+ ) {
1357
+ found.push(`imports '${spec}'`);
1358
+ }
1359
+ };
1360
+ /** @param {any} node */
1361
+ const visit = node => {
1362
+ if (!node || typeof node.type !== 'string') return;
1363
+ switch (node.type) {
1364
+ case 'ImportDeclaration':
1365
+ if (
1366
+ node.importKind !== 'type' &&
1367
+ !(
1368
+ node.specifiers.length > 0 &&
1369
+ node.specifiers.every(
1370
+ (/** @type {any} */ s) => s.importKind === 'type',
1371
+ )
1372
+ )
1373
+ ) {
1374
+ checkSpec(node.source.value);
1375
+ }
1376
+ return;
1377
+ case 'ExportNamedDeclaration':
1378
+ case 'ExportAllDeclaration':
1379
+ if (
1380
+ node.source &&
1381
+ node.exportKind !== 'type' &&
1382
+ !(
1383
+ node.specifiers?.length > 0 &&
1384
+ node.specifiers.every(
1385
+ (/** @type {any} */ s) => s.exportKind === 'type',
1386
+ )
1387
+ )
1388
+ ) {
1389
+ checkSpec(node.source.value);
1390
+ }
1391
+ break;
1392
+ case 'CallExpression':
1393
+ if (
1394
+ (node.callee.type === 'Identifier' &&
1395
+ node.callee.name === 'require') ||
1396
+ node.callee.type === 'Import'
1397
+ ) {
1398
+ checkSpec(node.arguments[0]?.value);
1399
+ }
1400
+ break;
1401
+ case 'ImportExpression':
1402
+ checkSpec(node.source?.value);
1403
+ break;
1404
+ case 'NewExpression': {
1405
+ const [first, second] = node.arguments ?? [];
1406
+ if (
1407
+ node.callee.type === 'Identifier' &&
1408
+ node.callee.name === 'URL' &&
1409
+ literalPath(first) != null &&
1410
+ /^\.{1,2}\//u.test(/** @type {string} */ (literalPath(first))) &&
1411
+ second?.type === 'MemberExpression' &&
1412
+ second.object?.type === 'MetaProperty' &&
1413
+ second.object.meta?.name === 'import' &&
1414
+ second.object.property?.name === 'meta' &&
1415
+ !second.computed &&
1416
+ second.property?.name === 'url'
1417
+ ) {
1418
+ assets.push(/** @type {string} */ (literalPath(first)));
1419
+ }
1420
+ break;
1421
+ }
1422
+ case 'MemberExpression': {
1423
+ const object = node.object;
1424
+ if (
1425
+ object.type === 'Identifier' &&
1426
+ object.name === 'process' &&
1427
+ !node.computed &&
1428
+ node.property.name === 'env'
1429
+ ) {
1430
+ found.push('reads process.env');
1431
+ return;
1432
+ }
1433
+ if (
1434
+ object.type === 'MemberExpression' &&
1435
+ object.object.type === 'Identifier' &&
1436
+ object.object.name === 'process' &&
1437
+ !object.computed &&
1438
+ object.property.name === 'env'
1439
+ ) {
1440
+ if (!node.computed && node.property.name === 'NODE_ENV') return;
1441
+ found.push('reads process.env');
1442
+ return;
1443
+ }
1444
+ break;
1445
+ }
1446
+ default:
1447
+ break;
1448
+ }
1449
+ for (const key of Object.keys(node)) {
1450
+ if (
1451
+ key === 'loc' ||
1452
+ key === 'start' ||
1453
+ key === 'end' ||
1454
+ key === 'leadingComments' ||
1455
+ key === 'trailingComments' ||
1456
+ key === 'innerComments'
1457
+ ) {
1458
+ continue;
1459
+ }
1460
+ const value = node[key];
1461
+ if (Array.isArray(value)) value.forEach(visit);
1462
+ else if (value && typeof value === 'object') visit(value);
1463
+ }
1464
+ };
1465
+ visit(ast.program);
1466
+ return {server: found, assets};
1467
+ }
1468
+
1469
+ /**
1470
+ * What a package's examples need to work everywhere they are shown: template
1471
+ * lists, docs pages and catalog cards, which render each block alone from
1472
+ * the packed package. Four `next` notes, each with a fix to paste
1473
+ * (architecture:cli-surface INV35, DEC-11):
1474
+ * - `component_without_example`: a published component no block template
1475
+ * shows, as its `exampleFor` with `isShowcase: true` (or in
1476
+ * `alsoShowcaseFor`). A block named like a showcase that sets neither is a
1477
+ * standalone block and does not count. Exempt, because an example cannot
1478
+ * fix them: a hidden doc (`hidden: true`), a member of a family (its
1479
+ * family's example covers it), a doc kept off the overview
1480
+ * (`isHiddenFromOverview: true`, for parts that only make sense inside a
1481
+ * parent), and a `Utility` component (providers and context).
1482
+ * - `template_category`: a template `category` written as a path, such as
1483
+ * `components/X`, with a `"<Group> - <Variant>"` one to write.
1484
+ * - `showcase_not_standalone`: a showcase that imports what a browser cannot
1485
+ * load (`server-only`, `next/headers`, `next/server`, `next/cache`, a Node
1486
+ * built-in) or reads `process.env` past `NODE_ENV`. Type-only imports and
1487
+ * comments don't count, and live data is fine: a showcase may fetch
1488
+ * through the app. Only the showcase's own file is read.
1489
+ * - `template_asset_not_packed`: a file a template loads with `new URL(…,
1490
+ * import.meta.url)` that does not exist, or that npm leaves out of the
1491
+ * package (`npm pack --dry-run`). When npm cannot answer, an asset no
1492
+ * `files` entry can reach is still a note, and any other is returned in
1493
+ * `unchecked`.
1494
+ * @param {LoadedIntegration} integration
1495
+ * @returns {Promise<{notes: Note[], unchecked: Array<{file: string, asset: string, reason: string}>}>}
1496
+ */
1497
+ export async function componentExamplesCheck(integration) {
1498
+ /** @type {Note[]} */
1499
+ const notes = [];
1500
+ const base = integration.__packageDir ?? integration.components ?? '';
1501
+ const root = integration.templates;
1502
+ /** @type {any[]} */
1503
+ let templates = [];
1504
+ if (root && !rootProblem(root)) {
1505
+ try {
1506
+ ({templates} = await discoverIntegrationTemplatesForOne(integration));
1507
+ } catch {
1508
+ // Templates that cannot be read are reported by the template check.
1509
+ return {notes, unchecked: []};
1510
+ }
1511
+ }
1512
+ const rel = (/** @type {string} */ file) => slash(path.relative(base, file));
1513
+ /** @type {unknown} */
1514
+ let packedFiles;
1515
+ /** @type {Set<string>} */
1516
+ const declared = new Set();
1517
+ try {
1518
+ const pkg = JSON.parse(
1519
+ fs.readFileSync(path.join(base, 'package.json'), 'utf8'),
1520
+ );
1521
+ packedFiles = pkg.files;
1522
+ for (const field of [
1523
+ 'dependencies',
1524
+ 'peerDependencies',
1525
+ 'optionalDependencies',
1526
+ 'devDependencies',
1527
+ ]) {
1528
+ for (const name of Object.keys(pkg[field] ?? {})) declared.add(name);
1529
+ }
1530
+ } catch {
1531
+ packedFiles = undefined;
1532
+ }
1533
+ /** @type {{paths: Set<string>} | {error: string} | undefined} what npm packs, read once */
1534
+ let packed;
1535
+ /** @type {Array<{file: string, asset: string, reason: string}>} */
1536
+ const unchecked = [];
1537
+ // A bare builtin name the package installs from npm (`buffer`, `events`)
1538
+ // is that package, which bundlers ship to the browser.
1539
+ const builtins = new Set(builtinModules.filter(name => !declared.has(name)));
1540
+ /** @type {Set<string>} */
1541
+ const shown = new Set();
1542
+ for (const template of templates) {
1543
+ const docFile = rel(template.docPath ?? template.filePath);
1544
+ if (template.type === 'block') {
1545
+ if (typeof template.exampleFor === 'string' && template.isShowcase) {
1546
+ shown.add(template.exampleFor);
1547
+ }
1548
+ for (const name of template.alsoShowcaseFor ?? []) shown.add(name);
1549
+ }
1550
+ if (
1551
+ typeof template.category === 'string' &&
1552
+ template.category !== '' &&
1553
+ PATH_CATEGORY.test(template.category)
1554
+ ) {
1555
+ const [group, ...rest] = template.category.split('/');
1556
+ const variant =
1557
+ rest.join(' ').trim() || template.displayName || template.id;
1558
+ const suggested = `${group.charAt(0).toUpperCase()}${group.slice(1)} - ${variant}`;
1559
+ notes.push({
1560
+ code: 'template_category',
1561
+ message: `${docFile}: category '${template.category}' reads as a file path, and \`astryx template\` lists templates under their category as written. Fix: category: '${suggested}', a "<Group> - <Variant>" name.`,
1562
+ });
1563
+ }
1564
+ /** @type {string} */
1565
+ let source;
1566
+ try {
1567
+ source = fs.readFileSync(template.filePath, 'utf8');
1568
+ } catch {
1569
+ continue;
1570
+ }
1571
+ const parsed = readModule(source, builtins);
1572
+ // A block is a showcase when it says so, or when it shows components
1573
+ // through `alsoShowcaseFor`, which counts them as shown above.
1574
+ const showcase =
1575
+ template.isShowcase === true ||
1576
+ (Array.isArray(template.alsoShowcaseFor) &&
1577
+ template.alsoShowcaseFor.length > 0);
1578
+ if (template.type === 'block' && showcase) {
1579
+ const blocked = parsed.server;
1580
+ if (blocked.length > 0) {
1581
+ notes.push({
1582
+ code: 'showcase_not_standalone',
1583
+ message: `${rel(template.filePath)}: the showcase ${[...new Set(blocked)].join(', ')}, which cannot run in a browser, so a docs page or catalog card cannot render it. Fix: move that code into the app; pass values in as props or a sample-data provider the showcase renders itself. Fetching live data through the app is fine.`,
1584
+ });
1585
+ }
1586
+ }
1587
+ for (const loaded of new Set(parsed.assets)) {
1588
+ const asset = path.resolve(path.dirname(template.filePath), loaded);
1589
+ const assetRel = rel(asset);
1590
+ const exists = fs.existsSync(asset);
1591
+ // npm packs nothing outside the package root, whatever `files` says.
1592
+ const fromBase = path.relative(base, asset);
1593
+ if (fromBase.startsWith('..') || path.isAbsolute(fromBase)) {
1594
+ notes.push({
1595
+ code: 'template_asset_not_packed',
1596
+ message: `${rel(template.filePath)}: loads ${assetRel}, which is outside the package, so npm never packs it and the template breaks once installed. Fix: move it inside the package (beside the template is simplest), point \`new URL()\` at the new place, and confirm with \`npm pack --dry-run\`.`,
1597
+ });
1598
+ continue;
1599
+ }
1600
+ // A folder URL is packed when npm packs anything inside it.
1601
+ const isFolder = exists && fs.statSync(asset).isDirectory();
1602
+ if (exists) {
1603
+ // With no `files` field npm packs everything but what an ignore file
1604
+ // drops, in the package root or any folder down to the asset, so
1605
+ // with no ignore file on that path there is nothing to ask.
1606
+ if (
1607
+ !Array.isArray(packedFiles) &&
1608
+ ignoreFilesFor(base, assetRel).length === 0
1609
+ ) {
1610
+ continue;
1611
+ }
1612
+ // What npm packs decides. Without npm's answer, an asset no entry
1613
+ // can reach is reported, and any other is listed as not checked.
1614
+ packed ??= npmPackedPaths(base);
1615
+ if ('paths' in packed) {
1616
+ if (packed.paths.has(assetRel)) continue;
1617
+ if (
1618
+ isFolder &&
1619
+ [...packed.paths].some(each => each.startsWith(`${assetRel}/`))
1620
+ ) {
1621
+ continue;
1622
+ }
1623
+ } else if (
1624
+ !Array.isArray(packedFiles) ||
1625
+ !outsideFiles(assetRel, packedFiles)
1626
+ ) {
1627
+ unchecked.push({
1628
+ file: rel(template.filePath),
1629
+ asset: assetRel,
1630
+ reason: Array.isArray(packedFiles)
1631
+ ? `${packed.error}, and a \`files\` entry may reach it`
1632
+ : `${packed.error}, and ${ignoreFilesFor(base, assetRel).at(-1) ?? '.npmignore'} may drop it`,
1633
+ });
1634
+ continue;
1635
+ }
1636
+ }
1637
+ const folder =
1638
+ path.posix.dirname(assetRel) === '.'
1639
+ ? assetRel
1640
+ : path.posix.dirname(assetRel);
1641
+ const negated = negatedFilesEntry(assetRel, packedFiles);
1642
+ notes.push({
1643
+ code: 'template_asset_not_packed',
1644
+ message: !exists
1645
+ ? `${rel(template.filePath)}: loads ${assetRel}, which does not exist. Fix: add the file, or point \`new URL()\` at one that does.`
1646
+ : negated != null && !outsideFiles(assetRel, packedFiles)
1647
+ ? `${rel(template.filePath)}: loads ${assetRel}, which the \`files\` entry "${negated}" leaves out of the package, so the template breaks once installed. Fix: drop or narrow "${negated}" so it no longer matches ${assetRel}, and confirm with \`npm pack --dry-run\`.`
1648
+ : Array.isArray(packedFiles) &&
1649
+ (outsideFiles(assetRel, packedFiles) ||
1650
+ !ignoreFilesFor(base, assetRel).some(file => file.includes('/')))
1651
+ ? `${rel(template.filePath)}: loads ${assetRel}, which npm leaves out of the package by its \`files\` field, so the template breaks once installed. Fix: add "${folder}" to \`files\`, drop any \`!\` entry that excludes it, and confirm with \`npm pack --dry-run\`.`
1652
+ : ignoreFix(
1653
+ base,
1654
+ rel(template.filePath),
1655
+ assetRel,
1656
+ Array.isArray(packedFiles),
1657
+ ),
1658
+ });
1659
+ }
1660
+ }
1661
+ if (!integration.components || rootProblem(integration.components)) {
1662
+ return {notes, unchecked};
1663
+ }
1664
+ /** @type {any[]} */
1665
+ let records;
1666
+ try {
1667
+ records = componentDiscovery.discoverIntegrationComponents(integration);
1668
+ } catch {
1669
+ return {notes, unchecked};
1670
+ }
1671
+ const templatesDir = root ? rel(root) || '.' : 'templates';
1672
+ /** @type {Set<unknown>} blocks a note has already asked to show one component */
1673
+ const claimed = new Set();
1674
+ // A block that names a component, by its category, name, display name or
1675
+ // file (`acme-badge-showcase`), is offered to that component alone, so two
1676
+ // notes never ask one block to show two components. The longest matching
1677
+ // name wins (`AcmeBadgeGroup` over `AcmeBadge`).
1678
+ const key = (/** @type {string} */ value) =>
1679
+ value.toLowerCase().replace(/[-_\s]/g, '');
1680
+ const componentNames = records
1681
+ .map(record => record.name)
1682
+ .filter(name => typeof name === 'string')
1683
+ .sort((a, b) => b.length - a.length);
1684
+ /** @type {Map<unknown, string>} */
1685
+ const ownerOf = new Map();
1686
+ for (const template of templates) {
1687
+ if (template.type !== 'block' || typeof template.exampleFor === 'string') {
1688
+ continue;
1689
+ }
1690
+ const words = [
1691
+ template.category,
1692
+ template.name,
1693
+ template.displayName,
1694
+ typeof template.filePath === 'string'
1695
+ ? path.basename(template.filePath).replace(/\.[^.]+$/u, '')
1696
+ : undefined,
1697
+ ]
1698
+ .filter(value => typeof value === 'string')
1699
+ .map(key);
1700
+ const owner = componentNames.find(name =>
1701
+ words.some(word => word.includes(key(name))),
1702
+ );
1703
+ if (owner) ownerOf.set(template, owner);
1704
+ }
1705
+ for (const record of records) {
1706
+ if (componentDiscovery.isIntegrationMember(record)) continue;
1707
+ if (shown.has(record.name)) continue;
1708
+ let doc;
1709
+ try {
1710
+ doc = await loadComponentDoc(record.docPath);
1711
+ } catch {
1712
+ continue;
1713
+ }
1714
+ if (doc?.hidden === true || doc?.isHiddenFromOverview === true) continue;
1715
+ if (doc?.category === 'Utility') continue;
1716
+ const name = record.name;
1717
+ const stem = `${name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase()}-showcase`;
1718
+ // A block that already composes the component only needs the fields.
1719
+ // A block that composes the component and shows nothing else takes the
1720
+ // fields; one that is already another component's showcase takes
1721
+ // `alsoShowcaseFor` instead, so it keeps its own.
1722
+ // A block whose `exampleFor` already names the component only needs
1723
+ // `isShowcase: true`.
1724
+ const named = templates.find(
1725
+ template => template.type === 'block' && template.exampleFor === name,
1726
+ );
1727
+ if (named) {
1728
+ notes.push({
1729
+ code: 'component_without_example',
1730
+ message: `${rel(record.docPath)}: no block template shows "${name}" (\`exampleFor: '${name}'\` with \`isShowcase: true\`), so template lists, docs pages and catalog cards have no example of it. Fix: add \`isShowcase: true\` to ${rel(named.docPath ?? named.filePath)}, whose \`exampleFor\` already names ${name}.`,
1731
+ });
1732
+ continue;
1733
+ }
1734
+ // Among the blocks that compose it, prefer the one that names it, then
1735
+ // one that names no component and shows nothing yet; a block that names
1736
+ // another component is that component's.
1737
+ const namesIt = (/** @type {any} */ template) =>
1738
+ ownerOf.get(template) === name;
1739
+ const composing = templates
1740
+ .filter(
1741
+ template =>
1742
+ template.type === 'block' &&
1743
+ Array.isArray(template.componentsUsed) &&
1744
+ template.componentsUsed.includes(name) &&
1745
+ (!ownerOf.has(template) || ownerOf.get(template) === name),
1746
+ )
1747
+ .sort(
1748
+ (a, b) =>
1749
+ Number(namesIt(b)) - Number(namesIt(a)) ||
1750
+ Number(typeof a.exampleFor === 'string') -
1751
+ Number(typeof b.exampleFor === 'string'),
1752
+ );
1753
+ const existing =
1754
+ composing.find(
1755
+ template =>
1756
+ typeof template.exampleFor !== 'string' && !claimed.has(template),
1757
+ ) ?? composing.find(template => typeof template.exampleFor === 'string');
1758
+ const showsAnother =
1759
+ existing != null && typeof existing.exampleFor === 'string';
1760
+ if (existing && !showsAnother) claimed.add(existing);
1761
+ // The stem path is free to suggest unless a block there already shows
1762
+ // another component; then the new files take the next free stem.
1763
+ const stemTemplate = templates.find(
1764
+ template =>
1765
+ typeof template.filePath === 'string' &&
1766
+ path.basename(template.filePath).replace(/\.[^.]+$/u, '') === stem,
1767
+ );
1768
+ const stemShowsAnother =
1769
+ stemTemplate != null &&
1770
+ typeof stemTemplate.exampleFor === 'string' &&
1771
+ stemTemplate.exampleFor !== name;
1772
+ let freeStem = stem;
1773
+ if (stemShowsAnother && root && !rootProblem(root)) {
1774
+ for (
1775
+ let n = 2;
1776
+ fs.existsSync(path.join(root, `${freeStem}.tsx`)) ||
1777
+ fs.existsSync(path.join(root, `${freeStem}.doc.mjs`));
1778
+ n++
1779
+ ) {
1780
+ freeStem = `${stem}-${n}`;
1781
+ }
1782
+ }
1783
+ const taken =
1784
+ !existing &&
1785
+ !stemShowsAnother &&
1786
+ root &&
1787
+ !rootProblem(root) &&
1788
+ fs.existsSync(path.join(root, `${stem}.tsx`));
1789
+ if (existing || taken) {
1790
+ const doc = existing
1791
+ ? rel(existing.docPath ?? existing.filePath)
1792
+ : `${templatesDir}/${stem}.doc.mjs`;
1793
+ notes.push({
1794
+ code: 'component_without_example',
1795
+ message: `${rel(record.docPath)}: no block template shows "${name}" (\`exampleFor: '${name}'\` with \`isShowcase: true\`), so template lists, docs pages and catalog cards have no example of it. Fix: ${showsAnother ? `add '${name}' to \`alsoShowcaseFor\` in ${doc}, the block that already composes ${name} as the showcase of ${existing.exampleFor}` : `add \`exampleFor: '${name}'\` and \`isShowcase: true\` to ${doc}${existing ? `, the block that already composes ${name}` : ''}`}. A doc set to \`hidden\`, \`isHiddenFromOverview\` or category \`Utility\` needs no example.`,
1796
+ });
1797
+ continue;
1798
+ }
1799
+ notes.push({
1800
+ code: 'component_without_example',
1801
+ message:
1802
+ `${rel(record.docPath)}: no block template shows "${name}" (\`exampleFor: '${name}'\` with \`isShowcase: true\`), so template lists, docs pages and catalog cards have no example of it.` +
1803
+ (root
1804
+ ? ''
1805
+ : " The manifest sets no `templates` root; add `templates: './templates'` to it.") +
1806
+ ` Fix: add ${templatesDir}/${freeStem}.tsx, a small composition that renders ${name}, and beside it ${templatesDir}/${freeStem}.doc.mjs:` +
1807
+ ` export default {type: 'block', name: '${freeStem}', displayName: '${name} showcase', description: 'A ${name} in use.', exampleFor: '${name}', isShowcase: true, aspectRatio: 16 / 10};` +
1808
+ ' A doc set to `hidden`, `isHiddenFromOverview` or category `Utility` needs no example.',
1809
+ });
1810
+ }
1811
+ return {notes, unchecked};
1812
+ }
1813
+
1026
1814
  /**
1027
1815
  * Warn about a `.tsx` directly in the templates root with no same-stem template
1028
1816
  * metadata: template discovery pairs sources with docs, so `astryx template`