@plumeria/utils 19.2.4 → 19.2.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.
- package/dist/resolver.js +10 -0
- package/package.json +1 -1
package/dist/resolver.js
CHANGED
|
@@ -282,12 +282,22 @@ const extensions = [
|
|
|
282
282
|
'/index.js',
|
|
283
283
|
'/index.jsx',
|
|
284
284
|
];
|
|
285
|
+
const rewritten = {
|
|
286
|
+
'.js': ['.ts', '.tsx'],
|
|
287
|
+
'.jsx': ['.tsx'],
|
|
288
|
+
};
|
|
285
289
|
function isFile(candidate) {
|
|
286
290
|
return fs.statSync(candidate, { throwIfNoEntry: false })?.isFile() ?? false;
|
|
287
291
|
}
|
|
288
292
|
function resolveWithExtension(basePath) {
|
|
289
293
|
if (isFile(basePath))
|
|
290
294
|
return basePath;
|
|
295
|
+
const extension = path.extname(basePath);
|
|
296
|
+
for (const replacement of rewritten[extension] ?? []) {
|
|
297
|
+
const candidate = basePath.slice(0, -extension.length) + replacement;
|
|
298
|
+
if (isFile(candidate))
|
|
299
|
+
return candidate;
|
|
300
|
+
}
|
|
291
301
|
for (const ext of extensions) {
|
|
292
302
|
const fullPath = basePath + ext;
|
|
293
303
|
if (isFile(fullPath))
|