@astryxdesign/cli 0.7.14 → 0.7.15-canary.g061b2fa

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 (164) hide show
  1. package/README.md +63 -63
  2. package/api/build/_adapter.d.mts +4 -0
  3. package/api/build/_adapter.mjs +28 -2
  4. package/api/build/blocks/blocks.d.mts +10 -1
  5. package/api/build/blocks/blocks.mjs +84 -7
  6. package/api/build/build.mjs +6 -1
  7. package/api/build/tree.d.mts +4 -0
  8. package/api/build/tree.mjs +9 -2
  9. package/api/doctor/_adapter.d.mts +3 -1
  10. package/api/doctor/_adapter.mjs +14 -1
  11. package/api/doctor/_authoring-audit.d.mts +42 -0
  12. package/api/doctor/_authoring-audit.mjs +106 -0
  13. package/api/doctor/doctor.d.mts +7 -0
  14. package/api/doctor/doctor.mjs +24 -39
  15. package/api/doctor/theme-checks.mjs +56 -21
  16. package/api/integration/validate-integration.mjs +17 -3
  17. package/api/integration/validateIntegration.doc.mjs +1 -1
  18. package/api/search/_adapter.mjs +124 -3
  19. package/api/search/_candidate-score.mjs +63 -9
  20. package/api/search/_entries.d.mts +10 -0
  21. package/api/search/_entries.mjs +68 -1
  22. package/api/search/_gather-templates.d.mts +11 -0
  23. package/api/search/_gather-templates.mjs +22 -2
  24. package/api/search/_words.mjs +26 -6
  25. package/api/swizzle/copy/copy.mjs +1 -1
  26. package/api/theme/_adapter.d.mts +17 -1
  27. package/api/theme/_adapter.mjs +185 -40
  28. package/api/theme/build/build.d.mts +29 -1
  29. package/api/theme/build/build.mjs +426 -65
  30. package/api/theme/eject/eject.mjs +10 -6
  31. package/api/theme/targets/targets.d.mts +8 -0
  32. package/api/theme/targets/targets.mjs +24 -4
  33. package/api/theme/template/template.mjs +48 -2
  34. package/api/theme/theme.type.d.mts +8 -0
  35. package/api/theme/theme.type.mjs +5 -1
  36. package/api/theme/themeBuild.doc.mjs +7 -4
  37. package/api/theme/themeEject.doc.mjs +3 -3
  38. package/api/theme/themeRemove.doc.mjs +5 -2
  39. package/api/theme/themeTargets.doc.mjs +1 -1
  40. package/api/theme/themeTemplate.doc.mjs +2 -2
  41. package/api/theme/themeUse.doc.mjs +8 -2
  42. package/api/theme-edit/_adapter.d.mts +46 -3
  43. package/api/theme-edit/_adapter.mjs +372 -109
  44. package/api/theme-edit/_check.d.mts +6 -3
  45. package/api/theme-edit/_check.mjs +665 -87
  46. package/api/theme-edit/_color.mjs +4 -2
  47. package/api/theme-edit/_compiler.d.mts +2 -1
  48. package/api/theme-edit/_compiler.mjs +27 -13
  49. package/api/theme-edit/_context.d.mts +2 -1
  50. package/api/theme-edit/_context.mjs +47 -8
  51. package/api/theme-edit/_edit.d.mts +9 -3
  52. package/api/theme-edit/_edit.mjs +484 -66
  53. package/api/theme-edit/_how-commands.d.mts +33 -7
  54. package/api/theme-edit/_how-commands.mjs +57 -45
  55. package/api/theme-edit/_how-question.d.mts +4 -0
  56. package/api/theme-edit/_how-question.mjs +1004 -223
  57. package/api/theme-edit/_how.mjs +96 -9
  58. package/api/theme-edit/_palette.d.mts +38 -13
  59. package/api/theme-edit/_palette.mjs +620 -223
  60. package/api/theme-edit/_parts.mjs +63 -7
  61. package/api/theme-edit/_png.d.mts +4 -4
  62. package/api/theme-edit/_png.mjs +4 -2
  63. package/api/theme-edit/_preview-app.d.mts +6 -0
  64. package/api/theme-edit/_preview-app.mjs +1194 -207
  65. package/api/theme-edit/_preview.mjs +2 -2
  66. package/api/theme-edit/_project.d.mts +12 -1
  67. package/api/theme-edit/_project.mjs +37 -6
  68. package/api/theme-edit/_settings.d.mts +104 -33
  69. package/api/theme-edit/_settings.mjs +818 -118
  70. package/api/theme-edit/_tables.d.mts +7 -0
  71. package/api/theme-edit/_tables.mjs +61 -0
  72. package/api/theme-edit/theme-edit.type.d.mts +11 -1
  73. package/api/theme-edit/theme-edit.type.mjs +4 -3
  74. package/api/theme-edit/themeEditHow.doc.mjs +6 -0
  75. package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
  76. package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
  77. package/api/theme-edit/themeEditPreviewList.doc.mjs +1 -1
  78. package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
  79. package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
  80. package/api/upgrade/_adapter.d.mts +1 -0
  81. package/assets/codemods/run-codemod.mjs +61 -0
  82. package/assets/codemods/runner.mjs +5 -4
  83. package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
  84. package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
  85. package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
  86. package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
  87. package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
  88. package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
  89. package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
  90. package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
  91. package/assets/docs/tree/calendars.doc.mjs +1 -3
  92. package/assets/docs/tree/checks.doc.mjs +22 -1
  93. package/assets/docs.generated.json +2 -1
  94. package/assets/self-audit.generated.json +1 -0
  95. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
  96. package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
  97. package/assets/templates/components.generated.json +1 -1
  98. package/authoring/integration/integration.doc.mjs +8 -0
  99. package/authoring/integration/schema.d.mts +8 -0
  100. package/authoring/integration/schema.mjs +1 -0
  101. package/authoring/integration/type.ts +9 -0
  102. package/clients/cli/bin/astryx.mjs +19 -15
  103. package/clients/cli/build-id.generated.json +1 -0
  104. package/clients/cli/commands/ensure-core-built.mjs +12 -5
  105. package/clients/cli/commands/experimental/theme.mjs +178 -78
  106. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  107. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
  108. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
  109. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  110. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
  111. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  112. package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
  113. package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
  114. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  115. package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
  116. package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
  117. package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
  118. package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
  119. package/clients/cli/commands/manifest.mjs +5 -2
  120. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  121. package/clients/cli/commands/theme-list.doc.mjs +1 -1
  122. package/clients/cli/commands/theme-template.doc.mjs +1 -1
  123. package/clients/cli/commands/theme.mjs +374 -42
  124. package/clients/cli/index.mjs +9 -3
  125. package/clients/cli/lib/manifest.mjs +37 -0
  126. package/clients/cli/lib/resolve-theme.mjs +2 -1
  127. package/clients/cli/manifest.generated.json +1 -0
  128. package/foundation/config/theme-state.d.mts +16 -0
  129. package/foundation/config/theme-state.mjs +84 -13
  130. package/foundation/discovery/module-exports.mjs +16 -2
  131. package/foundation/discovery/stored-self-audit.d.mts +31 -0
  132. package/foundation/discovery/stored-self-audit.mjs +119 -0
  133. package/foundation/discovery/template-adapter.d.mts +48 -2
  134. package/foundation/discovery/template-adapter.mjs +51 -19
  135. package/foundation/discovery/template-needs.d.mts +19 -0
  136. package/foundation/discovery/template-needs.mjs +50 -16
  137. package/foundation/discovery/template-source-tree.d.mts +7 -0
  138. package/foundation/discovery/template-source-tree.mjs +15 -0
  139. package/foundation/discovery/theme-discovery.d.mts +2 -1
  140. package/foundation/discovery/theme-discovery.mjs +2 -8
  141. package/foundation/discovery/theme-module-extensions.d.mts +18 -0
  142. package/foundation/discovery/theme-module-extensions.mjs +30 -0
  143. package/foundation/doc-compiler/import.mjs +22 -15
  144. package/foundation/doc-compiler/stored-docs.d.mts +18 -12
  145. package/foundation/doc-compiler/stored-docs.mjs +52 -19
  146. package/foundation/env/private-dir.d.mts +17 -0
  147. package/foundation/env/private-dir.mjs +42 -0
  148. package/foundation/fs/gather-cache.d.mts +108 -0
  149. package/foundation/fs/gather-cache.mjs +741 -0
  150. package/foundation/fs/jiti-cache.d.mts +21 -0
  151. package/foundation/fs/jiti-cache.mjs +66 -0
  152. package/foundation/fs/module-loader.mjs +14 -3
  153. package/foundation/fs/read-record.d.mts +31 -1
  154. package/foundation/fs/read-record.mjs +100 -7
  155. package/foundation/integrations/integrations.d.mts +8 -0
  156. package/foundation/integrations/integrations.mjs +4 -0
  157. package/foundation/integrations/validate-contributions.d.mts +62 -1
  158. package/foundation/integrations/validate-contributions.mjs +476 -40
  159. package/foundation/release/cache.d.mts +11 -2
  160. package/foundation/release/cache.mjs +59 -10
  161. package/foundation/release/folder-lock.d.mts +21 -0
  162. package/foundation/release/folder-lock.mjs +171 -0
  163. package/foundation/response/response-types.doc.mjs +1 -1
  164. package/package.json +8 -6
@@ -19,7 +19,7 @@
19
19
 
20
20
  import * as fs from 'node:fs';
21
21
  import * as path from 'node:path';
22
- import {parse} from '@babel/parser';
22
+ import {createRequire} from 'node:module';
23
23
  import {findInstalledPackage} from '../fs/paths.mjs';
24
24
  import {inspectPackageExport} from './package-exports.mjs';
25
25
 
@@ -103,12 +103,26 @@ function moduleText(file) {
103
103
  return text;
104
104
  }
105
105
 
106
+ const requireFromHere = createRequire(import.meta.url);
107
+ /** @type {typeof import('@babel/parser') | undefined} */
108
+ let parser;
109
+
110
+ /**
111
+ * @babel/parser, loaded on first use: a run that reads no module's exports
112
+ * never loads it.
113
+ * @returns {typeof import('@babel/parser')}
114
+ */
115
+ function babelParser() {
116
+ parser ??= requireFromHere('@babel/parser');
117
+ return /** @type {typeof import('@babel/parser')} */ (parser);
118
+ }
119
+
106
120
  /** @param {string} file */
107
121
  function parseModule(file) {
108
122
  const stamp = fileStamp(file);
109
123
  const cached = parsedModules.get(file);
110
124
  if (cached?.stamp === stamp) return cached.ast;
111
- const ast = parse(moduleText(file), PARSE_OPTIONS);
125
+ const ast = babelParser().parse(moduleText(file), PARSE_OPTIONS);
112
126
  parsedModules.set(file, {stamp, ast});
113
127
  return ast;
114
128
  }
