@astryxdesign/cli 0.7.10 → 0.7.11-canary.9782dea

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 (66) hide show
  1. package/api/build/blocks/blocks.weights.json +1 -1
  2. package/api/build/build.doc.mjs +1 -1
  3. package/api/build/kit/signals.mjs +9 -3
  4. package/api/build/kit/start.d.mts +19 -0
  5. package/api/build/kit/start.mjs +49 -2
  6. package/api/build/kit/weights.d.mts +12 -0
  7. package/api/build/kit/weights.mjs +52 -16
  8. package/api/docs/_adapter.mjs +2 -1
  9. package/api/doctor/_adapter.d.mts +28 -1
  10. package/api/doctor/_adapter.mjs +39 -2
  11. package/api/doctor/doctor.doc.mjs +1 -1
  12. package/api/doctor/doctor.mjs +9 -2
  13. package/api/doctor/theme-checks.d.mts +44 -3
  14. package/api/doctor/theme-checks.mjs +273 -6
  15. package/api/hook/hook.mjs +13 -0
  16. package/api/integration/pack-check.d.mts +8 -6
  17. package/api/integration/pack-check.mjs +16 -6
  18. package/api/render/_adapter.mjs +47 -1
  19. package/api/render/render.doc.mjs +2 -1
  20. package/api/search/_gather-components.mjs +2 -1
  21. package/api/swizzle/copy/copy.mjs +5 -1
  22. package/api/theme/build/build.mjs +15 -4
  23. package/assets/docs/author-a-theme.doc.mjs +2 -0
  24. package/assets/docs/getting-started.doc.mjs +20 -0
  25. package/assets/docs/tree/building-blocks.doc.mjs +1 -0
  26. package/assets/docs/tree/global-integrations.doc.mjs +1 -0
  27. package/assets/docs/tree/help.doc.mjs +1 -1
  28. package/assets/docs/tree/quick-start.doc.mjs +1 -0
  29. package/assets/docs/tree/render-pages.doc.mjs +1 -1
  30. package/assets/docs/tree/ship.doc.mjs +1 -1
  31. package/assets/docs/tree/tokens-color.doc.mjs +2 -2
  32. package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.doc.mjs +15 -0
  33. package/assets/templates/blocks/components/Table/TableLeadingMarkSelection.tsx +134 -0
  34. package/authoring/doctypes/_schema.d.mts +1 -1
  35. package/clients/cli/commands/build.doc.mjs +3 -2
  36. package/clients/cli/commands/build.mjs +34 -5
  37. package/clients/cli/index.mjs +36 -7
  38. package/foundation/discovery/authoring-self-docs.mjs +8 -3
  39. package/foundation/discovery/cli-self-docs.mjs +2 -1
  40. package/foundation/discovery/component-discovery.mjs +16 -0
  41. package/foundation/discovery/docs-discovery.mjs +6 -4
  42. package/foundation/discovery/icon-definition-discovery.mjs +3 -3
  43. package/foundation/discovery/module-exports.d.mts +91 -4
  44. package/foundation/discovery/module-exports.mjs +316 -42
  45. package/foundation/discovery/template-adapter.mjs +5 -7
  46. package/foundation/discovery/theme-discovery.mjs +8 -10
  47. package/foundation/doc-compiler/tree.mjs +2 -2
  48. package/foundation/env/package-manager.d.mts +12 -4
  49. package/foundation/env/package-manager.mjs +15 -6
  50. package/foundation/env/semver.mjs +41 -9
  51. package/foundation/fs/listing-cache.d.mts +3 -1
  52. package/foundation/fs/listing-cache.mjs +63 -11
  53. package/foundation/fs/paths.mjs +2 -1
  54. package/foundation/release/notices.d.mts +16 -0
  55. package/foundation/release/notices.mjs +27 -6
  56. package/foundation/render/embedded-imports.d.mts +7 -0
  57. package/foundation/render/embedded-imports.mjs +1 -1
  58. package/foundation/render/page-worker.mjs +109 -4
  59. package/foundation/render/render-page.d.mts +16 -1
  60. package/foundation/render/render-page.mjs +25 -18
  61. package/foundation/render/served-packages.d.mts +33 -0
  62. package/foundation/render/served-packages.mjs +75 -0
  63. package/foundation/render/single-copy-hooks.d.mts +18 -0
  64. package/foundation/render/single-copy-hooks.mjs +44 -0
  65. package/foundation/text/string-utils.mjs +25 -25
  66. package/package.json +6 -6
@@ -1,6 +1,14 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The file a relative import names: the path itself, then each module
6
+ * extension, then a folder's index. Null for a bare specifier or no file.
7
+ * @param {unknown} specifier
8
+ * @param {string} fromFile absolute path of the importing file
9
+ * @returns {string|null}
10
+ */
11
+ export function resolveLocalModule(specifier: unknown, fromFile: string): string | null;
4
12
  /**
5
13
  * The first module, from `file` through its relative re-exports, that does
6
14
  * not parse, with the parser's message; null when every one parses.
@@ -43,6 +51,28 @@ export function moduleExportSource(file: string, exportName: string, seen?: Set<
43
51
  * @returns {string[] | null}
44
52
  */
45
53
  export function moduleExportNames(file: string): string[] | null;
54
+ /**
55
+ * Every export of a module with where it is declared, in one pass: the same
56
+ * answers as {@link moduleExportOrigin} for each name, read once per module.
57
+ * Pass one `memo` to calls that read the same package, so a module behind
58
+ * many barrels is read once; a memo keeps value and type reads apart, and
59
+ * nothing is kept between memos. One difference follows ESM where
60
+ * {@link moduleExportOrigin} does not: a name re-exported by name from a
61
+ * module that cannot be followed is absent, never filled from `export *`.
62
+ * @param {string} file
63
+ * @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
64
+ * @returns {Map<string, {file: string, name: string}>}
65
+ */
66
+ export function moduleExportOrigins(file: string, { types, memo }?: {
67
+ types?: boolean;
68
+ memo?: Map<string, Map<string, {
69
+ file: string;
70
+ name: string;
71
+ }>>;
72
+ }): Map<string, {
73
+ file: string;
74
+ name: string;
75
+ }>;
46
76
  /**
47
77
  * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
48
78
  */
@@ -84,12 +114,16 @@ export function staticExportObject(file: string, exportNames: readonly string[])
84
114
  * has there, without executing anything: local re-exports, renames, and
85
115
  * imported bindings a module exports again are followed. Two exports are the
86
116
  * same value when their origins are equal. Null when it cannot be proved.
117
+ * With `types`, type-only exports and type declarations are followed too.
87
118
  * @param {string} file
88
119
  * @param {string} exportName
89
120
  * @param {Set<string>} [seen]
121
+ * @param {{types?: boolean}} [options]
90
122
  * @returns {{file: string, name: string} | null}
91
123
  */
92
- export function moduleExportOrigin(file: string, exportName: string, seen?: Set<string>): {
124
+ export function moduleExportOrigin(file: string, exportName: string, seen?: Set<string>, { types }?: {
125
+ types?: boolean;
126
+ }): {
93
127
  file: string;
94
128
  name: string;
95
129
  } | null;
@@ -114,12 +148,16 @@ export function exportOriginVerdict(file: string, exportName: string): ExportOri
114
148
  * named exports and, through `export *` from local files and installed
115
149
  * packages, theirs. Unlike {@link moduleExportNames}, it never gives up on an
116
150
  * `export *`: what it cannot read is left out. Type-only
117
- * exports and `default` are left out. Sorted.
151
+ * exports are left out unless `types` asks for them; `default` always is.
152
+ * Sorted.
118
153
  * @param {string} file
119
154
  * @param {Set<string>} [seen]
155
+ * @param {{types?: boolean}} [options]
120
156
  * @returns {string[]}
121
157
  */
122
- export function followedExportNames(file: string, seen?: Set<string>): string[];
158
+ export function followedExportNames(file: string, seen?: Set<string>, { types }?: {
159
+ types?: boolean;
160
+ }): string[];
123
161
  /**
124
162
  * What a module's runtime export is, read without running it: `component`
125
163
  * for a function, a class, or a value a call returns (`forwardRef(...)`);
@@ -146,17 +184,46 @@ export function exportScalarType(file: string, exportName: string): "string" | "
146
184
  * then have the same final origin. Null when an alias cannot be followed (to
147
185
  * a default or namespace import, a member such as `Icons.X`, or an import
148
186
  * that does not resolve), so a caller leaves the comparison unchecked.
187
+ * `unwrap`, when given, names a value a declaration stands for besides a
188
+ * plain alias (a theme made by `defineTheme({extends: base})` stands for
189
+ * `base`): it receives the declaration's initializer and returns the
190
+ * expression to follow, or null for none. A followed expression that is not
191
+ * an identifier makes the origin unknown.
149
192
  * @param {{file: string, name: string}} origin
150
193
  * @param {Set<string>} [seen]
194
+ * @param {(init: any) => any} [unwrap]
151
195
  * @returns {{file: string, name: string} | null}
152
196
  */
153
197
  export function aliasedOrigin(origin: {
154
198
  file: string;
155
199
  name: string;
156
- }, seen?: Set<string>): {
200
+ }, seen?: Set<string>, unwrap?: (init: any) => any): {
157
201
  file: string;
158
202
  name: string;
159
203
  } | null;
