pruny 1.2.6 → 1.2.8

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 +47 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7632,7 +7632,7 @@ var source_default = chalk;
7632
7632
 
7633
7633
  // src/index.ts
7634
7634
  import { rmSync } from "node:fs";
7635
- import { dirname as dirname2, join as join6 } from "node:path";
7635
+ import { dirname as dirname2, join as join7 } from "node:path";
7636
7636
 
7637
7637
  // src/scanner.ts
7638
7638
  var import_fast_glob4 = __toESM(require_out4(), 1);
@@ -9633,6 +9633,32 @@ function findConfigFile(dir) {
9633
9633
  return null;
9634
9634
  }
9635
9635
 
9636
+ // src/fixer.ts
9637
+ import { readFileSync as readFileSync6, writeFileSync } from "node:fs";
9638
+ import { join as join6 } from "node:path";
9639
+ function removeExportFromLine(rootDir, exp) {
9640
+ const fullPath = join6(rootDir, exp.file);
9641
+ try {
9642
+ const content = readFileSync6(fullPath, "utf-8");
9643
+ const lines = content.split(`
9644
+ `);
9645
+ const lineIndex = exp.line - 1;
9646
+ const originalLine = lines[lineIndex];
9647
+ const exportPrefixRegex = /^(export\s+(?:async\s+)?)/;
9648
+ if (exportPrefixRegex.test(originalLine.trim())) {
9649
+ const newLine = originalLine.replace(/(\s*)export\s+/, "$1");
9650
+ lines[lineIndex] = newLine;
9651
+ writeFileSync(fullPath, lines.join(`
9652
+ `), "utf-8");
9653
+ return true;
9654
+ }
9655
+ return false;
9656
+ } catch (err) {
9657
+ console.error(`Error fixing export in ${exp.file}:`, err);
9658
+ return false;
9659
+ }
9660
+ }
9661
+
9636
9662
  // src/index.ts
9637
9663
  var program2 = new Command;
9638
9664
  program2.name("pruny").description("Find and remove unused Next.js API routes").version("1.0.0").option("-d, --dir <path>", "Target directory to scan", "./").option("--fix", "Delete unused API routes").option("-c, --config <path>", "Path to config file").option("--json", "Output as JSON").option("--no-public", "Disable public assets scanning").option("-v, --verbose", "Show detailed info").action(async (options) => {
@@ -9641,7 +9667,7 @@ program2.name("pruny").description("Find and remove unused Next.js API routes").
9641
9667
  config: options.config,
9642
9668
  excludePublic: !options.public
9643
9669
  });
9644
- const absoluteDir = config.dir.startsWith("/") ? config.dir : join6(process.cwd(), config.dir);
9670
+ const absoluteDir = config.dir.startsWith("/") ? config.dir : join7(process.cwd(), config.dir);
9645
9671
  config.dir = absoluteDir;
9646
9672
  if (options.verbose) {
9647
9673
  console.log(source_default.dim(`
@@ -9735,7 +9761,7 @@ Config:`));
9735
9761
  Unused: result.unusedFiles.unused
9736
9762
  });
9737
9763
  }
9738
- if (result.unusedExports && result.unusedExports.exports.length > 0) {
9764
+ if (result.unusedExports) {
9739
9765
  summary.push({
9740
9766
  Category: "Exported Items",
9741
9767
  Total: result.unusedExports.total,
@@ -9769,7 +9795,7 @@ Config:`));
9769
9795
  console.log(source_default.yellow.bold(`\uD83D\uDDD1️ Deleting unused routes...
9770
9796
  `));
9771
9797
  for (const route of unusedRoutes) {
9772
- const routeDir = dirname2(join6(config.dir, route.filePath));
9798
+ const routeDir = dirname2(join7(config.dir, route.filePath));
9773
9799
  try {
9774
9800
  rmSync(routeDir, { recursive: true, force: true });
9775
9801
  console.log(source_default.red(` Deleted: ${route.filePath}`));
@@ -9777,12 +9803,25 @@ Config:`));
9777
9803
  console.log(source_default.yellow(` Failed to delete: ${route.filePath}`));
9778
9804
  }
9779
9805
  }
9780
- console.log(source_default.green(`
9781
- Deleted ${unusedRoutes.length} unused route(s).
9806
+ }
9807
+ if (result.unusedExports && result.unusedExports.exports.length > 0) {
9808
+ console.log(source_default.yellow.bold(`\uD83D\uDD27 Fixing unused exports (removing "export" keyword)...
9782
9809
  `));
9810
+ let fixedCount = 0;
9811
+ for (const exp of result.unusedExports.exports) {
9812
+ if (removeExportFromLine(config.dir, exp)) {
9813
+ console.log(source_default.green(` Fixed: ${exp.name} in ${exp.file}`));
9814
+ fixedCount++;
9815
+ }
9816
+ }
9817
+ if (fixedCount > 0) {
9818
+ console.log(source_default.green(`
9819
+ ✅ Removed "export" from ${fixedCount} item(s).
9820
+ `));
9821
+ }
9783
9822
  }
9784
- } else if (unusedRoutes.length > 0) {
9785
- console.log(source_default.dim(`\uD83D\uDCA1 Run with --fix to delete unused routes.
9823
+ } else if (unusedRoutes.length > 0 || result.unusedExports && result.unusedExports.exports.length > 0) {
9824
+ console.log(source_default.dim(`\uD83D\uDCA1 Run with --fix to automatically clean up unused routes and exports.
9786
9825
  `));
9787
9826
  }
9788
9827
  } catch (_err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pruny",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "Find and remove unused Next.js API routes",
5
5
  "type": "module",
6
6
  "files": [