pruny 1.7.0 → 1.7.1

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 +35 -32
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9403,13 +9403,16 @@ async function scanUnusedExports(config) {
9403
9403
  if (i === exp.line - 1)
9404
9404
  continue;
9405
9405
  const line = lines[i];
9406
- if (isCommentOrString(line))
9406
+ const trimmed = line.trim();
9407
+ if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
9407
9408
  continue;
9408
- const cleanLine = stripStringsAndComments(line);
9409
9409
  const referenceRegex = new RegExp(`\\b${exp.name}\\b`);
9410
- if (referenceRegex.test(cleanLine)) {
9411
- usedInternally = true;
9412
- break;
9410
+ if (referenceRegex.test(line)) {
9411
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9412
+ if (codePattern.test(line)) {
9413
+ usedInternally = true;
9414
+ break;
9415
+ }
9413
9416
  }
9414
9417
  }
9415
9418
  }
@@ -9417,23 +9420,41 @@ async function scanUnusedExports(config) {
9417
9420
  if (file === otherFile)
9418
9421
  continue;
9419
9422
  const jsxPattern = new RegExp(`<${exp.name}[\\s/>]`);
9423
+ if (jsxPattern.test(content)) {
9424
+ isUsed = true;
9425
+ break;
9426
+ }
9420
9427
  const importPattern = new RegExp(`import.*\\b${exp.name}\\b.*from`);
9421
- const destructurePattern = new RegExp(`\\{[^}]*\\b${exp.name}\\b[^}]*\\}`);
9422
- if (jsxPattern.test(content) || importPattern.test(content)) {
9428
+ if (importPattern.test(content)) {
9423
9429
  isUsed = true;
9424
9430
  break;
9425
9431
  }
9426
- if (!isUsed) {
9432
+ const wordBoundaryPattern = new RegExp(`\\b${exp.name}\\b`);
9433
+ if (wordBoundaryPattern.test(content)) {
9427
9434
  const lines = content.split(`
9428
9435
  `);
9436
+ let inMultilineComment = false;
9437
+ let inTemplate = false;
9429
9438
  for (const line of lines) {
9430
- if (isCommentOrString(line))
9439
+ const trimmed = line.trim();
9440
+ if (trimmed.includes("/*"))
9441
+ inMultilineComment = true;
9442
+ if (trimmed.includes("*/")) {
9443
+ inMultilineComment = false;
9431
9444
  continue;
9432
- const cleanLine = stripStringsAndComments(line);
9433
- const codeUsagePattern = new RegExp(`\\b${exp.name}\\s*[({]|\\b${exp.name}\\s*\\.|\\b${exp.name}\\s*,|\\b${exp.name}\\s*;|\\b${exp.name}\\s*\\)`);
9434
- if (codeUsagePattern.test(cleanLine)) {
9435
- isUsed = true;
9436
- break;
9445
+ }
9446
+ if (inMultilineComment)
9447
+ continue;
9448
+ if (trimmed.startsWith("//"))
9449
+ continue;
9450
+ if (trimmed.includes("{/*") || trimmed.includes("*/}"))
9451
+ continue;
9452
+ if (wordBoundaryPattern.test(line)) {
9453
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9454
+ if (codePattern.test(line)) {
9455
+ isUsed = true;
9456
+ break;
9457
+ }
9437
9458
  }
9438
9459
  }
9439
9460
  }
@@ -9452,24 +9473,6 @@ async function scanUnusedExports(config) {
9452
9473
  exports: unusedExports
9453
9474
  };
9454
9475
  }
9455
- function isCommentOrString(line) {
9456
- const trimmed = line.trim();
9457
- if (trimmed.startsWith("//"))
9458
- return true;
9459
- if (trimmed.startsWith("/*") || trimmed.startsWith("*"))
9460
- return true;
9461
- if (trimmed.includes("{/*") || trimmed.includes("*/}"))
9462
- return true;
9463
- return false;
9464
- }
9465
- function stripStringsAndComments(line) {
9466
- let result = line;
9467
- result = result.replace(/\/\/.*$/g, "");
9468
- result = result.replace(/'([^'\\]|\\.)*'/g, "''");
9469
- result = result.replace(/"([^"\\]|\\.)*"/g, '""');
9470
- result = result.replace(/`([^`\\]|\\.)*`/g, "``");
9471
- return result;
9472
- }
9473
9476
 
9474
9477
  // src/scanner.ts
9475
9478
  function extractRoutePath(filePath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [