pruny 1.10.0 → 1.10.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 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9249,6 +9249,13 @@ async function scanUnusedFiles(config) {
9249
9249
  } else if (imp.startsWith("@/") || imp.startsWith("~/")) {
9250
9250
  const aliasPath = imp.substring(2);
9251
9251
  resolvedFile = resolveImport(cwd, aliasPath, extensions, cwd) || resolveImport(join2(cwd, "src"), aliasPath, extensions, cwd) || resolveImport(join2(cwd, "app"), aliasPath, extensions, cwd);
9252
+ if (!resolvedFile) {
9253
+ const pathParts = currentFile.split(/[/\\]/);
9254
+ if (pathParts.length >= 2 && (pathParts[0] === "apps" || pathParts[0] === "packages")) {
9255
+ const projectRoot = join2(cwd, pathParts[0], pathParts[1]);
9256
+ resolvedFile = resolveImport(projectRoot, aliasPath, extensions, cwd) || resolveImport(join2(projectRoot, "src"), aliasPath, extensions, cwd) || resolveImport(join2(projectRoot, "app"), aliasPath, extensions, cwd);
9257
+ }
9258
+ }
9252
9259
  }
9253
9260
  if (resolvedFile && allFilesSet.has(resolvedFile)) {
9254
9261
  usedFiles.add(resolvedFile);
@@ -9494,17 +9501,34 @@ async function scanUnusedExports(config) {
9494
9501
  if (fileContent) {
9495
9502
  const lines = fileContent.split(`
9496
9503
  `);
9504
+ let fileInMultilineComment = false;
9505
+ let fileInTemplateLiteral = false;
9497
9506
  for (let i = 0;i < lines.length; i++) {
9498
9507
  if (i === exp.line - 1)
9499
9508
  continue;
9500
9509
  const line = lines[i];
9501
9510
  const trimmed = line.trim();
9502
- if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
9511
+ if (trimmed.includes("/*"))
9512
+ fileInMultilineComment = true;
9513
+ if (trimmed.includes("*/")) {
9514
+ fileInMultilineComment = false;
9515
+ continue;
9516
+ }
9517
+ if (fileInMultilineComment)
9503
9518
  continue;
9519
+ const backtickCount = (line.match(/`/g) || []).length;
9520
+ if (backtickCount % 2 !== 0) {
9521
+ fileInTemplateLiteral = !fileInTemplateLiteral;
9522
+ }
9523
+ if (fileInTemplateLiteral)
9524
+ continue;
9525
+ if (trimmed.startsWith("//"))
9526
+ continue;
9527
+ const lineWithoutStrings = line.replace(/'[^']*'/g, "''").replace(/"[^"]*"/g, '""');
9504
9528
  const referenceRegex = new RegExp(`\\b${exp.name}\\b`);
9505
- if (referenceRegex.test(line)) {
9506
- const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9507
- if (codePattern.test(line)) {
9529
+ if (referenceRegex.test(lineWithoutStrings)) {
9530
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;<>|&)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9531
+ if (codePattern.test(lineWithoutStrings)) {
9508
9532
  usedInternally = true;
9509
9533
  break;
9510
9534
  }
@@ -9530,7 +9554,8 @@ async function scanUnusedExports(config) {
9530
9554
  `);
9531
9555
  let inMultilineComment = false;
9532
9556
  let inTemplateLiteral = false;
9533
- for (const line of lines) {
9557
+ for (let lineIndex = 0;lineIndex < lines.length; lineIndex++) {
9558
+ const line = lines[lineIndex];
9534
9559
  const trimmed = line.trim();
9535
9560
  if (trimmed.includes("/*"))
9536
9561
  inMultilineComment = true;
@@ -9548,11 +9573,11 @@ async function scanUnusedExports(config) {
9548
9573
  continue;
9549
9574
  if (trimmed.startsWith("//"))
9550
9575
  continue;
9551
- if (trimmed.includes("{/*") || trimmed.includes("*/}"))
9552
- continue;
9553
- if (wordBoundaryPattern.test(line)) {
9554
- const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9555
- if (codePattern.test(line)) {
9576
+ const lineWithoutStrings = line.replace(/'[^']*'/g, "''").replace(/"[^"]*"/g, '""');
9577
+ if (wordBoundaryPattern.test(lineWithoutStrings)) {
9578
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;<>|&)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9579
+ const isMatch = codePattern.test(lineWithoutStrings);
9580
+ if (isMatch) {
9556
9581
  isUsed = true;
9557
9582
  break;
9558
9583
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [