@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
163 lines (156 loc) • 6.58 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import { readdir } from 'node:fs/promises';
import { resolveModulePath, resolveModulePaths, resolveImportResult, resolveVariantPaths } from "./resolveModulePath.js";
/**
* Node.js filesystem-based directory reader that converts Dirent objects
* to the DirectoryEntry interface expected by the resolver functions.
*/
var nodeDirectoryReader = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path) {
var entries;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return readdir(path, {
withFileTypes: true
});
case 2:
entries = _context.sent;
return _context.abrupt("return", entries.map(function (entry) {
return {
name: entry.name,
isFile: entry.isFile(),
isDirectory: entry.isDirectory()
};
}));
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return function nodeDirectoryReader(_x) {
return _ref.apply(this, arguments);
};
}();
/**
* Resolves a module path using Node.js filesystem APIs.
* This is a convenience wrapper around the generic resolveModulePath function.
*
* @param modulePath - The module path to resolve (without file extension)
* @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), or throws if not found
*/
export function resolveModulePathWithFs(_x2) {
return _resolveModulePathWithFs.apply(this, arguments);
}
/**
* Resolves multiple module paths using Node.js filesystem APIs.
* This is a convenience wrapper around the generic resolveModulePaths function.
*
* @param modulePaths - Array of module paths to resolve (without file extensions)
* @param options - Configuration options
* @returns Promise<Map<string, string>> - Map from input path to resolved file path
*/
function _resolveModulePathWithFs() {
_resolveModulePathWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(modulePath) {
var options,
includeTypeDefs,
_args2 = arguments;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
options = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
includeTypeDefs = _args2.length > 2 ? _args2[2] : undefined;
return _context2.abrupt("return", resolveModulePath(modulePath, nodeDirectoryReader, options, includeTypeDefs));
case 3:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return _resolveModulePathWithFs.apply(this, arguments);
}
export function resolveModulePathsWithFs(_x3) {
return _resolveModulePathsWithFs.apply(this, arguments);
}
/**
* Resolves import result by separating JavaScript modules from static assets,
* only resolving JavaScript modules and returning a combined map.
* This is a convenience wrapper around the generic resolveImportResult function
* that uses Node.js filesystem APIs.
*
* @param importResult - The result from parseImports containing all imports
* @param options - Configuration options for module resolution
* @returns Promise<Map<string, string>> - Map from import path to resolved file path
*/
function _resolveModulePathsWithFs() {
_resolveModulePathsWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(modulePaths) {
var options,
_args3 = arguments;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
options = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
return _context3.abrupt("return", resolveModulePaths(modulePaths, nodeDirectoryReader, options));
case 2:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return _resolveModulePathsWithFs.apply(this, arguments);
}
export function resolveImportResultWithFs(_x4) {
return _resolveImportResultWithFs.apply(this, arguments);
}
/**
* Resolves variant paths from a variants object mapping variant names to their file paths.
* This is a convenience wrapper around the generic resolveVariantPaths function
* that uses Node.js filesystem APIs.
*
* @param variants - Object mapping variant names to their file paths
* @param options - Configuration options for module resolution
* @returns Promise<Map<string, string>> - Map from variant name to resolved file URL
*/
function _resolveImportResultWithFs() {
_resolveImportResultWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(importResult) {
var options,
_args4 = arguments;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
return _context4.abrupt("return", resolveImportResult(importResult, nodeDirectoryReader, options));
case 2:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return _resolveImportResultWithFs.apply(this, arguments);
}
export function resolveVariantPathsWithFs(_x5) {
return _resolveVariantPathsWithFs.apply(this, arguments);
}
// Re-export types for convenience
function _resolveVariantPathsWithFs() {
_resolveVariantPathsWithFs = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(variants) {
var options,
_args5 = arguments;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
options = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : {};
return _context5.abrupt("return", resolveVariantPaths(variants, nodeDirectoryReader, options));
case 2:
case "end":
return _context5.stop();
}
}, _callee5);
}));
return _resolveVariantPathsWithFs.apply(this, arguments);
}