@reliverse/pathkit 1.1.1 → 1.1.2

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 (2) hide show
  1. package/bin/mod.js +24 -12
  2. package/package.json +1 -1
package/bin/mod.js CHANGED
@@ -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,16 @@ 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) && !importPath.startsWith("@")) {
496
+ continue;
497
+ }
498
+ if (importPath.startsWith("@") && !importPath.startsWith(baseAlias)) {
499
+ continue;
500
+ }
485
501
  const importExt = extname(importPath);
486
502
  const shouldProcess = pathExtFilter === "js" && importExt === ".js" || pathExtFilter === "ts" && importExt === ".ts" || pathExtFilter === "none" && importExt === "" || pathExtFilter === "js-ts-none";
487
503
  if (!shouldProcess) continue;
@@ -518,8 +534,7 @@ async function processAllFiles({
518
534
  entries.map(async (entry) => {
519
535
  const fullPath = join(srcDir, entry.name);
520
536
  if (entry.isDirectory()) {
521
- if (entry.name === "node_modules" || entry.name.startsWith("."))
522
- return;
537
+ if (entry.name === "node_modules") return;
523
538
  const subdirResults = await processAllFiles({
524
539
  srcDir: fullPath,
525
540
  aliasToReplace,
@@ -605,9 +620,7 @@ async function convertImportsExt({
605
620
  entries.map(async (entry) => {
606
621
  const fullPath = join(targetDir, entry.name);
607
622
  if (entry.isDirectory()) {
608
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
609
- return;
610
- }
623
+ if (entry.name === "node_modules") return;
611
624
  const subdirResults = await convertImportsExt({
612
625
  targetDir: fullPath,
613
626
  extFrom,
@@ -742,10 +755,7 @@ async function stripPathSegmentsInDirectory({
742
755
  entries.map(async (entry) => {
743
756
  const fullPath = join(targetDir, entry.name);
744
757
  if (entry.isDirectory()) {
745
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
746
- logInternal(` - skipping directory: ${entry.name}`);
747
- return;
748
- }
758
+ if (entry.name === "node_modules") return;
749
759
  logInternal(` - recursing into directory: ${entry.name}`);
750
760
  const subdirResults = await stripPathSegmentsInDirectory({
751
761
  targetDir: fullPath,
@@ -768,6 +778,10 @@ async function stripPathSegmentsInDirectory({
768
778
  logInternal(` - skipping non-path import: ${importPath}`);
769
779
  continue;
770
780
  }
781
+ if (importPath.startsWith("@") && !importPath.startsWith(alias.replace("/*", ""))) {
782
+ logInternal(` - skipping npm package import: ${importPath}`);
783
+ continue;
784
+ }
771
785
  logInternal(` Processing import: ${importPath}`);
772
786
  const strippedPath = stripPathSegments(
773
787
  importPath,
@@ -867,9 +881,7 @@ async function attachPathSegmentsInDirectory({
867
881
  entries.map(async (entry) => {
868
882
  const fullPath = join(targetDir, entry.name);
869
883
  if (entry.isDirectory()) {
870
- if (entry.name === "node_modules" || entry.name.startsWith(".")) {
871
- return;
872
- }
884
+ if (entry.name === "node_modules") return;
873
885
  const subdirResults = await attachPathSegmentsInDirectory({
874
886
  targetDir: fullPath,
875
887
  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.2",
9
9
  "devDependencies": {
10
10
  "@biomejs/biome": "1.9.4",
11
11
  "@eslint/js": "^9.27.0",