@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5

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 (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,9 +1,3 @@
1
- import _regeneratorValues from "@babel/runtime/helpers/esm/regeneratorValues";
2
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
6
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
1
  import { getFileNameFromUrl } from "./getFileNameFromUrl.js";
8
2
  import { fileUrlToPortablePath, portablePathToFileUrl } from "./fileUrlToPortablePath.js";
9
3
 
@@ -11,20 +5,20 @@ import { fileUrlToPortablePath, portablePathToFileUrl } from "./fileUrlToPortabl
11
5
  * Isomorphic path joining function that works in both Node.js and browser environments.
12
6
  * Uses string concatenation to handle path joining consistently across platforms.
13
7
  */
14
- function joinPath(basePath) {
8
+ function joinPath(basePath, ...segments) {
15
9
  // Start with the base path, ensuring it has a trailing slash for URL construction
16
- var result = basePath.endsWith('/') ? basePath : "".concat(basePath, "/");
10
+ let result = basePath.endsWith('/') ? basePath : `${basePath}/`;
17
11
 
18
12
  // Handle each segment
19
- for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i += 1) {
20
- var segment = i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1];
13
+ for (let i = 0; i < segments.length; i += 1) {
14
+ const segment = segments[i];
21
15
  if (segment) {
22
16
  // Remove leading slash from segment to avoid double slashes
23
- var cleanSegment = segment.startsWith('/') ? segment.slice(1) : segment;
17
+ const cleanSegment = segment.startsWith('/') ? segment.slice(1) : segment;
24
18
  // Append segment
25
19
  result += cleanSegment;
26
20
  // Add trailing slash for intermediate segments
27
- if (i < (arguments.length <= 1 ? 0 : arguments.length - 1) - 1) {
21
+ if (i < segments.length - 1) {
28
22
  result += '/';
29
23
  }
30
24
  }
@@ -35,17 +29,17 @@ function joinPath(basePath) {
35
29
  /**
36
30
  * Default file extensions for JavaScript/TypeScript modules that can be resolved
37
31
  */
38
- export var JAVASCRIPT_MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
32
+ export const JAVASCRIPT_MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
39
33
 
40
34
  /**
41
35
  * Extension priority for type-only imports - prioritize .d.ts first
42
36
  */
43
- export var TYPE_IMPORT_EXTENSIONS = ['.d.ts', '.ts', '.tsx', '.js', '.jsx', '.mdx'];
37
+ export const TYPE_IMPORT_EXTENSIONS = ['.d.ts', '.ts', '.tsx', '.js', '.jsx', '.mdx'];
44
38
 
45
39
  /**
46
40
  * Extension priority for value imports - standard priority with .d.ts last
47
41
  */
48
- export var VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
42
+ export const VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.ts'];
49
43
 
50
44
  /**
51
45
  * Checks if a file path or import path represents a JavaScript/TypeScript module
@@ -55,9 +49,7 @@ export var VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mdx', '.d.
55
49
  export function isJavaScriptModule(path) {
56
50
  // If the path has an extension, check if it's one of the JS/TS extensions
57
51
  if (/\.[^/]+$/.test(path)) {
58
- return JAVASCRIPT_MODULE_EXTENSIONS.some(function (ext) {
59
- return path.endsWith(ext);
60
- });
52
+ return JAVASCRIPT_MODULE_EXTENSIONS.some(ext => path.endsWith(ext));
61
53
  }
62
54
  // If no extension, assume it's a JS/TS module (will be resolved to one)
63
55
  return true;
@@ -77,543 +69,326 @@ export function isJavaScriptModule(path) {
77
69
  * @param includeTypeDefs - If true, returns both import and typeImport paths with different extension priorities
78
70
  * @returns Promise<string | TypeAwareResolveResult> - The resolved file:// URL(s)
79
71
  */
80
- export function resolveModulePath(_x, _x2) {
81
- return _resolveModulePath.apply(this, arguments);
72
+ export async function resolveModulePath(moduleUrl, readDirectory, options = {}, includeTypeDefs) {
73
+ const {
74
+ extensions = JAVASCRIPT_MODULE_EXTENSIONS
75
+ } = options;
76
+
77
+ // Convert file URL to portable path for internal processing
78
+ const modulePath = moduleUrl.startsWith('file://') ? fileUrlToPortablePath(moduleUrl) : moduleUrl;
79
+
80
+ // If includeTypeDefs is true, we need to resolve with both type and value extension priorities
81
+ if (includeTypeDefs) {
82
+ return resolveWithTypeAwareness(modulePath, readDirectory, options);
83
+ }
84
+
85
+ // Extract the parent directory and the module name
86
+ const lastSlashIndex = modulePath.lastIndexOf('/');
87
+ const parentDir = modulePath.substring(0, lastSlashIndex);
88
+ const moduleName = modulePath.substring(lastSlashIndex + 1);
89
+ const resolvedPath = await resolveSinglePath(modulePath, parentDir, moduleName, readDirectory, extensions);
90
+ return resolvedPath;
82
91
  }
83
92
 
84
93
  /**
85
94
  * Resolves a module path with type-aware resolution, returning both import and typeImport paths
86
95
  * This function is optimized to do only a single directory read instead of two separate reads.
87
96
  */
88
- function _resolveModulePath() {
89
- _resolveModulePath = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(moduleUrl, readDirectory) {
90
- var options,
91
- includeTypeDefs,
92
- _options$extensions,
93
- extensions,
94
- modulePath,
95
- lastSlashIndex,
96
- parentDir,
97
- moduleName,
98
- resolvedPath,
99
- _args = arguments;
100
- return _regenerator().w(function (_context) {
101
- while (1) switch (_context.n) {
102
- case 0:
103
- options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
104
- includeTypeDefs = _args.length > 3 ? _args[3] : undefined;
105
- _options$extensions = options.extensions, extensions = _options$extensions === void 0 ? JAVASCRIPT_MODULE_EXTENSIONS : _options$extensions; // Convert file URL to portable path for internal processing
106
- modulePath = moduleUrl.startsWith('file://') ? fileUrlToPortablePath(moduleUrl) : moduleUrl; // If includeTypeDefs is true, we need to resolve with both type and value extension priorities
107
- if (!includeTypeDefs) {
108
- _context.n = 1;
109
- break;
110
- }
111
- return _context.a(2, resolveWithTypeAwareness(modulePath, readDirectory, options));
112
- case 1:
113
- // Extract the parent directory and the module name
114
- lastSlashIndex = modulePath.lastIndexOf('/');
115
- parentDir = modulePath.substring(0, lastSlashIndex);
116
- moduleName = modulePath.substring(lastSlashIndex + 1);
117
- _context.n = 2;
118
- return resolveSinglePath(modulePath, parentDir, moduleName, readDirectory, extensions);
119
- case 2:
120
- resolvedPath = _context.v;
121
- return _context.a(2, resolvedPath);
97
+ async function resolveWithTypeAwareness(modulePath, readDirectory, _options = {}) {
98
+ const lastSlashIndex = modulePath.lastIndexOf('/');
99
+ const parentDir = modulePath.substring(0, lastSlashIndex);
100
+ const moduleName = modulePath.substring(lastSlashIndex + 1);
101
+
102
+ // Single filesystem read to get directory contents
103
+ const dirContents = await readDirectory(portablePathToFileUrl(parentDir));
104
+
105
+ // Build a map of available files by basename
106
+ const filesByBaseName = new Map();
107
+ for (const entry of dirContents) {
108
+ if (entry.isFile) {
109
+ const fileName = entry.name;
110
+ let fileBaseName;
111
+ let actualExtension;
112
+
113
+ // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts
114
+ if (fileName.endsWith('.d.ts')) {
115
+ actualExtension = '.d.ts';
116
+ fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
117
+ } else {
118
+ const {
119
+ extension: fileExt
120
+ } = getFileNameFromUrl(fileName);
121
+ actualExtension = fileExt;
122
+ fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
122
123
  }
123
- }, _callee);
124
- }));
125
- return _resolveModulePath.apply(this, arguments);
126
- }
127
- function resolveWithTypeAwareness(_x3, _x4) {
128
- return _resolveWithTypeAwareness.apply(this, arguments);
129
- }
130
- /**
131
- * Internal function to resolve a single path with given extensions
132
- */
133
- function _resolveWithTypeAwareness() {
134
- _resolveWithTypeAwareness = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(modulePath, readDirectory) {
135
- var _options,
136
- lastSlashIndex,
137
- parentDir,
138
- moduleName,
139
- dirContents,
140
- filesByBaseName,
141
- _iterator,
142
- _step,
143
- _entry4,
144
- _fileName,
145
- _fileBaseName,
146
- _actualExtension,
147
- _getFileNameFromUrl2,
148
- _fileExt,
149
- matchingFiles,
150
- entryMap,
151
- importPath,
152
- _iterator2,
153
- _step2,
154
- ext,
155
- _iterator4,
156
- _step4,
157
- entry,
158
- typeImportPath,
159
- _iterator3,
160
- _step3,
161
- _ext,
162
- _iterator5,
163
- _step5,
164
- _entry,
165
- directoryMatches,
166
- moduleDir,
167
- moduleDirContents,
168
- indexFilesByBaseName,
169
- _iterator6,
170
- _step6,
171
- moduleFile,
172
- fileName,
173
- fileBaseName,
174
- actualExtension,
175
- _getFileNameFromUrl,
176
- fileExt,
177
- indexFiles,
178
- indexEntryMap,
179
- _importPath,
180
- _iterator7,
181
- _step7,
182
- _ext2,
183
- _iterator9,
184
- _step9,
185
- _entry2,
186
- _typeImportPath,
187
- _iterator8,
188
- _step8,
189
- _ext3,
190
- _iterator0,
191
- _step0,
192
- _entry3,
193
- _args2 = arguments,
194
- _t,
195
- _t2,
196
- _t3,
197
- _t4,
198
- _t5,
199
- _t6,
200
- _t7,
201
- _t8,
202
- _t9;
203
- return _regenerator().w(function (_context2) {
204
- while (1) switch (_context2.p = _context2.n) {
205
- case 0:
206
- _options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
207
- lastSlashIndex = modulePath.lastIndexOf('/');
208
- parentDir = modulePath.substring(0, lastSlashIndex);
209
- moduleName = modulePath.substring(lastSlashIndex + 1); // Single filesystem read to get directory contents
210
- _context2.n = 1;
211
- return readDirectory(portablePathToFileUrl(parentDir));
212
- case 1:
213
- dirContents = _context2.v;
214
- // Build a map of available files by basename
215
- filesByBaseName = new Map();
216
- _iterator = _createForOfIteratorHelper(dirContents);
217
- try {
218
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
219
- _entry4 = _step.value;
220
- if (_entry4.isFile) {
221
- _fileName = _entry4.name;
222
- _fileBaseName = void 0;
223
- _actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts
224
- if (_fileName.endsWith('.d.ts')) {
225
- _actualExtension = '.d.ts';
226
- _fileBaseName = _fileName.substring(0, _fileName.length - 5); // Remove .d.ts
227
- } else {
228
- _getFileNameFromUrl2 = getFileNameFromUrl(_fileName), _fileExt = _getFileNameFromUrl2.extension;
229
- _actualExtension = _fileExt;
230
- _fileBaseName = _fileName.substring(0, _fileName.length - _fileExt.length);
231
- }
232
- if (!filesByBaseName.has(_fileBaseName)) {
233
- filesByBaseName.set(_fileBaseName, []);
234
- }
235
- // Store the entry with its actual extension for later matching
236
- filesByBaseName.get(_fileBaseName).push(_extends(_extends({}, _entry4), {}, {
237
- actualExtension: _actualExtension
238
- }));
239
- }
240
- }
124
+ if (!filesByBaseName.has(fileBaseName)) {
125
+ filesByBaseName.set(fileBaseName, []);
126
+ }
127
+ // Store the entry with its actual extension for later matching
128
+ filesByBaseName.get(fileBaseName).push({
129
+ ...entry,
130
+ actualExtension
131
+ });
132
+ }
133
+ }
241
134
 
242
- // Check for the module in both priority orders
243
- } catch (err) {
244
- _iterator.e(err);
245
- } finally {
246
- _iterator.f();
247
- }
248
- matchingFiles = filesByBaseName.get(moduleName);
249
- if (!matchingFiles) {
250
- _context2.n = 32;
251
- break;
252
- }
253
- entryMap = matchingFiles; // Find best match for value imports (VALUE_IMPORT_EXTENSIONS priority)
254
- importPath = null;
255
- _iterator2 = _createForOfIteratorHelper(VALUE_IMPORT_EXTENSIONS);
256
- _context2.p = 2;
257
- _iterator2.s();
258
- case 3:
259
- if ((_step2 = _iterator2.n()).done) {
260
- _context2.n = 12;
261
- break;
262
- }
263
- ext = _step2.value;
264
- _iterator4 = _createForOfIteratorHelper(entryMap);
265
- _context2.p = 4;
266
- _iterator4.s();
267
- case 5:
268
- if ((_step4 = _iterator4.n()).done) {
269
- _context2.n = 7;
270
- break;
271
- }
272
- entry = _step4.value;
273
- if (!(entry.actualExtension === ext)) {
274
- _context2.n = 6;
275
- break;
276
- }
135
+ // Check for the module in both priority orders
136
+ const matchingFiles = filesByBaseName.get(moduleName);
137
+ if (matchingFiles) {
138
+ const entryMap = matchingFiles;
139
+
140
+ // Find best match for value imports (VALUE_IMPORT_EXTENSIONS priority)
141
+ let importPath = null;
142
+ for (const ext of VALUE_IMPORT_EXTENSIONS) {
143
+ for (const entry of entryMap) {
144
+ if (entry.actualExtension === ext) {
277
145
  importPath = portablePathToFileUrl(joinPath(parentDir, entry.name));
278
- return _context2.a(3, 7);
279
- case 6:
280
- _context2.n = 5;
281
- break;
282
- case 7:
283
- _context2.n = 9;
284
- break;
285
- case 8:
286
- _context2.p = 8;
287
- _t = _context2.v;
288
- _iterator4.e(_t);
289
- case 9:
290
- _context2.p = 9;
291
- _iterator4.f();
292
- return _context2.f(9);
293
- case 10:
294
- if (!importPath) {
295
- _context2.n = 11;
296
- break;
297
- }
298
- return _context2.a(3, 12);
299
- case 11:
300
- _context2.n = 3;
301
146
  break;
302
- case 12:
303
- _context2.n = 14;
147
+ }
148
+ }
149
+ if (importPath) {
150
+ break;
151
+ }
152
+ }
153
+
154
+ // Find best match for type imports (TYPE_IMPORT_EXTENSIONS priority)
155
+ let typeImportPath = null;
156
+ for (const ext of TYPE_IMPORT_EXTENSIONS) {
157
+ for (const entry of entryMap) {
158
+ if (entry.actualExtension === ext) {
159
+ typeImportPath = portablePathToFileUrl(joinPath(parentDir, entry.name));
304
160
  break;
305
- case 13:
306
- _context2.p = 13;
307
- _t2 = _context2.v;
308
- _iterator2.e(_t2);
309
- case 14:
310
- _context2.p = 14;
311
- _iterator2.f();
312
- return _context2.f(14);
313
- case 15:
314
- // Find best match for type imports (TYPE_IMPORT_EXTENSIONS priority)
315
- typeImportPath = null;
316
- _iterator3 = _createForOfIteratorHelper(TYPE_IMPORT_EXTENSIONS);
317
- _context2.p = 16;
318
- _iterator3.s();
319
- case 17:
320
- if ((_step3 = _iterator3.n()).done) {
321
- _context2.n = 26;
322
- break;
161
+ }
162
+ }
163
+ if (typeImportPath) {
164
+ break;
165
+ }
166
+ }
167
+ if (importPath && typeImportPath && importPath !== typeImportPath) {
168
+ return {
169
+ import: importPath,
170
+ typeImport: typeImportPath
171
+ };
172
+ }
173
+ if (importPath) {
174
+ return {
175
+ import: importPath
176
+ };
177
+ }
178
+ if (typeImportPath) {
179
+ return {
180
+ import: typeImportPath
181
+ };
182
+ }
183
+ }
184
+
185
+ // Try index files with the same single-pass approach
186
+ const directoryMatches = dirContents.filter(entry => entry.isDirectory && entry.name === moduleName);
187
+ if (directoryMatches.length > 0) {
188
+ const moduleDir = joinPath(parentDir, directoryMatches[0].name);
189
+ try {
190
+ const moduleDirContents = await readDirectory(portablePathToFileUrl(moduleDir));
191
+
192
+ // Build a map of available index files by basename
193
+ const indexFilesByBaseName = new Map();
194
+ for (const moduleFile of moduleDirContents) {
195
+ if (moduleFile.isFile) {
196
+ const fileName = moduleFile.name;
197
+ let fileBaseName;
198
+ let actualExtension;
199
+
200
+ // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts
201
+ if (fileName.endsWith('.d.ts')) {
202
+ actualExtension = '.d.ts';
203
+ fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
204
+ } else {
205
+ const {
206
+ extension: fileExt
207
+ } = getFileNameFromUrl(fileName);
208
+ actualExtension = fileExt;
209
+ fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
210
+ }
211
+ if (!indexFilesByBaseName.has(fileBaseName)) {
212
+ indexFilesByBaseName.set(fileBaseName, []);
213
+ }
214
+ // Store the entry with its actual extension for later matching
215
+ indexFilesByBaseName.get(fileBaseName).push({
216
+ ...moduleFile,
217
+ actualExtension
218
+ });
219
+ }
220
+ }
221
+
222
+ // Check for index files in both priority orders
223
+ const indexFiles = indexFilesByBaseName.get('index');
224
+ if (indexFiles) {
225
+ const indexEntryMap = indexFiles;
226
+
227
+ // Find best match for value imports
228
+ let importPath = null;
229
+ for (const ext of VALUE_IMPORT_EXTENSIONS) {
230
+ for (const entry of indexEntryMap) {
231
+ if (entry.actualExtension === ext) {
232
+ importPath = portablePathToFileUrl(joinPath(moduleDir, entry.name));
233
+ break;
234
+ }
323
235
  }
324
- _ext = _step3.value;
325
- _iterator5 = _createForOfIteratorHelper(entryMap);
326
- _context2.p = 18;
327
- _iterator5.s();
328
- case 19:
329
- if ((_step5 = _iterator5.n()).done) {
330
- _context2.n = 21;
236
+ if (importPath) {
331
237
  break;
332
238
  }
333
- _entry = _step5.value;
334
- if (!(_entry.actualExtension === _ext)) {
335
- _context2.n = 20;
336
- break;
239
+ }
240
+
241
+ // Find best match for type imports
242
+ let typeImportPath = null;
243
+ for (const ext of TYPE_IMPORT_EXTENSIONS) {
244
+ for (const entry of indexEntryMap) {
245
+ if (entry.actualExtension === ext) {
246
+ typeImportPath = portablePathToFileUrl(joinPath(moduleDir, entry.name));
247
+ break;
248
+ }
337
249
  }
338
- typeImportPath = portablePathToFileUrl(joinPath(parentDir, _entry.name));
339
- return _context2.a(3, 21);
340
- case 20:
341
- _context2.n = 19;
342
- break;
343
- case 21:
344
- _context2.n = 23;
345
- break;
346
- case 22:
347
- _context2.p = 22;
348
- _t3 = _context2.v;
349
- _iterator5.e(_t3);
350
- case 23:
351
- _context2.p = 23;
352
- _iterator5.f();
353
- return _context2.f(23);
354
- case 24:
355
- if (!typeImportPath) {
356
- _context2.n = 25;
250
+ if (typeImportPath) {
357
251
  break;
358
252
  }
359
- return _context2.a(3, 26);
360
- case 25:
361
- _context2.n = 17;
362
- break;
363
- case 26:
364
- _context2.n = 28;
365
- break;
366
- case 27:
367
- _context2.p = 27;
368
- _t4 = _context2.v;
369
- _iterator3.e(_t4);
370
- case 28:
371
- _context2.p = 28;
372
- _iterator3.f();
373
- return _context2.f(28);
374
- case 29:
375
- if (!(importPath && typeImportPath && importPath !== typeImportPath)) {
376
- _context2.n = 30;
377
- break;
378
- }
379
- return _context2.a(2, {
380
- "import": importPath,
253
+ }
254
+ if (importPath && typeImportPath && importPath !== typeImportPath) {
255
+ return {
256
+ import: importPath,
381
257
  typeImport: typeImportPath
382
- });
383
- case 30:
384
- if (!importPath) {
385
- _context2.n = 31;
386
- break;
387
- }
388
- return _context2.a(2, {
389
- "import": importPath
390
- });
391
- case 31:
392
- if (!typeImportPath) {
393
- _context2.n = 32;
394
- break;
395
- }
396
- return _context2.a(2, {
397
- "import": typeImportPath
398
- });
399
- case 32:
400
- // Try index files with the same single-pass approach
401
- directoryMatches = dirContents.filter(function (entry) {
402
- return entry.isDirectory && entry.name === moduleName;
403
- });
404
- if (!(directoryMatches.length > 0)) {
405
- _context2.n = 67;
406
- break;
258
+ };
259
+ }
260
+ if (importPath) {
261
+ return {
262
+ import: importPath
263
+ };
264
+ }
265
+ if (typeImportPath) {
266
+ return {
267
+ import: typeImportPath
268
+ };
269
+ }
270
+ }
271
+ } catch {
272
+ // Could not read module directory, continue
273
+ }
274
+ }
275
+ throw new Error(`Could not resolve module at path "${modulePath}". Tried extensions: ${VALUE_IMPORT_EXTENSIONS.join(', ')}, ${TYPE_IMPORT_EXTENSIONS.join(', ')}`);
276
+ }
277
+
278
+ /**
279
+ * Internal function to resolve a single path with given extensions
280
+ */
281
+ async function resolveSinglePath(modulePath, parentDir, moduleName, readDirectory, extensions) {
282
+ try {
283
+ // Read the parent directory contents
284
+ const dirContents = await readDirectory(portablePathToFileUrl(parentDir));
285
+
286
+ // Look for direct file matches in extension priority order
287
+ // Create a map of baseName -> files with that basename for efficient lookup
288
+ const filesByBaseName = new Map();
289
+ for (const entry of dirContents) {
290
+ if (entry.isFile) {
291
+ const fileName = entry.name;
292
+ let fileBaseName;
293
+ let actualExtension;
294
+
295
+ // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts
296
+ if (fileName.endsWith('.d.ts')) {
297
+ actualExtension = '.d.ts';
298
+ fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
299
+ } else {
300
+ const {
301
+ extension: fileExt
302
+ } = getFileNameFromUrl(fileName);
303
+ actualExtension = fileExt;
304
+ fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
305
+ }
306
+ if (!filesByBaseName.has(fileBaseName)) {
307
+ filesByBaseName.set(fileBaseName, []);
308
+ }
309
+ // Store the entry with its actual extension for later matching
310
+ filesByBaseName.get(fileBaseName).push({
311
+ ...entry,
312
+ // Add a custom property to track the actual extension
313
+ actualExtension
314
+ });
315
+ }
316
+ }
317
+
318
+ // Check for the module in extension priority order
319
+ const matchingFiles = filesByBaseName.get(moduleName);
320
+ if (matchingFiles) {
321
+ for (const ext of extensions) {
322
+ for (const entry of matchingFiles) {
323
+ const entryWithExt = entry;
324
+ if (entryWithExt.actualExtension === ext) {
325
+ const resolvedPath = joinPath(parentDir, entry.name);
326
+ return portablePathToFileUrl(resolvedPath);
327
+ }
328
+ }
329
+ }
330
+ }
331
+
332
+ // Look for directory with index files
333
+ const directoryMatches = dirContents.filter(entry => entry.isDirectory && entry.name === moduleName);
334
+ if (directoryMatches.length > 0) {
335
+ const moduleDir = joinPath(parentDir, directoryMatches[0].name);
336
+ try {
337
+ const moduleDirContents = await readDirectory(portablePathToFileUrl(moduleDir));
338
+
339
+ // Look for index files in extension priority order
340
+ // Create a map of baseName -> files for efficient lookup
341
+ const indexFilesByBaseName = new Map();
342
+ for (const moduleFile of moduleDirContents) {
343
+ if (moduleFile.isFile) {
344
+ const fileName = moduleFile.name;
345
+ let fileBaseName;
346
+ let actualExtension;
347
+
348
+ // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts
349
+ if (fileName.endsWith('.d.ts')) {
350
+ actualExtension = '.d.ts';
351
+ fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
352
+ } else {
353
+ const {
354
+ extension: fileExt
355
+ } = getFileNameFromUrl(fileName);
356
+ actualExtension = fileExt;
357
+ fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
358
+ }
359
+ if (!indexFilesByBaseName.has(fileBaseName)) {
360
+ indexFilesByBaseName.set(fileBaseName, []);
361
+ }
362
+ // Store the entry with its actual extension for later matching
363
+ indexFilesByBaseName.get(fileBaseName).push({
364
+ ...moduleFile,
365
+ actualExtension
366
+ });
407
367
  }
408
- moduleDir = joinPath(parentDir, directoryMatches[0].name);
409
- _context2.p = 33;
410
- _context2.n = 34;
411
- return readDirectory(portablePathToFileUrl(moduleDir));
412
- case 34:
413
- moduleDirContents = _context2.v;
414
- // Build a map of available index files by basename
415
- indexFilesByBaseName = new Map();
416
- _iterator6 = _createForOfIteratorHelper(moduleDirContents);
417
- try {
418
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
419
- moduleFile = _step6.value;
420
- if (moduleFile.isFile) {
421
- fileName = moduleFile.name;
422
- fileBaseName = void 0;
423
- actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts
424
- if (fileName.endsWith('.d.ts')) {
425
- actualExtension = '.d.ts';
426
- fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
427
- } else {
428
- _getFileNameFromUrl = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl.extension;
429
- actualExtension = fileExt;
430
- fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
431
- }
432
- if (!indexFilesByBaseName.has(fileBaseName)) {
433
- indexFilesByBaseName.set(fileBaseName, []);
434
- }
435
- // Store the entry with its actual extension for later matching
436
- indexFilesByBaseName.get(fileBaseName).push(_extends(_extends({}, moduleFile), {}, {
437
- actualExtension: actualExtension
438
- }));
368
+ }
369
+
370
+ // Check for index files in extension priority order
371
+ const indexFiles = indexFilesByBaseName.get('index');
372
+ if (indexFiles) {
373
+ for (const ext of extensions) {
374
+ for (const entry of indexFiles) {
375
+ const entryWithExt = entry;
376
+ if (entryWithExt.actualExtension === ext) {
377
+ return portablePathToFileUrl(joinPath(moduleDir, entry.name));
439
378
  }
440
379
  }
441
-
442
- // Check for index files in both priority orders
443
- } catch (err) {
444
- _iterator6.e(err);
445
- } finally {
446
- _iterator6.f();
447
- }
448
- indexFiles = indexFilesByBaseName.get('index');
449
- if (!indexFiles) {
450
- _context2.n = 65;
451
- break;
452
- }
453
- indexEntryMap = indexFiles; // Find best match for value imports
454
- _importPath = null;
455
- _iterator7 = _createForOfIteratorHelper(VALUE_IMPORT_EXTENSIONS);
456
- _context2.p = 35;
457
- _iterator7.s();
458
- case 36:
459
- if ((_step7 = _iterator7.n()).done) {
460
- _context2.n = 45;
461
- break;
462
- }
463
- _ext2 = _step7.value;
464
- _iterator9 = _createForOfIteratorHelper(indexEntryMap);
465
- _context2.p = 37;
466
- _iterator9.s();
467
- case 38:
468
- if ((_step9 = _iterator9.n()).done) {
469
- _context2.n = 40;
470
- break;
471
- }
472
- _entry2 = _step9.value;
473
- if (!(_entry2.actualExtension === _ext2)) {
474
- _context2.n = 39;
475
- break;
476
- }
477
- _importPath = portablePathToFileUrl(joinPath(moduleDir, _entry2.name));
478
- return _context2.a(3, 40);
479
- case 39:
480
- _context2.n = 38;
481
- break;
482
- case 40:
483
- _context2.n = 42;
484
- break;
485
- case 41:
486
- _context2.p = 41;
487
- _t5 = _context2.v;
488
- _iterator9.e(_t5);
489
- case 42:
490
- _context2.p = 42;
491
- _iterator9.f();
492
- return _context2.f(42);
493
- case 43:
494
- if (!_importPath) {
495
- _context2.n = 44;
496
- break;
497
- }
498
- return _context2.a(3, 45);
499
- case 44:
500
- _context2.n = 36;
501
- break;
502
- case 45:
503
- _context2.n = 47;
504
- break;
505
- case 46:
506
- _context2.p = 46;
507
- _t6 = _context2.v;
508
- _iterator7.e(_t6);
509
- case 47:
510
- _context2.p = 47;
511
- _iterator7.f();
512
- return _context2.f(47);
513
- case 48:
514
- // Find best match for type imports
515
- _typeImportPath = null;
516
- _iterator8 = _createForOfIteratorHelper(TYPE_IMPORT_EXTENSIONS);
517
- _context2.p = 49;
518
- _iterator8.s();
519
- case 50:
520
- if ((_step8 = _iterator8.n()).done) {
521
- _context2.n = 59;
522
- break;
523
- }
524
- _ext3 = _step8.value;
525
- _iterator0 = _createForOfIteratorHelper(indexEntryMap);
526
- _context2.p = 51;
527
- _iterator0.s();
528
- case 52:
529
- if ((_step0 = _iterator0.n()).done) {
530
- _context2.n = 54;
531
- break;
532
- }
533
- _entry3 = _step0.value;
534
- if (!(_entry3.actualExtension === _ext3)) {
535
- _context2.n = 53;
536
- break;
537
- }
538
- _typeImportPath = portablePathToFileUrl(joinPath(moduleDir, _entry3.name));
539
- return _context2.a(3, 54);
540
- case 53:
541
- _context2.n = 52;
542
- break;
543
- case 54:
544
- _context2.n = 56;
545
- break;
546
- case 55:
547
- _context2.p = 55;
548
- _t7 = _context2.v;
549
- _iterator0.e(_t7);
550
- case 56:
551
- _context2.p = 56;
552
- _iterator0.f();
553
- return _context2.f(56);
554
- case 57:
555
- if (!_typeImportPath) {
556
- _context2.n = 58;
557
- break;
558
- }
559
- return _context2.a(3, 59);
560
- case 58:
561
- _context2.n = 50;
562
- break;
563
- case 59:
564
- _context2.n = 61;
565
- break;
566
- case 60:
567
- _context2.p = 60;
568
- _t8 = _context2.v;
569
- _iterator8.e(_t8);
570
- case 61:
571
- _context2.p = 61;
572
- _iterator8.f();
573
- return _context2.f(61);
574
- case 62:
575
- if (!(_importPath && _typeImportPath && _importPath !== _typeImportPath)) {
576
- _context2.n = 63;
577
- break;
578
380
  }
579
- return _context2.a(2, {
580
- "import": _importPath,
581
- typeImport: _typeImportPath
582
- });
583
- case 63:
584
- if (!_importPath) {
585
- _context2.n = 64;
586
- break;
587
- }
588
- return _context2.a(2, {
589
- "import": _importPath
590
- });
591
- case 64:
592
- if (!_typeImportPath) {
593
- _context2.n = 65;
594
- break;
595
- }
596
- return _context2.a(2, {
597
- "import": _typeImportPath
598
- });
599
- case 65:
600
- _context2.n = 67;
601
- break;
602
- case 66:
603
- _context2.p = 66;
604
- _t9 = _context2.v;
605
- case 67:
606
- throw new Error("Could not resolve module at path \"".concat(modulePath, "\". Tried extensions: ").concat(VALUE_IMPORT_EXTENSIONS.join(', '), ", ").concat(TYPE_IMPORT_EXTENSIONS.join(', ')));
607
- case 68:
608
- return _context2.a(2);
381
+ }
382
+ } catch {
383
+ // Could not read module directory, continue
609
384
  }
610
- }, _callee2, null, [[51, 55, 56, 57], [49, 60, 61, 62], [37, 41, 42, 43], [35, 46, 47, 48], [33, 66], [18, 22, 23, 24], [16, 27, 28, 29], [4, 8, 9, 10], [2, 13, 14, 15]]);
611
- }));
612
- return _resolveWithTypeAwareness.apply(this, arguments);
613
- }
614
- function resolveSinglePath(_x5, _x6, _x7, _x8, _x9) {
615
- return _resolveSinglePath.apply(this, arguments);
385
+ }
386
+ } catch {
387
+ // Could not read parent directory
388
+ }
389
+ throw new Error(`Could not resolve module at path "${modulePath}". Tried extensions: ${extensions.join(', ')}`);
616
390
  }
391
+
617
392
  /**
618
393
  * Resolves multiple module paths efficiently by grouping them by directory
619
394
  * and performing batch directory lookups.
@@ -623,241 +398,172 @@ function resolveSinglePath(_x5, _x6, _x7, _x8, _x9) {
623
398
  * @param options - Configuration options
624
399
  * @returns Promise<Map<string, string>> - Map from input path to resolved file path
625
400
  */
626
- function _resolveSinglePath() {
627
- _resolveSinglePath = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(modulePath, parentDir, moduleName, readDirectory, extensions) {
628
- var dirContents, filesByBaseName, _iterator1, _step1, _entry6, _fileName2, _fileBaseName2, _actualExtension2, _getFileNameFromUrl4, _fileExt2, matchingFiles, _iterator10, _step10, ext, _iterator11, _step11, entry, entryWithExt, resolvedPath, directoryMatches, moduleDir, moduleDirContents, indexFilesByBaseName, _iterator12, _step12, moduleFile, fileName, fileBaseName, actualExtension, _getFileNameFromUrl3, fileExt, indexFiles, _iterator13, _step13, _ext4, _iterator14, _step14, _entry5, _entryWithExt, _t0, _t1, _t10, _t11, _t12, _t13;
629
- return _regenerator().w(function (_context3) {
630
- while (1) switch (_context3.p = _context3.n) {
631
- case 0:
632
- _context3.p = 0;
633
- _context3.n = 1;
634
- return readDirectory(portablePathToFileUrl(parentDir));
635
- case 1:
636
- dirContents = _context3.v;
637
- // Look for direct file matches in extension priority order
638
- // Create a map of baseName -> files with that basename for efficient lookup
639
- filesByBaseName = new Map();
640
- _iterator1 = _createForOfIteratorHelper(dirContents);
641
- try {
642
- for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
643
- _entry6 = _step1.value;
644
- if (_entry6.isFile) {
645
- _fileName2 = _entry6.name;
646
- _fileBaseName2 = void 0;
647
- _actualExtension2 = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts
648
- if (_fileName2.endsWith('.d.ts')) {
649
- _actualExtension2 = '.d.ts';
650
- _fileBaseName2 = _fileName2.substring(0, _fileName2.length - 5); // Remove .d.ts
651
- } else {
652
- _getFileNameFromUrl4 = getFileNameFromUrl(_fileName2), _fileExt2 = _getFileNameFromUrl4.extension;
653
- _actualExtension2 = _fileExt2;
654
- _fileBaseName2 = _fileName2.substring(0, _fileName2.length - _fileExt2.length);
655
- }
656
- if (!filesByBaseName.has(_fileBaseName2)) {
657
- filesByBaseName.set(_fileBaseName2, []);
658
- }
659
- // Store the entry with its actual extension for later matching
660
- filesByBaseName.get(_fileBaseName2).push(_extends(_extends({}, _entry6), {}, {
661
- // Add a custom property to track the actual extension
662
- actualExtension: _actualExtension2
663
- }));
401
+ export async function resolveModulePaths(modulePaths, readDirectory, options = {}) {
402
+ const {
403
+ extensions = JAVASCRIPT_MODULE_EXTENSIONS
404
+ } = options;
405
+ const results = new Map();
406
+
407
+ // Group paths by their parent directory
408
+ const pathsByDirectory = new Map();
409
+ for (const modulePath of modulePaths) {
410
+ const lastSlashIndex = modulePath.lastIndexOf('/');
411
+ const parentDir = modulePath.substring(0, lastSlashIndex);
412
+ const moduleName = modulePath.substring(lastSlashIndex + 1);
413
+ if (!pathsByDirectory.has(parentDir)) {
414
+ pathsByDirectory.set(parentDir, []);
415
+ }
416
+ pathsByDirectory.get(parentDir).push({
417
+ fullPath: modulePath,
418
+ moduleName
419
+ });
420
+ }
421
+
422
+ // Process each directory group
423
+ const directoryEntries = Array.from(pathsByDirectory.entries());
424
+ const directoryResults = await Promise.all(directoryEntries.map(async ([parentDir, pathGroup]) => {
425
+ try {
426
+ // Read the directory contents once for all paths in this directory
427
+ const dirContents = await readDirectory(portablePathToFileUrl(parentDir));
428
+ const unresolved = [];
429
+ const resolved = [];
430
+
431
+ // Look for direct file matches in extension priority order
432
+ // Create a map of baseName -> files for efficient lookup
433
+ const filesByBaseName = new Map();
434
+ for (const entry of dirContents) {
435
+ if (entry.isFile) {
436
+ const fileName = entry.name;
437
+ const {
438
+ extension: fileExt
439
+ } = getFileNameFromUrl(fileName);
440
+ const fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
441
+ if (!filesByBaseName.has(fileBaseName)) {
442
+ filesByBaseName.set(fileBaseName, []);
443
+ }
444
+ filesByBaseName.get(fileBaseName).push(entry);
445
+ }
446
+ }
447
+
448
+ // Check each module path against the file map
449
+ for (const {
450
+ fullPath,
451
+ moduleName
452
+ } of pathGroup) {
453
+ let foundMatch = false;
454
+ const matchingFiles = filesByBaseName.get(moduleName);
455
+ if (matchingFiles) {
456
+ for (const ext of extensions) {
457
+ for (const entry of matchingFiles) {
458
+ const {
459
+ extension: entryExt
460
+ } = getFileNameFromUrl(entry.name);
461
+ if (entryExt === ext) {
462
+ resolved.push({
463
+ fullPath,
464
+ resolvedPath: portablePathToFileUrl(joinPath(parentDir, entry.name))
465
+ });
466
+ foundMatch = true;
467
+ break;
664
468
  }
665
469
  }
666
-
667
- // Check for the module in extension priority order
668
- } catch (err) {
669
- _iterator1.e(err);
670
- } finally {
671
- _iterator1.f();
672
- }
673
- matchingFiles = filesByBaseName.get(moduleName);
674
- if (!matchingFiles) {
675
- _context3.n = 14;
676
- break;
677
- }
678
- _iterator10 = _createForOfIteratorHelper(extensions);
679
- _context3.p = 2;
680
- _iterator10.s();
681
- case 3:
682
- if ((_step10 = _iterator10.n()).done) {
683
- _context3.n = 11;
684
- break;
685
- }
686
- ext = _step10.value;
687
- _iterator11 = _createForOfIteratorHelper(matchingFiles);
688
- _context3.p = 4;
689
- _iterator11.s();
690
- case 5:
691
- if ((_step11 = _iterator11.n()).done) {
692
- _context3.n = 7;
693
- break;
694
- }
695
- entry = _step11.value;
696
- entryWithExt = entry;
697
- if (!(entryWithExt.actualExtension === ext)) {
698
- _context3.n = 6;
699
- break;
470
+ if (foundMatch) {
471
+ break;
472
+ }
700
473
  }
701
- resolvedPath = joinPath(parentDir, entry.name);
702
- return _context3.a(2, portablePathToFileUrl(resolvedPath));
703
- case 6:
704
- _context3.n = 5;
705
- break;
706
- case 7:
707
- _context3.n = 9;
708
- break;
709
- case 8:
710
- _context3.p = 8;
711
- _t0 = _context3.v;
712
- _iterator11.e(_t0);
713
- case 9:
714
- _context3.p = 9;
715
- _iterator11.f();
716
- return _context3.f(9);
717
- case 10:
718
- _context3.n = 3;
719
- break;
720
- case 11:
721
- _context3.n = 13;
722
- break;
723
- case 12:
724
- _context3.p = 12;
725
- _t1 = _context3.v;
726
- _iterator10.e(_t1);
727
- case 13:
728
- _context3.p = 13;
729
- _iterator10.f();
730
- return _context3.f(13);
731
- case 14:
732
- // Look for directory with index files
733
- directoryMatches = dirContents.filter(function (entry) {
734
- return entry.isDirectory && entry.name === moduleName;
474
+ }
475
+ if (!foundMatch) {
476
+ unresolved.push({
477
+ fullPath,
478
+ moduleName
735
479
  });
736
- if (!(directoryMatches.length > 0)) {
737
- _context3.n = 31;
738
- break;
739
- }
740
- moduleDir = joinPath(parentDir, directoryMatches[0].name);
741
- _context3.p = 15;
742
- _context3.n = 16;
743
- return readDirectory(portablePathToFileUrl(moduleDir));
744
- case 16:
745
- moduleDirContents = _context3.v;
746
- // Look for index files in extension priority order
747
- // Create a map of baseName -> files for efficient lookup
748
- indexFilesByBaseName = new Map();
749
- _iterator12 = _createForOfIteratorHelper(moduleDirContents);
750
- try {
751
- for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
752
- moduleFile = _step12.value;
753
- if (moduleFile.isFile) {
754
- fileName = moduleFile.name;
755
- fileBaseName = void 0;
756
- actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts
757
- if (fileName.endsWith('.d.ts')) {
758
- actualExtension = '.d.ts';
759
- fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts
760
- } else {
761
- _getFileNameFromUrl3 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl3.extension;
762
- actualExtension = fileExt;
763
- fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
480
+ }
481
+ }
482
+
483
+ // For unresolved paths, check if they are directories with index files
484
+ if (unresolved.length > 0) {
485
+ const directories = new Set(dirContents.filter(entry => entry.isDirectory).map(entry => entry.name));
486
+ const indexResults = await Promise.all(unresolved.map(async ({
487
+ fullPath,
488
+ moduleName
489
+ }) => {
490
+ if (directories.has(moduleName)) {
491
+ const moduleDir = joinPath(parentDir, moduleName);
492
+ try {
493
+ const moduleDirContents = await readDirectory(portablePathToFileUrl(moduleDir));
494
+
495
+ // Look for index files in extension priority order
496
+ // Create a map of baseName -> files for efficient lookup
497
+ const indexFilesByBaseName = new Map();
498
+ for (const moduleFile of moduleDirContents) {
499
+ if (moduleFile.isFile) {
500
+ const fileName = moduleFile.name;
501
+ const {
502
+ extension: fileExt
503
+ } = getFileNameFromUrl(fileName);
504
+ const fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
505
+ if (!indexFilesByBaseName.has(fileBaseName)) {
506
+ indexFilesByBaseName.set(fileBaseName, []);
507
+ }
508
+ indexFilesByBaseName.get(fileBaseName).push(moduleFile);
764
509
  }
765
- if (!indexFilesByBaseName.has(fileBaseName)) {
766
- indexFilesByBaseName.set(fileBaseName, []);
510
+ }
511
+
512
+ // Check for index files in extension priority order
513
+ const indexFiles = indexFilesByBaseName.get('index');
514
+ if (indexFiles) {
515
+ for (const ext of extensions) {
516
+ for (const entry of indexFiles) {
517
+ const {
518
+ extension: entryExt
519
+ } = getFileNameFromUrl(entry.name);
520
+ if (entryExt === ext) {
521
+ return {
522
+ fullPath,
523
+ resolvedPath: portablePathToFileUrl(joinPath(moduleDir, entry.name))
524
+ };
525
+ }
526
+ }
767
527
  }
768
- // Store the entry with its actual extension for later matching
769
- indexFilesByBaseName.get(fileBaseName).push(_extends(_extends({}, moduleFile), {}, {
770
- actualExtension: actualExtension
771
- }));
772
528
  }
529
+ } catch {
530
+ // Could not read module directory, leave unresolved
773
531
  }
774
-
775
- // Check for index files in extension priority order
776
- } catch (err) {
777
- _iterator12.e(err);
778
- } finally {
779
- _iterator12.f();
780
- }
781
- indexFiles = indexFilesByBaseName.get('index');
782
- if (!indexFiles) {
783
- _context3.n = 29;
784
- break;
785
- }
786
- _iterator13 = _createForOfIteratorHelper(extensions);
787
- _context3.p = 17;
788
- _iterator13.s();
789
- case 18:
790
- if ((_step13 = _iterator13.n()).done) {
791
- _context3.n = 26;
792
- break;
793
- }
794
- _ext4 = _step13.value;
795
- _iterator14 = _createForOfIteratorHelper(indexFiles);
796
- _context3.p = 19;
797
- _iterator14.s();
798
- case 20:
799
- if ((_step14 = _iterator14.n()).done) {
800
- _context3.n = 22;
801
- break;
802
- }
803
- _entry5 = _step14.value;
804
- _entryWithExt = _entry5;
805
- if (!(_entryWithExt.actualExtension === _ext4)) {
806
- _context3.n = 21;
807
- break;
808
532
  }
809
- return _context3.a(2, portablePathToFileUrl(joinPath(moduleDir, _entry5.name)));
810
- case 21:
811
- _context3.n = 20;
812
- break;
813
- case 22:
814
- _context3.n = 24;
815
- break;
816
- case 23:
817
- _context3.p = 23;
818
- _t10 = _context3.v;
819
- _iterator14.e(_t10);
820
- case 24:
821
- _context3.p = 24;
822
- _iterator14.f();
823
- return _context3.f(24);
824
- case 25:
825
- _context3.n = 18;
826
- break;
827
- case 26:
828
- _context3.n = 28;
829
- break;
830
- case 27:
831
- _context3.p = 27;
832
- _t11 = _context3.v;
833
- _iterator13.e(_t11);
834
- case 28:
835
- _context3.p = 28;
836
- _iterator13.f();
837
- return _context3.f(28);
838
- case 29:
839
- _context3.n = 31;
840
- break;
841
- case 30:
842
- _context3.p = 30;
843
- _t12 = _context3.v;
844
- case 31:
845
- _context3.n = 33;
846
- break;
847
- case 32:
848
- _context3.p = 32;
849
- _t13 = _context3.v;
850
- case 33:
851
- throw new Error("Could not resolve module at path \"".concat(modulePath, "\". Tried extensions: ").concat(extensions.join(', ')));
852
- case 34:
853
- return _context3.a(2);
533
+ return {
534
+ fullPath,
535
+ resolvedPath: null
536
+ };
537
+ }));
538
+ for (const {
539
+ fullPath,
540
+ resolvedPath
541
+ } of indexResults) {
542
+ if (resolvedPath) {
543
+ resolved.push({
544
+ fullPath,
545
+ resolvedPath
546
+ });
547
+ }
548
+ }
854
549
  }
855
- }, _callee3, null, [[19, 23, 24, 25], [17, 27, 28, 29], [15, 30], [4, 8, 9, 10], [2, 12, 13, 14], [0, 32]]);
550
+ return resolved;
551
+ } catch {
552
+ // Could not read parent directory, return empty array
553
+ return [];
554
+ }
856
555
  }));
857
- return _resolveSinglePath.apply(this, arguments);
858
- }
859
- export function resolveModulePaths(_x0, _x1) {
860
- return _resolveModulePaths.apply(this, arguments);
556
+
557
+ // Collect all resolved paths
558
+ for (const directoryResult of directoryResults) {
559
+ for (const {
560
+ fullPath,
561
+ resolvedPath
562
+ } of directoryResult) {
563
+ results.set(fullPath, resolvedPath);
564
+ }
565
+ }
566
+ return results;
861
567
  }
862
568
 
863
569
  /**
@@ -870,390 +576,79 @@ export function resolveModulePaths(_x0, _x1) {
870
576
  * @param options - Configuration options for module resolution
871
577
  * @returns Promise<Map<string, string>> - Map from import path to resolved file path
872
578
  */
873
- function _resolveModulePaths() {
874
- _resolveModulePaths = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(modulePaths, readDirectory) {
875
- var options,
876
- _options$extensions2,
877
- extensions,
878
- results,
879
- pathsByDirectory,
880
- _iterator15,
881
- _step15,
882
- modulePath,
883
- lastSlashIndex,
884
- parentDir,
885
- moduleName,
886
- directoryEntries,
887
- directoryResults,
888
- _iterator24,
889
- _step24,
890
- directoryResult,
891
- _iterator25,
892
- _step25,
893
- _step25$value,
894
- fullPath,
895
- resolvedPath,
896
- _args6 = arguments;
897
- return _regenerator().w(function (_context6) {
898
- while (1) switch (_context6.n) {
899
- case 0:
900
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
901
- _options$extensions2 = options.extensions, extensions = _options$extensions2 === void 0 ? JAVASCRIPT_MODULE_EXTENSIONS : _options$extensions2;
902
- results = new Map(); // Group paths by their parent directory
903
- pathsByDirectory = new Map();
904
- _iterator15 = _createForOfIteratorHelper(modulePaths);
905
- try {
906
- for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
907
- modulePath = _step15.value;
908
- lastSlashIndex = modulePath.lastIndexOf('/');
909
- parentDir = modulePath.substring(0, lastSlashIndex);
910
- moduleName = modulePath.substring(lastSlashIndex + 1);
911
- if (!pathsByDirectory.has(parentDir)) {
912
- pathsByDirectory.set(parentDir, []);
913
- }
914
- pathsByDirectory.get(parentDir).push({
915
- fullPath: modulePath,
916
- moduleName: moduleName
917
- });
918
- }
579
+ export async function resolveImportResult(importResult, readDirectory, options = {}) {
580
+ const resolvedPathsMap = new Map();
919
581
 
920
- // Process each directory group
921
- } catch (err) {
922
- _iterator15.e(err);
923
- } finally {
924
- _iterator15.f();
925
- }
926
- directoryEntries = Array.from(pathsByDirectory.entries());
927
- _context6.n = 1;
928
- return Promise.all(directoryEntries.map(/*#__PURE__*/function () {
929
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref) {
930
- var _ref3, parentDir, pathGroup, dirContents, unresolved, resolved, filesByBaseName, _iterator16, _step16, entry, fileName, _getFileNameFromUrl7, fileExt, fileBaseName, _iterator17, _step17, _step17$value, _fullPath, moduleName, foundMatch, matchingFiles, _iterator22, _step22, ext, _iterator23, _step23, _entry7, _getFileNameFromUrl8, entryExt, directories, indexResults, _iterator21, _step21, _step21$value, fullPath, resolvedPath, _t17, _t18, _t19, _t20;
931
- return _regenerator().w(function (_context5) {
932
- while (1) switch (_context5.p = _context5.n) {
933
- case 0:
934
- _ref3 = _slicedToArray(_ref, 2), parentDir = _ref3[0], pathGroup = _ref3[1];
935
- _context5.p = 1;
936
- _context5.n = 2;
937
- return readDirectory(portablePathToFileUrl(parentDir));
938
- case 2:
939
- dirContents = _context5.v;
940
- unresolved = [];
941
- resolved = []; // Look for direct file matches in extension priority order
942
- // Create a map of baseName -> files for efficient lookup
943
- filesByBaseName = new Map();
944
- _iterator16 = _createForOfIteratorHelper(dirContents);
945
- try {
946
- for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
947
- entry = _step16.value;
948
- if (entry.isFile) {
949
- fileName = entry.name;
950
- _getFileNameFromUrl7 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl7.extension;
951
- fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
952
- if (!filesByBaseName.has(fileBaseName)) {
953
- filesByBaseName.set(fileBaseName, []);
954
- }
955
- filesByBaseName.get(fileBaseName).push(entry);
956
- }
957
- }
582
+ // Separate imports into categories for processing
583
+ const jsModulesToResolve = [];
584
+ const jsModulesWithExtensions = [];
585
+ const staticAssets = [];
586
+ for (const [importPath, {
587
+ url,
588
+ includeTypeDefs
589
+ }] of Object.entries(importResult)) {
590
+ if (isJavaScriptModule(importPath)) {
591
+ // If the import path already has a JS/TS extension, use it as-is
592
+ if (JAVASCRIPT_MODULE_EXTENSIONS.some(ext => importPath.endsWith(ext))) {
593
+ jsModulesWithExtensions.push(url);
594
+ } else {
595
+ jsModulesToResolve.push({
596
+ url,
597
+ includeTypeDefs
598
+ });
599
+ }
600
+ } else {
601
+ // Static asset - use url as-is
602
+ staticAssets.push(url);
603
+ }
604
+ }
958
605
 
959
- // Check each module path against the file map
960
- } catch (err) {
961
- _iterator16.e(err);
962
- } finally {
963
- _iterator16.f();
964
- }
965
- _iterator17 = _createForOfIteratorHelper(pathGroup);
966
- _context5.p = 3;
967
- _iterator17.s();
968
- case 4:
969
- if ((_step17 = _iterator17.n()).done) {
970
- _context5.n = 20;
971
- break;
972
- }
973
- _step17$value = _step17.value, _fullPath = _step17$value.fullPath, moduleName = _step17$value.moduleName;
974
- foundMatch = false;
975
- matchingFiles = filesByBaseName.get(moduleName);
976
- if (!matchingFiles) {
977
- _context5.n = 18;
978
- break;
979
- }
980
- _iterator22 = _createForOfIteratorHelper(extensions);
981
- _context5.p = 5;
982
- _iterator22.s();
983
- case 6:
984
- if ((_step22 = _iterator22.n()).done) {
985
- _context5.n = 15;
986
- break;
987
- }
988
- ext = _step22.value;
989
- _iterator23 = _createForOfIteratorHelper(matchingFiles);
990
- _context5.p = 7;
991
- _iterator23.s();
992
- case 8:
993
- if ((_step23 = _iterator23.n()).done) {
994
- _context5.n = 10;
995
- break;
996
- }
997
- _entry7 = _step23.value;
998
- _getFileNameFromUrl8 = getFileNameFromUrl(_entry7.name), entryExt = _getFileNameFromUrl8.extension;
999
- if (!(entryExt === ext)) {
1000
- _context5.n = 9;
1001
- break;
1002
- }
1003
- resolved.push({
1004
- fullPath: _fullPath,
1005
- resolvedPath: portablePathToFileUrl(joinPath(parentDir, _entry7.name))
1006
- });
1007
- foundMatch = true;
1008
- return _context5.a(3, 10);
1009
- case 9:
1010
- _context5.n = 8;
1011
- break;
1012
- case 10:
1013
- _context5.n = 12;
1014
- break;
1015
- case 11:
1016
- _context5.p = 11;
1017
- _t17 = _context5.v;
1018
- _iterator23.e(_t17);
1019
- case 12:
1020
- _context5.p = 12;
1021
- _iterator23.f();
1022
- return _context5.f(12);
1023
- case 13:
1024
- if (!foundMatch) {
1025
- _context5.n = 14;
1026
- break;
1027
- }
1028
- return _context5.a(3, 15);
1029
- case 14:
1030
- _context5.n = 6;
1031
- break;
1032
- case 15:
1033
- _context5.n = 17;
1034
- break;
1035
- case 16:
1036
- _context5.p = 16;
1037
- _t18 = _context5.v;
1038
- _iterator22.e(_t18);
1039
- case 17:
1040
- _context5.p = 17;
1041
- _iterator22.f();
1042
- return _context5.f(17);
1043
- case 18:
1044
- if (!foundMatch) {
1045
- unresolved.push({
1046
- fullPath: _fullPath,
1047
- moduleName: moduleName
1048
- });
1049
- }
1050
- case 19:
1051
- _context5.n = 4;
1052
- break;
1053
- case 20:
1054
- _context5.n = 22;
1055
- break;
1056
- case 21:
1057
- _context5.p = 21;
1058
- _t19 = _context5.v;
1059
- _iterator17.e(_t19);
1060
- case 22:
1061
- _context5.p = 22;
1062
- _iterator17.f();
1063
- return _context5.f(22);
1064
- case 23:
1065
- if (!(unresolved.length > 0)) {
1066
- _context5.n = 25;
1067
- break;
1068
- }
1069
- directories = new Set(dirContents.filter(function (entry) {
1070
- return entry.isDirectory;
1071
- }).map(function (entry) {
1072
- return entry.name;
1073
- }));
1074
- _context5.n = 24;
1075
- return Promise.all(unresolved.map(/*#__PURE__*/function () {
1076
- var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
1077
- var fullPath, moduleName, moduleDir, moduleDirContents, indexFilesByBaseName, _iterator18, _step18, moduleFile, fileName, _getFileNameFromUrl6, fileExt, fileBaseName, indexFiles, _iterator19, _step19, ext, _iterator20, _step20, entry, _getFileNameFromUrl5, entryExt, _t14, _t15, _t16;
1078
- return _regenerator().w(function (_context4) {
1079
- while (1) switch (_context4.p = _context4.n) {
1080
- case 0:
1081
- fullPath = _ref4.fullPath, moduleName = _ref4.moduleName;
1082
- if (!directories.has(moduleName)) {
1083
- _context4.n = 17;
1084
- break;
1085
- }
1086
- moduleDir = joinPath(parentDir, moduleName);
1087
- _context4.p = 1;
1088
- _context4.n = 2;
1089
- return readDirectory(portablePathToFileUrl(moduleDir));
1090
- case 2:
1091
- moduleDirContents = _context4.v;
1092
- // Look for index files in extension priority order
1093
- // Create a map of baseName -> files for efficient lookup
1094
- indexFilesByBaseName = new Map();
1095
- _iterator18 = _createForOfIteratorHelper(moduleDirContents);
1096
- try {
1097
- for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
1098
- moduleFile = _step18.value;
1099
- if (moduleFile.isFile) {
1100
- fileName = moduleFile.name;
1101
- _getFileNameFromUrl6 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl6.extension;
1102
- fileBaseName = fileName.substring(0, fileName.length - fileExt.length);
1103
- if (!indexFilesByBaseName.has(fileBaseName)) {
1104
- indexFilesByBaseName.set(fileBaseName, []);
1105
- }
1106
- indexFilesByBaseName.get(fileBaseName).push(moduleFile);
1107
- }
1108
- }
606
+ // Add modules with extensions as-is
607
+ jsModulesWithExtensions.forEach(url => {
608
+ resolvedPathsMap.set(url, url);
609
+ });
1109
610
 
1110
- // Check for index files in extension priority order
1111
- } catch (err) {
1112
- _iterator18.e(err);
1113
- } finally {
1114
- _iterator18.f();
1115
- }
1116
- indexFiles = indexFilesByBaseName.get('index');
1117
- if (!indexFiles) {
1118
- _context4.n = 15;
1119
- break;
1120
- }
1121
- _iterator19 = _createForOfIteratorHelper(extensions);
1122
- _context4.p = 3;
1123
- _iterator19.s();
1124
- case 4:
1125
- if ((_step19 = _iterator19.n()).done) {
1126
- _context4.n = 12;
1127
- break;
1128
- }
1129
- ext = _step19.value;
1130
- _iterator20 = _createForOfIteratorHelper(indexFiles);
1131
- _context4.p = 5;
1132
- _iterator20.s();
1133
- case 6:
1134
- if ((_step20 = _iterator20.n()).done) {
1135
- _context4.n = 8;
1136
- break;
1137
- }
1138
- entry = _step20.value;
1139
- _getFileNameFromUrl5 = getFileNameFromUrl(entry.name), entryExt = _getFileNameFromUrl5.extension;
1140
- if (!(entryExt === ext)) {
1141
- _context4.n = 7;
1142
- break;
1143
- }
1144
- return _context4.a(2, {
1145
- fullPath: fullPath,
1146
- resolvedPath: portablePathToFileUrl(joinPath(moduleDir, entry.name))
1147
- });
1148
- case 7:
1149
- _context4.n = 6;
1150
- break;
1151
- case 8:
1152
- _context4.n = 10;
1153
- break;
1154
- case 9:
1155
- _context4.p = 9;
1156
- _t14 = _context4.v;
1157
- _iterator20.e(_t14);
1158
- case 10:
1159
- _context4.p = 10;
1160
- _iterator20.f();
1161
- return _context4.f(10);
1162
- case 11:
1163
- _context4.n = 4;
1164
- break;
1165
- case 12:
1166
- _context4.n = 14;
1167
- break;
1168
- case 13:
1169
- _context4.p = 13;
1170
- _t15 = _context4.v;
1171
- _iterator19.e(_t15);
1172
- case 14:
1173
- _context4.p = 14;
1174
- _iterator19.f();
1175
- return _context4.f(14);
1176
- case 15:
1177
- _context4.n = 17;
1178
- break;
1179
- case 16:
1180
- _context4.p = 16;
1181
- _t16 = _context4.v;
1182
- case 17:
1183
- return _context4.a(2, {
1184
- fullPath: fullPath,
1185
- resolvedPath: null
1186
- });
1187
- }
1188
- }, _callee4, null, [[5, 9, 10, 11], [3, 13, 14, 15], [1, 16]]);
1189
- }));
1190
- return function (_x15) {
1191
- return _ref5.apply(this, arguments);
1192
- };
1193
- }()));
1194
- case 24:
1195
- indexResults = _context5.v;
1196
- _iterator21 = _createForOfIteratorHelper(indexResults);
1197
- try {
1198
- for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
1199
- _step21$value = _step21.value, fullPath = _step21$value.fullPath, resolvedPath = _step21$value.resolvedPath;
1200
- if (resolvedPath) {
1201
- resolved.push({
1202
- fullPath: fullPath,
1203
- resolvedPath: resolvedPath
1204
- });
1205
- }
1206
- }
1207
- } catch (err) {
1208
- _iterator21.e(err);
1209
- } finally {
1210
- _iterator21.f();
1211
- }
1212
- case 25:
1213
- return _context5.a(2, resolved);
1214
- case 26:
1215
- _context5.p = 26;
1216
- _t20 = _context5.v;
1217
- return _context5.a(2, []);
1218
- }
1219
- }, _callee5, null, [[7, 11, 12, 13], [5, 16, 17, 18], [3, 21, 22, 23], [1, 26]]);
1220
- }));
1221
- return function (_x14) {
1222
- return _ref2.apply(this, arguments);
1223
- };
1224
- }()));
1225
- case 1:
1226
- directoryResults = _context6.v;
1227
- // Collect all resolved paths
1228
- _iterator24 = _createForOfIteratorHelper(directoryResults);
1229
- try {
1230
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
1231
- directoryResult = _step24.value;
1232
- _iterator25 = _createForOfIteratorHelper(directoryResult);
1233
- try {
1234
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
1235
- _step25$value = _step25.value, fullPath = _step25$value.fullPath, resolvedPath = _step25$value.resolvedPath;
1236
- results.set(fullPath, resolvedPath);
1237
- }
1238
- } catch (err) {
1239
- _iterator25.e(err);
1240
- } finally {
1241
- _iterator25.f();
1242
- }
1243
- }
1244
- } catch (err) {
1245
- _iterator24.e(err);
1246
- } finally {
1247
- _iterator24.f();
1248
- }
1249
- return _context6.a(2, results);
611
+ // Add static assets as-is
612
+ staticAssets.forEach(url => {
613
+ resolvedPathsMap.set(url, url);
614
+ });
615
+
616
+ // Resolve JS modules without extensions
617
+ if (jsModulesToResolve.length > 0) {
618
+ const resolutionPromises = jsModulesToResolve.map(async ({
619
+ url,
620
+ includeTypeDefs
621
+ }) => {
622
+ try {
623
+ const resolved = await resolveModulePath(url, readDirectory, options, includeTypeDefs);
624
+ if (typeof resolved === 'string') {
625
+ // Simple string result
626
+ return {
627
+ url,
628
+ resolved
629
+ };
630
+ }
631
+
632
+ // Type-aware result - for now, just use the import path
633
+ // TODO: We might want to store both paths in the future
634
+ return {
635
+ url,
636
+ resolved: resolved.import
637
+ };
638
+ } catch (error) {
639
+ return null; // Mark as failed
1250
640
  }
1251
- }, _callee6);
1252
- }));
1253
- return _resolveModulePaths.apply(this, arguments);
1254
- }
1255
- export function resolveImportResult(_x10, _x11) {
1256
- return _resolveImportResult.apply(this, arguments);
641
+ });
642
+ const resolutionResults = await Promise.all(resolutionPromises);
643
+
644
+ // Add successful resolutions to the map
645
+ resolutionResults.forEach(result => {
646
+ if (result) {
647
+ resolvedPathsMap.set(result.url, result.resolved);
648
+ }
649
+ });
650
+ }
651
+ return resolvedPathsMap;
1257
652
  }
1258
653
 
1259
654
  /**
@@ -1266,173 +661,19 @@ export function resolveImportResult(_x10, _x11) {
1266
661
  * @param options - Configuration options for module resolution
1267
662
  * @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
1268
663
  */
1269
- function _resolveImportResult() {
1270
- _resolveImportResult = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(importResult, readDirectory) {
1271
- var options,
1272
- resolvedPathsMap,
1273
- jsModulesToResolve,
1274
- jsModulesWithExtensions,
1275
- staticAssets,
1276
- _loop,
1277
- _i,
1278
- _Object$entries,
1279
- resolutionPromises,
1280
- resolutionResults,
1281
- _args9 = arguments;
1282
- return _regenerator().w(function (_context9) {
1283
- while (1) switch (_context9.n) {
1284
- case 0:
1285
- options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
1286
- resolvedPathsMap = new Map(); // Separate imports into categories for processing
1287
- jsModulesToResolve = [];
1288
- jsModulesWithExtensions = [];
1289
- staticAssets = [];
1290
- _loop = /*#__PURE__*/_regenerator().m(function _loop() {
1291
- var _Object$entries$_i, importPath, _Object$entries$_i$, url, includeTypeDefs;
1292
- return _regenerator().w(function (_context7) {
1293
- while (1) switch (_context7.n) {
1294
- case 0:
1295
- _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), importPath = _Object$entries$_i[0], _Object$entries$_i$ = _Object$entries$_i[1], url = _Object$entries$_i$.url, includeTypeDefs = _Object$entries$_i$.includeTypeDefs;
1296
- if (isJavaScriptModule(importPath)) {
1297
- // If the import path already has a JS/TS extension, use it as-is
1298
- if (JAVASCRIPT_MODULE_EXTENSIONS.some(function (ext) {
1299
- return importPath.endsWith(ext);
1300
- })) {
1301
- jsModulesWithExtensions.push(url);
1302
- } else {
1303
- jsModulesToResolve.push({
1304
- url: url,
1305
- includeTypeDefs: includeTypeDefs
1306
- });
1307
- }
1308
- } else {
1309
- // Static asset - use url as-is
1310
- staticAssets.push(url);
1311
- }
1312
- case 1:
1313
- return _context7.a(2);
1314
- }
1315
- }, _loop);
1316
- });
1317
- _i = 0, _Object$entries = Object.entries(importResult);
1318
- case 1:
1319
- if (!(_i < _Object$entries.length)) {
1320
- _context9.n = 3;
1321
- break;
1322
- }
1323
- return _context9.d(_regeneratorValues(_loop()), 2);
1324
- case 2:
1325
- _i++;
1326
- _context9.n = 1;
1327
- break;
1328
- case 3:
1329
- // Add modules with extensions as-is
1330
- jsModulesWithExtensions.forEach(function (url) {
1331
- resolvedPathsMap.set(url, url);
1332
- });
1333
-
1334
- // Add static assets as-is
1335
- staticAssets.forEach(function (url) {
1336
- resolvedPathsMap.set(url, url);
1337
- });
664
+ export async function resolveVariantPaths(variants, readDirectory, options = {}) {
665
+ // Extract the variant paths and resolve them
666
+ const variantPaths = Object.values(variants);
667
+ const resolvedVariantPaths = await resolveModulePaths(variantPaths, readDirectory, options);
1338
668
 
1339
- // Resolve JS modules without extensions
1340
- if (!(jsModulesToResolve.length > 0)) {
1341
- _context9.n = 5;
1342
- break;
1343
- }
1344
- resolutionPromises = jsModulesToResolve.map(/*#__PURE__*/function () {
1345
- var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref6) {
1346
- var url, includeTypeDefs, resolved, _t21;
1347
- return _regenerator().w(function (_context8) {
1348
- while (1) switch (_context8.p = _context8.n) {
1349
- case 0:
1350
- url = _ref6.url, includeTypeDefs = _ref6.includeTypeDefs;
1351
- _context8.p = 1;
1352
- _context8.n = 2;
1353
- return resolveModulePath(url, readDirectory, options, includeTypeDefs);
1354
- case 2:
1355
- resolved = _context8.v;
1356
- if (!(typeof resolved === 'string')) {
1357
- _context8.n = 3;
1358
- break;
1359
- }
1360
- return _context8.a(2, {
1361
- url: url,
1362
- resolved: resolved
1363
- });
1364
- case 3:
1365
- return _context8.a(2, {
1366
- url: url,
1367
- resolved: resolved["import"]
1368
- });
1369
- case 4:
1370
- _context8.p = 4;
1371
- _t21 = _context8.v;
1372
- return _context8.a(2, null);
1373
- }
1374
- }, _callee7, null, [[1, 4]]);
1375
- }));
1376
- return function (_x16) {
1377
- return _ref7.apply(this, arguments);
1378
- };
1379
- }());
1380
- _context9.n = 4;
1381
- return Promise.all(resolutionPromises);
1382
- case 4:
1383
- resolutionResults = _context9.v;
1384
- // Add successful resolutions to the map
1385
- resolutionResults.forEach(function (result) {
1386
- if (result) {
1387
- resolvedPathsMap.set(result.url, result.resolved);
1388
- }
1389
- });
1390
- case 5:
1391
- return _context9.a(2, resolvedPathsMap);
1392
- }
1393
- }, _callee8);
1394
- }));
1395
- return _resolveImportResult.apply(this, arguments);
1396
- }
1397
- export function resolveVariantPaths(_x12, _x13) {
1398
- return _resolveVariantPaths.apply(this, arguments);
1399
- }
1400
- function _resolveVariantPaths() {
1401
- _resolveVariantPaths = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(variants, readDirectory) {
1402
- var options,
1403
- variantPaths,
1404
- resolvedVariantPaths,
1405
- variantMap,
1406
- _i2,
1407
- _Object$entries2,
1408
- _Object$entries2$_i,
1409
- variantName,
1410
- variantPath,
1411
- resolvedVariantPath,
1412
- _args0 = arguments;
1413
- return _regenerator().w(function (_context0) {
1414
- while (1) switch (_context0.n) {
1415
- case 0:
1416
- options = _args0.length > 2 && _args0[2] !== undefined ? _args0[2] : {};
1417
- // Extract the variant paths and resolve them
1418
- variantPaths = Object.values(variants);
1419
- _context0.n = 1;
1420
- return resolveModulePaths(variantPaths, readDirectory, options);
1421
- case 1:
1422
- resolvedVariantPaths = _context0.v;
1423
- // Build a map from variant name to resolved file URL
1424
- variantMap = new Map();
1425
- for (_i2 = 0, _Object$entries2 = Object.entries(variants); _i2 < _Object$entries2.length; _i2++) {
1426
- _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2), variantName = _Object$entries2$_i[0], variantPath = _Object$entries2$_i[1];
1427
- resolvedVariantPath = resolvedVariantPaths.get(variantPath);
1428
- if (resolvedVariantPath) {
1429
- // Store as a file URL (portablePathToFileUrl handles portable paths correctly)
1430
- variantMap.set(variantName, portablePathToFileUrl(resolvedVariantPath));
1431
- }
1432
- }
1433
- return _context0.a(2, variantMap);
1434
- }
1435
- }, _callee9);
1436
- }));
1437
- return _resolveVariantPaths.apply(this, arguments);
669
+ // Build a map from variant name to resolved file URL
670
+ const variantMap = new Map();
671
+ for (const [variantName, variantPath] of Object.entries(variants)) {
672
+ const resolvedVariantPath = resolvedVariantPaths.get(variantPath);
673
+ if (resolvedVariantPath) {
674
+ // Store as a file URL (portablePathToFileUrl handles portable paths correctly)
675
+ variantMap.set(variantName, portablePathToFileUrl(resolvedVariantPath));
676
+ }
677
+ }
678
+ return variantMap;
1438
679
  }