UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

1,254 lines (1,239 loc) 58 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper"; import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime"; import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator"; import { getFileNameFromUrl } from "./getFileNameFromUrl.js"; /** * Isomorphic path joining function that works in both Node.js and browser environments. * Uses string concatenation to handle path joining consistently across platforms. */ function joinPath(basePath) { // Start with the base path, ensuring it has a trailing slash for URL construction var result = basePath.endsWith('/') ? basePath : "".concat(basePath, "/"); // Handle each segment for (var i = 0; i < (arguments.length <= 1 ? 0 : arguments.length - 1); i += 1) { var segment = i + 1 < 1 || arguments.length <= i + 1 ? undefined : arguments[i + 1]; if (segment) { // Remove leading slash from segment to avoid double slashes var cleanSegment = segment.startsWith('/') ? segment.slice(1) : segment; // Append segment result += cleanSegment; // Add trailing slash for intermediate segments if (i < (arguments.length <= 1 ? 0 : arguments.length - 1) - 1) { result += '/'; } } } return result; } /** * Default file extensions for JavaScript/TypeScript modules that can be resolved */ export var JAVASCRIPT_MODULE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.d.ts']; /** * Extension priority for type-only imports - prioritize .d.ts first */ export var TYPE_IMPORT_EXTENSIONS = ['.d.ts', '.ts', '.tsx', '.js', '.jsx']; /** * Extension priority for value imports - standard priority with .d.ts last */ export var VALUE_IMPORT_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.d.ts']; /** * Checks if a file path or import path represents a JavaScript/TypeScript module * @param path - The file path or import path to check * @returns true if it's a JS/TS module, false otherwise */ export function isJavaScriptModule(path) { // If the path has an extension, check if it's one of the JS/TS extensions if (/\.[^/]+$/.test(path)) { return JAVASCRIPT_MODULE_EXTENSIONS.some(function (ext) { return path.endsWith(ext); }); } // If no extension, assume it's a JS/TS module (will be resolved to one) return true; } /** * Resolves a module path by reading directory contents to find matching files. * This is more efficient than checking each file individually with stat calls. * * Given a path like `/Code/mui-public/packages/docs-infra/docs/app/components/code-highlighter/demos/code/BasicCode`, * this function will try to find the actual file by checking for: * - `BasicCode.ts`, `BasicCode.tsx`, `BasicCode.js`, `BasicCode.jsx` * - `BasicCode/index.ts`, `BasicCode/index.tsx`, `BasicCode/index.js`, `BasicCode/index.jsx` * * @param modulePath - The module path to resolve (without file extension) * @param readDirectory - Function to read directory contents * @param options - Configuration options * @param includeTypeDefs - If true, returns both import and typeImport paths with different extension priorities * @returns Promise<string | TypeAwareResolveResult> - The resolved file path(s) */ export function resolveModulePath(_x, _x2) { return _resolveModulePath.apply(this, arguments); } /** * Resolves a module path with type-aware resolution, returning both import and typeImport paths * This function is optimized to do only a single directory read instead of two separate reads. */ function _resolveModulePath() { _resolveModulePath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(modulePath, readDirectory) { var options, includeTypeDefs, _options$extensions, extensions, lastSlashIndex, parentDir, moduleName, resolvedPath, _args = arguments; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}; includeTypeDefs = _args.length > 3 ? _args[3] : undefined; _options$extensions = options.extensions, extensions = _options$extensions === void 0 ? JAVASCRIPT_MODULE_EXTENSIONS : _options$extensions; // If includeTypeDefs is true, we need to resolve with both type and value extension priorities if (!includeTypeDefs) { _context.next = 5; break; } return _context.abrupt("return", resolveWithTypeAwareness(modulePath, readDirectory, options)); case 5: // Extract the parent directory and the module name lastSlashIndex = modulePath.lastIndexOf('/'); parentDir = modulePath.substring(0, lastSlashIndex); moduleName = modulePath.substring(lastSlashIndex + 1); _context.next = 10; return resolveSinglePath(modulePath, parentDir, moduleName, readDirectory, extensions); case 10: resolvedPath = _context.sent; return _context.abrupt("return", resolvedPath); case 12: case "end": return _context.stop(); } }, _callee); })); return _resolveModulePath.apply(this, arguments); } function resolveWithTypeAwareness(_x3, _x4) { return _resolveWithTypeAwareness.apply(this, arguments); } /** * Internal function to resolve a single path with given extensions */ function _resolveWithTypeAwareness() { _resolveWithTypeAwareness = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(modulePath, readDirectory) { var _options, lastSlashIndex, parentDir, moduleName, dirContents, filesByBaseName, _iterator, _step, _entry4, _fileName, _fileBaseName, _actualExtension, _getFileNameFromUrl2, _fileExt, matchingFiles, entryMap, importPath, _iterator2, _step2, ext, _iterator4, _step4, entry, typeImportPath, _iterator3, _step3, _ext, _iterator5, _step5, _entry, directoryMatches, moduleDir, moduleDirContents, indexFilesByBaseName, _iterator6, _step6, moduleFile, fileName, fileBaseName, actualExtension, _getFileNameFromUrl, fileExt, indexFiles, indexEntryMap, _importPath, _iterator7, _step7, _ext2, _iterator9, _step9, _entry2, _typeImportPath, _iterator8, _step8, _ext3, _iterator0, _step0, _entry3, _args2 = arguments; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {}; lastSlashIndex = modulePath.lastIndexOf('/'); parentDir = modulePath.substring(0, lastSlashIndex); moduleName = modulePath.substring(lastSlashIndex + 1); // Single filesystem read to get directory contents _context2.next = 6; return readDirectory(parentDir); case 6: dirContents = _context2.sent; // Build a map of available files by basename filesByBaseName = new Map(); _iterator = _createForOfIteratorHelper(dirContents); try { for (_iterator.s(); !(_step = _iterator.n()).done;) { _entry4 = _step.value; if (_entry4.isFile) { _fileName = _entry4.name; _fileBaseName = void 0; _actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts if (_fileName.endsWith('.d.ts')) { _actualExtension = '.d.ts'; _fileBaseName = _fileName.substring(0, _fileName.length - 5); // Remove .d.ts } else { _getFileNameFromUrl2 = getFileNameFromUrl(_fileName), _fileExt = _getFileNameFromUrl2.extension; _actualExtension = _fileExt; _fileBaseName = _fileName.substring(0, _fileName.length - _fileExt.length); } if (!filesByBaseName.has(_fileBaseName)) { filesByBaseName.set(_fileBaseName, []); } // Store the entry with its actual extension for later matching filesByBaseName.get(_fileBaseName).push(_objectSpread(_objectSpread({}, _entry4), {}, { actualExtension: _actualExtension })); } } // Check for the module in both priority orders } catch (err) { _iterator.e(err); } finally { _iterator.f(); } matchingFiles = filesByBaseName.get(moduleName); if (!matchingFiles) { _context2.next = 91; break; } entryMap = matchingFiles; // Find best match for value imports (VALUE_IMPORT_EXTENSIONS priority) importPath = null; _iterator2 = _createForOfIteratorHelper(VALUE_IMPORT_EXTENSIONS); _context2.prev = 15; _iterator2.s(); case 17: if ((_step2 = _iterator2.n()).done) { _context2.next = 41; break; } ext = _step2.value; _iterator4 = _createForOfIteratorHelper(entryMap); _context2.prev = 20; _iterator4.s(); case 22: if ((_step4 = _iterator4.n()).done) { _context2.next = 29; break; } entry = _step4.value; if (!(entry.actualExtension === ext)) { _context2.next = 27; break; } importPath = joinPath(parentDir, entry.name); return _context2.abrupt("break", 29); case 27: _context2.next = 22; break; case 29: _context2.next = 34; break; case 31: _context2.prev = 31; _context2.t0 = _context2["catch"](20); _iterator4.e(_context2.t0); case 34: _context2.prev = 34; _iterator4.f(); return _context2.finish(34); case 37: if (!importPath) { _context2.next = 39; break; } return _context2.abrupt("break", 41); case 39: _context2.next = 17; break; case 41: _context2.next = 46; break; case 43: _context2.prev = 43; _context2.t1 = _context2["catch"](15); _iterator2.e(_context2.t1); case 46: _context2.prev = 46; _iterator2.f(); return _context2.finish(46); case 49: // Find best match for type imports (TYPE_IMPORT_EXTENSIONS priority) typeImportPath = null; _iterator3 = _createForOfIteratorHelper(TYPE_IMPORT_EXTENSIONS); _context2.prev = 51; _iterator3.s(); case 53: if ((_step3 = _iterator3.n()).done) { _context2.next = 77; break; } _ext = _step3.value; _iterator5 = _createForOfIteratorHelper(entryMap); _context2.prev = 56; _iterator5.s(); case 58: if ((_step5 = _iterator5.n()).done) { _context2.next = 65; break; } _entry = _step5.value; if (!(_entry.actualExtension === _ext)) { _context2.next = 63; break; } typeImportPath = joinPath(parentDir, _entry.name); return _context2.abrupt("break", 65); case 63: _context2.next = 58; break; case 65: _context2.next = 70; break; case 67: _context2.prev = 67; _context2.t2 = _context2["catch"](56); _iterator5.e(_context2.t2); case 70: _context2.prev = 70; _iterator5.f(); return _context2.finish(70); case 73: if (!typeImportPath) { _context2.next = 75; break; } return _context2.abrupt("break", 77); case 75: _context2.next = 53; break; case 77: _context2.next = 82; break; case 79: _context2.prev = 79; _context2.t3 = _context2["catch"](51); _iterator3.e(_context2.t3); case 82: _context2.prev = 82; _iterator3.f(); return _context2.finish(82); case 85: if (!(importPath && typeImportPath && importPath !== typeImportPath)) { _context2.next = 87; break; } return _context2.abrupt("return", { "import": importPath, typeImport: typeImportPath }); case 87: if (!importPath) { _context2.next = 89; break; } return _context2.abrupt("return", { "import": importPath }); case 89: if (!typeImportPath) { _context2.next = 91; break; } return _context2.abrupt("return", { "import": typeImportPath }); case 91: // Try index files with the same single-pass approach directoryMatches = dirContents.filter(function (entry) { return entry.isDirectory && entry.name === moduleName; }); if (!(directoryMatches.length > 0)) { _context2.next = 186; break; } moduleDir = joinPath(parentDir, directoryMatches[0].name); _context2.prev = 94; _context2.next = 97; return readDirectory(moduleDir); case 97: moduleDirContents = _context2.sent; // Build a map of available index files by basename indexFilesByBaseName = new Map(); _iterator6 = _createForOfIteratorHelper(moduleDirContents); try { for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) { moduleFile = _step6.value; if (moduleFile.isFile) { fileName = moduleFile.name; fileBaseName = void 0; actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts if (fileName.endsWith('.d.ts')) { actualExtension = '.d.ts'; fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts } else { _getFileNameFromUrl = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl.extension; actualExtension = fileExt; fileBaseName = fileName.substring(0, fileName.length - fileExt.length); } if (!indexFilesByBaseName.has(fileBaseName)) { indexFilesByBaseName.set(fileBaseName, []); } // Store the entry with its actual extension for later matching indexFilesByBaseName.get(fileBaseName).push(_objectSpread(_objectSpread({}, moduleFile), {}, { actualExtension: actualExtension })); } } // Check for index files in both priority orders } catch (err) { _iterator6.e(err); } finally { _iterator6.f(); } indexFiles = indexFilesByBaseName.get('index'); if (!indexFiles) { _context2.next = 182; break; } indexEntryMap = indexFiles; // Find best match for value imports _importPath = null; _iterator7 = _createForOfIteratorHelper(VALUE_IMPORT_EXTENSIONS); _context2.prev = 106; _iterator7.s(); case 108: if ((_step7 = _iterator7.n()).done) { _context2.next = 132; break; } _ext2 = _step7.value; _iterator9 = _createForOfIteratorHelper(indexEntryMap); _context2.prev = 111; _iterator9.s(); case 113: if ((_step9 = _iterator9.n()).done) { _context2.next = 120; break; } _entry2 = _step9.value; if (!(_entry2.actualExtension === _ext2)) { _context2.next = 118; break; } _importPath = joinPath(moduleDir, _entry2.name); return _context2.abrupt("break", 120); case 118: _context2.next = 113; break; case 120: _context2.next = 125; break; case 122: _context2.prev = 122; _context2.t4 = _context2["catch"](111); _iterator9.e(_context2.t4); case 125: _context2.prev = 125; _iterator9.f(); return _context2.finish(125); case 128: if (!_importPath) { _context2.next = 130; break; } return _context2.abrupt("break", 132); case 130: _context2.next = 108; break; case 132: _context2.next = 137; break; case 134: _context2.prev = 134; _context2.t5 = _context2["catch"](106); _iterator7.e(_context2.t5); case 137: _context2.prev = 137; _iterator7.f(); return _context2.finish(137); case 140: // Find best match for type imports _typeImportPath = null; _iterator8 = _createForOfIteratorHelper(TYPE_IMPORT_EXTENSIONS); _context2.prev = 142; _iterator8.s(); case 144: if ((_step8 = _iterator8.n()).done) { _context2.next = 168; break; } _ext3 = _step8.value; _iterator0 = _createForOfIteratorHelper(indexEntryMap); _context2.prev = 147; _iterator0.s(); case 149: if ((_step0 = _iterator0.n()).done) { _context2.next = 156; break; } _entry3 = _step0.value; if (!(_entry3.actualExtension === _ext3)) { _context2.next = 154; break; } _typeImportPath = joinPath(moduleDir, _entry3.name); return _context2.abrupt("break", 156); case 154: _context2.next = 149; break; case 156: _context2.next = 161; break; case 158: _context2.prev = 158; _context2.t6 = _context2["catch"](147); _iterator0.e(_context2.t6); case 161: _context2.prev = 161; _iterator0.f(); return _context2.finish(161); case 164: if (!_typeImportPath) { _context2.next = 166; break; } return _context2.abrupt("break", 168); case 166: _context2.next = 144; break; case 168: _context2.next = 173; break; case 170: _context2.prev = 170; _context2.t7 = _context2["catch"](142); _iterator8.e(_context2.t7); case 173: _context2.prev = 173; _iterator8.f(); return _context2.finish(173); case 176: if (!(_importPath && _typeImportPath && _importPath !== _typeImportPath)) { _context2.next = 178; break; } return _context2.abrupt("return", { "import": _importPath, typeImport: _typeImportPath }); case 178: if (!_importPath) { _context2.next = 180; break; } return _context2.abrupt("return", { "import": _importPath }); case 180: if (!_typeImportPath) { _context2.next = 182; break; } return _context2.abrupt("return", { "import": _typeImportPath }); case 182: _context2.next = 186; break; case 184: _context2.prev = 184; _context2.t8 = _context2["catch"](94); case 186: throw new Error("Could not resolve module at path \"".concat(modulePath, "\". Tried extensions: ").concat(VALUE_IMPORT_EXTENSIONS.join(', '), ", ").concat(TYPE_IMPORT_EXTENSIONS.join(', '))); case 187: case "end": return _context2.stop(); } }, _callee2, null, [[15, 43, 46, 49], [20, 31, 34, 37], [51, 79, 82, 85], [56, 67, 70, 73], [94, 184], [106, 134, 137, 140], [111, 122, 125, 128], [142, 170, 173, 176], [147, 158, 161, 164]]); })); return _resolveWithTypeAwareness.apply(this, arguments); } function resolveSinglePath(_x5, _x6, _x7, _x8, _x9) { return _resolveSinglePath.apply(this, arguments); } /** * Resolves multiple module paths efficiently by grouping them by directory * and performing batch directory lookups. * * @param modulePaths - Array of module paths to resolve (without file extensions) * @param readDirectory - Function to read directory contents * @param options - Configuration options * @returns Promise<Map<string, string>> - Map from input path to resolved file path */ function _resolveSinglePath() { _resolveSinglePath = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(modulePath, parentDir, moduleName, readDirectory, extensions) { 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; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: _context3.prev = 0; _context3.next = 3; return readDirectory(parentDir); case 3: dirContents = _context3.sent; // Look for direct file matches in extension priority order // Create a map of baseName -> files with that basename for efficient lookup filesByBaseName = new Map(); _iterator1 = _createForOfIteratorHelper(dirContents); try { for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) { _entry6 = _step1.value; if (_entry6.isFile) { _fileName2 = _entry6.name; _fileBaseName2 = void 0; _actualExtension2 = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for types.d.ts if (_fileName2.endsWith('.d.ts')) { _actualExtension2 = '.d.ts'; _fileBaseName2 = _fileName2.substring(0, _fileName2.length - 5); // Remove .d.ts } else { _getFileNameFromUrl4 = getFileNameFromUrl(_fileName2), _fileExt2 = _getFileNameFromUrl4.extension; _actualExtension2 = _fileExt2; _fileBaseName2 = _fileName2.substring(0, _fileName2.length - _fileExt2.length); } if (!filesByBaseName.has(_fileBaseName2)) { filesByBaseName.set(_fileBaseName2, []); } // Store the entry with its actual extension for later matching filesByBaseName.get(_fileBaseName2).push(_objectSpread(_objectSpread({}, _entry6), {}, { // Add a custom property to track the actual extension actualExtension: _actualExtension2 })); } } // Check for the module in extension priority order } catch (err) { _iterator1.e(err); } finally { _iterator1.f(); } matchingFiles = filesByBaseName.get(moduleName); if (!matchingFiles) { _context3.next = 43; break; } _iterator10 = _createForOfIteratorHelper(extensions); _context3.prev = 10; _iterator10.s(); case 12: if ((_step10 = _iterator10.n()).done) { _context3.next = 35; break; } ext = _step10.value; _iterator11 = _createForOfIteratorHelper(matchingFiles); _context3.prev = 15; _iterator11.s(); case 17: if ((_step11 = _iterator11.n()).done) { _context3.next = 25; break; } entry = _step11.value; entryWithExt = entry; if (!(entryWithExt.actualExtension === ext)) { _context3.next = 23; break; } resolvedPath = joinPath(parentDir, entry.name); return _context3.abrupt("return", resolvedPath); case 23: _context3.next = 17; break; case 25: _context3.next = 30; break; case 27: _context3.prev = 27; _context3.t0 = _context3["catch"](15); _iterator11.e(_context3.t0); case 30: _context3.prev = 30; _iterator11.f(); return _context3.finish(30); case 33: _context3.next = 12; break; case 35: _context3.next = 40; break; case 37: _context3.prev = 37; _context3.t1 = _context3["catch"](10); _iterator10.e(_context3.t1); case 40: _context3.prev = 40; _iterator10.f(); return _context3.finish(40); case 43: // Look for directory with index files directoryMatches = dirContents.filter(function (entry) { return entry.isDirectory && entry.name === moduleName; }); if (!(directoryMatches.length > 0)) { _context3.next = 92; break; } moduleDir = joinPath(parentDir, directoryMatches[0].name); _context3.prev = 46; _context3.next = 49; return readDirectory(moduleDir); case 49: moduleDirContents = _context3.sent; // Look for index files in extension priority order // Create a map of baseName -> files for efficient lookup indexFilesByBaseName = new Map(); _iterator12 = _createForOfIteratorHelper(moduleDirContents); try { for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) { moduleFile = _step12.value; if (moduleFile.isFile) { fileName = moduleFile.name; fileBaseName = void 0; actualExtension = void 0; // Handle .d.ts files specially since getFileNameFromUrl returns .ts for index.d.ts if (fileName.endsWith('.d.ts')) { actualExtension = '.d.ts'; fileBaseName = fileName.substring(0, fileName.length - 5); // Remove .d.ts } else { _getFileNameFromUrl3 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl3.extension; actualExtension = fileExt; fileBaseName = fileName.substring(0, fileName.length - fileExt.length); } if (!indexFilesByBaseName.has(fileBaseName)) { indexFilesByBaseName.set(fileBaseName, []); } // Store the entry with its actual extension for later matching indexFilesByBaseName.get(fileBaseName).push(_objectSpread(_objectSpread({}, moduleFile), {}, { actualExtension: actualExtension })); } } // Check for index files in extension priority order } catch (err) { _iterator12.e(err); } finally { _iterator12.f(); } indexFiles = indexFilesByBaseName.get('index'); if (!indexFiles) { _context3.next = 88; break; } _iterator13 = _createForOfIteratorHelper(extensions); _context3.prev = 56; _iterator13.s(); case 58: if ((_step13 = _iterator13.n()).done) { _context3.next = 80; break; } _ext4 = _step13.value; _iterator14 = _createForOfIteratorHelper(indexFiles); _context3.prev = 61; _iterator14.s(); case 63: if ((_step14 = _iterator14.n()).done) { _context3.next = 70; break; } _entry5 = _step14.value; _entryWithExt = _entry5; if (!(_entryWithExt.actualExtension === _ext4)) { _context3.next = 68; break; } return _context3.abrupt("return", joinPath(moduleDir, _entry5.name)); case 68: _context3.next = 63; break; case 70: _context3.next = 75; break; case 72: _context3.prev = 72; _context3.t2 = _context3["catch"](61); _iterator14.e(_context3.t2); case 75: _context3.prev = 75; _iterator14.f(); return _context3.finish(75); case 78: _context3.next = 58; break; case 80: _context3.next = 85; break; case 82: _context3.prev = 82; _context3.t3 = _context3["catch"](56); _iterator13.e(_context3.t3); case 85: _context3.prev = 85; _iterator13.f(); return _context3.finish(85); case 88: _context3.next = 92; break; case 90: _context3.prev = 90; _context3.t4 = _context3["catch"](46); case 92: _context3.next = 96; break; case 94: _context3.prev = 94; _context3.t5 = _context3["catch"](0); case 96: throw new Error("Could not resolve module at path \"".concat(modulePath, "\". Tried extensions: ").concat(extensions.join(', '))); case 97: case "end": return _context3.stop(); } }, _callee3, null, [[0, 94], [10, 37, 40, 43], [15, 27, 30, 33], [46, 90], [56, 82, 85, 88], [61, 72, 75, 78]]); })); return _resolveSinglePath.apply(this, arguments); } export function resolveModulePaths(_x0, _x1) { return _resolveModulePaths.apply(this, arguments); } /** * Resolves import result by separating JavaScript modules from static assets, * only resolving JavaScript modules and returning a combined map. * This function uses the new type-aware resolveModulePath function internally. * * @param importResult - The result from parseImports containing all imports * @param readDirectory - Function to read directory contents * @param options - Configuration options for module resolution * @returns Promise<Map<string, string>> - Map from import path to resolved file path */ function _resolveModulePaths() { _resolveModulePaths = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6(modulePaths, readDirectory) { var options, _options$extensions2, extensions, results, pathsByDirectory, _iterator15, _step15, modulePath, lastSlashIndex, parentDir, moduleName, directoryEntries, directoryResults, _iterator24, _step24, directoryResult, _iterator25, _step25, _step25$value, fullPath, resolvedPath, _args6 = arguments; return _regeneratorRuntime().wrap(function _callee6$(_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {}; _options$extensions2 = options.extensions, extensions = _options$extensions2 === void 0 ? JAVASCRIPT_MODULE_EXTENSIONS : _options$extensions2; results = new Map(); // Group paths by their parent directory pathsByDirectory = new Map(); _iterator15 = _createForOfIteratorHelper(modulePaths); try { for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) { modulePath = _step15.value; lastSlashIndex = modulePath.lastIndexOf('/'); parentDir = modulePath.substring(0, lastSlashIndex); moduleName = modulePath.substring(lastSlashIndex + 1); if (!pathsByDirectory.has(parentDir)) { pathsByDirectory.set(parentDir, []); } pathsByDirectory.get(parentDir).push({ fullPath: modulePath, moduleName: moduleName }); } // Process each directory group } catch (err) { _iterator15.e(err); } finally { _iterator15.f(); } directoryEntries = Array.from(pathsByDirectory.entries()); _context6.next = 9; return Promise.all(directoryEntries.map(/*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref) { 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; return _regeneratorRuntime().wrap(function _callee5$(_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _ref3 = _slicedToArray(_ref, 2), parentDir = _ref3[0], pathGroup = _ref3[1]; _context5.prev = 1; _context5.next = 4; return readDirectory(parentDir); case 4: dirContents = _context5.sent; unresolved = []; resolved = []; // Look for direct file matches in extension priority order // Create a map of baseName -> files for efficient lookup filesByBaseName = new Map(); _iterator16 = _createForOfIteratorHelper(dirContents); try { for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) { entry = _step16.value; if (entry.isFile) { fileName = entry.name; _getFileNameFromUrl7 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl7.extension; fileBaseName = fileName.substring(0, fileName.length - fileExt.length); if (!filesByBaseName.has(fileBaseName)) { filesByBaseName.set(fileBaseName, []); } filesByBaseName.get(fileBaseName).push(entry); } } // Check each module path against the file map } catch (err) { _iterator16.e(err); } finally { _iterator16.f(); } _iterator17 = _createForOfIteratorHelper(pathGroup); _context5.prev = 11; _iterator17.s(); case 13: if ((_step17 = _iterator17.n()).done) { _context5.next = 58; break; } _step17$value = _step17.value, _fullPath = _step17$value.fullPath, moduleName = _step17$value.moduleName; foundMatch = false; matchingFiles = filesByBaseName.get(moduleName); if (!matchingFiles) { _context5.next = 55; break; } _iterator22 = _createForOfIteratorHelper(extensions); _context5.prev = 19; _iterator22.s(); case 21: if ((_step22 = _iterator22.n()).done) { _context5.next = 47; break; } ext = _step22.value; _iterator23 = _createForOfIteratorHelper(matchingFiles); _context5.prev = 24; _iterator23.s(); case 26: if ((_step23 = _iterator23.n()).done) { _context5.next = 35; break; } _entry7 = _step23.value; _getFileNameFromUrl8 = getFileNameFromUrl(_entry7.name), entryExt = _getFileNameFromUrl8.extension; if (!(entryExt === ext)) { _context5.next = 33; break; } resolved.push({ fullPath: _fullPath, resolvedPath: joinPath(parentDir, _entry7.name) }); foundMatch = true; return _context5.abrupt("break", 35); case 33: _context5.next = 26; break; case 35: _context5.next = 40; break; case 37: _context5.prev = 37; _context5.t0 = _context5["catch"](24); _iterator23.e(_context5.t0); case 40: _context5.prev = 40; _iterator23.f(); return _context5.finish(40); case 43: if (!foundMatch) { _context5.next = 45; break; } return _context5.abrupt("break", 47); case 45: _context5.next = 21; break; case 47: _context5.next = 52; break; case 49: _context5.prev = 49; _context5.t1 = _context5["catch"](19); _iterator22.e(_context5.t1); case 52: _context5.prev = 52; _iterator22.f(); return _context5.finish(52); case 55: if (!foundMatch) { unresolved.push({ fullPath: _fullPath, moduleName: moduleName }); } case 56: _context5.next = 13; break; case 58: _context5.next = 63; break; case 60: _context5.prev = 60; _context5.t2 = _context5["catch"](11); _iterator17.e(_context5.t2); case 63: _context5.prev = 63; _iterator17.f(); return _context5.finish(63); case 66: if (!(unresolved.length > 0)) { _context5.next = 73; break; } directories = new Set(dirContents.filter(function (entry) { return entry.isDirectory; }).map(function (entry) { return entry.name; })); _context5.next = 70; return Promise.all(unresolved.map(/*#__PURE__*/function () { var _ref5 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4) { var fullPath, moduleName, moduleDir, moduleDirContents, indexFilesByBaseName, _iterator18, _step18, moduleFile, fileName, _getFileNameFromUrl6, fileExt, fileBaseName, indexFiles, _iterator19, _step19, ext, _iterator20, _step20, entry, _getFileNameFromUrl5, entryExt; return _regeneratorRuntime().wrap(function _callee4$(_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: fullPath = _ref4.fullPath, moduleName = _ref4.moduleName; if (!directories.has(moduleName)) { _context4.next = 49; break; } moduleDir = joinPath(parentDir, moduleName); _context4.prev = 3; _context4.next = 6; return readDirectory(moduleDir); case 6: moduleDirContents = _context4.sent; // Look for index files in extension priority order // Create a map of baseName -> files for efficient lookup indexFilesByBaseName = new Map(); _iterator18 = _createForOfIteratorHelper(moduleDirContents); try { for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) { moduleFile = _step18.value; if (moduleFile.isFile) { fileName = moduleFile.name; _getFileNameFromUrl6 = getFileNameFromUrl(fileName), fileExt = _getFileNameFromUrl6.extension; fileBaseName = fileName.substring(0, fileName.length - fileExt.length); if (!indexFilesByBaseName.has(fileBaseName)) { indexFilesByBaseName.set(fileBaseName, []); } indexFilesByBaseName.get(fileBaseName).push(moduleFile); } } // Check for index files in extension priority order } catch (err) { _iterator18.e(err); } finally { _iterator18.f(); } indexFiles = indexFilesByBaseName.get('index'); if (!indexFiles) { _context4.next = 45; break; } _iterator19 = _createForOfIteratorHelper(extensions); _context4.prev = 13; _iterator19.s(); case 15: if ((_step19 = _iterator19.n()).done) { _context4.next = 37; break; } ext = _step19.value; _iterator20 = _createForOfIteratorHelper(indexFiles); _context4.prev = 18; _iterator20.s(); case 20: if ((_step20 = _iterator20.n()).done) { _context4.next = 27; break; } entry = _step20.value; _getFileNameFromUrl5 = getFileNameFromUrl(entry.name), entryExt = _getFileNameFromUrl5.extension; if (!(entryExt === ext)) { _context4.next = 25; break; } return _context4.abrupt("return", { fullPath: fullPath, resolvedPath: joinPath(moduleDir, entry.name) }); case 25: _context4.next = 20; break; case 27: _context4.next = 32; break; case 29: _context4.prev = 29; _context4.t0 = _context4["catch"](18); _iterator20.e(_context4.t0); case 32: _context4.prev = 32; _iterator20.f(); return _context4.finish(32); case 35: _context4.next = 15; break; case 37: _context4.next = 42; break; case 39: _context4.prev = 39; _context4.t1 = _context4["catch"](13); _iterator19.e(_context4.t1); case 42: _context4.prev = 42; _iterator19.f(); return _context4.finish(42); case 45: _context4.next = 49; break; case 47: _context4.prev = 47; _context4.t2 = _context4["catch"](3); case 49: return _context4.abrupt("return", { fullPath: fullPath, resolvedPath: null }); case 50: case "end": return _context4.stop(); } }, _callee4, null, [[3, 47], [13, 39, 42, 45], [18, 29, 32, 35]]); })); return function (_x15) { return _ref5.apply(this, arguments); }; }())); case 70: indexResults = _context5.sent; _iterator21 = _createForOfIteratorHelper(indexResults); try { for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) { _step21$value = _step21.value, fullPath = _step21$value.fullPath, resolvedPath = _step21$value.resolvedPath; if (resolvedPath) { resolved.push({ fullPath: fullPath, resolvedPath: resolvedPath }); } } } catch (err) { _iterator21.e(err); } finally { _iterator21.f(); } case 73: return _context5.abrupt("return", resolved); case 76: _context5.prev = 76; _context5.t3 = _context5["catch"](1); return _context5.abrupt("return", []); case 79: case "end": return _context5.stop(); } }, _callee5, null, [[1, 76], [11, 60, 63, 66], [19, 49, 52, 55], [24, 37, 40, 43]]); })); return function (_x14) { return _ref2.apply(this, arguments); }; }())); case 9: directoryResults = _context6.sent; // Collect all resolved paths _iterator24 = _createForOfIteratorHelper(directoryResults); try { for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) { directoryResult = _step24.value; _iterator25 = _createForOfIteratorHelper(directoryResult); try { for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) { _step25$value = _step25.value, fullPath = _step25$value.fullPath, resolvedPath = _step25$value.resolvedPath; results.set(fullPath, resolvedPath); } } catch (err) { _iterator25.e(err); } finally { _iterator25.f(); } } } catch (err) { _iterator24.e(err); } finally { _iterator24.f(); } return _context6.abrupt("return", results); case 13: case "end": return _context6.stop(); } }, _callee6); })); r