pruny 1.10.0 → 1.11.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 +52 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9204,19 +9204,27 @@ async function scanUnusedFiles(config) {
9204
9204
  "**/loading.{ts,tsx,js,jsx}",
9205
9205
  "**/error.{ts,tsx,js,jsx}",
9206
9206
  "**/not-found.{ts,tsx,js,jsx}",
9207
+ "**/template.{ts,tsx,js,jsx}",
9208
+ "**/default.{ts,tsx,js,jsx}",
9207
9209
  "**/middleware.{ts,js}",
9208
9210
  "**/proxy.{ts,js}",
9209
9211
  "**/instrumentation.{ts,js}",
9210
- "next.config.{js,mjs,ts}",
9211
- "tailwind.config.{js,ts}",
9212
- "postcss.config.{js,ts}",
9213
- "app/robots.{ts,js}",
9214
- "app/sitemap.{ts,js}",
9215
- "next-sitemap.config.js",
9216
- "cypress.config.ts",
9217
- "env.d.ts",
9218
- "next-env.d.ts",
9212
+ "**/next.config.{js,mjs,ts}",
9213
+ "**/tailwind.config.{js,ts,mjs,cjs}",
9214
+ "**/postcss.config.{js,ts,mjs,cjs}",
9215
+ "**/robots.{ts,js}",
9216
+ "**/sitemap.{ts,js}",
9217
+ "**/manifest.{ts,js}",
9218
+ "**/icon.{ts,tsx,js,jsx}",
9219
+ "**/apple-icon.{ts,tsx,js,jsx}",
9220
+ "**/opengraph-image.{ts,tsx,js,jsx}",
9221
+ "**/twitter-image.{ts,tsx,js,jsx}",
9222
+ "**/next-sitemap.config.js",
9223
+ "**/cypress.config.ts",
9224
+ "**/env.d.ts",
9225
+ "**/next-env.d.ts",
9219
9226
  "**/*.d.ts",
9227
+ "**/*.config.{js,ts,mjs,cjs}",
9220
9228
  "scripts/**/*.{ts,js}",
9221
9229
  "cypress/**/*.{ts,js,tsx}",
9222
9230
  "public/sw.js"
@@ -9249,6 +9257,13 @@ async function scanUnusedFiles(config) {
9249
9257
  } else if (imp.startsWith("@/") || imp.startsWith("~/")) {
9250
9258
  const aliasPath = imp.substring(2);
9251
9259
  resolvedFile = resolveImport(cwd, aliasPath, extensions, cwd) || resolveImport(join2(cwd, "src"), aliasPath, extensions, cwd) || resolveImport(join2(cwd, "app"), aliasPath, extensions, cwd);
9260
+ if (!resolvedFile) {
9261
+ const pathParts = currentFile.split(/[/\\]/);
9262
+ if (pathParts.length >= 2 && (pathParts[0] === "apps" || pathParts[0] === "packages")) {
9263
+ const projectRoot = join2(cwd, pathParts[0], pathParts[1]);
9264
+ resolvedFile = resolveImport(projectRoot, aliasPath, extensions, cwd) || resolveImport(join2(projectRoot, "src"), aliasPath, extensions, cwd) || resolveImport(join2(projectRoot, "app"), aliasPath, extensions, cwd);
9265
+ }
9266
+ }
9252
9267
  }
9253
9268
  if (resolvedFile && allFilesSet.has(resolvedFile)) {
9254
9269
  usedFiles.add(resolvedFile);
@@ -9494,17 +9509,34 @@ async function scanUnusedExports(config) {
9494
9509
  if (fileContent) {
9495
9510
  const lines = fileContent.split(`
9496
9511
  `);
9512
+ let fileInMultilineComment = false;
9513
+ let fileInTemplateLiteral = false;
9497
9514
  for (let i = 0;i < lines.length; i++) {
9498
9515
  if (i === exp.line - 1)
9499
9516
  continue;
9500
9517
  const line = lines[i];
9501
9518
  const trimmed = line.trim();
9502
- if (trimmed.startsWith("//") || trimmed.startsWith("/*") || trimmed.startsWith("*"))
9519
+ if (trimmed.includes("/*"))
9520
+ fileInMultilineComment = true;
9521
+ if (trimmed.includes("*/")) {
9522
+ fileInMultilineComment = false;
9523
+ continue;
9524
+ }
9525
+ if (fileInMultilineComment)
9503
9526
  continue;
9527
+ const backtickCount = (line.match(/`/g) || []).length;
9528
+ if (backtickCount % 2 !== 0) {
9529
+ fileInTemplateLiteral = !fileInTemplateLiteral;
9530
+ }
9531
+ if (fileInTemplateLiteral)
9532
+ continue;
9533
+ if (trimmed.startsWith("//"))
9534
+ continue;
9535
+ const lineWithoutStrings = line.replace(/'[^']*'/g, "''").replace(/"[^"]*"/g, '""');
9504
9536
  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)) {
9537
+ if (referenceRegex.test(lineWithoutStrings)) {
9538
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;<>|&)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9539
+ if (codePattern.test(lineWithoutStrings)) {
9508
9540
  usedInternally = true;
9509
9541
  break;
9510
9542
  }
@@ -9530,7 +9562,8 @@ async function scanUnusedExports(config) {
9530
9562
  `);
9531
9563
  let inMultilineComment = false;
9532
9564
  let inTemplateLiteral = false;
9533
- for (const line of lines) {
9565
+ for (let lineIndex = 0;lineIndex < lines.length; lineIndex++) {
9566
+ const line = lines[lineIndex];
9534
9567
  const trimmed = line.trim();
9535
9568
  if (trimmed.includes("/*"))
9536
9569
  inMultilineComment = true;
@@ -9548,11 +9581,11 @@ async function scanUnusedExports(config) {
9548
9581
  continue;
9549
9582
  if (trimmed.startsWith("//"))
9550
9583
  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)) {
9584
+ const lineWithoutStrings = line.replace(/'[^']*'/g, "''").replace(/"[^"]*"/g, '""');
9585
+ if (wordBoundaryPattern.test(lineWithoutStrings)) {
9586
+ const codePattern = new RegExp(`\\b${exp.name}\\s*[({.,;<>|&)]|\\b${exp.name}\\s*\\)|\\s+${exp.name}\\b`);
9587
+ const isMatch = codePattern.test(lineWithoutStrings);
9588
+ if (isMatch) {
9556
9589
  isUsed = true;
9557
9590
  break;
9558
9591
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Find and remove unused Next.js API routes & Nest.js Controllers",
5
5
  "type": "module",
6
6
  "files": [