pruny 1.43.2 → 1.43.4

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 +49 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -12576,31 +12576,32 @@ var EXPORTED_METHOD_PATTERN = /export\s+(?:async\s+)?(?:function|const)\s+(GET|P
12576
12576
  var NEST_CONTROLLER_PATTERN = /@Controller\s*\(\s*(?:['"`]([^'"`]*)['"`])?\s*\)/;
12577
12577
  var NEST_METHOD_PATTERN = /@(Get|Post|Put|Delete|Patch|Options|Head|All)\s*\(\s*(?:['"`]([^'"`]*)['"`])?\s*\)/g;
12578
12578
  var API_METHOD_PATTERNS = [
12579
- { regex: /(?:axios|api|http|client|service)!?\.get\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "GET" },
12580
- { regex: /(?:axios|api|http|client|service)!?\.post\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "POST" },
12581
- { regex: /(?:axios|api|http|client|service)!?\.put\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PUT" },
12582
- { regex: /(?:axios|api|http|client|service)!?\.delete\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "DELETE" },
12583
- { regex: /(?:axios|api|http|client|service)!?\.patch\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PATCH" },
12584
- { regex: /(?:axios|api|http|client|service)!?\.get\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "GET" },
12585
- { regex: /(?:axios|api|http|client|service)!?\.post\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "POST" },
12586
- { regex: /(?:axios|api|http|client|service)!?\.put\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "PUT" },
12587
- { regex: /(?:axios|api|http|client|service)!?\.delete\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "DELETE" },
12588
- { regex: /(?:axios|api|http|client|service)!?\.patch\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "PATCH" },
12589
- { regex: /useSWR\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "GET" },
12590
- { regex: /useSWR\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "GET" },
12591
- { regex: /fetch\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: undefined },
12592
- { regex: /fetch\s*\(\s*`([^`]*?\/[^`]*)`/g, method: undefined },
12593
- { regex: /['"`](\/api\/[^'"`\s]+)['"`]/g, method: undefined },
12594
- { regex: /`([^`\n]*?\/api\/[^`\n]*)`/g, method: undefined },
12595
- { regex: /`[^`]*?(\/api\/[\w-]+(?:\/[\w-]+)*(?:\/\$\{[^}]+\})*)[^`]*?`/gs, method: undefined },
12596
- { regex: /`([^`\n]*?(\/[\w-]{2,}\/[^`\n]*))`/g, method: undefined },
12597
- { regex: /https?:\/\/[^/]+(\/[^'"`\s]*)/g, method: undefined },
12598
- { regex: /['"`](\/[\w-]{2,}\/[^'"`\s]*)['"`]/g, method: undefined },
12599
- { regex: /['"`](\/api\/[^'"`\s]*)['"`]/g, method: undefined }
12579
+ { regex: /(?:axios|api|http|client|service)!?\.get\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "GET", source: "http-client" },
12580
+ { regex: /(?:axios|api|http|client|service)!?\.post\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "POST", source: "http-client" },
12581
+ { regex: /(?:axios|api|http|client|service)!?\.put\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PUT", source: "http-client" },
12582
+ { regex: /(?:axios|api|http|client|service)!?\.delete\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "DELETE", source: "http-client" },
12583
+ { regex: /(?:axios|api|http|client|service)!?\.patch\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PATCH", source: "http-client" },
12584
+ { regex: /(?:axios|api|http|client|service)!?\.get\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "GET", source: "http-client" },
12585
+ { regex: /(?:axios|api|http|client|service)!?\.post\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "POST", source: "http-client" },
12586
+ { regex: /(?:axios|api|http|client|service)!?\.put\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "PUT", source: "http-client" },
12587
+ { regex: /(?:axios|api|http|client|service)!?\.delete\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "DELETE", source: "http-client" },
12588
+ { regex: /(?:axios|api|http|client|service)!?\.patch\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "PATCH", source: "http-client" },
12589
+ { regex: /useSWR\s*(?:<[^>]+>)?\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "GET", source: "http-client" },
12590
+ { regex: /useSWR\s*(?:<[^>]+>)?\s*\(\s*`([^`]*?\/[^`]*)`/g, method: "GET", source: "http-client" },
12591
+ { regex: /fetch\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: undefined, source: "http-client" },
12592
+ { regex: /fetch\s*\(\s*`([^`]*?\/[^`]*)`/g, method: undefined, source: "http-client" },
12593
+ { regex: /['"`](\/api\/[^'"`\s]+)['"`]/g, method: undefined, source: "http-client" },
12594
+ { regex: /`([^`\n]*?\/api\/[^`\n]*)`/g, method: undefined, source: "http-client" },
12595
+ { regex: /`[^`]{0,500}?(\/api\/[\w-]+(?:\/[\w-]+)*(?:\/\$\{[^}]+\})*)[^`]{0,500}?`/gs, method: undefined, source: "http-client" },
12596
+ { regex: /`[^`\n]*(?:API_URL|BASE_URL|BACKEND_URL|SERVER_URL)\}(\/[^`\n]*)`/g, method: undefined, source: "http-client" },
12597
+ { regex: /`([^`\n]*?(\/[\w-]{2,}\/[^`\n]*))`/g, method: undefined, source: "generic" },
12598
+ { regex: /https?:\/\/[^/]+(\/[^'"`\s]*)/g, method: undefined, source: "http-client" },
12599
+ { regex: /['"`](\/[\w-]{2,}\/[^'"`\s]*)['"`]/g, method: undefined, source: "generic" },
12600
+ { regex: /['"`](\/api\/[^'"`\s]*)['"`]/g, method: undefined, source: "http-client" }
12600
12601
  ];
12601
12602
  function extractApiReferences(content) {
12602
12603
  const matches = [];
12603
- for (const { regex, method } of API_METHOD_PATTERNS) {
12604
+ for (const { regex, method, source } of API_METHOD_PATTERNS) {
12604
12605
  regex.lastIndex = 0;
12605
12606
  let regexMatch;
12606
12607
  while ((regexMatch = regex.exec(content)) !== null) {
@@ -12608,6 +12609,7 @@ function extractApiReferences(content) {
12608
12609
  matches.push({
12609
12610
  path: regexMatch[1],
12610
12611
  method,
12612
+ source,
12611
12613
  start: regexMatch.index,
12612
12614
  end: regexMatch.index + regexMatch[0].length
12613
12615
  });
@@ -12630,7 +12632,7 @@ function extractApiReferences(content) {
12630
12632
  const acceptedMatches = [];
12631
12633
  for (const match of matches) {
12632
12634
  const isRedundant = acceptedMatches.some((accepted) => {
12633
- return accepted.start <= match.start && accepted.end >= match.end;
12635
+ return accepted.path === match.path && accepted.start <= match.start && accepted.end >= match.end;
12634
12636
  });
12635
12637
  if (!isRedundant) {
12636
12638
  acceptedMatches.push(match);
@@ -12641,8 +12643,15 @@ function extractApiReferences(content) {
12641
12643
  for (const match of acceptedMatches) {
12642
12644
  const key = `${match.path}::${match.method || "ANY"}`;
12643
12645
  if (!seen.has(key)) {
12644
- references.push({ path: match.path, method: match.method });
12646
+ references.push({ path: match.path, method: match.method, source: match.source });
12645
12647
  seen.add(key);
12648
+ } else {
12649
+ if (match.source === "http-client") {
12650
+ const existing = references.find((r) => `${r.path}::${r.method || "ANY"}` === key);
12651
+ if (existing && existing.source === "generic") {
12652
+ existing.source = "http-client";
12653
+ }
12654
+ }
12646
12655
  }
12647
12656
  }
12648
12657
  return references;
@@ -16143,6 +16152,20 @@ function extractNestRoutes(filePath, content, globalPrefix = "api") {
16143
16152
  console.log(`[DEBUG] Extracted Route: ${fullPath} from ${filePath}`);
16144
16153
  }
16145
16154
  }
16155
+ if (routes.length === 0 && controllerMatch) {
16156
+ const fullPath = `/${globalPrefix}/${controllerPath}`.replace(/\/+/g, "/").replace(/\/$/, "") || "/";
16157
+ routes.push({
16158
+ type: "nestjs",
16159
+ path: fullPath,
16160
+ filePath,
16161
+ used: false,
16162
+ references: [],
16163
+ methods: [],
16164
+ unusedMethods: [],
16165
+ methodLines: {},
16166
+ methodNames: {}
16167
+ });
16168
+ }
16146
16169
  return routes;
16147
16170
  }
16148
16171
  function extractNestMethodName(content) {
@@ -16239,7 +16262,8 @@ function checkRouteUsage(route, references, nestGlobalPrefix = "") {
16239
16262
  }
16240
16263
  const usedMethods = new Set;
16241
16264
  let used = false;
16242
- for (const ref of references) {
16265
+ const filteredRefs = route.type === "nestjs" ? references.filter((r) => r.source === "http-client") : references;
16266
+ for (const ref of filteredRefs) {
16243
16267
  let normalizedFound = ref.path.replace(/\s+/g, "").replace(/\$\{[^}]+\}/g, "*").replace(/\/$/, "").replace(/\?.*$/, "").replace(/\/+/g, "/").toLowerCase();
16244
16268
  if (normalizedFound.startsWith("*")) {
16245
16269
  const firstSlash = normalizedFound.indexOf("/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.43.2",
3
+ "version": "1.43.4",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [