@astryxdesign/cli 0.6.3-canary.98a2e4e → 0.6.3-canary.a860a50

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 (291) hide show
  1. package/README.md +32 -18
  2. package/api/build/build.doc.mjs +3 -3
  3. package/api/build/build.test.mjs +14 -3
  4. package/api/build/build.type.d.mts +36 -2
  5. package/api/build/build.type.mjs +25 -4
  6. package/api/build/help/help.d.mts +8 -5
  7. package/api/build/help/help.mjs +56 -6
  8. package/api/component/component.doc.mjs +11 -2
  9. package/api/component/component.mjs +29 -0
  10. package/api/component/component.test.mjs +38 -0
  11. package/api/component/component.type.d.mts +17 -7
  12. package/api/component/component.type.mjs +27 -20
  13. package/api/discover/discover.doc.mjs +1 -1
  14. package/api/discover/discover.type.d.mts +4 -4
  15. package/api/discover/discover.type.mjs +10 -10
  16. package/api/docs/_adapter.d.mts +30 -27
  17. package/api/docs/_adapter.mjs +154 -124
  18. package/api/docs/compiled-topics.test.mjs +78 -0
  19. package/api/docs/detail/detail.d.mts +0 -15
  20. package/api/docs/detail/detail.mjs +14 -78
  21. package/api/docs/detail/section/section.mjs +22 -18
  22. package/api/docs/detail/section/section.test.mjs +4 -3
  23. package/api/docs/docs.type.d.mts +4 -4
  24. package/api/docs/docs.type.mjs +10 -10
  25. package/api/docs/index/index.mjs +6 -5
  26. package/api/doctor/doctor.mjs +3 -7
  27. package/api/gap-report/gap-report.doc.mjs +7 -4
  28. package/api/hook/hook.type.d.mts +3 -3
  29. package/api/hook/hook.type.mjs +11 -11
  30. package/api/init/init.doc.mjs +4 -0
  31. package/api/init/init.test.mjs +41 -1
  32. package/api/init/remove/remove.mjs +1 -1
  33. package/api/init/run/run.mjs +20 -10
  34. package/api/integration/add-contribution.component-names.test.mjs +120 -0
  35. package/api/integration/add-contribution.mjs +16 -3
  36. package/api/integration/add-contribution.test.mjs +84 -4
  37. package/api/integration/integrationAdd.doc.mjs +7 -4
  38. package/api/integration/integrationAddComponent.doc.mjs +1 -1
  39. package/api/integration/pack-check.mjs +49 -7
  40. package/api/integration/pack-check.test.mjs +249 -0
  41. package/api/integration/validate-integration.mjs +2 -0
  42. package/api/integration/validate-integration.test.mjs +91 -0
  43. package/api/integration/validateIntegration.doc.mjs +1 -1
  44. package/api/json/envelope-types.test.mjs +76 -0
  45. package/api/json/parseResponse.doc.mjs +2 -2
  46. package/api/layout/expand/expand.mjs +7 -5
  47. package/api/layout/expand/expand.path-safety.test.mjs +53 -0
  48. package/api/layout/grammar/grammar.mjs +2 -1
  49. package/api/layout/layoutExpand.doc.mjs +1 -1
  50. package/api/search/search-return-type.test.mjs +54 -0
  51. package/api/search/search.d.mts +2 -9
  52. package/api/search/search.doc.mjs +5 -1
  53. package/api/search/search.mjs +15 -8
  54. package/api/search/search.test.mjs +34 -0
  55. package/api/search/search.type.d.mts +1 -1
  56. package/api/search/search.type.mjs +1 -1
  57. package/api/swizzle/copy/copy.mjs +28 -11
  58. package/api/swizzle/swizzle.doc.mjs +1 -1
  59. package/api/swizzle/swizzle.type.d.mts +2 -2
  60. package/api/swizzle/swizzle.type.mjs +2 -2
  61. package/api/template/copy/copy.mjs +17 -23
  62. package/api/template/copy/copy.test.mjs +17 -0
  63. package/api/template/template.doc.mjs +2 -1
  64. package/api/template/template.type.d.mts +5 -5
  65. package/api/template/template.type.mjs +12 -12
  66. package/api/theme/add/add.binary.test.mjs +91 -0
  67. package/api/theme/add/add.mjs +15 -2
  68. package/api/theme/build/build.mjs +133 -42
  69. package/api/theme/build/build.public-component-vars.test.mjs +1 -1
  70. package/api/theme/build/build.receipt-doc.test.mjs +111 -0
  71. package/api/theme/build/build.test.mjs +127 -0
  72. package/api/theme/build/font-warning.mjs +3 -3
  73. package/api/theme/build/font-warning.test.mjs +5 -2
  74. package/api/theme/palette/generate/generate.mjs +8 -3
  75. package/api/theme/palette/generate/generate.test.mjs +96 -0
  76. package/api/theme/palette/generate/generator.d.mts +10 -13
  77. package/api/theme/palette/generate/generator.mjs +15 -4
  78. package/api/theme/palette/generate/generator.test.mjs +10 -0
  79. package/api/theme/template/template.mjs +11 -2
  80. package/api/theme/template/template.test.mjs +15 -0
  81. package/api/theme/theme.type.d.mts +170 -11
  82. package/api/theme/theme.type.mjs +94 -27
  83. package/api/theme/themeBuild.doc.mjs +7 -4
  84. package/api/theme/themeTemplate.doc.mjs +4 -1
  85. package/api/upgrade/_adapter.mjs +27 -4
  86. package/api/upgrade/list/list.mjs +2 -1
  87. package/api/upgrade/list/list.test.mjs +73 -0
  88. package/api/upgrade/status/status.mjs +2 -2
  89. package/api/upgrade/upgrade.doc.mjs +2 -1
  90. package/api/upgrade/upgrade.type.d.mts +8 -4
  91. package/api/upgrade/upgrade.type.mjs +11 -10
  92. package/assets/codemods/integration-discovery.mjs +40 -2
  93. package/assets/codemods/integration-discovery.test.mjs +58 -0
  94. package/assets/codemods/term-log.mjs +32 -8
  95. package/assets/codemods/term-log.test.mjs +19 -1
  96. package/assets/codemods/transforms/v0.3.0/__tests__/unwrap-authoring-factories.test.mjs +27 -5
  97. package/assets/codemods/transforms/v0.3.0/unwrap-authoring-factories.mjs +20 -5
  98. package/assets/codemods/transforms/v0.6.0/__tests__/next-codemods.test.mjs +47 -0
  99. package/assets/codemods/transforms/v0.6.0/rename-resizable-pixel-bounds.mjs +57 -10
  100. package/assets/docs/cli-integrations.doc.mjs +9 -0
  101. package/assets/docs/styling-libraries.doc.mjs +1 -1
  102. package/assets/docs/working-with-ai.doc.mjs +1 -1
  103. package/assets/templates/pages/table-tree/page.tsx +1704 -0
  104. package/assets/templates/pages/table-tree/template.doc.mjs +12 -0
  105. package/authoring/_shared/contract.ts +22 -0
  106. package/authoring/codemod/codemod.doc.mjs +6 -1
  107. package/authoring/codemod/parse.d.mts +8 -8
  108. package/authoring/codemod/parse.mjs +8 -6
  109. package/authoring/config/config.doc.mjs +1 -1
  110. package/authoring/config/debug-composition.test.mjs +92 -0
  111. package/authoring/config/parse.d.mts +13 -13
  112. package/authoring/config/parse.mjs +8 -8
  113. package/authoring/config/type.ts +18 -6
  114. package/authoring/debug/parse.d.mts +4 -4
  115. package/authoring/debug/parse.mjs +3 -3
  116. package/authoring/doctypes/_schema.d.mts +121 -11
  117. package/authoring/doctypes/_schema.mjs +144 -13
  118. package/authoring/doctypes/base/graph-fields.doc.mjs +11 -4
  119. package/authoring/doctypes/base/type.ts +8 -4
  120. package/authoring/doctypes/command/command.doc.mjs +3 -2
  121. package/authoring/doctypes/command/parse.d.mts +2 -2
  122. package/authoring/doctypes/command/parse.mjs +1 -1
  123. package/authoring/doctypes/command/type.ts +2 -2
  124. package/authoring/doctypes/component/component.doc.mjs +5 -2
  125. package/authoring/doctypes/component/parse.d.mts +2 -2
  126. package/authoring/doctypes/component/parse.mjs +1 -1
  127. package/authoring/doctypes/component/type.ts +1 -1
  128. package/authoring/doctypes/enum/parse.d.mts +2 -2
  129. package/authoring/doctypes/enum/parse.mjs +1 -1
  130. package/authoring/doctypes/enum/type.ts +1 -1
  131. package/authoring/doctypes/function/function.doc.mjs +4 -0
  132. package/authoring/doctypes/function/parse.d.mts +2 -2
  133. package/authoring/doctypes/function/parse.mjs +1 -1
  134. package/authoring/doctypes/function/type.ts +1 -1
  135. package/authoring/doctypes/hook/hook.doc.mjs +4 -0
  136. package/authoring/doctypes/hook/parse.d.mts +2 -2
  137. package/authoring/doctypes/hook/parse.mjs +1 -1
  138. package/authoring/doctypes/hook/type.ts +1 -1
  139. package/authoring/doctypes/legacy.d.mts +6 -6
  140. package/authoring/doctypes/legacy.mjs +3 -3
  141. package/authoring/doctypes/load-contract.test.mjs +207 -0
  142. package/authoring/doctypes/namespace/namespace.doc.mjs +7 -3
  143. package/authoring/doctypes/namespace/parse.d.mts +2 -2
  144. package/authoring/doctypes/namespace/parse.mjs +1 -1
  145. package/authoring/doctypes/namespace/type.ts +2 -2
  146. package/authoring/doctypes/parse.d.mts +18 -18
  147. package/authoring/doctypes/parse.mjs +9 -9
  148. package/authoring/doctypes/reference/parse.d.mts +2 -2
  149. package/authoring/doctypes/reference/parse.mjs +1 -1
  150. package/authoring/doctypes/reference/reference.doc.mjs +6 -2
  151. package/authoring/doctypes/reference/type.ts +1 -1
  152. package/authoring/doctypes/schema/parse.d.mts +2 -2
  153. package/authoring/doctypes/schema/parse.mjs +1 -1
  154. package/authoring/doctypes/schema/type.ts +2 -2
  155. package/authoring/doctypes/template/parse.d.mts +92 -1
  156. package/authoring/doctypes/template/parse.mjs +33 -1
  157. package/authoring/doctypes/template/template.doc.mjs +4 -0
  158. package/authoring/doctypes/template/type.ts +4 -1
  159. package/authoring/doctypes/types.ts +10 -10
  160. package/authoring/gap-report/parse.d.mts +9 -9
  161. package/authoring/gap-report/parse.mjs +6 -6
  162. package/authoring/gap-report/type.ts +1 -1
  163. package/authoring/identity/identity.doc.mjs +3 -2
  164. package/authoring/identity/type.ts +10 -10
  165. package/authoring/index.d.ts +19 -19
  166. package/authoring/integration/parse.d.mts +2 -2
  167. package/authoring/integration/parse.mjs +1 -1
  168. package/authoring/integration/schema.d.mts +4 -4
  169. package/authoring/integration/schema.mjs +3 -3
  170. package/authoring/integration/type.ts +1 -1
  171. package/clients/cli/command-load-failure.test.mjs +83 -0
  172. package/clients/cli/commands/blog.mjs +23 -8
  173. package/clients/cli/commands/blog.test.mjs +42 -1
  174. package/clients/cli/commands/build-theme.ascii-output.test.mjs +161 -0
  175. package/clients/cli/commands/build-theme.flag-docs.test.mjs +110 -0
  176. package/clients/cli/commands/build-theme.mjs +5 -5
  177. package/clients/cli/commands/build-theme.path-safety.test.mjs +86 -1
  178. package/clients/cli/commands/build-theme.variants.test.mjs +76 -0
  179. package/clients/cli/commands/build.doc.mjs +4 -1
  180. package/clients/cli/commands/build.exit-codes-doc.test.mjs +50 -0
  181. package/clients/cli/commands/build.mjs +32 -47
  182. package/clients/cli/commands/build.playbook.test.mjs +75 -0
  183. package/clients/cli/commands/build.text-fields.test.mjs +40 -0
  184. package/clients/cli/commands/component/index.mjs +2 -7
  185. package/clients/cli/commands/component-package.test.mjs +18 -0
  186. package/clients/cli/commands/component-resolution.test.mjs +21 -0
  187. package/clients/cli/commands/component.test.mjs +19 -0
  188. package/clients/cli/commands/detail-levels.test.mjs +2 -2
  189. package/clients/cli/commands/discover.broken-integration.test.mjs +48 -0
  190. package/clients/cli/commands/discover.components-flag.test.mjs +97 -0
  191. package/clients/cli/commands/discover.doc.mjs +4 -2
  192. package/clients/cli/commands/discover.mjs +3 -3
  193. package/clients/cli/commands/discover.text-projection.test.mjs +103 -0
  194. package/clients/cli/commands/doctor-integration.package-json.test.mjs +53 -0
  195. package/clients/cli/commands/doctor.mjs +6 -16
  196. package/clients/cli/commands/doctor.test.mjs +42 -0
  197. package/clients/cli/commands/gap-report.doc.mjs +16 -5
  198. package/clients/cli/commands/gap-report.test.mjs +72 -0
  199. package/clients/cli/commands/hook/index.mjs +7 -17
  200. package/clients/cli/commands/hook.text-projection.test.mjs +45 -0
  201. package/clients/cli/commands/init.doc.mjs +19 -8
  202. package/clients/cli/commands/init.flag-help.test.mjs +153 -0
  203. package/clients/cli/commands/integration-add.controls.test.mjs +132 -0
  204. package/clients/cli/commands/integration-add.doc.mjs +21 -5
  205. package/clients/cli/commands/integration-authoring.test.mjs +13 -9
  206. package/clients/cli/commands/interactive-guard.test.mjs +101 -24
  207. package/clients/cli/commands/json-contract.test.mjs +33 -0
  208. package/clients/cli/commands/layout-check.doc.mjs +14 -3
  209. package/clients/cli/commands/layout-expand.doc.mjs +21 -4
  210. package/clients/cli/commands/layout.doc.mjs +2 -2
  211. package/clients/cli/commands/layout.mjs +21 -9
  212. package/clients/cli/commands/layout.path-help.test.mjs +33 -0
  213. package/clients/cli/commands/layout.stdin-cap.test.mjs +47 -0
  214. package/clients/cli/commands/layout.text-fields.test.mjs +39 -0
  215. package/clients/cli/commands/no-prompt-wording.test.mjs +94 -0
  216. package/clients/cli/commands/search.doc.mjs +5 -2
  217. package/clients/cli/commands/search.mjs +13 -2
  218. package/clients/cli/commands/search.test.mjs +61 -0
  219. package/clients/cli/commands/swizzle.doc.mjs +2 -1
  220. package/clients/cli/commands/swizzle.path-safety.test.mjs +42 -0
  221. package/clients/cli/commands/template.doc.mjs +28 -6
  222. package/clients/cli/commands/template.flag-help.test.mjs +117 -0
  223. package/clients/cli/commands/template.path-help.test.mjs +40 -0
  224. package/clients/cli/commands/theme-add.doc.mjs +2 -1
  225. package/clients/cli/commands/theme-build.doc.mjs +7 -6
  226. package/clients/cli/commands/theme-palette-generate.test.mjs +19 -0
  227. package/clients/cli/commands/theme-template.behavior.test.mjs +12 -0
  228. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  229. package/clients/cli/commands/upgrade.ascii-output.test.mjs +87 -0
  230. package/clients/cli/commands/upgrade.doc.mjs +17 -6
  231. package/clients/cli/commands/upgrade.flag-help.test.mjs +188 -0
  232. package/clients/cli/commands/upgrade.hook-output.test.mjs +88 -0
  233. package/clients/cli/index.mjs +13 -30
  234. package/clients/cli/latest-version-env.test.mjs +50 -0
  235. package/clients/cli/lib/cli-error.test.mjs +7 -0
  236. package/clients/cli/lib/component-format.mjs +9 -9
  237. package/clients/cli/lib/component-format.test.mjs +1 -1
  238. package/clients/cli/lib/define-command.mjs +32 -6
  239. package/clients/cli/lib/doc-text-ascii.test.mjs +82 -0
  240. package/clients/cli/lib/exit-codes.test.mjs +97 -0
  241. package/clients/cli/lib/hook-format.mjs +5 -5
  242. package/clients/cli/lib/json-shim.mjs +38 -2
  243. package/clients/cli/lib/json-shim.test.mjs +83 -0
  244. package/clients/cli/lib/manifest.d.ts +2 -0
  245. package/clients/cli/lib/manifest.mjs +22 -0
  246. package/clients/cli/lib/manifest.test.mjs +17 -0
  247. package/foundation/agent-docs/agent-docs.d.mts +4 -0
  248. package/foundation/agent-docs/agent-docs.mjs +69 -3
  249. package/foundation/agent-docs/agent-docs.path-safety.test.mjs +266 -4
  250. package/foundation/config/integration-debug.test.mjs +28 -3
  251. package/foundation/config/project.mjs +123 -9
  252. package/foundation/config/project.test.mjs +126 -0
  253. package/foundation/discovery/authoring-self-docs.test.mjs +71 -12
  254. package/foundation/discovery/docs-discovery.d.mts +4 -0
  255. package/foundation/discovery/docs-discovery.mjs +16 -2
  256. package/foundation/discovery/docs-discovery.test.mjs +47 -11
  257. package/foundation/discovery/template-adapter.d.mts +14 -5
  258. package/foundation/discovery/template-adapter.fixture-refs.test.mjs +248 -0
  259. package/foundation/discovery/template-adapter.integration-isolation.test.mjs +94 -0
  260. package/foundation/discovery/template-adapter.mjs +292 -25
  261. package/foundation/discovery/theming-targets.test.mjs +4 -0
  262. package/foundation/doc-compiler/compile.d.mts +162 -0
  263. package/foundation/doc-compiler/compile.mjs +262 -0
  264. package/foundation/doc-compiler/doc-compiler.test.mjs +687 -0
  265. package/foundation/doc-compiler/ir.d.mts +9 -0
  266. package/foundation/doc-compiler/ir.mjs +287 -0
  267. package/foundation/doc-compiler/lenses.d.mts +33 -0
  268. package/foundation/doc-compiler/lenses.mjs +127 -0
  269. package/foundation/fs/module-loader.d.mts +1 -0
  270. package/foundation/fs/module-loader.mjs +50 -1
  271. package/foundation/fs/module-loader.stdout.test.mjs +332 -0
  272. package/foundation/fs/path-safety.d.mts +3 -2
  273. package/foundation/fs/path-safety.mjs +49 -19
  274. package/foundation/fs/path-safety.test.mjs +50 -0
  275. package/foundation/fs/publish-file-hardlink-unavailable.test.mjs +129 -94
  276. package/foundation/integrations/autolink.mjs +6 -1
  277. package/foundation/response/base.d.ts +8 -4
  278. package/foundation/response/error-codes.doc.mjs +1 -2
  279. package/foundation/response/error-codes.mjs +1 -1
  280. package/foundation/response/error-codes.test.mjs +83 -0
  281. package/foundation/response/json-contract.test.mjs +11 -0
  282. package/foundation/response/json.d.mts +4 -2
  283. package/foundation/response/json.mjs +8 -10
  284. package/foundation/response/response-types.doc.mjs +3 -3
  285. package/foundation/xle/expand.d.mts +2 -0
  286. package/foundation/xle/expand.mjs +3 -2
  287. package/foundation/xle/expand.test.mjs +54 -0
  288. package/package.json +9 -11
  289. package/clients/cli/lib/update-check.mjs +0 -83
  290. package/clients/cli/lib/update-check.test.mjs +0 -137
  291. package/clients/cli/update-hint-commands.test.mjs +0 -54
@@ -23,6 +23,7 @@
23
23
 
24
24
  import * as fs from 'node:fs';
25
25
  import * as path from 'node:path';
26
+ import {createRequire} from 'node:module';
26
27
  import {createJiti} from 'jiti';
27
28
  import {loadModuleWithParser} from '../fs/module-loader.mjs';
28
29
  import {parseTemplate} from '../../authoring/doctypes/template/parse.mjs';
@@ -30,6 +31,8 @@ import {CLI_ROOT, discoverExternalPackages} from '../fs/paths.mjs';
30
31
  import {CORE_PROVIDER_ID} from '../identity/providers.mjs';
31
32
  import {Project} from '../config/project.mjs';
32
33
 
34
+ const require = createRequire(import.meta.url);
35
+
33
36
  /** Identity used for core (built-in) templates in package-scoped listings. */
34
37
  const CORE_PACKAGE = CORE_PROVIDER_ID;
35
38
 
@@ -185,17 +188,53 @@ const IMAGE_EXTENSIONS = new Set([
185
188
  ]);
186
189
 
187
190
  /**
188
- * Demo-asset sources to strip from scaffolded projects. Template demo imagery
191
+ * First path segment of every Astryx template fixture. Template demo imagery
189
192
  * is self-hosted under the docsite's `/template-assets/*` dir (committed there,
190
- * mirrored into the sandbox preview by scripts/sync-templates.js). Those paths
191
- * only resolve inside the Astryx docsite/sandbox, so on scaffold they're
192
- * replaced — a scaffolded project has no `/template-assets/` dir and would
193
- * otherwise 404. Genuine third-party URLs (e.g. brand logos from
194
- * paypalobjects.com) are intentionally left untouched.
195
- *
196
- * @type {RegExp}
193
+ * mirrored into the sandbox preview by scripts/sync-templates.js), so those
194
+ * paths only resolve inside the Astryx docsite/sandbox and are replaced on
195
+ * scaffold. Only a root-relative URL whose first segment this is counts: the
196
+ * same text inside a third-party URL or a product path is left untouched.
197
197
  */
198
- const DEMO_ASSET_PATTERN = /\/template-assets\/[\w.-]+\.(\w+)/g;
198
+ const FIXTURE_SEGMENT = 'template-assets';
199
+
200
+ /** Characters that end a URL token in template source, besides whitespace. */
201
+ const TOKEN_DELIMITERS = new Set([
202
+ "'",
203
+ '"',
204
+ '`',
205
+ '(',
206
+ ')',
207
+ '<',
208
+ '>',
209
+ '{',
210
+ '}',
211
+ '[',
212
+ ']',
213
+ '\\',
214
+ '|',
215
+ '^',
216
+ ]);
217
+
218
+ /** The closing delimiter each opening delimiter must pair with. */
219
+ const CLOSING_DELIMITERS = new Map([
220
+ ["'", "'"],
221
+ ['"', '"'],
222
+ ['`', '`'],
223
+ ['(', ')'],
224
+ ]);
225
+ const CLOSERS = new Set(CLOSING_DELIMITERS.values());
226
+
227
+ /** A URL with a scheme: absolute, so never a fixture reference. */
228
+ const ABSOLUTE_URL = /^[a-z][a-z\d+.-]*:/iu;
229
+
230
+ /** What may lead up to the fixture segment inside a relative product path. */
231
+ const RELATIVE_PATH_PREFIX = /^[\w.~%@/-]+$/u;
232
+
233
+ /** Punctuation that ends a sentence or list item after a path in text. */
234
+ const PROSE_PUNCTUATION = new Set(['.', ',', ';', ':', '!', '?']);
235
+
236
+ /** `from`, `import` or `require` right before a quoted module specifier. */
237
+ const MODULE_SPECIFIER_LEAD = /(?:^|[^\w$])(?:from|import|require)\s*\(?$/u;
199
238
 
200
239
  /**
201
240
  * Normalize path into Unix path (using forward slashes) for consistent comparison
@@ -209,26 +248,246 @@ function toPosixPath(p) {
209
248
  }
210
249
 
211
250
  /**
212
- * Replace demo asset references with a placeholder so scaffolded pages
213
- * render with zero setup. Images get a self-contained data URI; videos
214
- * (which have no equivalent inline placeholder — see VIDEO_EXTENSIONS) are
215
- * stripped to an empty src instead of being mis-replaced with image data.
216
- * Builders drop in their own media either way.
251
+ * Replace each Astryx template fixture reference with a placeholder so
252
+ * scaffolded pages render with zero setup. Images get a self-contained data
253
+ * URI; videos (which have no equivalent inline placeholder — see
254
+ * VIDEO_EXTENSIONS) are stripped to an empty src instead of being
255
+ * mis-replaced with image data. Builders drop in their own media either way.
256
+ *
257
+ * A reference is a URL token that resolves to a root-relative path under
258
+ * FIXTURE_SEGMENT. It is replaced whole, query and fragment included, and
259
+ * classified by the suffix of its last path segment. A reference that cannot
260
+ * be replaced safely throws with its path rather than being guessed at or
261
+ * left behind. Prose is left as written: in text (JSX text, a word inside a
262
+ * longer string) trailing punctuation is not part of a path and a path with
263
+ * no suffix, such as the bare directory, is a mention; inside a comment
264
+ * nothing throws.
217
265
  *
218
266
  * @param {string} source - Template source code.
219
267
  * @returns {string} Source with demo asset references replaced.
220
268
  */
221
269
  export function stripTemplateAssetRefs(source) {
222
- return source.replace(DEMO_ASSET_PATTERN, (match, extension) => {
223
- const ext = extension.toLowerCase();
224
- if (VIDEO_EXTENSIONS.has(ext)) {
225
- return '';
270
+ const needle = `/${FIXTURE_SEGMENT}`;
271
+ let output = '';
272
+ let copied = 0;
273
+ /** @type {Array<[number, number]> | undefined} */
274
+ let comments;
275
+ let at = source.indexOf(needle);
276
+ while (at !== -1) {
277
+ let start = at;
278
+ while (start > 0 && !isTokenDelimiter(source[start - 1])) start--;
279
+ let end = at + needle.length;
280
+ while (end < source.length && !isTokenDelimiter(source[end])) end++;
281
+ /** @type {{text: string, end: number} | null} */
282
+ let edit;
283
+ try {
284
+ edit = fixtureEdit(source, start, at, end);
285
+ } catch (err) {
286
+ comments ??= commentRanges(source);
287
+ if (!comments.some(([from, to]) => from <= at && at < to)) throw err;
288
+ edit = null;
226
289
  }
227
- if (IMAGE_EXTENSIONS.has(ext)) {
228
- return PLACEHOLDER_IMAGE;
290
+ if (edit) {
291
+ output += source.slice(copied, start) + edit.text;
292
+ copied = edit.end;
229
293
  }
230
- throw new Error(`Unrecognized template asset format ${ext} for ${match}`);
231
- });
294
+ at = source.indexOf(needle, end);
295
+ }
296
+ return output + source.slice(copied);
297
+ }
298
+
299
+ /** @param {string | undefined} char */
300
+ function isTokenDelimiter(char) {
301
+ return char === undefined || /\s/u.test(char) || TOKEN_DELIMITERS.has(char);
302
+ }
303
+
304
+ /**
305
+ * Whitespace, the source edge, or a tag bracket: what bounds a word of text.
306
+ * @param {string | undefined} char
307
+ */
308
+ function isTextDelimiter(char) {
309
+ return char === undefined || /\s/u.test(char) || char === '<' || char === '>';
310
+ }
311
+
312
+ /**
313
+ * The path segments of a root-relative URL under FIXTURE_SEGMENT, or null.
314
+ * @param {string} reference
315
+ * @returns {string[] | null}
316
+ */
317
+ function fixtureSegments(reference) {
318
+ if (!reference.startsWith('/') || reference.startsWith('//')) return null;
319
+ const segments = new URL(reference, 'http://template.invalid').pathname.split(
320
+ '/',
321
+ );
322
+ return segments[1] === FIXTURE_SEGMENT ? segments : null;
323
+ }
324
+
325
+ /**
326
+ * The replacement for the fixture reference in the URL token [start, end),
327
+ * which contains FIXTURE_SEGMENT's path at `at`; null when the token is not a
328
+ * fixture reference or is a prose mention.
329
+ * @param {string} source
330
+ * @param {number} start
331
+ * @param {number} at
332
+ * @param {number} end
333
+ * @returns {{text: string, end: number} | null}
334
+ */
335
+ function fixtureEdit(source, start, at, end) {
336
+ const token = source.slice(start, end);
337
+ if (ABSOLUTE_URL.test(token)) return null;
338
+ if (!token.startsWith('/')) {
339
+ if (!fixtureSegments(source.slice(at, end))) return null;
340
+ if (
341
+ source[start - 1] !== '\\' &&
342
+ RELATIVE_PATH_PREFIX.test(source.slice(start, at))
343
+ ) {
344
+ return null;
345
+ }
346
+ throw unsafeFixtureReference(
347
+ source,
348
+ at,
349
+ 'it is joined to text the copy cannot parse',
350
+ );
351
+ }
352
+
353
+ const before = source[start - 1];
354
+ const after = source[end];
355
+ if (after === '{' && token.endsWith('$')) {
356
+ if (!fixtureSegments(token.slice(0, -1))) return null;
357
+ throw unsafeFixtureReference(
358
+ source,
359
+ at,
360
+ 'it is built by a template-literal interpolation',
361
+ );
362
+ }
363
+ const quoted =
364
+ before !== undefined && CLOSING_DELIMITERS.get(before) === after;
365
+ const escapedQuoted =
366
+ (before === "'" || before === '"') &&
367
+ source[start - 2] === '\\' &&
368
+ after === '\\' &&
369
+ source[end + 1] === before;
370
+ const whole = quoted || escapedQuoted;
371
+ let referenceEnd = end;
372
+ if (!whole) {
373
+ while (
374
+ referenceEnd > at &&
375
+ PROSE_PUNCTUATION.has(source[referenceEnd - 1])
376
+ ) {
377
+ referenceEnd--;
378
+ }
379
+ }
380
+ const segments = fixtureSegments(source.slice(start, referenceEnd));
381
+ if (!segments) return null;
382
+
383
+ const inText =
384
+ (isTextDelimiter(before) || CLOSING_DELIMITERS.has(before)) &&
385
+ (isTextDelimiter(after) || CLOSERS.has(after)) &&
386
+ (isTextDelimiter(before) || isTextDelimiter(after));
387
+ if (!whole && !inText) {
388
+ throw unsafeFixtureReference(
389
+ source,
390
+ at,
391
+ 'it is not a whole quoted, url(), or text value',
392
+ );
393
+ }
394
+ if (quoted && before !== '(') {
395
+ const use = expressionUse(source, start - 1, end);
396
+ if (use) throw unsafeFixtureReference(source, at, use);
397
+ }
398
+
399
+ const ext = path.posix
400
+ .extname(segments[segments.length - 1])
401
+ .slice(1)
402
+ .toLowerCase();
403
+ if (VIDEO_EXTENSIONS.has(ext)) return {text: '', end: referenceEnd};
404
+ if (IMAGE_EXTENSIONS.has(ext)) {
405
+ return {text: PLACEHOLDER_IMAGE, end: referenceEnd};
406
+ }
407
+ if (whole || ext) {
408
+ throw new Error(
409
+ `Unrecognized template asset format ${ext || '(none)'} for ${displayReference(source, at)}`,
410
+ );
411
+ }
412
+ return null;
413
+ }
414
+
415
+ /**
416
+ * Why the string quoted at `open` and `close` cannot be replaced on its own,
417
+ * or null when it is a plain value.
418
+ * @param {string} source
419
+ * @param {number} open
420
+ * @param {number} close
421
+ * @returns {string | null}
422
+ */
423
+ function expressionUse(source, open, close) {
424
+ let prev = open - 1;
425
+ while (prev >= 0 && /\s/u.test(source[prev])) prev--;
426
+ let next = close + 1;
427
+ while (next < source.length && /\s/u.test(source[next])) next++;
428
+ if (
429
+ source[prev] === '+' ||
430
+ (source[prev] === '=' && source[prev - 1] === '+') ||
431
+ source[next] === '+'
432
+ ) {
433
+ return 'the string is concatenated with another value';
434
+ }
435
+ if (source[next] === '.' && /[A-Za-z_$]/u.test(source[next + 1] ?? '')) {
436
+ return 'a method is called on the string';
437
+ }
438
+ if (
439
+ MODULE_SPECIFIER_LEAD.test(source.slice(Math.max(0, prev - 16), prev + 1))
440
+ ) {
441
+ return 'it is imported as a module';
442
+ }
443
+ return null;
444
+ }
445
+
446
+ /**
447
+ * The [start, end) range of every comment in `source`, or none when it does
448
+ * not parse as TSX.
449
+ * @param {string} source
450
+ * @returns {Array<[number, number]>}
451
+ */
452
+ function commentRanges(source) {
453
+ try {
454
+ const {parse} = require('@babel/parser');
455
+ const {comments} = parse(source, {
456
+ sourceType: 'module',
457
+ plugins: ['jsx', 'typescript'],
458
+ });
459
+ return (comments ?? []).map(
460
+ comment =>
461
+ /** @type {[number, number]} */ ([
462
+ comment.start ?? 0,
463
+ comment.end ?? 0,
464
+ ]),
465
+ );
466
+ } catch {
467
+ return [];
468
+ }
469
+ }
470
+
471
+ /**
472
+ * The fixture path at `at`, up to the next whitespace, quote, or tag bracket.
473
+ * @param {string} source
474
+ * @param {number} at
475
+ */
476
+ function displayReference(source, at) {
477
+ let end = at;
478
+ while (end < source.length && !/[\s'"`<>]/u.test(source[end])) end++;
479
+ return source.slice(at, end);
480
+ }
481
+
482
+ /**
483
+ * @param {string} source
484
+ * @param {number} at
485
+ * @param {string} reason
486
+ */
487
+ function unsafeFixtureReference(source, at, reason) {
488
+ return new Error(
489
+ `Template asset reference ${displayReference(source, at)} cannot be replaced safely: ${reason}. Use the complete path as one static string.`,
490
+ );
232
491
  }
233
492
  /**
234
493
  * Load a template-spec module and return its metadata object. Supports both
@@ -545,9 +804,17 @@ async function discoverIntegrationTemplates(cwd = process.cwd()) {
545
804
  }
546
805
 
547
806
  for (const integration of loadedIntegrations) {
548
- const result = await discoverIntegrationTemplatesForOne(integration);
549
- templates.push(...result.templates);
550
- errors.push(...result.errors);
807
+ // One integration's unreadable root must not cost core or the others theirs.
808
+ try {
809
+ const result = await discoverIntegrationTemplatesForOne(integration);
810
+ templates.push(...result.templates);
811
+ errors.push(...result.errors);
812
+ } catch (err) {
813
+ errors.push({
814
+ package: integration?.name ?? integration?.__spec ?? 'integration',
815
+ message: err instanceof Error ? err.message : String(err),
816
+ });
817
+ }
551
818
  }
552
819
 
553
820
  return {templates, errors};
@@ -265,14 +265,18 @@ describe('collectThemingTargets', () => {
265
265
  expect(doc.subComponentOf).toBe('Dialog');
266
266
  expect(doc.theming.targets).toEqual([
267
267
  {className: 'astryx-dialog-header'},
268
+ {className: 'astryx-dialog-header-start-content'},
268
269
  {className: 'astryx-dialog-header-title-block'},
270
+ {className: 'astryx-dialog-header-end-content'},
269
271
  {className: 'astryx-dialog-header-close-icon'},
270
272
  ]);
271
273
  });
272
274
 
273
275
  it.each([
274
276
  'dialog-header',
277
+ 'dialog-header-start-content',
275
278
  'dialog-header-title-block',
279
+ 'dialog-header-end-content',
276
280
  'dialog-header-close-icon',
277
281
  ])('enumerates %s once under its canonical Dialog owner', async key => {
278
282
  const matches = (await enumerated).filter(target => target.key === key);
@@ -0,0 +1,162 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * One authored file, as discovery loaded it.
6
+ * @typedef {object} AuthoredFile
7
+ * @property {string} file the file's name, for messages only
8
+ * @property {any} [doc] the parsed doc, when it loaded
9
+ * @property {unknown} [error] why it did not load or parse
10
+ * @property {any} [overlay] the language overlay's export, when one applies
11
+ * @property {unknown} [overlayError] why the overlay did not load
12
+ */
13
+ /**
14
+ * @typedef {object} ReferenceTopicInput
15
+ * @property {string} id the topic's name in the catalog
16
+ * @property {string} provider the package that owns the topic
17
+ * @property {string | null} replaces the topic it took the place of
18
+ * @property {string | null} lang the overlay language, or null for authored text
19
+ * @property {AuthoredFile} base
20
+ * @property {Array<AuthoredFile & {provider: string}>} extensions in merge order
21
+ */
22
+ /**
23
+ * A token reference after linking: the target section's content, or why it
24
+ * has none.
25
+ * @typedef {{status: 'resolved', topic: string, section: string, previewType?: string, content: any[]}
26
+ * | {status: 'unknown-topic'}
27
+ * | {status: 'unknown-section'}} TokenRefResolution
28
+ */
29
+ /**
30
+ * @typedef {object} CompiledReferenceNode
31
+ * @property {number} schemaVersion
32
+ * @property {'reference'} kind
33
+ * @property {'lowered' | 'linked'} stage `linked` once every token reference
34
+ * carries its resolution; a lowered node carries none
35
+ * @property {string} id the topic's name in the catalog
36
+ * @property {string | null} lang
37
+ * @property {{provider: string, replaces: string | null, extensions: string[]}} provenance
38
+ * @property {Record<string, string>} sourceTitles section key -> authored title
39
+ * @property {any} doc the topic: authored fields in authored order, every
40
+ * section keyed; a linked node's token references carry `resolved`
41
+ */
42
+ /**
43
+ * Lower one topic: overlay each file, merge the extensions in order, and stamp
44
+ * every section with its key.
45
+ * @param {ReferenceTopicInput} input
46
+ * @returns {CompiledReferenceNode}
47
+ */
48
+ export function lowerReferenceTopic(input: ReferenceTopicInput): CompiledReferenceNode;
49
+ /**
50
+ * Link every section of a lowered node.
51
+ * @param {CompiledReferenceNode} node
52
+ * @param {(topic: string) => Promise<CompiledReferenceNode | null>} lowerTarget
53
+ * the lowered node a reference names, or null when no topic has that name
54
+ * @returns {Promise<CompiledReferenceNode>}
55
+ */
56
+ export function linkReferenceTopic(node: CompiledReferenceNode, lowerTarget: (topic: string) => Promise<CompiledReferenceNode | null>): Promise<CompiledReferenceNode>;
57
+ /**
58
+ * Resolve the token references in one section. A section with none comes back
59
+ * as it went in.
60
+ * @template {{content: any[]}} S
61
+ * @param {S} section
62
+ * @param {(topic: string) => Promise<CompiledReferenceNode | null>} lowerTarget
63
+ * @returns {Promise<S>}
64
+ */
65
+ export function linkReferenceSection<S extends {
66
+ content: any[];
67
+ }>(section: S, lowerTarget: (topic: string) => Promise<CompiledReferenceNode | null>): Promise<S>;
68
+ /** Bumped whenever the shape of a compiled node changes. */
69
+ export const COMPILED_DOC_SCHEMA_VERSION: 1;
70
+ /**
71
+ * One authored file, as discovery loaded it.
72
+ */
73
+ export type AuthoredFile = {
74
+ /**
75
+ * the file's name, for messages only
76
+ */
77
+ file: string;
78
+ /**
79
+ * the parsed doc, when it loaded
80
+ */
81
+ doc?: any;
82
+ /**
83
+ * why it did not load or parse
84
+ */
85
+ error?: unknown;
86
+ /**
87
+ * the language overlay's export, when one applies
88
+ */
89
+ overlay?: any;
90
+ /**
91
+ * why the overlay did not load
92
+ */
93
+ overlayError?: unknown;
94
+ };
95
+ export type ReferenceTopicInput = {
96
+ /**
97
+ * the topic's name in the catalog
98
+ */
99
+ id: string;
100
+ /**
101
+ * the package that owns the topic
102
+ */
103
+ provider: string;
104
+ /**
105
+ * the topic it took the place of
106
+ */
107
+ replaces: string | null;
108
+ /**
109
+ * the overlay language, or null for authored text
110
+ */
111
+ lang: string | null;
112
+ base: AuthoredFile;
113
+ /**
114
+ * in merge order
115
+ */
116
+ extensions: Array<AuthoredFile & {
117
+ provider: string;
118
+ }>;
119
+ };
120
+ /**
121
+ * A token reference after linking: the target section's content, or why it
122
+ * has none.
123
+ */
124
+ export type TokenRefResolution = {
125
+ status: "resolved";
126
+ topic: string;
127
+ section: string;
128
+ previewType?: string;
129
+ content: any[];
130
+ } | {
131
+ status: "unknown-topic";
132
+ } | {
133
+ status: "unknown-section";
134
+ };
135
+ export type CompiledReferenceNode = {
136
+ schemaVersion: number;
137
+ kind: "reference";
138
+ /**
139
+ * `linked` once every token reference
140
+ * carries its resolution; a lowered node carries none
141
+ */
142
+ stage: "lowered" | "linked";
143
+ /**
144
+ * the topic's name in the catalog
145
+ */
146
+ id: string;
147
+ lang: string | null;
148
+ provenance: {
149
+ provider: string;
150
+ replaces: string | null;
151
+ extensions: string[];
152
+ };
153
+ /**
154
+ * section key -> authored title
155
+ */
156
+ sourceTitles: Record<string, string>;
157
+ /**
158
+ * the topic: authored fields in authored order, every
159
+ * section keyed; a linked node's token references carry `resolved`
160
+ */
161
+ doc: any;
162
+ };