204
+ /**
205
+ * Where the value each `<Name prop={value}>` element of a module passes is
206
+ * declared, one entry per element, read without running anything. `Name` is
207
+ * a runtime import of `name` from one of `sources` (renames included). The
208
+ * value is followed with {@link aliasedOrigin} (passing `unwrap`) from the
209
+ * module-scope binding it names, through local files and installed packages.
210
+ * An entry is null when the value is not an identifier or its origin cannot
211
+ * be proved (a parameter or an import that does not resolve gives the
212
+ * module's own name, and a member or a default import gives null). An element
213
+ * without `prop` gives no entry.
214
+ * @param {string} file
215
+ * @param {{sources: ReadonlySet<string>, name: string, prop: string, unwrap?: (init: any) => any}} element
216
+ * @returns {Array<{file: string, name: string} | null>}
217
+ */
218
+ export function elementPropOrigins(file: string, { sources, name, prop, unwrap }: {
219
+ sources: ReadonlySet<string>;
220
+ name: string;
221
+ prop: string;
222
+ unwrap?: (init: any) => any;
223
+ }): Array<{
224
+ file: string;
225
+ name: string;
226
+ } | null>;
160
227
  /**
161
228
  * The object a module exports under `exportName`, read without running it:
162
229
  * each property's key and the binding its value names (an identifier, or the
@@ -178,6 +245,26 @@ export function staticExportBindings(file: string, exportName: string): Map<stri
178
245
  * enumerable, so the object compares and serializes as its literal properties.
179
246
  */
180
247
  export const HAS_COMPUTED: unique symbol;
