@astryxdesign/cli 0.7.11 → 0.7.12-canary.0840fcc
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.
- package/api/build/blocks/blocks.d.mts +41 -0
- package/api/build/blocks/blocks.mjs +118 -68
- package/api/build/kit/rank.mjs +21 -4
- package/api/build/kit/words.d.mts +1 -0
- package/api/build/kit/words.mjs +1 -1
- package/api/component/__fixtures__/resolutions/modules.txt +5 -5
- package/api/docs/_adapter.d.mts +22 -0
- package/api/docs/_adapter.mjs +81 -3
- package/api/docs/docs.doc.mjs +5 -5
- package/api/docs/docs.type.d.mts +21 -0
- package/api/docs/docs.type.mjs +11 -0
- package/api/docs/list/list.d.mts +5 -1
- package/api/docs/list/list.mjs +72 -6
- package/api/docs/node/node.mjs +2 -40
- package/api/icon/_adapter.d.mts +3 -2
- package/api/icon/_adapter.mjs +8 -2
- package/api/icon/_authoring.d.mts +1 -0
- package/api/icon/_authoring.mjs +594 -67
- package/api/icon/_default-look.d.mts +155 -0
- package/api/icon/_default-look.mjs +474 -0
- package/api/icon/_records.d.mts +1 -1
- package/api/icon/_records.mjs +1 -0
- package/api/icon/add/add.mjs +269 -43
- package/api/icon/icon.type.d.mts +46 -2
- package/api/icon/icon.type.mjs +12 -2
- package/api/icon/iconAdd.doc.mjs +2 -2
- package/api/icon/iconNewDefinition.doc.mjs +3 -2
- package/api/icon/iconNewSet.doc.mjs +4 -4
- package/api/icon/map/map.mjs +11 -4
- package/api/icon/search/search.mjs +10 -9
- package/api/index.d.mts +1 -0
- package/api/index.mjs +1 -0
- package/api/integration/add-helpers.d.mts +15 -1
- package/api/integration/add-helpers.mjs +5 -2
- package/api/integration/authoring-checks.d.mts +0 -2
- package/api/integration/authoring-checks.mjs +1 -6
- package/api/logger.mjs +2 -1
- package/api/render/_adapter.mjs +9 -0
- package/api/render/render.doc.mjs +3 -3
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +3 -0
- package/api/search/_adapter.d.mts +32 -3
- package/api/search/_adapter.mjs +50 -22
- package/api/search/_fit-order.d.mts +47 -0
- package/api/search/_fit-order.mjs +257 -0
- package/api/search/_main-searcher.mjs +15 -5
- package/api/search/exportSearchIndex.doc.d.mts +10 -0
- package/api/search/exportSearchIndex.doc.mjs +58 -0
- package/api/search/rankSearchIndex.doc.d.mts +10 -0
- package/api/search/rankSearchIndex.doc.mjs +79 -0
- package/api/search/search-index.d.mts +44 -0
- package/api/search/search-index.mjs +270 -0
- package/api/search/search.type.d.mts +28 -0
- package/api/search/search.type.mjs +17 -0
- package/api/swizzle/_adapter.d.mts +1 -0
- package/api/swizzle/_adapter.mjs +4 -1
- package/api/swizzle/_moduleGraph.d.mts +178 -0
- package/api/swizzle/_moduleGraph.mjs +903 -0
- package/api/swizzle/copy/copy.d.mts +2 -43
- package/api/swizzle/copy/copy.mjs +287 -315
- package/api/swizzle/swizzle.d.mts +0 -2
- package/api/swizzle/swizzle.doc.mjs +13 -4
- package/api/swizzle/swizzle.mjs +3 -7
- package/api/swizzle/swizzle.type.d.mts +7 -1
- package/api/swizzle/swizzle.type.mjs +4 -2
- package/api/template/template.mjs +1 -0
- package/assets/discover/official-packages.json +36 -0
- package/assets/docs/browser-support.doc.mjs +2 -2
- package/assets/docs/styling-overview.doc.mjs +6 -2
- package/assets/docs/tree/icon-sets.doc.mjs +13 -7
- package/assets/docs/tree/render-pages.doc.mjs +3 -3
- package/assets/docs/tree/tailwind.doc.mjs +41 -1
- package/assets/docs/tree/type-scale.doc.mjs +19 -2
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarConstraintsHookUsage.tsx +146 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Calendar/useCalendarNavigationHookUsage.tsx +173 -0
- package/assets/templates/blocks/components/Hooks/useInputStatusIconHookUsage.tsx +1 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useInteractiveRoleHookUsage.tsx +56 -0
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.doc.mjs +2 -2
- package/assets/templates/blocks/components/Hooks/useStreamingTextHookUsage.tsx +66 -10
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Link/useLinkifyHookUsage.tsx +39 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/PowerSearch/usePowerSearchConfigHookUsage.tsx +83 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/RowsVirtualizationHookUsage.tsx +41 -0
- package/assets/templates/blocks/components/Table/TableRowIndexTable.doc.mjs +1 -1
- package/assets/templates/blocks/components/Table/TableRowIndexTable.tsx +2 -2
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/useTableColumnSettingsStateHookUsage.tsx +97 -0
- package/assets/templates/pages/course-detail/page.tsx +699 -0
- package/assets/templates/pages/course-detail/template.doc.mjs +37 -0
- package/assets/templates/pages/file-explorer/page.tsx +103 -79
- package/assets/templates/pages/table-filter/page.tsx +15 -23
- package/assets/templates/pages/table-grouped/page.tsx +160 -232
- package/assets/templates/pages/table-grouped/template.doc.mjs +0 -2
- package/assets/templates/pages/table-inbox/page.tsx +3 -6
- package/assets/templates/pages/theme-showcase/page.tsx +724 -792
- package/assets/templates/pages/theme-showcase/template.doc.mjs +4 -5
- package/assets/templates/themes/butter/butterTheme.ts +2 -2
- package/assets/templates/themes/gothic/gothicTheme.ts +16 -0
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -1
- package/assets/templates/themes/neutral/neutralTheme.ts +6 -0
- package/assets/templates/themes/stone/stoneTheme.ts +1 -1
- package/assets/templates/themes/y2k/y2kPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/y2k/y2kTheme.ts +2 -2
- package/authoring/doctypes/template/type.ts +1 -0
- package/clients/cli/commands/docs.doc.mjs +5 -1
- package/clients/cli/commands/docs.mjs +30 -2
- package/clients/cli/commands/experimental/icon.mjs +56 -14
- package/clients/cli/commands/experimental-icon-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-icon-new-definition.doc.mjs +2 -1
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-render.doc.mjs +1 -1
- package/clients/cli/commands/swizzle.doc.mjs +12 -3
- package/clients/cli/commands/swizzle.mjs +33 -9
- package/clients/cli/lib/resolve-theme.mjs +16 -7
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/doc-types.mjs +9 -2
- package/foundation/discovery/hook-discovery.mjs +31 -8
- package/foundation/discovery/icon-ranking.d.mts +27 -3
- package/foundation/discovery/icon-ranking.mjs +125 -8
- package/foundation/discovery/icon-set-checks.mjs +44 -35
- package/foundation/discovery/icon-set-discovery.d.mts +13 -0
- package/foundation/discovery/icon-set-discovery.mjs +25 -0
- package/foundation/discovery/icon-set-writer.d.mts +258 -20
- package/foundation/discovery/icon-set-writer.mjs +785 -87
- package/foundation/discovery/module-exports.d.mts +3 -2
- package/foundation/discovery/module-exports.mjs +167 -37
- package/foundation/doc-compiler/import.d.mts +5 -1
- package/foundation/doc-compiler/import.mjs +40 -6
- package/foundation/fs/import-url.d.mts +20 -0
- package/foundation/fs/import-url.mjs +22 -0
- package/foundation/fs/module-loader.d.mts +24 -3
- package/foundation/fs/module-loader.mjs +69 -47
- package/foundation/fs/paths.d.mts +2 -1
- package/foundation/fs/paths.mjs +3 -4
- package/foundation/render/charts.d.mts +59 -0
- package/foundation/render/charts.mjs +216 -0
- package/foundation/render/embedded-imports.d.mts +7 -7
- package/foundation/render/embedded-imports.mjs +63 -54
- package/foundation/render/page-host.d.mts +4 -0
- package/foundation/render/page-host.mjs +45 -0
- package/foundation/render/page-worker.mjs +350 -57
- package/foundation/render/render-page.d.mts +11 -6
- package/foundation/render/render-page.mjs +164 -54
- package/foundation/render/ts-paths.d.mts +63 -0
- package/foundation/render/ts-paths.mjs +138 -0
- package/foundation/response/error-codes.doc.mjs +3 -3
- package/foundation/response/error-codes.mjs +3 -2
- package/foundation/text/levenshtein.d.mts +6 -1
- package/foundation/text/levenshtein.mjs +25 -9
- package/foundation/text/shell-arg.d.mts +14 -0
- package/foundation/text/shell-arg.mjs +17 -0
- package/foundation/text/suggest-order.d.mts +8 -1
- package/foundation/text/suggest-order.mjs +72 -6
- package/package.json +7 -6
|
@@ -53,11 +53,12 @@ export function moduleExportSource(file: string, exportName: string, seen?: Set<
|
|
|
53
53
|
export function moduleExportNames(file: string): string[] | null;
|
|
54
54
|
/**
|
|
55
55
|
* Every export of a module with where it is declared, in one pass: the same
|
|
56
|
-
* answers as {@link
|
|
56
|
+
* answers as the whole-tree {@link exportOrigin} for each name, read once per
|
|
57
|
+
* module.
|
|
57
58
|
* Pass one `memo` to calls that read the same package, so a module behind
|
|
58
59
|
* many barrels is read once; a memo keeps value and type reads apart, and
|
|
59
60
|
* nothing is kept between memos. One difference follows ESM where
|
|
60
|
-
* {@link
|
|
61
|
+
* {@link exportOrigin} does not: a name re-exported by name from a
|
|
61
62
|
* module that cannot be followed is absent, never filled from `export *`.
|
|
62
63
|
* @param {string} file
|
|
63
64
|
* @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
|
|
@@ -161,17 +161,46 @@ const nodesByTree = new WeakMap();
|
|
|
161
161
|
* @returns {readonly any[]}
|
|
162
162
|
*/
|
|
163
163
|
function nodesOfType(node, type) {
|
|
164
|
+
return cachedNodes(node, `all\0${type}`, () =>
|
|
165
|
+
collectNodesOfType(node, type, []),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The module declarations of `type` at a program's top level, in source
|
|
171
|
+
* order: a library file is read without a walk of every function in it. A
|
|
172
|
+
* declaration nested in a namespace is not one of them. Only the readers of
|
|
173
|
+
* icon-set libraries use this: the parse-failure and re-export checks,
|
|
174
|
+
* {@link moduleExportOrigin} and the readers built on it, and
|
|
175
|
+
* {@link followedExportNames}. {@link bindingOrigin}, and so
|
|
176
|
+
* {@link aliasedOrigin}, {@link elementPropOrigins} and
|
|
177
|
+
* {@link moduleExportOrigins}, read with {@link nodesOfType}, as do the
|
|
178
|
+
* other readers.
|
|
179
|
+
* @param {any} program
|
|
180
|
+
* @param {string} type
|
|
181
|
+
* @returns {readonly any[]}
|
|
182
|
+
*/
|
|
183
|
+
function moduleDeclarations(program, type) {
|
|
184
|
+
return cachedNodes(program, `top\0${type}`, () => topLevel(program, type));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {any} node
|
|
189
|
+
* @param {string} key
|
|
190
|
+
* @param {() => readonly any[]} find
|
|
191
|
+
* @returns {readonly any[]}
|
|
192
|
+
*/
|
|
193
|
+
function cachedNodes(node, key, find) {
|
|
164
194
|
if (node == null || typeof node !== 'object') return [];
|
|
165
195
|
let byType = nodesByTree.get(node);
|
|
166
196
|
if (!byType) {
|
|
167
197
|
byType = new Map();
|
|
168
198
|
nodesByTree.set(node, byType);
|
|
169
199
|
}
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
200
|
+
const cached = byType.get(key);
|
|
201
|
+
if (cached) return cached;
|
|
202
|
+
const found = find();
|
|
203
|
+
byType.set(key, found);
|
|
175
204
|
return found;
|
|
176
205
|
}
|
|
177
206
|
|
|
@@ -315,7 +344,7 @@ export function moduleParseFailure(file) {
|
|
|
315
344
|
};
|
|
316
345
|
}
|
|
317
346
|
for (const type of ['ExportNamedDeclaration', 'ExportAllDeclaration']) {
|
|
318
|
-
for (const node of
|
|
347
|
+
for (const node of moduleDeclarations(ast.program, type)) {
|
|
319
348
|
const specifier = node.source?.value;
|
|
320
349
|
if (typeof specifier !== 'string' || !specifier.startsWith('.')) {
|
|
321
350
|
continue;
|
|
@@ -344,7 +373,7 @@ export function unfollowedReexports(file) {
|
|
|
344
373
|
/** @type {Set<string>} */
|
|
345
374
|
const missing = new Set();
|
|
346
375
|
for (const type of ['ExportNamedDeclaration', 'ExportAllDeclaration']) {
|
|
347
|
-
for (const node of
|
|
376
|
+
for (const node of moduleDeclarations(ast.program, type)) {
|
|
348
377
|
const specifier = node.source?.value;
|
|
349
378
|
if (typeof specifier !== 'string' || node.exportKind === 'type') continue;
|
|
350
379
|
if (!resolveModuleOrPackage(specifier, file)) missing.add(specifier);
|
|
@@ -608,11 +637,12 @@ export function moduleExportNames(file) {
|
|
|
608
637
|
|
|
609
638
|
/**
|
|
610
639
|
* Every export of a module with where it is declared, in one pass: the same
|
|
611
|
-
* answers as {@link
|
|
640
|
+
* answers as the whole-tree {@link exportOrigin} for each name, read once per
|
|
641
|
+
* module.
|
|
612
642
|
* Pass one `memo` to calls that read the same package, so a module behind
|
|
613
643
|
* many barrels is read once; a memo keeps value and type reads apart, and
|
|
614
644
|
* nothing is kept between memos. One difference follows ESM where
|
|
615
|
-
* {@link
|
|
645
|
+
* {@link exportOrigin} does not: a name re-exported by name from a
|
|
616
646
|
* module that cannot be followed is absent, never filled from `export *`.
|
|
617
647
|
* @param {string} file
|
|
618
648
|
* @param {{types?: boolean, memo?: Map<string, Map<string, {file: string, name: string}>>}} [options]
|
|
@@ -677,7 +707,12 @@ function exportOriginsOf(file, read) {
|
|
|
677
707
|
for (const node of declarations) {
|
|
678
708
|
for (const name of declaredNames(node.declaration, types)) {
|
|
679
709
|
named.add(name);
|
|
680
|
-
if (!origins.has(name))
|
|
710
|
+
if (!origins.has(name)) {
|
|
711
|
+
origins.set(
|
|
712
|
+
name,
|
|
713
|
+
declaredOrigin(ast, file, node.declaration, name, types),
|
|
714
|
+
);
|
|
715
|
+
}
|
|
681
716
|
}
|
|
682
717
|
}
|
|
683
718
|
for (const [exportName, entries] of specifiers) {
|
|
@@ -697,7 +732,7 @@ function exportOriginsOf(file, read) {
|
|
|
697
732
|
origin =
|
|
698
733
|
result.origins.get(local) ??
|
|
699
734
|
(result.low < Infinity
|
|
700
|
-
?
|
|
735
|
+
? exportOrigin(target, local, new Set(), nodesOfType, types)
|
|
701
736
|
: null);
|
|
702
737
|
}
|
|
703
738
|
} else {
|
|
@@ -1087,23 +1122,34 @@ export function staticExportObject(file, exportNames) {
|
|
|
1087
1122
|
/**
|
|
1088
1123
|
* A module's runtime named exports, indexed once per parsed tree: the
|
|
1089
1124
|
* export declarations that declare something, and each export specifier by
|
|
1090
|
-
* the name it exports, in source order.
|
|
1091
|
-
*
|
|
1125
|
+
* the name it exports, in source order. Each reader of export declarations
|
|
1126
|
+
* has its own index, since the readers can find different declarations.
|
|
1127
|
+
* @type {WeakMap<object, Map<Function, {declarations: any[], specifiers: Map<string, Array<{node: any, specifier: any}>>}>>}
|
|
1092
1128
|
*/
|
|
1093
1129
|
const namedExportIndexes = new WeakMap();
|
|
1094
1130
|
/** The same index with type-only exports included. */
|
|
1095
1131
|
const typedExportIndexes = new WeakMap();
|
|
1096
1132
|
|
|
1097
|
-
/**
|
|
1098
|
-
|
|
1133
|
+
/**
|
|
1134
|
+
* @param {any} program
|
|
1135
|
+
* @param {boolean} [types] include type-only exports
|
|
1136
|
+
* @param {(node: any, type: string) => readonly any[]} [read] how the
|
|
1137
|
+
* module's export declarations are read
|
|
1138
|
+
*/
|
|
1139
|
+
function namedExportIndex(program, types = false, read = nodesOfType) {
|
|
1099
1140
|
const indexes = types ? typedExportIndexes : namedExportIndexes;
|
|
1100
|
-
|
|
1141
|
+
let byReader = indexes.get(program);
|
|
1142
|
+
if (!byReader) {
|
|
1143
|
+
byReader = new Map();
|
|
1144
|
+
indexes.set(program, byReader);
|
|
1145
|
+
}
|
|
1146
|
+
const cached = byReader.get(read);
|
|
1101
1147
|
if (cached) return cached;
|
|
1102
1148
|
/** @type {any[]} */
|
|
1103
1149
|
const declarations = [];
|
|
1104
1150
|
/** @type {Map<string, Array<{node: any, specifier: any}>>} */
|
|
1105
1151
|
const specifiers = new Map();
|
|
1106
|
-
for (const node of
|
|
1152
|
+
for (const node of read(program, 'ExportNamedDeclaration')) {
|
|
1107
1153
|
if (node.exportKind === 'type' && !types) continue;
|
|
1108
1154
|
if (node.declaration) declarations.push(node);
|
|
1109
1155
|
for (const specifier of node.specifiers ?? []) {
|
|
@@ -1120,7 +1166,7 @@ function namedExportIndex(program, types = false) {
|
|
|
1120
1166
|
}
|
|
1121
1167
|
}
|
|
1122
1168
|
const index = {declarations, specifiers};
|
|
1123
|
-
|
|
1169
|
+
byReader.set(read, index);
|
|
1124
1170
|
return index;
|
|
1125
1171
|
}
|
|
1126
1172
|
|
|
@@ -1142,6 +1188,21 @@ export function moduleExportOrigin(
|
|
|
1142
1188
|
seen = new Set(),
|
|
1143
1189
|
{types = false} = {},
|
|
1144
1190
|
) {
|
|
1191
|
+
return exportOrigin(file, exportName, seen, moduleDeclarations, types);
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* {@link moduleExportOrigin} with the reader of a module's export
|
|
1196
|
+
* declarations: {@link moduleDeclarations} for icon-set libraries, or
|
|
1197
|
+
* {@link nodesOfType} for every other caller.
|
|
1198
|
+
* @param {string} file
|
|
1199
|
+
* @param {string} exportName
|
|
1200
|
+
* @param {Set<string>} seen
|
|
1201
|
+
* @param {(node: any, type: string) => readonly any[]} read
|
|
1202
|
+
* @param {boolean} [types] also follow type-only exports and declarations
|
|
1203
|
+
* @returns {{file: string, name: string} | null}
|
|
1204
|
+
*/
|
|
1205
|
+
function exportOrigin(file, exportName, seen, read, types = false) {
|
|
1145
1206
|
const identity = `${file}\0${exportName}`;
|
|
1146
1207
|
if (seen.has(identity)) return null;
|
|
1147
1208
|
seen.add(identity);
|
|
@@ -1152,10 +1213,18 @@ export function moduleExportOrigin(
|
|
|
1152
1213
|
} catch {
|
|
1153
1214
|
return null;
|
|
1154
1215
|
}
|
|
1155
|
-
const {declarations, specifiers} = namedExportIndex(ast.program, types);
|
|
1216
|
+
const {declarations, specifiers} = namedExportIndex(ast.program, types, read);
|
|
1156
1217
|
for (const node of declarations) {
|
|
1157
1218
|
if (declarationExports(node.declaration, exportName, types)) {
|
|
1158
|
-
return
|
|
1219
|
+
return declaredOrigin(
|
|
1220
|
+
ast,
|
|
1221
|
+
file,
|
|
1222
|
+
node.declaration,
|
|
1223
|
+
exportName,
|
|
1224
|
+
types,
|
|
1225
|
+
seen,
|
|
1226
|
+
read,
|
|
1227
|
+
);
|
|
1159
1228
|
}
|
|
1160
1229
|
}
|
|
1161
1230
|
for (const {node, specifier} of specifiers.get(exportName) ?? []) {
|
|
@@ -1163,28 +1232,28 @@ export function moduleExportOrigin(
|
|
|
1163
1232
|
if (node.source) {
|
|
1164
1233
|
const target = resolveModuleOrPackage(node.source.value, file);
|
|
1165
1234
|
const origin = target
|
|
1166
|
-
?
|
|
1235
|
+
? exportOrigin(target, local, seen, read, types)
|
|
1167
1236
|
: null;
|
|
1168
1237
|
if (origin) return origin;
|
|
1169
1238
|
continue;
|
|
1170
1239
|
}
|
|
1171
|
-
return bindingOrigin(ast, file, local, seen, types);
|
|
1240
|
+
return bindingOrigin(ast, file, local, seen, types, read);
|
|
1172
1241
|
}
|
|
1173
1242
|
if (exportName === 'default') {
|
|
1174
|
-
for (const node of
|
|
1243
|
+
for (const node of read(ast.program, 'ExportDefaultDeclaration')) {
|
|
1175
1244
|
const declaration = node.declaration;
|
|
1176
1245
|
if (!types && !runtimeDefault(declaration)) continue;
|
|
1177
1246
|
if (declaration.type === 'Identifier') {
|
|
1178
|
-
return bindingOrigin(ast, file, declaration.name, seen, types);
|
|
1247
|
+
return bindingOrigin(ast, file, declaration.name, seen, types, read);
|
|
1179
1248
|
}
|
|
1180
1249
|
return {file, name: 'default'};
|
|
1181
1250
|
}
|
|
1182
1251
|
}
|
|
1183
|
-
for (const node of
|
|
1252
|
+
for (const node of read(ast.program, 'ExportAllDeclaration')) {
|
|
1184
1253
|
if ((node.exportKind === 'type' && !types) || node.exported) continue;
|
|
1185
1254
|
const target = resolveModuleOrPackage(node.source?.value, file);
|
|
1186
1255
|
const origin = target
|
|
1187
|
-
?
|
|
1256
|
+
? exportOrigin(target, exportName, seen, read, types)
|
|
1188
1257
|
: null;
|
|
1189
1258
|
if (origin) return origin;
|
|
1190
1259
|
}
|
|
@@ -1240,7 +1309,10 @@ function originGapReason(file, exportName, seen = new Set()) {
|
|
|
1240
1309
|
}
|
|
1241
1310
|
/** @type {string | null} */
|
|
1242
1311
|
let local = null;
|
|
1243
|
-
for (const node of
|
|
1312
|
+
for (const node of moduleDeclarations(
|
|
1313
|
+
ast.program,
|
|
1314
|
+
'ExportNamedDeclaration',
|
|
1315
|
+
)) {
|
|
1244
1316
|
for (const specifier of node.specifiers ?? []) {
|
|
1245
1317
|
const exported = specifier.exported?.name ?? specifier.exported?.value;
|
|
1246
1318
|
if (exported !== exportName) continue;
|
|
@@ -1261,7 +1333,10 @@ function originGapReason(file, exportName, seen = new Set()) {
|
|
|
1261
1333
|
}
|
|
1262
1334
|
}
|
|
1263
1335
|
if (exportName === 'default') {
|
|
1264
|
-
for (const node of
|
|
1336
|
+
for (const node of moduleDeclarations(
|
|
1337
|
+
ast.program,
|
|
1338
|
+
'ExportDefaultDeclaration',
|
|
1339
|
+
)) {
|
|
1265
1340
|
if (node.declaration?.type === 'Identifier') {
|
|
1266
1341
|
local = node.declaration.name;
|
|
1267
1342
|
}
|
|
@@ -1269,7 +1344,10 @@ function originGapReason(file, exportName, seen = new Set()) {
|
|
|
1269
1344
|
}
|
|
1270
1345
|
if (!local) {
|
|
1271
1346
|
// Bound behind `export *`: the module it comes from says why.
|
|
1272
|
-
for (const node of
|
|
1347
|
+
for (const node of moduleDeclarations(
|
|
1348
|
+
ast.program,
|
|
1349
|
+
'ExportAllDeclaration',
|
|
1350
|
+
)) {
|
|
1273
1351
|
if (node.exportKind === 'type' || node.exported) continue;
|
|
1274
1352
|
const target = resolveModuleOrPackage(node.source?.value, file);
|
|
1275
1353
|
if (
|
|
@@ -1330,7 +1408,10 @@ export function followedExportNames(
|
|
|
1330
1408
|
}
|
|
1331
1409
|
/** @type {Set<string>} */
|
|
1332
1410
|
const names = new Set();
|
|
1333
|
-
for (const node of
|
|
1411
|
+
for (const node of moduleDeclarations(
|
|
1412
|
+
ast.program,
|
|
1413
|
+
'ExportNamedDeclaration',
|
|
1414
|
+
)) {
|
|
1334
1415
|
if (node.exportKind === 'type' && !types) continue;
|
|
1335
1416
|
const declaration = node.declaration;
|
|
1336
1417
|
if (declaration && (declaration.declare !== true || types)) {
|
|
@@ -1360,7 +1441,7 @@ export function followedExportNames(
|
|
|
1360
1441
|
}
|
|
1361
1442
|
}
|
|
1362
1443
|
}
|
|
1363
|
-
for (const node of
|
|
1444
|
+
for (const node of moduleDeclarations(ast.program, 'ExportAllDeclaration')) {
|
|
1364
1445
|
if ((node.exportKind === 'type' && !types) || node.exported) continue;
|
|
1365
1446
|
const target = resolveModuleOrPackage(node.source?.value, file);
|
|
1366
1447
|
if (target) {
|
|
@@ -1422,7 +1503,7 @@ export function exportValueKind(file, exportName) {
|
|
|
1422
1503
|
return 'unknown';
|
|
1423
1504
|
};
|
|
1424
1505
|
if (origin.name === 'default') {
|
|
1425
|
-
const [node] =
|
|
1506
|
+
const [node] = moduleDeclarations(ast.program, 'ExportDefaultDeclaration');
|
|
1426
1507
|
return node ? kindOf(node.declaration) : 'unknown';
|
|
1427
1508
|
}
|
|
1428
1509
|
for (const statement of ast.program.body) {
|
|
@@ -1479,7 +1560,7 @@ export function exportScalarType(file, exportName) {
|
|
|
1479
1560
|
return null;
|
|
1480
1561
|
};
|
|
1481
1562
|
if (origin.name === 'default') {
|
|
1482
|
-
const [node] =
|
|
1563
|
+
const [node] = moduleDeclarations(ast.program, 'ExportDefaultDeclaration');
|
|
1483
1564
|
return node ? typeOf(node.declaration) : null;
|
|
1484
1565
|
}
|
|
1485
1566
|
for (const statement of ast.program.body) {
|
|
@@ -1622,6 +1703,48 @@ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
|
|
|
1622
1703
|
return origins;
|
|
1623
1704
|
}
|
|
1624
1705
|
|
|
1706
|
+
/**
|
|
1707
|
+
* Where a declared export is defined. An `export const X = Y` whose value is
|
|
1708
|
+
* another binding is that binding, so an alias of an imported value has the
|
|
1709
|
+
* imported value's origin.
|
|
1710
|
+
* @param {any} ast
|
|
1711
|
+
* @param {string} file
|
|
1712
|
+
* @param {any} declaration
|
|
1713
|
+
* @param {string} name
|
|
1714
|
+
* @param {boolean} types
|
|
1715
|
+
* @param {Set<string>} [seen]
|
|
1716
|
+
* @param {(node: any, type: string) => readonly any[]} [read]
|
|
1717
|
+
* @returns {{file: string, name: string}}
|
|
1718
|
+
*/
|
|
1719
|
+
function declaredOrigin(
|
|
1720
|
+
ast,
|
|
1721
|
+
file,
|
|
1722
|
+
declaration,
|
|
1723
|
+
name,
|
|
1724
|
+
types,
|
|
1725
|
+
seen = new Set(),
|
|
1726
|
+
read = nodesOfType,
|
|
1727
|
+
) {
|
|
1728
|
+
if (
|
|
1729
|
+
declaration?.type === 'VariableDeclaration' &&
|
|
1730
|
+
declaration.kind === 'const'
|
|
1731
|
+
) {
|
|
1732
|
+
for (const declarator of declaration.declarations) {
|
|
1733
|
+
if (
|
|
1734
|
+
declarator.id?.type === 'Identifier' &&
|
|
1735
|
+
declarator.id.name === name &&
|
|
1736
|
+
declarator.init?.type === 'Identifier'
|
|
1737
|
+
) {
|
|
1738
|
+
const init = declarator.init.name;
|
|
1739
|
+
return (
|
|
1740
|
+
bindingOrigin(ast, file, init, seen, types, read) ?? {file, name}
|
|
1741
|
+
);
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return {file, name};
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1625
1748
|
/**
|
|
1626
1749
|
* Where a top-level binding of a parsed module comes from: an import from a
|
|
1627
1750
|
* local module is followed to its origin; anything else is declared here.
|
|
@@ -1630,9 +1753,18 @@ export function elementPropOrigins(file, {sources, name, prop, unwrap}) {
|
|
|
1630
1753
|
* @param {string} local
|
|
1631
1754
|
* @param {Set<string>} seen
|
|
1632
1755
|
* @param {boolean} [types] also follow `import type`
|
|
1756
|
+
* @param {(node: any, type: string) => readonly any[]} [read] how an
|
|
1757
|
+
* imported module's export declarations are read
|
|
1633
1758
|
* @returns {{file: string, name: string} | null}
|
|
1634
1759
|
*/
|
|
1635
|
-
function bindingOrigin(
|
|
1760
|
+
function bindingOrigin(
|
|
1761
|
+
ast,
|
|
1762
|
+
file,
|
|
1763
|
+
local,
|
|
1764
|
+
seen,
|
|
1765
|
+
types = false,
|
|
1766
|
+
read = nodesOfType,
|
|
1767
|
+
) {
|
|
1636
1768
|
for (const node of ast.program.body) {
|
|
1637
1769
|
if (
|
|
1638
1770
|
node.type !== 'ImportDeclaration' ||
|
|
@@ -1646,9 +1778,7 @@ function bindingOrigin(ast, file, local, seen, types = false) {
|
|
|
1646
1778
|
const imported =
|
|
1647
1779
|
specifier.imported?.name ?? specifier.imported?.value ?? local;
|
|
1648
1780
|
const target = resolveModuleOrPackage(node.source.value, file);
|
|
1649
|
-
return target
|
|
1650
|
-
? moduleExportOrigin(target, imported, seen, {types})
|
|
1651
|
-
: null;
|
|
1781
|
+
return target ? exportOrigin(target, imported, seen, read, types) : null;
|
|
1652
1782
|
}
|
|
1653
1783
|
}
|
|
1654
1784
|
return {file, name: local};
|
|
@@ -17,7 +17,11 @@ export function importDocModule(file: string): Promise<any>;
|
|
|
17
17
|
export function importTemplateModule(file: string): Promise<any>;
|
|
18
18
|
/**
|
|
19
19
|
* Import a module natively, by file URL: how the docs API, search, and the
|
|
20
|
-
* unchecked component and hook readers have always imported docs.
|
|
20
|
+
* unchecked component and hook readers have always imported docs. A `.ts`
|
|
21
|
+
* file goes through jiti, as {@link importDocModule} imports it: Node cannot
|
|
22
|
+
* strip types from a file under node_modules, and below 22.18 it does not
|
|
23
|
+
* strip types at all, so a plain import of an installed or linked
|
|
24
|
+
* integration's `.doc.ts` fails.
|
|
21
25
|
* @param {string} file
|
|
22
26
|
* @returns {Promise<any>}
|
|
23
27
|
*/
|
|
@@ -24,7 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
import {pathToFileURL} from 'node:url';
|
|
26
26
|
import {createJiti} from 'jiti';
|
|
27
|
-
import {
|
|
27
|
+
import {importUrl} from '../fs/import-url.mjs';
|
|
28
|
+
import {
|
|
29
|
+
importUserModule,
|
|
30
|
+
readFreshInTurn,
|
|
31
|
+
readInTurn,
|
|
32
|
+
} from '../fs/module-loader.mjs';
|
|
28
33
|
import {fileStamp, recordContentRead} from '../fs/read-record.mjs';
|
|
29
34
|
|
|
30
35
|
/** @type {ReturnType<typeof createJiti> | undefined} */
|
|
@@ -78,6 +83,28 @@ function freshUrl(file) {
|
|
|
78
83
|
return url.href;
|
|
79
84
|
}
|
|
80
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Import `file` from `url`, in its turn with every other read of the file in
|
|
88
|
+
* this process (`readInTurn`, ../fs/module-loader.mjs).
|
|
89
|
+
* @param {string} file
|
|
90
|
+
* @param {string} url
|
|
91
|
+
* @returns {Promise<any>}
|
|
92
|
+
*/
|
|
93
|
+
function importInTurn(file, url) {
|
|
94
|
+
return readInTurn(file, () => importUrl(url));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Import `file` again, for a change, as a new module. Node chooses its format
|
|
99
|
+
* as for the first import. The read takes its turn without the file's
|
|
100
|
+
* CommonJS cache entry (`readFreshInTurn`, ../fs/module-loader.mjs).
|
|
101
|
+
* @param {string} file
|
|
102
|
+
* @returns {Promise<any>}
|
|
103
|
+
*/
|
|
104
|
+
function importFresh(file) {
|
|
105
|
+
return readFreshInTurn(file, () => importUrl(freshUrl(file)));
|
|
106
|
+
}
|
|
107
|
+
|
|
81
108
|
/**
|
|
82
109
|
* Import a component, hook, topic, or self-doc module: `.ts` through jiti,
|
|
83
110
|
* anything else natively.
|
|
@@ -105,28 +132,35 @@ export function importTemplateModule(file) {
|
|
|
105
132
|
jsxJiti ??= createJiti(import.meta.url, {jsx: true});
|
|
106
133
|
return jsxJiti.import(first);
|
|
107
134
|
}
|
|
108
|
-
return
|
|
135
|
+
return importInTurn(first, `file://${first}`);
|
|
109
136
|
},
|
|
110
137
|
changed =>
|
|
111
138
|
changed.endsWith('.ts')
|
|
112
139
|
? createJiti(import.meta.url, {jsx: true, moduleCache: false}).import(
|
|
113
140
|
changed,
|
|
114
141
|
)
|
|
115
|
-
:
|
|
142
|
+
: importFresh(changed),
|
|
116
143
|
);
|
|
117
144
|
}
|
|
118
145
|
|
|
119
146
|
/**
|
|
120
147
|
* Import a module natively, by file URL: how the docs API, search, and the
|
|
121
|
-
* unchecked component and hook readers have always imported docs.
|
|
148
|
+
* unchecked component and hook readers have always imported docs. A `.ts`
|
|
149
|
+
* file goes through jiti, as {@link importDocModule} imports it: Node cannot
|
|
150
|
+
* strip types from a file under node_modules, and below 22.18 it does not
|
|
151
|
+
* strip types at all, so a plain import of an installed or linked
|
|
152
|
+
* integration's `.doc.ts` fails.
|
|
122
153
|
* @param {string} file
|
|
123
154
|
* @returns {Promise<any>}
|
|
124
155
|
*/
|
|
125
156
|
export function importNativeModule(file) {
|
|
157
|
+
if (file.endsWith('.ts')) {
|
|
158
|
+
return importDocModule(file);
|
|
159
|
+
}
|
|
126
160
|
return importCurrent(
|
|
127
161
|
file,
|
|
128
162
|
'native',
|
|
129
|
-
first =>
|
|
130
|
-
changed =>
|
|
163
|
+
first => importInTurn(first, pathToFileURL(first).href),
|
|
164
|
+
changed => importFresh(changed),
|
|
131
165
|
);
|
|
132
166
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 dynamic import of an authored module by its file URL.
|
|
6
|
+
*
|
|
7
|
+
* @input An absolute `file:` URL, with any query its caller adds to name a
|
|
8
|
+
* fresh module.
|
|
9
|
+
* @output The module's namespace object, as a plain `import()` gives it.
|
|
10
|
+
* @position Called by the doc importers (../doc-compiler/import.mjs). The
|
|
11
|
+
* node test project loads this file natively, as the CLI does
|
|
12
|
+
* (vitest.config.ts). The doc files that a catalog command imports then load
|
|
13
|
+
* natively as well, without a request to the test runner for each of them.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Import the module at `url`.
|
|
17
|
+
* @param {string} url an absolute `file:` URL
|
|
18
|
+
* @returns {Promise<any>}
|
|
19
|
+
*/
|
|
20
|
+
export function importUrl(url: string): Promise<any>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file The dynamic import of an authored module by its file URL.
|
|
5
|
+
*
|
|
6
|
+
* @input An absolute `file:` URL, with any query its caller adds to name a
|
|
7
|
+
* fresh module.
|
|
8
|
+
* @output The module's namespace object, as a plain `import()` gives it.
|
|
9
|
+
* @position Called by the doc importers (../doc-compiler/import.mjs). The
|
|
10
|
+
* node test project loads this file natively, as the CLI does
|
|
11
|
+
* (vitest.config.ts). The doc files that a catalog command imports then load
|
|
12
|
+
* natively as well, without a request to the test runner for each of them.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Import the module at `url`.
|
|
17
|
+
* @param {string} url an absolute `file:` URL
|
|
18
|
+
* @returns {Promise<any>}
|
|
19
|
+
*/
|
|
20
|
+
export function importUrl(url) {
|
|
21
|
+
return import(url);
|
|
22
|
+
}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* Import a user-authored module. `.ts` is loaded via jiti; `.mjs`/`.js` use
|
|
6
6
|
* native dynamic import for ordinary cached reads. A fresh `.ts` read uses a
|
|
7
|
-
* no-cache jiti instance.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* no-cache jiti instance. Any other fresh read drops the module from the
|
|
8
|
+
* require cache and imports a cache-busted file URL. Node then chooses its
|
|
9
|
+
* format as for the first read, so a fresh read gives what a first read gives.
|
|
10
10
|
* Normal loads retain module caching. `fresh` rereads a file that changed
|
|
11
11
|
* during this process: one a codemod rewrote, or an edited doc file (the doc
|
|
12
12
|
* importers in ../doc-compiler/import.mjs read each change once).
|
|
@@ -29,6 +29,27 @@ export function importUserModule(file: string, { fresh }?: {
|
|
|
29
29
|
* @returns {Promise<Record<string, unknown>>}
|
|
30
30
|
*/
|
|
31
31
|
export function importThemeArtifact(specifier: string, cwd: string): Promise<Record<string, unknown>>;
|
|
32
|
+
/**
|
|
33
|
+
* Run `read`, an import of `file`, once the imports of `file` started before
|
|
34
|
+
* it have ended. Imports of other files do not wait. A fresh read removes the
|
|
35
|
+
* file from Node's CommonJS cache. A CommonJS import still in progress needs
|
|
36
|
+
* that entry until it ends.
|
|
37
|
+
* @template T
|
|
38
|
+
* @param {string} file absolute path
|
|
39
|
+
* @param {() => Promise<T>} read
|
|
40
|
+
* @returns {Promise<T>}
|
|
41
|
+
*/
|
|
42
|
+
export function readInTurn<T>(file: string, read: () => Promise<T>): Promise<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Run `read`, a fresh import of `file`, in the file's turn (`readInTurn`),
|
|
45
|
+
* once the file is gone from Node's CommonJS cache. A new URL names a new ES
|
|
46
|
+
* module only, so a CommonJS module also needs its cache entry gone.
|
|
47
|
+
* @template T
|
|
48
|
+
* @param {string} file absolute path
|
|
49
|
+
* @param {() => Promise<T>} read
|
|
50
|
+
* @returns {Promise<T>}
|
|
51
|
+
*/
|
|
52
|
+
export function readFreshInTurn<T>(file: string, read: () => Promise<T>): Promise<T>;
|
|
32
53
|
/**
|
|
33
54
|
* Import a user-authored module, take its default export, and validate it
|
|
34
55
|
* through an authoring parser. This is the single load/validation boundary for
|