@reliverse/pathkit 1.1.7 → 1.1.9
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.d.ts +1 -1
- package/bin/mod.js +13 -7
- package/package.json +1 -1
package/bin/mod.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface FormatInputPathObject {
|
|
|
19
19
|
name?: string;
|
|
20
20
|
}
|
|
21
21
|
type PathExtFilter = "js" | "ts" | "none" | "js-ts-none";
|
|
22
|
-
type ImportExtType = "js" | "ts" | "none"
|
|
22
|
+
type ImportExtType = "js" | "ts" | "none";
|
|
23
23
|
/**
|
|
24
24
|
* normalizes windows paths to use forward slashes
|
|
25
25
|
*/
|
package/bin/mod.js
CHANGED
|
@@ -576,12 +576,20 @@ async function convertImportsExt({
|
|
|
576
576
|
extFrom,
|
|
577
577
|
extTo
|
|
578
578
|
}) {
|
|
579
|
-
const fromExtStr = extFrom === "none" ? "" :
|
|
579
|
+
const fromExtStr = extFrom === "none" ? "" : `.${extFrom}`;
|
|
580
580
|
const toExtStr = extTo === "none" ? "" : `.${extTo}`;
|
|
581
581
|
const importRegex = new RegExp(
|
|
582
582
|
`(?:import\\s+(?:[\\s\\S]*?)\\s+from\\s+|import\\s*\\(\\s*)\\s*(['"])([^'"]+${fromExtStr.replace(".", "\\.")})(\\1)`,
|
|
583
583
|
"g"
|
|
584
584
|
);
|
|
585
|
+
function shouldSkipPath(path2) {
|
|
586
|
+
if (path2.startsWith("node:") || path2.startsWith("bun:") || path2.startsWith("npm:") || path2.startsWith("jsr:") || path2.startsWith("node_modules"))
|
|
587
|
+
return true;
|
|
588
|
+
if (path2.startsWith("@") || !path2.includes("/")) return true;
|
|
589
|
+
if (path2.startsWith("http://") || path2.startsWith("https://")) return true;
|
|
590
|
+
if (extTo !== "none" && path2.endsWith(`.${extTo}`)) return true;
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
585
593
|
try {
|
|
586
594
|
const entries = await fs.readdir(targetDir, { withFileTypes: true });
|
|
587
595
|
const results = [];
|
|
@@ -606,15 +614,13 @@ async function convertImportsExt({
|
|
|
606
614
|
const quote = match[1];
|
|
607
615
|
const importPath = match[2];
|
|
608
616
|
if (!importPath) continue;
|
|
617
|
+
if (shouldSkipPath(importPath)) {
|
|
618
|
+
match = importRegex.exec(updated);
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
609
621
|
let replacementPath;
|
|
610
622
|
if (extFrom === "none") {
|
|
611
623
|
replacementPath = importPath + toExtStr;
|
|
612
|
-
} else if (extFrom === "none-and-js") {
|
|
613
|
-
if (importPath.endsWith(".js")) {
|
|
614
|
-
replacementPath = importPath.slice(0, -3) + toExtStr;
|
|
615
|
-
} else {
|
|
616
|
-
replacementPath = importPath + toExtStr;
|
|
617
|
-
}
|
|
618
624
|
} else if (extTo === "none") {
|
|
619
625
|
replacementPath = importPath.slice(0, -fromExtStr.length);
|
|
620
626
|
} else {
|