@reliverse/pathkit 1.1.1 → 1.1.3

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/bin/mod.js +22 -13
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  - ⚙️ **node.js api compatible** – familiar methods, no learning curve
13
13
  - 🚀 **modern & fast** – typescript, pure esm, bun & node‑ready
14
14
  - 🧠 **predictable & testable** – deterministic output across windows / macos / linux
15
- - 🧼 **no dependencies** – just better path api + couple of cool utilities = [4.2 kB](https://bundlephobia.com/package/@reliverse/pathkit@latest)
15
+ - 🧼 **no dependencies** – just better path api + couple of cool utilities = [5kB](https://bundlephobia.com/package/@reliverse/pathkit@latest)
16
16
 
17
17
  ## Installation
18
18
 
package/bin/mod.js CHANGED
@@ -14,7 +14,7 @@ const UNC_REGEX = /^[/\\]{2}/;
14
14
  const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
15
15
  const ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
16
16
  const PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/;
17
- const IMPORT_REGEX = /(?:import\s+(?:[\s\S]*?)\s+from\s+|import\s*\(\s*)\s*(['"])((?:@)[^'"]+)\1/g;
17
+ const IMPORT_REGEX = /(?:import\s+(?:[\s\S]*?)\s+from\s+|import\s*\(\s*)\s*(['"])([^'"]+)\1/g;
18
18
  async function cleanDirs(dirs) {
19
19
  await Promise.all(
20
20
  dirs.map(async (d) => {
@@ -377,6 +377,11 @@ function reverseResolveAlias(path2, aliases) {
377
377
  return matches.sort((a, b) => b.length - a.length);
378
378
  }
379
379
  const findAliasMatch = (importPath, paths) => {
380
+ const firstPathKey = Object.keys(paths)[0];
381
+ const baseAlias = firstPathKey.replace("/*", "");
382
+ if (importPath.startsWith("@") && !importPath.startsWith(baseAlias)) {
383
+ return null;
384
+ }
380
385
  if (paths[importPath]?.[0]) {
381
386
  return {
382
387
  key: importPath,
@@ -448,6 +453,10 @@ async function convertStringAliasRelative({
448
453
  pathPattern,
449
454
  targetDir
450
455
  }) {
456
+ const baseAlias = pathPattern.replace("/*", "");
457
+ if (importPath.startsWith("@") && !importPath.startsWith(baseAlias)) {
458
+ return importPath;
459
+ }
451
460
  const paths = { [pathPattern]: ["./*"] };
452
461
  const importerDir = dirname(importerFile);
453
462
  const match = findAliasMatch(importPath, paths);
@@ -479,9 +488,13 @@ async function processFile(filePath, aliasToReplace, targetDir, pathExtFilter) {
479
488
  const changes = [];
480
489
  const matches = Array.from(content.matchAll(IMPORT_REGEX));
481
490
  const normalizedAlias = aliasToReplace.endsWith("/*") ? aliasToReplace : `${aliasToReplace}/*`;
491
+ const baseAlias = aliasToReplace.replace("/*", "");
482
492
  for (const match of matches) {
483
493
  const originalQuote = match[1];
484
494
  const importPath = match[2];
495
+ if (!importPath.startsWith(baseAlias)) {
496
+ continue;
497
+ }
485
498
  const importExt = extname(importPath);
486
499
  const shouldProcess = pathExtFilter === "js" && importExt === ".js" || pathExtFilter === "ts" && importExt === ".ts" || pathExtFilter === "none" && importExt === "" || pathExtFilter === "js-ts-none";
487
500
  if (!shouldProcess) continue;
@@ -518,8 +531,7 @@ async function processAllFiles({
518
531
  entries.map(async (entry) => {
519
532
  const fullPath = join(srcDir, entry.name);
520
533
  if (entry.isDirectory()) {
521
- if (entry.name === "node_modules" || entry.name.startsWith("."))
522
- return;
534
+ if (entry.name === "node_modules") return;
523
535
  const subdirResults = await processAllFiles({
524
536
  srcDir: fullPath,
525
537
  aliasToReplace,
@@ -605,9 +617,7 @@ async function convertImportsExt({
605
617
  entries.map(async (entry) => {
606
618
  const fullPath = join(targetDir, entry.name);
607
619
  if (entry.isDirectory()) {
608
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
609
- return;
610
- }
620
+ if (entry.name === "node_modules") return;
611
621
  const subdirResults = await convertImportsExt({
612
622
  targetDir: fullPath,
613
623
  extFrom,
@@ -742,10 +752,7 @@ async function stripPathSegmentsInDirectory({
742
752
  entries.map(async (entry) => {
743
753
  const fullPath = join(targetDir, entry.name);
744
754
  if (entry.isDirectory()) {
745
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
746
- logInternal(` - skipping directory: ${entry.name}`);
747
- return;
748
- }
755
+ if (entry.name === "node_modules") return;
749
756
  logInternal(` - recursing into directory: ${entry.name}`);
750
757
  const subdirResults = await stripPathSegmentsInDirectory({
751
758
  targetDir: fullPath,
@@ -768,6 +775,10 @@ async function stripPathSegmentsInDirectory({
768
775
  logInternal(` - skipping non-path import: ${importPath}`);
769
776
  continue;
770
777
  }
778
+ if (alias && !importPath.startsWith(alias.replace("/*", ""))) {
779
+ logInternal(` - skipping non-alias import: ${importPath}`);
780
+ continue;
781
+ }
771
782
  logInternal(` Processing import: ${importPath}`);
772
783
  const strippedPath = stripPathSegments(
773
784
  importPath,
@@ -867,9 +878,7 @@ async function attachPathSegmentsInDirectory({
867
878
  entries.map(async (entry) => {
868
879
  const fullPath = join(targetDir, entry.name);
869
880
  if (entry.isDirectory()) {
870
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
871
- return;
872
- }
881
+ if (entry.name === "node_modules") return;
873
882
  const subdirResults = await attachPathSegmentsInDirectory({
874
883
  targetDir: fullPath,
875
884
  segments,
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.1",
8
+ "version": "1.1.3",
9
9
  "devDependencies": {
10
10
  "@biomejs/biome": "1.9.4",
11
11
  "@eslint/js": "^9.27.0",