@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 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" | "none-and-js";
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" ? "" : extFrom === "none-and-js" ? "(?:\\.js)?" : `.${extFrom}`;
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 {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "license": "MIT",
6
6
  "name": "@reliverse/pathkit",
7
7
  "type": "module",
8
- "version": "1.1.7",
8
+ "version": "1.1.9",
9
9
  "devDependencies": {},
10
10
  "exports": {
11
11
  ".": "./bin/mod.js"