@@ -0,0 +1,31 @@
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
+ * A file's or folder's state as an audit read it: a file by its content
6
+ * (package.json by its packer-stable fields), a folder by the names it holds
7
+ * (but PACKING_NAMES), `-` when absent.
8
+ * @param {string} file
9
+ * @returns {string}
10
+ */
11
+ export function inputState(file: string): string;
12
+ /**
13
+ * The inputs an audit read, by path in the package, with their state. Code
14
+ * in node_modules is the package's dependencies, not its own files.
15
+ * Paths outside the package are where it runs (the package manager is found
16
+ * from the working folder, to spell commands in rendered docs); the
17
+ * generator proves the audit's answer is the same wherever it runs, so they
18
+ * are not inputs.
19
+ * @param {Iterable<string>} files every path the audit read
20
+ * @returns {Record<string, string>}
21
+ */
22
+ export function selfAuditInputs(files: Iterable<string>): Record<string, string>;
23
+ /**
24
+ * The stored value of the audit `name`, while every file and folder it read
25
+ * is unchanged, else undefined.
26
+ * @param {string} name
27
+ * @returns {unknown}
28
+ */
29
+ export function storedSelfAudit(name: string): unknown;
30
+ /** Where the stored audits are, in the published package. */
31
+ export const SELF_AUDIT_FILE: string;
@@ -0,0 +1,119 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file Doctor's audits of the CLI's own shipped files, stored at publish.
5
+ * @input assets/self-audit.generated.json, written at `prepack` by
6
+ * scripts/generate-self-audit.mjs: for each audit, the value it found and
7
+ * the state of every file and folder it read.
8
+ * @output `storedSelfAudit(name)`: the stored value while the package version
9
+ * and every doc, type file and folder the audit read are as they were when
10
+ * stored, else undefined (the caller audits as before). The audit's own code
11
+ * is the package's and is not checked again. A checkout has no file, so it
12
+ * always audits.
13
+ * @position Read by api/doctor/doctor.mjs. These audits read only the
14
+ * package's own files, so their answer is fixed until one of them changes.
15
+ */
16
+
17
+ import * as fs from 'node:fs';
18
+ import * as path from 'node:path';
19
+ import {CLI_ROOT} from '../fs/paths.mjs';
20
+ import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
21
+
22
+ /** Where the stored audits are, in the published package. */
23
+ export const SELF_AUDIT_FILE = path.join(
24
+ CLI_ROOT,
25
+ 'assets',
26
+ 'self-audit.generated.json',
27
+ );
28
+
29
+ /**
30
+ * Names a folder's state leaves out, being where and how the package is
31
+ * packed or installed rather than its content: what `prepack` writes (each
32
+ * `*.generated.json`, there or not depending on the order prepack writes
33
+ * in), dependencies placed inside it, and the files every packer adds to a
34
+ * package's root. No audit reads any of them.
35
+ */
36
+ const PACKING_NAMES =
37
+ /^(?:.*\.generated\.json|node_modules|(?:LICEN[CS]E|README|CHANGELOG|NOTICE)(?:\..*)?)$/i;
38
+
39
+ /** The package.json fields a packer leaves as written. */
40
+ const PACKAGE_FIELDS = [
41
+ 'name',
42
+ 'version',
43
+ 'type',
44
+ 'exports',
45
+ 'bin',
46
+ 'main',
47
+ 'types',
48
+ ];
49
+
50
+ /**
51
+ * A file's or folder's state as an audit read it: a file by its content
52
+ * (package.json by its packer-stable fields), a folder by the names it holds
53
+ * (but PACKING_NAMES), `-` when absent.
54
+ * @param {string} file
55
+ * @returns {string}
56
+ */
57
+ export function inputState(file) {
58
+ try {
59
+ if (fs.statSync(file).isDirectory()) {
60
+ const names = fs
61
+ .readdirSync(file)
62
+ .filter(name => !PACKING_NAMES.test(name))
63
+ .sort();
64
+ return `dir:${storedKey(names.join('\n'))}`;
65
+ }
66
+ if (path.basename(file) === 'package.json') {
67
+ // A packer rewrites package.json (pnpm resolves `catalog:` ranges and
68
+ // drops lifecycle scripts): only the fields that say what the package
69
+ // is and holds count.
70
+ const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
71
+ return `pkg:${storedKey(
72
+ JSON.stringify(PACKAGE_FIELDS.map(field => pkg[field] ?? null)),
73
+ )}`;
74
+ }
75
+ return storedKey(fs.readFileSync(file));
76
+ } catch {
77
+ return '-';
78
+ }
79
+ }
80
+
81
+ /**
82
+ * The inputs an audit read, by path in the package, with their state. Code
83
+ * in node_modules is the package's dependencies, not its own files.
84
+ * Paths outside the package are where it runs (the package manager is found
85
+ * from the working folder, to spell commands in rendered docs); the
86
+ * generator proves the audit's answer is the same wherever it runs, so they
87
+ * are not inputs.
88
+ * @param {Iterable<string>} files every path the audit read
89
+ * @returns {Record<string, string>}
90
+ */
91
+ export function selfAuditInputs(files) {
92
+ /** @type {Record<string, string>} */
93
+ const inputs = {};
94
+ for (const file of [...files].sort()) {
95
+ if (file.split(path.sep).includes('node_modules')) continue;
96
+ const rel = path.relative(CLI_ROOT, file);
97
+ if (rel.startsWith('..') || path.isAbsolute(rel)) continue;
98
+ inputs[rel.split(path.sep).join('/')] = inputState(file);
99
+ }
100
+ return inputs;
101
+ }
102
+
103
+ /**
104
+ * The stored value of the audit `name`, while every file and folder it read
105
+ * is unchanged, else undefined.
106
+ * @param {string} name
107
+ * @returns {unknown}
108
+ */
109
+ export function storedSelfAudit(name) {
110
+ /** @type {{inputs: Record<string, string>, value: unknown} | undefined} */
111
+ const entry = readStore(SELF_AUDIT_FILE).get(name);
112
+ if (!entry) return undefined;
113
+ for (const [rel, state] of Object.entries(entry.inputs)) {
114
+ if (inputState(path.join(CLI_ROOT, ...rel.split('/'))) !== state) {
115
+ return undefined;
116
+ }
117
+ }
118
+ return entry.value;
119
+ }
@@ -66,6 +66,33 @@ export function replaceDemoMedia(source: string, { videoPlaceholder }?: {
66
66
  source: string;
67
67
  demoMediaReplaced: number;
68
68
  };
69
+ /**
70
+ * One Astryx template fixture reference in template source.
71
+ * @typedef {object} FixtureRef
72
+ * @property {string} reference - The whole reference, query and fragment
73
+ * included.
74
+ * @property {'image' | 'video'} kind - What the suffix of its last path
75
+ * segment names.
76
+ * @property {boolean} isValue - Whether the reference is a whole quoted or
77
+ * `url()` value. False for a mention in text.
78
+ */
79
+ /**
80
+ * Replace each Astryx template fixture reference with what `map` returns for
81
+ * it. This is the one scanner for fixture references: a copy replaces them
82
+ * with placeholders ({@link replaceDemoMedia}), and the docsite's preview
83
+ * build points them at its image optimizer. It finds and refuses references
84
+ * as {@link stripTemplateAssetRefs} describes.
85
+ *
86
+ * @param {string} source - Template source code.
87
+ * @param {(ref: FixtureRef) => string | null} map - The replacement text, or
88
+ * null to keep the reference as written.
89
+ * @returns {{source: string, replaced: number}} `replaced` counts the
90
+ * references that `map` replaced.
91
+ */
92
+ export function mapFixtureRefs(source: string, map: (ref: FixtureRef) => string | null): {
93
+ source: string;
94
+ replaced: number;
95
+ };
69
96
  /**
70
97
  * Replace each JSX element imported from {@link DEMO_CONTENT_MODULE} with a
71
98
  * generic `<Text>` placeholder and remove that import, so emitted source never
@@ -273,8 +300,27 @@ export const MARKED_VIDEO_PLACEHOLDER: "data:,placeholder-video-add-your-own";
273
300
  * {@link replaceDemoContent}).
274
301
  */
275
302
  export const DEMO_CONTENT_MODULE: "@astryx-docs/demo-content";
276
- /** Where the component lists of the templates Astryx ships are stored. */
277
- export const TEMPLATE_COMPONENTS_FILE: string;
303
+ export { TEMPLATE_COMPONENTS_FILE } from "./template-source-tree.mjs";
304
+ /**
305
+ * One Astryx template fixture reference in template source.
306
+ */
307
+ export type FixtureRef = {
308
+ /**
309
+ * - The whole reference, query and fragment
310
+ * included.
311
+ */
312
+ reference: string;
313
+ /**
314
+ * - What the suffix of its last path
315
+ * segment names.
316
+ */
317
+ kind: "image" | "video";
318
+ /**
319
+ * - Whether the reference is a whole quoted or
320
+ * `url()` value. False for a mention in text.
321
+ */
322
+ isValue: boolean;
323
+ };
278
324
  /**
279
325
  * A discovered template (page or block), normalized across core, external, and
280
326
  * integration sources. Not every source populates every field, so
@@ -38,6 +38,7 @@ import {
38
38
  programPath,
39
39
  traverseTemplateSource,
40
40
  writtenNames,
41
+ TEMPLATE_COMPONENTS_FILE,
41
42
  } from './template-source-tree.mjs';
42
43
 
43
44
  const require = createRequire(import.meta.url);
@@ -358,10 +359,41 @@ export function stripTemplateAssetRefs(source) {
358
359
  * @returns {{source: string, demoMediaReplaced: number}}
359
360
  */
360
361
  export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
362
+ const {source: output, replaced} = mapFixtureRefs(source, ({kind}) =>
363
+ kind === 'video' ? videoPlaceholder : PLACEHOLDER_IMAGE,
364
+ );
365
+ return {source: output, demoMediaReplaced: replaced};
366
+ }
367
+
368
+ /**
369
+ * One Astryx template fixture reference in template source.
370
+ * @typedef {object} FixtureRef
371
+ * @property {string} reference - The whole reference, query and fragment
372
+ * included.
373
+ * @property {'image' | 'video'} kind - What the suffix of its last path
374
+ * segment names.
375
+ * @property {boolean} isValue - Whether the reference is a whole quoted or
376
+ * `url()` value. False for a mention in text.
377
+ */
378
+
379
+ /**
380
+ * Replace each Astryx template fixture reference with what `map` returns for
381
+ * it. This is the one scanner for fixture references: a copy replaces them
382
+ * with placeholders ({@link replaceDemoMedia}), and the docsite's preview
383
+ * build points them at its image optimizer. It finds and refuses references
384
+ * as {@link stripTemplateAssetRefs} describes.
385
+ *
386
+ * @param {string} source - Template source code.
387
+ * @param {(ref: FixtureRef) => string | null} map - The replacement text, or
388
+ * null to keep the reference as written.
389
+ * @returns {{source: string, replaced: number}} `replaced` counts the
390
+ * references that `map` replaced.
391
+ */
392
+ export function mapFixtureRefs(source, map) {
361
393
  const needle = `/${FIXTURE_SEGMENT}`;
362
394
  let output = '';
363
395
  let copied = 0;
364
- let demoMediaReplaced = 0;
396
+ let replaced = 0;
365
397
  /** @type {Array<[number, number]> | undefined} */
366
398
  let comments;
367
399
  let at = source.indexOf(needle);
@@ -373,7 +405,7 @@ export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
373
405
  /** @type {{text: string, end: number} | null} */
374
406
  let edit;
375
407
  try {
376
- edit = fixtureEdit(source, start, at, end, videoPlaceholder);
408
+ edit = fixtureEdit(source, start, at, end, map);
377
409
  } catch (err) {
378
410
  comments ??= commentRanges(source);
379
411
  if (!comments.some(([from, to]) => from <= at && at < to)) throw err;
@@ -382,11 +414,11 @@ export function replaceDemoMedia(source, {videoPlaceholder = ''} = {}) {
382
414
  if (edit) {
383
415
  output += source.slice(copied, start) + edit.text;
384
416
  copied = edit.end;
385
- demoMediaReplaced += 1;
417
+ replaced += 1;
386
418
  }
387
419
  at = source.indexOf(needle, end);
388
420
  }
389
- return {source: output + source.slice(copied), demoMediaReplaced};
421
+ return {source: output + source.slice(copied), replaced};
390
422
  }
391
423
 
392
424
  /**
@@ -911,15 +943,15 @@ function fixtureSegments(reference) {
911
943
  /**
912
944
  * The replacement for the fixture reference in the URL token [start, end),
913
945
  * which contains FIXTURE_SEGMENT's path at `at`; null when the token is not a
914
- * fixture reference or is a prose mention.
946
+ * fixture reference, is a prose mention, or `map` keeps it.
915
947
  * @param {string} source
916
948
  * @param {number} start
917
949
  * @param {number} at
918
950
  * @param {number} end
919
- * @param {string} videoPlaceholder
951
+ * @param {(ref: FixtureRef) => string | null} map
920
952
  * @returns {{text: string, end: number} | null}
921
953
  */
922
- function fixtureEdit(source, start, at, end, videoPlaceholder) {
954
+ function fixtureEdit(source, start, at, end, map) {
923
955
  const token = source.slice(start, end);
924
956
  if (ABSOLUTE_URL.test(token)) return null;
925
957
  if (!token.startsWith('/')) {
@@ -987,11 +1019,17 @@ function fixtureEdit(source, start, at, end, videoPlaceholder) {
987
1019
  .extname(segments[segments.length - 1])
988
1020
  .slice(1)
989
1021
  .toLowerCase();
990
- if (VIDEO_EXTENSIONS.has(ext)) {
991
- return {text: videoPlaceholder, end: referenceEnd};
992
- }
993
- if (IMAGE_EXTENSIONS.has(ext)) {
994
- return {text: PLACEHOLDER_IMAGE, end: referenceEnd};
1022
+ /** @type {FixtureRef['kind'] | null} */
1023
+ let kind = null;
1024
+ if (VIDEO_EXTENSIONS.has(ext)) kind = 'video';
1025
+ else if (IMAGE_EXTENSIONS.has(ext)) kind = 'image';
1026
+ if (kind) {
1027
+ const text = map({
1028
+ reference: source.slice(start, referenceEnd),
1029
+ kind,
1030
+ isValue: whole,
1031
+ });
1032
+ return text === null ? null : {text, end: referenceEnd};
995
1033
  }
996
1034
  if (whole || ext) {
997
1035
  throw new Error(
@@ -2109,13 +2147,7 @@ export function componentsInSource(src) {
2109
2147
  return parsedComponents(src);
2110
2148
  }
2111
2149
 
2112
- /** Where the component lists of the templates Astryx ships are stored. */
2113
- export const TEMPLATE_COMPONENTS_FILE = path.join(
2114
- CLI_ROOT,
2115
- 'assets',
2116
- 'templates',
2117
- 'components.generated.json',
2118
- );
2150
+ export {TEMPLATE_COMPONENTS_FILE} from './template-source-tree.mjs';
2119
2151
 
2120
2152
  /**
2121
2153
  * The components a template source composes, read from its syntax tree (see
@@ -16,6 +16,25 @@
16
16
  * `@scope/name`, unscoped to the first path segment).
17
17
  */
18
18
  export function extractImportedPackages(source: string): Set<string>;
19
+ /**
20
+ * moduleSpecifiers, read from the source's syntax tree.
21
+ * @param {string} source
22
+ * @returns {string[]}
23
+ */
24
+ export function parsedSpecifiers(source: string): string[];
25
+ /**
26
+ * The command that installs `packages` in the project at `cwd`, in its package
27
+ * manager and with the CLI workspace's version ranges. Null, with the reason,
28
+ * when several lockfiles leave the package manager undetermined; null with no
29
+ * reason when there is nothing to install.
30
+ * @param {string[]} packages
31
+ * @param {string} cwd
32
+ * @returns {{installCommand: string | null, noCommandReason: string | null}}
33
+ */
34
+ export function installCommandFor(packages: string[], cwd: string): {
35
+ installCommand: string | null;
36
+ noCommandReason: string | null;
37
+ };
19
38
  /**
20
39
  * Analyze what a template source needs that the target project lacks.
21
40
  *
@@ -18,7 +18,12 @@
18
18
  import * as fs from 'node:fs';
19
19
  import * as path from 'node:path';
20
20
  import module from 'node:module';
21
- import {parseTemplateSource, walk} from './template-source-tree.mjs';
21
+ import {
22
+ parseTemplateSource,
23
+ TEMPLATE_COMPONENTS_FILE,
24
+ walk,
25
+ } from './template-source-tree.mjs';
26
+ import {readStore, storedKey} from '../doc-compiler/stored-docs.mjs';
22
27
  import {CLI_ROOT, findWorkspaceRoot} from '../fs/paths.mjs';
23
28
  import {detectStylingSystem} from '../agent-docs/agent-docs.mjs';
24
29
  import {
@@ -81,6 +86,20 @@ export function extractImportedPackages(source) {
81
86
  * @returns {string[]}
82
87
  */
83
88
  function moduleSpecifiers(source) {
89
+ // A template Astryx ships answers from what parsing it returned at publish.
90
+ const stored = readStore(TEMPLATE_COMPONENTS_FILE).get(
91
+ `imports:${storedKey(source)}`,
92
+ );
93
+ if (Array.isArray(stored)) return [...stored];
94
+ return parsedSpecifiers(source);
95
+ }
96
+
97
+ /**
98
+ * moduleSpecifiers, read from the source's syntax tree.
99
+ * @param {string} source
100
+ * @returns {string[]}
101
+ */
102
+ export function parsedSpecifiers(source) {
84
103
  let file;
85
104
  try {
86
105
  file = parseTemplateSource(source, {errorRecovery: true});
@@ -226,6 +245,35 @@ function cliPackageRanges() {
226
245
  }
227
246
  }
228
247
 
248
+ /**
249
+ * The command that installs `packages` in the project at `cwd`, in its package
250
+ * manager and with the CLI workspace's version ranges. Null, with the reason,
251
+ * when several lockfiles leave the package manager undetermined; null with no
252
+ * reason when there is nothing to install.
253
+ * @param {string[]} packages
254
+ * @param {string} cwd
255
+ * @returns {{installCommand: string | null, noCommandReason: string | null}}
256
+ */
257
+ export function installCommandFor(packages, cwd) {
258
+ if (packages.length === 0) {
259
+ return {installCommand: null, noCommandReason: null};
260
+ }
261
+ const resolved = resolveInstallVerb(cwd);
262
+ const ranges = cliPackageRanges();
263
+ const specs = packages.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
264
+ if (resolved.verb !== null) {
265
+ return {
266
+ installCommand: `${resolved.verb} ${specs.join(' ')}`,
267
+ noCommandReason: null,
268
+ };
269
+ }
270
+ const where = path.relative(cwd, resolved.dir) || '.';
271
+ return {
272
+ installCommand: null,
273
+ noCommandReason: `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`,
274
+ };
275
+ }
276
+
229
277
  /**
230
278
  * Analyze what a template source needs that the target project lacks.
231
279
  *
@@ -266,21 +314,7 @@ export function analyzeTemplateNeeds(source, cwd) {
266
314
 
267
315
  const missing = external.filter(p => !(p in projectDeps));
268
316
 
269
- // Build the install command with version ranges from the CLI workspace.
270
- let installCommand = null;
271
- /** @type {string | null} */
272
- let noCommandReason = null;
273
- if (missing.length > 0) {
274
- const resolved = resolveInstallVerb(cwd);
275
- const ranges = cliPackageRanges();
276
- const specs = missing.map(p => (ranges[p] ? `${p}@"${ranges[p]}"` : p));
277
- if (resolved.verb !== null) {
278
- installCommand = `${resolved.verb} ${specs.join(' ')}`;
279
- } else {
280
- const where = path.relative(cwd, resolved.dir) || '.';
281
- noCommandReason = `Install missing dependencies: ${specs.join(' ')}. No install command: ${where} has ${resolved.lockfiles.join(' and ')}, and nothing there says which package manager to use.`;
282
- }
283
- }
317
+ const {installCommand, noCommandReason} = installCommandFor(missing, cwd);
284
318
 
285
319
  // ── StyleX compiler ────────────────────────────────────────────────────
286
320
  const usesStylex = imported.has(STYLEX_RUNTIME);
@@ -50,3 +50,10 @@ export function isReference(node: any, parent: any, key: string): any;
50
50
  * @returns {Set<string>}
51
51
  */
52
52
  export function writtenNames(file: any): Set<string>;
53
+ /**
54
+ * Where what parsing returns for each template Astryx ships is stored at
55
+ * publish (scripts/generate-template-components.mjs): its component list
56
+ * under its source's key, and the module specifiers it imports under
57
+ * `imports:` and that key.
58
+ */
59
+ export const TEMPLATE_COMPONENTS_FILE: string;
@@ -12,6 +12,21 @@
12
12
  */
13
13
 
14
14
  import {createRequire} from 'node:module';
15
+ import * as path from 'node:path';
16
+ import {CLI_ROOT} from '../fs/paths.mjs';
17
+
18
+ /**
19
+ * Where what parsing returns for each template Astryx ships is stored at
20
+ * publish (scripts/generate-template-components.mjs): its component list
21
+ * under its source's key, and the module specifiers it imports under
22
+ * `imports:` and that key.
23
+ */
24
+ export const TEMPLATE_COMPONENTS_FILE = path.join(
25
+ CLI_ROOT,
26
+ 'assets',
27
+ 'templates',
28
+ 'components.generated.json',
29
+ );
15
30
 
16
31
  const require = createRequire(import.meta.url);
17
32
 
@@ -147,7 +147,7 @@ export function discoverIntegrationThemes(integration: import("../integrations/i
147
147
  export const BUNDLED_THEME_PACKAGE: "@astryxdesign/cli";
148
148
  export const THEMES_DIR: string;
149
149
  export const THEME_DOC_SUFFIX: ".doc.mjs";
150
- export const THEME_MODULE_EXTENSIONS: string[];
150
+ export { THEME_MODULE_EXTENSIONS };
151
151
  /** A theme directory's name: lower-kebab, starting with a letter. */
152
152
  export const THEME_SLUG_RE: RegExp;
153
153
  export type DiscoveredTheme = {
@@ -196,3 +196,4 @@ export type UnmigratedThemeCopy = {
196
196
  exportName: string;
197
197
  descriptor: string;
198
198
  };
199
+ import { THEME_MODULE_EXTENSIONS } from './theme-module-extensions.mjs';
@@ -26,6 +26,7 @@ import {listDirEntries} from '../fs/listing-cache.mjs';
26
26
  import {formatCliCommand} from '../env/package-manager.mjs';
27
27
  import {LOCAL_THEME_ROOT} from '../config/theme-state.mjs';
28
28
  import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
29
+ import {THEME_MODULE_EXTENSIONS} from './theme-module-extensions.mjs';
29
30
 
30
31
  export const BUNDLED_THEME_PACKAGE = '@astryxdesign/cli';
31
32
  export const THEMES_DIR = path.join(CLI_ROOT, 'assets', 'templates', 'themes');
@@ -114,14 +115,7 @@ function resolveThemePath(value, root, label) {
114
115
  }
115
116
  }
116
117
 
117
- export const THEME_MODULE_EXTENSIONS = [
118
- '.mjs',
119
- '.js',
120
- '.mts',
121
- '.ts',
122
- '.tsx',
123
- '.jsx',
124
- ];
118
+ export {THEME_MODULE_EXTENSIONS};
125
119
 
126
120
  /** A theme directory's name: lower-kebab, starting with a letter. */
127
121
  export const THEME_SLUG_RE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
@@ -0,0 +1,18 @@
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
+ * @file The file extensions a theme source module can have.
6
+ *
7
+ * @input none
8
+ * @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
9
+ * @position read by theme discovery (which theme sources it accepts) and by
10
+ * `theme build` (which inputs it loads), so both accept the same files
11
+ */
12
+ /** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
13
+ export const THEME_MODULE_EXTENSIONS: string[];
14
+ /**
15
+ * The extensions `theme build` loads as a theme source: the discoverable ones,
16
+ * and their CommonJS forms, which a theme may also be written in.
17
+ */
18
+ export const THEME_SOURCE_EXTENSIONS: string[];
@@ -0,0 +1,30 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The file extensions a theme source module can have.
5
+ *
6
+ * @input none
7
+ * @output THEME_MODULE_EXTENSIONS and THEME_SOURCE_EXTENSIONS
8
+ * @position read by theme discovery (which theme sources it accepts) and by
9
+ * `theme build` (which inputs it loads), so both accept the same files
10
+ */
11
+
12
+ /** The extensions of a discoverable theme source, `<name>Theme.<ext>`. */
13
+ export const THEME_MODULE_EXTENSIONS = [
14
+ '.mjs',
15
+ '.js',
16
+ '.mts',
17
+ '.ts',
18
+ '.tsx',
19
+ '.jsx',
20
+ ];
21
+
22
+ /**
23
+ * The extensions `theme build` loads as a theme source: the discoverable ones,
24
+ * and their CommonJS forms, which a theme may also be written in.
25
+ */
26
+ export const THEME_SOURCE_EXTENSIONS = [
27
+ ...THEME_MODULE_EXTENSIONS,
28
+ '.cjs',
29
+ '.cts',
30
+ ];