248
+ export type OriginsRead = {
249
+ types: boolean;
250
+ /**
251
+ * finished maps, keyed by read mode and file
252
+ */
253
+ memo: Map<string, Map<string, {
254
+ file: string;
255
+ name: string;
256
+ }>>;
257
+ /**
258
+ * the modules being read now, by memo key
259
+ */
260
+ reading: Map<string, {
261
+ depth: number;
262
+ origins: Map<string, {
263
+ file: string;
264
+ name: string;
265
+ }>;
266
+ }>;
267
+ };
181
268
  export type ExportVerdict = {
182
269
  verdict: "exports";
183
270
  } | {
@@ -198,8 +198,14 @@ function collectNodesOfType(node, type, found) {
198
198
  return found;
199
199
  }
200
200
 
201
- /** @param {unknown} specifier @param {string} fromFile */
202
- function resolveLocalModule(specifier, fromFile) {
201
+ /**
202
+ * The file a relative import names: the path itself, then each module
203
+ * extension, then a folder's index. Null for a bare specifier or no file.
204
+ * @param {unknown} specifier
205
+ * @param {string} fromFile absolute path of the importing file
206
+ * @returns {string|null}
207
+ */
208
+ export function resolveLocalModule(specifier, fromFile) {
203
209
  if (typeof specifier !== 'string' || !specifier.startsWith('.')) return null;
204
210
  const base = path.resolve(path.dirname(fromFile), specifier);
205
211
  const candidates = [
@@ -347,17 +353,43 @@ export function unfollowedReexports(file) {
347
353
  return [...missing].sort();
348
354
  }
349
355
 
350
- /** @param {any} declaration @param {string} exportName */
351
- function declarationExports(declaration, exportName) {
352
- if (!declaration || declaration.declare === true) return false;
353
- if (['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)) {
354
- return declaration.id?.name === exportName;
356
+ /** Declarations that name a type, which a type-aware read also follows. */
357
+ const TYPE_DECLARATIONS = [
358
+ 'TSInterfaceDeclaration',
359
+ 'TSTypeAliasDeclaration',
360
+ 'TSEnumDeclaration',
361
+ 'TSModuleDeclaration',
362
+ 'TSDeclareFunction',
363
+ ];
364
+
365
+ /**
366
+ * @param {any} declaration
367
+ * @param {string} exportName
368
+ * @param {boolean} [types] also count type declarations and `declare` ones
369
+ */
370
+ function declarationExports(declaration, exportName, types = false) {
371
+ return declaredNames(declaration, types).includes(exportName);
372
+ }
373
+
374
+ /**
375
+ * The names an exported declaration binds.
376
+ * @param {any} declaration
377
+ * @param {boolean} [types] also count type declarations and `declare` ones
378
+ * @returns {string[]}
379
+ */
380
+ function declaredNames(declaration, types = false) {
381
+ if (!declaration || (declaration.declare === true && !types)) return [];
382
+ if (
383
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type) ||
384
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
385
+ ) {
386
+ const name = declaration.id?.name;
387
+ return typeof name === 'string' ? [name] : [];
355
388
  }
356
- if (declaration.type !== 'VariableDeclaration') return false;
357
- return declaration.declarations.some(
358
- (/** @type {any} */ item) =>
359
- item.id?.type === 'Identifier' && item.id.name === exportName,
360
- );
389
+ if (declaration.type !== 'VariableDeclaration') return [];
390
+ return declaration.declarations
391
+ .filter((/** @type {any} */ item) => item.id?.type === 'Identifier')
392
+ .map((/** @type {any} */ item) => item.id.name);
361
393
  }
362
394
 
363
395
  /** @param {any} declaration */
@@ -574,6 +606,139 @@ export function moduleExportNames(file) {
574
606
  return [...names].sort();
575
607
  }
576
608
 
609
+ /**
610
+ * Every export of a module with where it is declared, in one pass: the same
611
+ * answers as {@link moduleExportOrigin} for each name, read once per module.
612
+ * Pass one `memo` to calls that read the same package, so a module behind
613
+ * many barrels is read once; a memo keeps value and type reads apart, and
614
+ * nothing is kept between memos. One difference follows ESM where
615
+ * {@link moduleExportOrigin} does not: a name re-exported by name from a
616
+ * module that cannot be followed is absent, never filled from `export *`.
617
+ * @param {string} file
618
+ * @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
619
+ * @returns {Map<string, {file: string, name: string}>}
620
+ */
621
+ export function moduleExportOrigins(
622
+ file,
623
+ {types = false, memo = new Map()} = {},
624
+ ) {
625
+ return exportOriginsOf(file, {types, memo, reading: new Map()}).origins;
626
+ }
627
+
628
+ /**
629
+ * @typedef {object} OriginsRead
630
+ * @property {boolean} types
631
+ * @property {Map<string, Map<string, {file: string, name: string}>>} memo
632
+ * finished maps, keyed by read mode and file
633
+ * @property {Map<string, {depth: number, origins: Map<string, {file: string, name: string}>}>} reading
634
+ * the modules being read now, by memo key
635
+ */
636
+
637
+ /**
638
+ * One module's export map, and the shallowest module still being read that
639
+ * it depends on (`low`). A map that depends on a module above it in an
640
+ * `export *` cycle is incomplete until that module finishes, so only a map
641
+ * whose `low` is its own depth goes in the memo.
642
+ * @param {string} file
643
+ * @param {OriginsRead} read
644
+ * @returns {{origins: Map<string, {file: string, name: string}>, low: number}}
645
+ */
646
+ function exportOriginsOf(file, read) {
647
+ const key = `${read.types ? 'type' : 'value'}\0${file}`;
648
+ const known = read.memo.get(key);
649
+ if (known) return {origins: known, low: Infinity};
650
+ const open = read.reading.get(key);
651
+ // A module reached again through a cycle reads as what is known so far.
652
+ if (open) return {origins: open.origins, low: open.depth};
653
+ const depth = read.reading.size;
654
+ /** @type {Map<string, {file: string, name: string}>} */
655
+ const origins = new Map();
656
+ let low = Infinity;
657
+ read.reading.set(key, {depth, origins});
658
+ /** @param {string} target */
659
+ const originsOf = target => {
660
+ const result = exportOriginsOf(target, read);
661
+ low = Math.min(low, result.low);
662
+ return result.origins;
663
+ };
664
+ try {
665
+ let ast;
666
+ try {
667
+ if (!fs.statSync(file).isFile()) return {origins, low};
668
+ ast = parseModule(file);
669
+ } catch {
670
+ return {origins, low};
671
+ }
672
+ const {types} = read;
673
+ // A name the module exports by name shadows every `export *`, even when
674
+ // its binding cannot be followed.
675
+ const named = new Set();
676
+ const {declarations, specifiers} = namedExportIndex(ast.program, types);
677
+ for (const node of declarations) {
678
+ for (const name of declaredNames(node.declaration, types)) {
679
+ named.add(name);
680
+ if (!origins.has(name)) origins.set(name, {file, name});
681
+ }
682
+ }
683
+ for (const [exportName, entries] of specifiers) {
684
+ named.add(exportName);
685
+ if (origins.has(exportName)) continue;
686
+ for (const {node, specifier} of entries) {
687
+ const local =
688
+ specifier.local?.name ?? specifier.local?.value ?? exportName;
689
+ let origin = null;
690
+ if (node.source) {
691
+ const target = resolveModuleOrPackage(node.source.value, file);
692
+ if (target) {
693
+ const result = exportOriginsOf(target, read);
694
+ low = Math.min(low, result.low);
695
+ // A map that depends on a module still being read is partial, so
696
+ // a name missing from it is followed on its own.
697
+ origin =
698
+ result.origins.get(local) ??
699
+ (result.low < Infinity
700
+ ? moduleExportOrigin(target, local, new Set(), {types})
701
+ : null);
702
+ }
703
+ } else {
704
+ origin = bindingOrigin(ast, file, local, new Set(), types);
705
+ }
706
+ if (origin) {
707
+ origins.set(exportName, origin);
708
+ break;
709
+ }
710
+ if (!node.source) break;
711
+ }
712
+ }
713
+ for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
714
+ named.add('default');
715
+ if (origins.has('default')) break;
716
+ const declaration = node.declaration;
717
+ if (!types && !runtimeDefault(declaration)) continue;
718
+ const origin =
719
+ declaration.type === 'Identifier'
720
+ ? bindingOrigin(ast, file, declaration.name, new Set(), types)
721
+ : {file, name: 'default'};
722
+ if (origin) origins.set('default', origin);
723
+ break;
724
+ }
725
+ for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
726
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
727
+ const target = resolveModuleOrPackage(node.source?.value, file);
728
+ if (!target) continue;
729
+ for (const [name, origin] of originsOf(target)) {
730
+ if (name !== 'default' && !named.has(name) && !origins.has(name)) {
731
+ origins.set(name, origin);
732
+ }
733
+ }
734
+ }
735
+ return {origins, low};
736
+ } finally {
737
+ read.reading.delete(key);
738
+ if (low >= depth) read.memo.set(key, origins);
739
+ }
740
+ }
741
+
577
742
  /**
578
743
  * @typedef {{verdict: 'exports'} | {verdict: 'lacks'} | {verdict: 'unknown', reason: string}} ExportVerdict
579
744
  */
@@ -926,22 +1091,25 @@ export function staticExportObject(file, exportNames) {
926
1091
  * @type {WeakMap<object, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>}
927
1092
  */
928
1093
  const namedExportIndexes = new WeakMap();
1094
+ /** The same index with type-only exports included. */
1095
+ const typedExportIndexes = new WeakMap();
929
1096
 
930
- /** @param {any} program */
931
- function namedExportIndex(program) {
932
- const cached = namedExportIndexes.get(program);
1097
+ /** @param {any} program @param {boolean} [types] include type-only exports */
1098
+ function namedExportIndex(program, types = false) {
1099
+ const indexes = types ? typedExportIndexes : namedExportIndexes;
1100
+ const cached = indexes.get(program);
933
1101
  if (cached) return cached;
934
1102
  /** @type {any[]} */
935
1103
  const declarations = [];
936
1104
  /** @type {Map<string, Array<{node: any, specifier: any}>>} */
937
1105
  const specifiers = new Map();
938
1106
  for (const node of nodesOfType(program, 'ExportNamedDeclaration')) {
939
- if (node.exportKind === 'type') continue;
1107
+ if (node.exportKind === 'type' && !types) continue;
940
1108
  if (node.declaration) declarations.push(node);
941
1109
  for (const specifier of node.specifiers ?? []) {
942
1110
  if (
943
1111
  specifier.type !== 'ExportSpecifier' ||
944
- specifier.exportKind === 'type'
1112
+ (specifier.exportKind === 'type' && !types)
945
1113
  ) {
946
1114
  continue;
947
1115
  }
@@ -952,7 +1120,7 @@ function namedExportIndex(program) {
952
1120
  }
953
1121
  }
954
1122
  const index = {declarations, specifiers};
955
- namedExportIndexes.set(program, index);
1123
+ indexes.set(program, index);
956
1124
  return index;
957
1125
  }
958
1126
 
@@ -961,12 +1129,19 @@ function namedExportIndex(program) {
961
1129
  * has there, without executing anything: local re-exports, renames, and
962
1130
  * imported bindings a module exports again are followed. Two exports are the
963
1131
  * same value when their origins are equal. Null when it cannot be proved.
1132
+ * With `types`, type-only exports and type declarations are followed too.
964
1133
  * @param {string} file
965
1134
  * @param {string} exportName
966
1135
  * @param {Set<string>} [seen]
1136
+ * @param {{types?: boolean}} [options]
967
1137
  * @returns {{file: string, name: string} | null}
968
1138
  */
969
- export function moduleExportOrigin(file, exportName, seen = new Set()) {
1139
+ export function moduleExportOrigin(
1140
+ file,
1141
+ exportName,
1142
+ seen = new Set(),
1143
+ {types = false} = {},
1144
+ ) {
970
1145
  const identity = `${file}\0${exportName}`;
971
1146
  if (seen.has(identity)) return null;
972
1147
  seen.add(identity);
@@ -977,9 +1152,9 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
977
1152
  } catch {
978
1153
  return null;
979
1154
  }
980
- const {declarations, specifiers} = namedExportIndex(ast.program);
1155
+ const {declarations, specifiers} = namedExportIndex(ast.program, types);
981
1156
  for (const node of declarations) {
982
- if (declarationExports(node.declaration, exportName)) {
1157
+ if (declarationExports(node.declaration, exportName, types)) {
983
1158
  return {file, name: exportName};
984
1159
  }
985
1160
  }
@@ -987,26 +1162,30 @@ export function moduleExportOrigin(file, exportName, seen = new Set()) {
987
1162
  const local = specifier.local?.name ?? specifier.local?.value ?? exportName;
988
1163
  if (node.source) {
989
1164
  const target = resolveModuleOrPackage(node.source.value, file);
990
- const origin = target ? moduleExportOrigin(target, local, seen) : null;
1165
+ const origin = target
1166
+ ? moduleExportOrigin(target, local, seen, {types})
1167
+ : null;
991
1168
  if (origin) return origin;
992
1169
  continue;
993
1170
  }
994
- return bindingOrigin(ast, file, local, seen);
1171
+ return bindingOrigin(ast, file, local, seen, types);
995
1172
  }
996
1173
  if (exportName === 'default') {
997
1174
  for (const node of nodesOfType(ast.program, 'ExportDefaultDeclaration')) {
998
1175
  const declaration = node.declaration;
999
- if (!runtimeDefault(declaration)) continue;
1176
+ if (!types && !runtimeDefault(declaration)) continue;
1000
1177
  if (declaration.type === 'Identifier') {
1001
- return bindingOrigin(ast, file, declaration.name, seen);
1178
+ return bindingOrigin(ast, file, declaration.name, seen, types);
1002
1179
  }
1003
1180
  return {file, name: 'default'};
1004
1181
  }
1005
1182
  }
1006
1183
  for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1007
- if (node.exportKind === 'type' || node.exported) continue;
1184
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1008
1185
  const target = resolveModuleOrPackage(node.source?.value, file);
1009
- const origin = target ? moduleExportOrigin(target, exportName, seen) : null;
1186
+ const origin = target
1187
+ ? moduleExportOrigin(target, exportName, seen, {types})
1188
+ : null;
1010
1189
  if (origin) return origin;
1011
1190
  }
1012
1191
  return null;
@@ -1128,12 +1307,18 @@ function originGapReason(file, exportName, seen = new Set()) {
1128
1307
  * named exports and, through `export *` from local files and installed
1129
1308
  * packages, theirs. Unlike {@link moduleExportNames}, it never gives up on an
1130
1309
  * `export *`: what it cannot read is left out. Type-only
1131
- * exports and `default` are left out. Sorted.
1310
+ * exports are left out unless `types` asks for them; `default` always is.
1311
+ * Sorted.
1132
1312
  * @param {string} file
1133
1313
  * @param {Set<string>} [seen]
1314
+ * @param {{types?: boolean}} [options]
1134
1315
  * @returns {string[]}
1135
1316
  */
1136
- export function followedExportNames(file, seen = new Set()) {
1317
+ export function followedExportNames(
1318
+ file,
1319
+ seen = new Set(),
1320
+ {types = false} = {},
1321
+ ) {
1137
1322
  if (seen.has(file)) return [];
1138
1323
  seen.add(file);
1139
1324
  let ast;
@@ -1146,11 +1331,14 @@ export function followedExportNames(file, seen = new Set()) {
1146
1331
  /** @type {Set<string>} */
1147
1332
  const names = new Set();
1148
1333
  for (const node of nodesOfType(ast.program, 'ExportNamedDeclaration')) {
1149
- if (node.exportKind === 'type') continue;
1334
+ if (node.exportKind === 'type' && !types) continue;
1150
1335
  const declaration = node.declaration;
1151
- if (declaration && declaration.declare !== true) {
1336
+ if (declaration && (declaration.declare !== true || types)) {
1152
1337
  if (
1153
- ['FunctionDeclaration', 'ClassDeclaration'].includes(declaration.type)
1338
+ ['FunctionDeclaration', 'ClassDeclaration'].includes(
1339
+ declaration.type,
1340
+ ) ||
1341
+ (types && TYPE_DECLARATIONS.includes(declaration.type))
1154
1342
  ) {
1155
1343
  if (declaration.id?.name) names.add(declaration.id.name);
1156
1344
  } else if (declaration.type === 'VariableDeclaration') {
@@ -1162,7 +1350,7 @@ export function followedExportNames(file, seen = new Set()) {
1162
1350
  for (const specifier of node.specifiers ?? []) {
1163
1351
  if (
1164
1352
  specifier.type !== 'ExportSpecifier' ||
1165
- specifier.exportKind === 'type'
1353
+ (specifier.exportKind === 'type' && !types)
1166
1354
  ) {
1167
1355
  continue;
1168
1356
  }
@@ -1173,10 +1361,12 @@ export function followedExportNames(file, seen = new Set()) {
1173
1361
  }
1174
1362
  }
1175
1363
  for (const node of nodesOfType(ast.program, 'ExportAllDeclaration')) {
1176
- if (node.exportKind === 'type' || node.exported) continue;
1364
+ if ((node.exportKind === 'type' && !types) || node.exported) continue;
1177
1365
  const target = resolveModuleOrPackage(node.source?.value, file);
1178
1366
  if (target) {
1179
- for (const name of followedExportNames(target, seen)) names.add(name);
1367
+ for (const name of followedExportNames(target, seen, {types})) {
1368
+ names.add(name);
1369
+ }
1180
1370
  }
1181
1371
  }
1182
1372
  return [...names].sort();
@@ -1317,11 +1507,17 @@ export function exportScalarType(file, exportName) {
1317
1507
  * then have the same final origin. Null when an alias cannot be followed (to
1318
1508
  * a default or namespace import, a member such as `Icons.X`, or an import
1319
1509
  * that does not resolve), so a caller leaves the comparison unchecked.
1510
+ * `unwrap`, when given, names a value a declaration stands for besides a
1511
+ * plain alias (a theme made by `defineTheme({extends: base})` stands for
1512
+ * `base`): it receives the declaration's initializer and returns the
1513
+ * expression to follow, or null for none. A followed expression that is not
1514
+ * an identifier makes the origin unknown.
1320
1515
  * @param {{file: string, name: string}} origin
1321
1516
  * @param {Set<string>} [seen]
1517
+ * @param {(init: any) => any} [unwrap]
1322
1518
  * @returns {{file: string, name: string} | null}
1323
1519
  */
1324
- export function aliasedOrigin(origin, seen = new Set()) {
1520
+ export function aliasedOrigin(origin, seen = new Set(), unwrap) {
1325
1521
  const identity = `${origin.file}\0${origin.name}`;
1326
1522
  if (seen.has(identity)) return null;
1327
1523
  seen.add(identity);
@@ -1344,16 +1540,88 @@ export function aliasedOrigin(origin, seen = new Set()) {
1344
1540
  ) {
1345
1541
  continue;
1346
1542
  }
1347
- const init = withoutTypeWrappers(declarator.init);
1543
+ const declared = withoutTypeWrappers(declarator.init);
1544
+ const followed = declared && unwrap ? unwrap(declared) : null;
1545
+ const init = followed ? withoutTypeWrappers(followed) : declared;
1348
1546
  if (init?.type === 'MemberExpression') return null;
1349
- if (init?.type !== 'Identifier') return origin;
1547
+ if (init?.type !== 'Identifier') return followed ? null : origin;
1350
1548
  const next = bindingOrigin(ast, origin.file, init.name, new Set());
1351
- return next ? aliasedOrigin(next, seen) : null;
1549
+ return next ? aliasedOrigin(next, seen, unwrap) : null;
1352
1550
  }
1353
1551
  }
1354
1552
  return origin;
1355
1553
  }
1356
1554
 
1555
+ /**
1556
+ * Where the value each `<Name prop={value}>` element of a module passes is
1557
+ * declared, one entry per element, read without running anything. `Name` is
1558
+ * a runtime import of `name` from one of `sources` (renames included). The
1559
+ * value is followed with {@link aliasedOrigin} (passing `unwrap`) from the
1560
+ * module-scope binding it names, through local files and installed packages.
1561
+ * An entry is null when the value is not an identifier or its origin cannot
1562
+ * be proved (a parameter or an import that does not resolve gives the
1563
+ * module's own name, and a member or a default import gives null). An element
1564
+ * without `prop` gives no entry.
1565
+ * @param {string} file
1566
+ * @param {{sources: ReadonlySet<string>, name: string, prop: string, unwrap?: (init: any) => any}} element
1567
+ * @returns {Array<{file: string, name: string} | null>}
1568
+ */
1569
+ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
1570
+ let ast;
1571
+ try {
1572
+ ast = parseModule(file);
1573
+ } catch {
1574
+ return [];
1575
+ }
1576
+ /** @type {Set<string>} */
1577
+ const locals = new Set();
1578
+ for (const node of ast.program.body) {
1579
+ if (
1580
+ node.type !== 'ImportDeclaration' ||
1581
+ node.importKind === 'type' ||
1582
+ !sources.has(node.source?.value)
1583
+ ) {
1584
+ continue;
1585
+ }
1586
+ for (const specifier of node.specifiers ?? []) {
1587
+ if (
1588
+ specifier.type === 'ImportSpecifier' &&
1589
+ specifier.importKind !== 'type' &&
1590
+ (specifier.imported?.name ?? specifier.imported?.value) === name
1591
+ ) {
1592
+ locals.add(specifier.local.name);
1593
+ }
1594
+ }
1595
+ }
1596
+ if (locals.size === 0) return [];
1597
+ /** @type {Array<{file: string, name: string} | null>} */
1598
+ const origins = [];
1599
+ for (const element of nodesOfType(ast.program, 'JSXOpeningElement')) {
1600
+ if (
1601
+ element.name?.type !== 'JSXIdentifier' ||
1602
+ !locals.has(element.name.name)
1603
+ ) {
1604
+ continue;
1605
+ }
1606
+ const attribute = (element.attributes ?? []).find(
1607
+ (/** @type {any} */ item) =>
1608
+ item.type === 'JSXAttribute' && item.name?.name === prop,
1609
+ );
1610
+ if (!attribute) continue;
1611
+ const value =
1612
+ attribute.value?.type === 'JSXExpressionContainer'
1613
+ ? withoutTypeWrappers(attribute.value.expression)
1614
+ : null;
1615
+ if (value?.type !== 'Identifier') {
1616
+ origins.push(null);
1617
+ continue;
1618
+ }
1619
+ const binding = bindingOrigin(ast, file, value.name, new Set());
1620
+ origins.push(binding ? aliasedOrigin(binding, new Set(), unwrap) : null);
1621
+ }
1622
+ return origins;
1623
+ }
1624
+
1357
1625
  /**
1358
1626
  * Where a top-level binding of a parsed module comes from: an import from a
1359
1627
  * local module is followed to its origin; anything else is declared here.
@@ -1361,11 +1629,15 @@ export function aliasedOrigin(origin, seen = new Set()) {
1361
1629
  * @param {string} file
1362
1630
  * @param {string} local
1363
1631
  * @param {Set<string>} seen
1632
+ * @param {boolean} [types] also follow `import type`
1364
1633
  * @returns {{file: string, name: string} | null}
1365
1634
  */
1366
- function bindingOrigin(ast, file, local, seen) {
1635
+ function bindingOrigin(ast, file, local, seen, types = false) {
1367
1636
  for (const node of ast.program.body) {
1368
- if (node.type !== 'ImportDeclaration' || node.importKind === 'type') {
1637
+ if (
1638
+ node.type !== 'ImportDeclaration' ||
1639
+ (node.importKind === 'type' && !types)
1640
+ ) {
1369
1641
  continue;
1370
1642
  }
1371
1643
  for (const specifier of node.specifiers ?? []) {
@@ -1374,7 +1646,9 @@ function bindingOrigin(ast, file, local, seen) {
1374
1646
  const imported =
1375
1647
  specifier.imported?.name ?? specifier.imported?.value ?? local;
1376
1648
  const target = resolveModuleOrPackage(node.source.value, file);
1377
- return target ? moduleExportOrigin(target, imported, seen) : null;
1649
+ return target
1650
+ ? moduleExportOrigin(target, imported, seen, {types})
1651
+ : null;
1378
1652
  }
1379
1653
  }
1380
1654
  return {file, name: local};