@reliverse/pathkit 1.1.10 → 1.2.0

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
@@ -111,10 +111,11 @@ declare function convertImportsAliasToRelative({ targetDir, aliasToReplace, path
111
111
  /**
112
112
  * converts extensions in import paths from one format to another
113
113
  */
114
- declare function convertImportsExt({ targetDir, extFrom, extTo, }: {
114
+ declare function convertImportsExt({ targetDir, extFrom, extTo, alias, }: {
115
115
  targetDir: string;
116
116
  extFrom: ImportExtType;
117
117
  extTo: ImportExtType;
118
+ alias?: string;
118
119
  }): Promise<{
119
120
  file: string;
120
121
  changes: {
package/bin/mod.js CHANGED
@@ -574,10 +574,13 @@ async function convertImportsAliasToRelative({
574
574
  async function convertImportsExt({
575
575
  targetDir,
576
576
  extFrom,
577
- extTo
577
+ extTo,
578
+ alias
578
579
  }) {
579
580
  const fromExtStr = extFrom === "none" ? "" : `.${extFrom}`;
580
581
  const toExtStr = extTo === "none" ? "" : `.${extTo}`;
582
+ const normalizedAlias = alias ? alias.endsWith("/*") ? alias : `${alias}/*` : void 0;
583
+ const aliasPrefix = normalizedAlias?.replace("/*", "");
581
584
  const importRegex = new RegExp(
582
585
  `(?:^|;|\\n)\\s*(?:import\\s+(?:[\\s\\S]*?)\\s+from\\s+|import\\s*\\(\\s*|export\\s+\\*\\s+from\\s+)\\s*(['"])([^'"]+${fromExtStr.replace(".", "\\.")})(\\1)`,
583
586
  "gm"
@@ -585,7 +588,16 @@ async function convertImportsExt({
585
588
  function shouldSkipPath(path2) {
586
589
  if (path2.startsWith("node:") || path2.startsWith("bun:") || path2.startsWith("npm:") || path2.startsWith("jsr:") || path2.startsWith("node_modules"))
587
590
  return true;
588
- if (path2.startsWith("@") || !path2.includes("/")) return true;
591
+ if (aliasPrefix && path2.startsWith(aliasPrefix)) {
592
+ return false;
593
+ }
594
+ const segments = path2.split("/");
595
+ const firstSegment = segments[0];
596
+ if (!firstSegment) return false;
597
+ if (path2.startsWith("@") || // scoped packages
598
+ !firstSegment.includes(".") || // simple package names
599
+ firstSegment.includes("-") && !firstSegment.startsWith("."))
600
+ return true;
589
601
  if (path2.startsWith("http://") || path2.startsWith("https://")) return true;
590
602
  if (extTo !== "none" && path2.endsWith(`.${extTo}`)) return true;
591
603
  return false;
@@ -601,7 +613,8 @@ async function convertImportsExt({
601
613
  const subdirResults = await convertImportsExt({
602
614
  targetDir: fullPath,
603
615
  extFrom,
604
- extTo
616
+ extTo,
617
+ alias
605
618
  });
606
619
  results.push(...subdirResults);
607
620
  } else if (EXTENSIONS.includes(extname(entry.name))) {
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.10",
8
+ "version": "1.2.0",
9
9
  "devDependencies": {},
10
10
  "exports": {
11
11
  ".": "./bin/mod.js"