pruny 1.18.0 → 1.19.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.
Files changed (2) hide show
  1. package/dist/index.js +30 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7649,13 +7649,20 @@ var API_METHOD_PATTERNS = [
7649
7649
  { regex: /axios\.put\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PUT" },
7650
7650
  { regex: /axios\.delete\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "DELETE" },
7651
7651
  { regex: /axios\.patch\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "PATCH" },
7652
+ { regex: /axios\.get\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "GET" },
7653
+ { regex: /axios\.post\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "POST" },
7654
+ { regex: /axios\.put\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "PUT" },
7655
+ { regex: /axios\.delete\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "DELETE" },
7656
+ { regex: /axios\.patch\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "PATCH" },
7652
7657
  { regex: /useSWR\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: "GET" },
7658
+ { regex: /useSWR\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: "GET" },
7653
7659
  { regex: /fetch\s*\(\s*['"`](\/[^'"`\s)]+)['"`]/g, method: undefined },
7654
- { regex: /fetch\s*\(\s*`[^`]*(\/[^`\s)]+)`/g, method: undefined },
7660
+ { regex: /fetch\s*\(\s*`[^`]*?(\/[^`\s)]+)`/g, method: undefined },
7655
7661
  { regex: /['"`](\/api\/[^'"`\s]+)['"`]/g, method: undefined },
7656
- { regex: /['"`](?:https?:\/\/[^/]+)?(\/api\/[^'"`\s]+)['"`]/g, method: undefined },
7657
- { regex: /`[^`]*(\/[\w-]+\/[^`\s]+)`/g, method: undefined },
7658
- { regex: /['"`](\/[\w-]{2,}\/[\w-./]+)['"`]/g, method: undefined }
7662
+ { regex: /`[^`]*?(\/api\/[^`\s]+)`/g, method: undefined },
7663
+ { regex: /`[^`]*?(\/[\w-]{2,}\/[^`\s]*)`/g, method: undefined },
7664
+ { regex: /['"`](\/[\w-]{2,}\/[^'"`\s]*)['"`]/g, method: undefined },
7665
+ { regex: /['"`](\/api\/[^'"`\s]*)['"`]/g, method: undefined }
7659
7666
  ];
7660
7667
  function extractApiReferences(content) {
7661
7668
  const matches = [];
@@ -9704,21 +9711,32 @@ function normalizeNextPath(path2) {
9704
9711
  function normalizeNestPath(path2) {
9705
9712
  return path2.replace(/\/$/, "").replace(/\?.*$/, "").replace(/:[^/]+/g, "*").toLowerCase();
9706
9713
  }
9707
- function checkRouteUsage(route, references, nestGlobalPrefix = "api") {
9714
+ function checkRouteUsage(route, references, nestGlobalPrefix = "") {
9708
9715
  const normalize = route.type === "nextjs" ? normalizeNextPath : normalizeNestPath;
9709
9716
  const normalizedRoute = normalize(route.path);
9710
- const prefixToRemove = `/${nestGlobalPrefix}`;
9711
- const normalizedRouteNoPrefix = route.type === "nestjs" && route.path.startsWith(prefixToRemove) ? normalize(route.path.substring(prefixToRemove.length)) : null;
9717
+ const variations = new Set([normalizedRoute]);
9718
+ if (route.type === "nestjs") {
9719
+ if (nestGlobalPrefix) {
9720
+ const prefixToRemove = `/${nestGlobalPrefix}`.replace(/\/+/g, "/");
9721
+ if (route.path.startsWith(prefixToRemove)) {
9722
+ variations.add(normalize(route.path.substring(prefixToRemove.length)));
9723
+ }
9724
+ }
9725
+ if (route.path.startsWith("/api/")) {
9726
+ variations.add(normalize(route.path.substring(4)));
9727
+ } else {
9728
+ variations.add(normalize("/api" + route.path));
9729
+ }
9730
+ }
9712
9731
  const usedMethods = new Set;
9713
9732
  let used = false;
9714
9733
  for (const ref of references) {
9715
9734
  const normalizedFound = ref.path.replace(/\/$/, "").replace(/\?.*$/, "").replace(/\$\{[^}]+\}/g, "*").toLowerCase();
9716
9735
  let match2 = false;
9717
- if (normalizedRoute === normalizedFound || normalizedFound.startsWith(normalizedRoute + "/") || minimatch(normalizedFound, normalizedRoute)) {
9718
- match2 = true;
9719
- } else if (normalizedRouteNoPrefix) {
9720
- if (normalizedRouteNoPrefix === normalizedFound || normalizedFound.startsWith(normalizedRouteNoPrefix + "/") || minimatch(normalizedFound, normalizedRouteNoPrefix)) {
9736
+ for (const v of variations) {
9737
+ if (v === normalizedFound || normalizedFound.startsWith(v + "/") || minimatch(normalizedFound, v)) {
9721
9738
  match2 = true;
9739
+ break;
9722
9740
  }
9723
9741
  }
9724
9742
  if (match2) {
@@ -9895,7 +9913,7 @@ var DEFAULT_CONFIG = {
9895
9913
  ]
9896
9914
  },
9897
9915
  extensions: [".ts", ".tsx", ".js", ".jsx"],
9898
- nestGlobalPrefix: "api",
9916
+ nestGlobalPrefix: "",
9899
9917
  extraRoutePatterns: []
9900
9918
  };
9901
9919
  function loadConfig(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.18.0",
3
+ "version": "1.19.0",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [