pruny 1.2.12 → 1.2.14
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.
- package/dist/index.js +58 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9698,8 +9698,17 @@ function loadConfig(options) {
|
|
|
9698
9698
|
extraRoutePatterns.push(...config.extraRoutePatterns);
|
|
9699
9699
|
if (config.excludePublic !== undefined)
|
|
9700
9700
|
excludePublic = config.excludePublic;
|
|
9701
|
+
if (config.excludePublic !== undefined)
|
|
9702
|
+
excludePublic = config.excludePublic;
|
|
9701
9703
|
} catch {}
|
|
9702
9704
|
}
|
|
9705
|
+
const gitIgnorePatterns = parseGitIgnore(cwd);
|
|
9706
|
+
if (gitIgnorePatterns.length > 0) {
|
|
9707
|
+
mergedIgnore.folders.push(...gitIgnorePatterns);
|
|
9708
|
+
}
|
|
9709
|
+
mergedIgnore.routes = [...new Set(mergedIgnore.routes)];
|
|
9710
|
+
mergedIgnore.folders = [...new Set(mergedIgnore.folders)];
|
|
9711
|
+
mergedIgnore.files = [...new Set(mergedIgnore.files)];
|
|
9703
9712
|
return {
|
|
9704
9713
|
dir: cwd,
|
|
9705
9714
|
ignore: mergedIgnore,
|
|
@@ -9709,6 +9718,18 @@ function loadConfig(options) {
|
|
|
9709
9718
|
extraRoutePatterns
|
|
9710
9719
|
};
|
|
9711
9720
|
}
|
|
9721
|
+
function parseGitIgnore(dir) {
|
|
9722
|
+
const gitIgnorePath = join5(dir, ".gitignore");
|
|
9723
|
+
if (!existsSync4(gitIgnorePath))
|
|
9724
|
+
return [];
|
|
9725
|
+
try {
|
|
9726
|
+
const content = readFileSync5(gitIgnorePath, "utf-8");
|
|
9727
|
+
return content.split(`
|
|
9728
|
+
`).map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
9729
|
+
} catch {
|
|
9730
|
+
return [];
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9712
9733
|
function findConfigFile(dir) {
|
|
9713
9734
|
const candidates = ["pruny.config.json", ".prunyrc.json", ".prunyrc"];
|
|
9714
9735
|
for (const name of candidates) {
|
|
@@ -9766,7 +9787,7 @@ function init(cwd = process.cwd()) {
|
|
|
9766
9787
|
|
|
9767
9788
|
// src/index.ts
|
|
9768
9789
|
var program2 = new Command;
|
|
9769
|
-
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");
|
|
9790
|
+
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").option("-f, --filter <pattern>", "Filter results by file path or app name");
|
|
9770
9791
|
program2.command("init").description("Create a default pruny.config.json file").action(() => {
|
|
9771
9792
|
init();
|
|
9772
9793
|
});
|
|
@@ -9779,16 +9800,48 @@ program2.action(async (options) => {
|
|
|
9779
9800
|
const absoluteDir = config.dir.startsWith("/") ? config.dir : join8(process.cwd(), config.dir);
|
|
9780
9801
|
config.dir = absoluteDir;
|
|
9781
9802
|
if (options.verbose) {
|
|
9782
|
-
console.log(source_default.dim(`
|
|
9783
|
-
Config:`));
|
|
9784
|
-
console.log(source_default.dim(JSON.stringify(config, null, 2)));
|
|
9785
9803
|
console.log("");
|
|
9786
9804
|
}
|
|
9787
9805
|
console.log(source_default.bold(`
|
|
9788
9806
|
\uD83D\uDD0D Scanning for unused API routes...
|
|
9789
9807
|
`));
|
|
9790
9808
|
try {
|
|
9791
|
-
|
|
9809
|
+
let result = await scan(config);
|
|
9810
|
+
if (options.filter) {
|
|
9811
|
+
const filter2 = options.filter.toLowerCase();
|
|
9812
|
+
console.log(source_default.blue(`
|
|
9813
|
+
\uD83D\uDD0D Filtering results by "${filter2}"...
|
|
9814
|
+
`));
|
|
9815
|
+
const getAppName2 = (filePath) => {
|
|
9816
|
+
if (filePath.startsWith("apps/"))
|
|
9817
|
+
return filePath.split("/").slice(0, 2).join("/");
|
|
9818
|
+
if (filePath.startsWith("packages/"))
|
|
9819
|
+
return filePath.split("/").slice(0, 2).join("/");
|
|
9820
|
+
return "Root";
|
|
9821
|
+
};
|
|
9822
|
+
const matchesFilter = (path2) => {
|
|
9823
|
+
return path2.toLowerCase().includes(filter2) || getAppName2(path2).toLowerCase().includes(filter2);
|
|
9824
|
+
};
|
|
9825
|
+
result.routes = result.routes.filter((r) => matchesFilter(r.filePath));
|
|
9826
|
+
if (result.publicAssets) {
|
|
9827
|
+
result.publicAssets.assets = result.publicAssets.assets.filter((a) => matchesFilter(a.path));
|
|
9828
|
+
result.publicAssets.total = result.publicAssets.assets.length;
|
|
9829
|
+
result.publicAssets.used = result.publicAssets.assets.filter((a) => a.used).length;
|
|
9830
|
+
result.publicAssets.unused = result.publicAssets.assets.filter((a) => !a.used).length;
|
|
9831
|
+
}
|
|
9832
|
+
if (result.unusedFiles) {
|
|
9833
|
+
result.unusedFiles.files = result.unusedFiles.files.filter((f) => matchesFilter(f.path));
|
|
9834
|
+
result.unusedFiles.total = result.unusedFiles.files.length;
|
|
9835
|
+
result.unusedFiles.used = 0;
|
|
9836
|
+
result.unusedFiles.unused = result.unusedFiles.files.length;
|
|
9837
|
+
}
|
|
9838
|
+
if (result.unusedExports) {
|
|
9839
|
+
result.unusedExports.exports = result.unusedExports.exports.filter((e) => matchesFilter(e.file));
|
|
9840
|
+
result.unusedExports.total = result.unusedExports.exports.length;
|
|
9841
|
+
result.unusedExports.used = 0;
|
|
9842
|
+
result.unusedExports.unused = result.unusedExports.exports.length;
|
|
9843
|
+
}
|
|
9844
|
+
}
|
|
9792
9845
|
if (options.json) {
|
|
9793
9846
|
console.log(JSON.stringify(result, null, 2));
|
|
9794
9847
|
return;
|