@modern-js/utils
Version:
A Progressive React Framework for modern web development.
88 lines (87 loc) • 3.55 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
JS_LIKE_EXTENSION_RE: ()=>JS_LIKE_EXTENSION_RE,
SOURCE_EXTENSIONS: ()=>SOURCE_EXTENSIONS,
findMatchedSourcePath: ()=>findMatchedSourcePath,
findSourceEntry: ()=>findSourceEntry
});
const external_node_fs_namespaceObject = require("node:fs");
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
const external_node_path_namespaceObject = require("node:path");
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
const SOURCE_EXTENSIONS = [
'.ts',
'.js'
];
const JS_LIKE_EXTENSION_RE = /\.(?:c|m)?js$/;
const isFile = (filepath)=>external_node_fs_default().existsSync(filepath) && external_node_fs_default().statSync(filepath).isFile();
const findSourceEntry = (resolvedPath)=>{
const ext = external_node_path_default().extname(resolvedPath);
if (ext) {
if (isFile(resolvedPath)) return resolvedPath;
if (JS_LIKE_EXTENSION_RE.test(resolvedPath)) {
const tsPath = `${resolvedPath.slice(0, -ext.length)}.ts`;
if (isFile(tsPath)) return tsPath;
}
return;
}
for (const candidateExt of SOURCE_EXTENSIONS){
const filePath = `${resolvedPath}${candidateExt}`;
if (isFile(filePath)) return filePath;
}
for (const candidateExt of SOURCE_EXTENSIONS){
const indexPath = external_node_path_default().join(resolvedPath, `index${candidateExt}`);
if (isFile(indexPath)) return indexPath;
}
};
const findMatchedSourcePath = (matchPath, specifier)=>{
let matchedPath = matchPath(specifier, void 0, void 0, SOURCE_EXTENSIONS);
if (!matchedPath && JS_LIKE_EXTENSION_RE.test(specifier)) matchedPath = matchPath(specifier.replace(JS_LIKE_EXTENSION_RE, ''), void 0, void 0, SOURCE_EXTENSIONS);
return matchedPath;
};
exports.JS_LIKE_EXTENSION_RE = __webpack_exports__.JS_LIKE_EXTENSION_RE;
exports.SOURCE_EXTENSIONS = __webpack_exports__.SOURCE_EXTENSIONS;
exports.findMatchedSourcePath = __webpack_exports__.findMatchedSourcePath;
exports.findSourceEntry = __webpack_exports__.findSourceEntry;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"JS_LIKE_EXTENSION_RE",
"SOURCE_EXTENSIONS",
"findMatchedSourcePath",
"findSourceEntry"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});