pruny 1.43.3 → 1.43.5

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/dist/index.js +50 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12592,7 +12592,7 @@ var API_METHOD_PATTERNS = [
12592
12592
  { regex: /fetch\s*\(\s*`([^`]*?\/[^`]*)`/g, method: undefined, source: "http-client" },
12593
12593
  { regex: /['"`](\/api\/[^'"`\s]+)['"`]/g, method: undefined, source: "http-client" },
12594
12594
  { regex: /`([^`\n]*?\/api\/[^`\n]*)`/g, method: undefined, source: "http-client" },
12595
- { regex: /`[^`]*?(\/api\/[\w-]+(?:\/[\w-]+)*(?:\/\$\{[^}]+\})*)[^`]*?`/gs, method: undefined, source: "http-client" },
12595
+ { regex: /`[^`]{0,500}?(\/api\/[\w-]+(?:\/[\w-]+)*(?:\/\$\{[^}]+\})*)[^`]{0,500}?`/gs, method: undefined, source: "http-client" },
12596
12596
  { regex: /`[^`\n]*(?:API_URL|BASE_URL|BACKEND_URL|SERVER_URL)\}(\/[^`\n]*)`/g, method: undefined, source: "http-client" },
12597
12597
  { regex: /`([^`\n]*?(\/[\w-]{2,}\/[^`\n]*))`/g, method: undefined, source: "generic" },
12598
12598
  { regex: /https?:\/\/[^/]+(\/[^'"`\s]*)/g, method: undefined, source: "http-client" },
@@ -12632,7 +12632,7 @@ function extractApiReferences(content) {
12632
12632
  const acceptedMatches = [];
12633
12633
  for (const match of matches) {
12634
12634
  const isRedundant = acceptedMatches.some((accepted) => {
12635
- return accepted.start <= match.start && accepted.end >= match.end;
12635
+ return accepted.path === match.path && accepted.start <= match.start && accepted.end >= match.end;
12636
12636
  });
12637
12637
  if (!isRedundant) {
12638
12638
  acceptedMatches.push(match);
@@ -16485,6 +16485,20 @@ async function scan(config) {
16485
16485
  }
16486
16486
  } catch {}
16487
16487
  }
16488
+ const existingNextApiPaths = new Set;
16489
+ for (const nr of nextRoutes) {
16490
+ existingNextApiPaths.add(normalizeNextPath(nr.path));
16491
+ }
16492
+ if (config.appSpecificScan) {
16493
+ const monorepoNextFiles = await import_fast_glob10.default(nextPatterns, {
16494
+ cwd: config.appSpecificScan.rootDir,
16495
+ ignore: config.ignore.folders
16496
+ });
16497
+ for (const f of monorepoNextFiles) {
16498
+ const apiPath = extractRoutePath(f);
16499
+ existingNextApiPaths.add(normalizeNextPath(apiPath));
16500
+ }
16501
+ }
16488
16502
  for (const route of routes) {
16489
16503
  if (shouldIgnore(route.path, config.ignore.routes) || shouldIgnore(route.filePath, config.ignore.routes)) {
16490
16504
  route.used = true;
@@ -16512,6 +16526,40 @@ async function scan(config) {
16512
16526
  }
16513
16527
  }
16514
16528
  }
16529
+ for (const route of routes) {
16530
+ if (route.type !== "nestjs" || !route.used)
16531
+ continue;
16532
+ const apiVariation = route.path.startsWith("/api/") ? normalizeNestPath(route.path) : normalizeNestPath("/api" + route.path);
16533
+ const hasNextReplacement = existingNextApiPaths.has(apiVariation) || [...existingNextApiPaths].some((np) => np.startsWith(apiVariation + "/") || apiVariation.startsWith(np + "/"));
16534
+ if (hasNextReplacement) {
16535
+ const nestPathDirect = normalizeNestPath(route.path);
16536
+ let hasDirectReference = false;
16537
+ for (const ref of allReferences) {
16538
+ if (ref.source !== "http-client")
16539
+ continue;
16540
+ let normalizedRef = ref.path.replace(/\s+/g, "").replace(/\$\{[^}]+\}/g, "*").replace(/\/$/, "").replace(/\?.*$/, "").replace(/\/+/g, "/").toLowerCase();
16541
+ if (normalizedRef.startsWith("*")) {
16542
+ const firstSlash = normalizedRef.indexOf("/");
16543
+ if (firstSlash !== -1)
16544
+ normalizedRef = normalizedRef.substring(firstSlash);
16545
+ }
16546
+ if (!normalizedRef.startsWith("/api/") && !normalizedRef.startsWith("/api?")) {
16547
+ if (normalizedRef === nestPathDirect || normalizedRef.startsWith(nestPathDirect + "/") || minimatch(normalizedRef, nestPathDirect)) {
16548
+ hasDirectReference = true;
16549
+ break;
16550
+ }
16551
+ }
16552
+ }
16553
+ if (!hasDirectReference) {
16554
+ if (process.env.DEBUG_PRUNY) {
16555
+ console.log(`[DEBUG] NestJS route ${route.path} de-marked: Next.js replacement exists at ${apiVariation}`);
16556
+ }
16557
+ route.used = false;
16558
+ route.references = [];
16559
+ route.unusedMethods = [...route.methods];
16560
+ }
16561
+ }
16562
+ }
16515
16563
  let publicAssets;
16516
16564
  if (!config.excludePublic) {
16517
16565
  publicAssets = await scanPublicAssets(config);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.43.3",
3
+ "version": "1.43.5",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [