@reliverse/pathkit 1.2.4 → 1.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/bin/mod.js +13 -4
- package/package.json +1 -1
package/bin/mod.js
CHANGED
|
@@ -356,7 +356,9 @@ function reverseResolveAlias(path2, aliases) {
|
|
|
356
356
|
}
|
|
357
357
|
const findAliasMatch = (importPath, paths) => {
|
|
358
358
|
const firstPathKey = Object.keys(paths)[0];
|
|
359
|
-
if (!firstPathKey)
|
|
359
|
+
if (!firstPathKey) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
360
362
|
const baseAlias = firstPathKey.replace("/*", "");
|
|
361
363
|
if (importPath.startsWith("@") && !importPath.startsWith(baseAlias)) {
|
|
362
364
|
return null;
|
|
@@ -435,12 +437,15 @@ async function convertStringAliasRelative({
|
|
|
435
437
|
const paths = { [pathPattern]: ["./*"] };
|
|
436
438
|
const importerDir = dirname(importerFile);
|
|
437
439
|
const match = findAliasMatch(importPath, paths);
|
|
438
|
-
if (!match)
|
|
440
|
+
if (!match) {
|
|
441
|
+
return importPath;
|
|
442
|
+
}
|
|
439
443
|
const absPath = resolve(targetDir, match.resolvedPath, match.suffix);
|
|
440
444
|
const resolvedFile = await resolveFileWithExtensions(absPath);
|
|
441
445
|
const relPath = toRelativeImport(resolvedFile || absPath, importerDir);
|
|
442
446
|
const originalExt = extname(importPath);
|
|
443
|
-
|
|
447
|
+
const result = getTargetExtension(relPath, originalExt);
|
|
448
|
+
return result;
|
|
444
449
|
}
|
|
445
450
|
function replaceAllInString(original, searchValue, replaceValue) {
|
|
446
451
|
let currentPosition = 0;
|
|
@@ -473,7 +478,9 @@ async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter) {
|
|
|
473
478
|
}
|
|
474
479
|
const importExt = extname(importPath);
|
|
475
480
|
const shouldProcess = pathExtFilter === "js" && importExt === ".js" || pathExtFilter === "ts" && importExt === ".ts" || pathExtFilter === "none" && importExt === "" || pathExtFilter === "js-ts-none";
|
|
476
|
-
if (!shouldProcess)
|
|
481
|
+
if (!shouldProcess) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
477
484
|
const relPath = await convertStringAliasRelative({
|
|
478
485
|
importPath,
|
|
479
486
|
importerFile: filePath,
|
|
@@ -486,10 +493,12 @@ async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter) {
|
|
|
486
493
|
const searchString = `${originalQuote}${importPath}${originalQuote}`;
|
|
487
494
|
const replacementString = `${originalQuote}${finalPath}${originalQuote}`;
|
|
488
495
|
updated = replaceAllInString(updated, searchString, replacementString);
|
|
496
|
+
} else {
|
|
489
497
|
}
|
|
490
498
|
}
|
|
491
499
|
if (content !== updated) {
|
|
492
500
|
await fs.writeFile(filePath, updated);
|
|
501
|
+
} else {
|
|
493
502
|
}
|
|
494
503
|
return changes;
|
|
495
504
|
}
|