pruny 1.15.0 → 1.15.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.
- package/dist/index.js +46 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10230,6 +10230,7 @@ program2.action(async (options) => {
|
|
|
10230
10230
|
`));
|
|
10231
10231
|
}
|
|
10232
10232
|
if (options.fix) {
|
|
10233
|
+
let fixedSomething = false;
|
|
10233
10234
|
if (unusedRoutes.length > 0) {
|
|
10234
10235
|
console.log(source_default.yellow.bold(`\uD83D\uDDD1️ Deleting unused routes...
|
|
10235
10236
|
`));
|
|
@@ -10238,10 +10239,15 @@ program2.action(async (options) => {
|
|
|
10238
10239
|
try {
|
|
10239
10240
|
rmSync(routeDir, { recursive: true, force: true });
|
|
10240
10241
|
console.log(source_default.red(` Deleted: ${route.filePath}`));
|
|
10242
|
+
fixedSomething = true;
|
|
10243
|
+
const idx = result.routes.indexOf(route);
|
|
10244
|
+
if (idx !== -1)
|
|
10245
|
+
result.routes.splice(idx, 1);
|
|
10241
10246
|
} catch (_err) {
|
|
10242
10247
|
console.log(source_default.yellow(` Failed to delete: ${route.filePath}`));
|
|
10243
10248
|
}
|
|
10244
10249
|
}
|
|
10250
|
+
console.log("");
|
|
10245
10251
|
}
|
|
10246
10252
|
const partiallyRoutes = result.routes.filter((r) => r.used && r.unusedMethods.length > 0);
|
|
10247
10253
|
if (partiallyRoutes.length > 0) {
|
|
@@ -10249,15 +10255,42 @@ program2.action(async (options) => {
|
|
|
10249
10255
|
`));
|
|
10250
10256
|
for (const route of partiallyRoutes) {
|
|
10251
10257
|
const sortedMethods = [...route.unusedMethods].filter((m) => route.methodLines[m] !== undefined).sort((a, b) => route.methodLines[b] - route.methodLines[a]);
|
|
10258
|
+
let fixedCount = 0;
|
|
10252
10259
|
for (const method of sortedMethods) {
|
|
10253
10260
|
const lineNum = route.methodLines[method];
|
|
10254
10261
|
if (removeMethodFromRoute(config.dir, route.filePath, method, lineNum)) {
|
|
10255
10262
|
console.log(source_default.green(` Fixed: Removed ${method} from ${route.path}`));
|
|
10263
|
+
fixedCount++;
|
|
10264
|
+
fixedSomething = true;
|
|
10256
10265
|
}
|
|
10257
10266
|
}
|
|
10267
|
+
if (fixedCount === route.methods.length) {
|
|
10268
|
+
const idx = result.routes.indexOf(route);
|
|
10269
|
+
if (idx !== -1)
|
|
10270
|
+
result.routes.splice(idx, 1);
|
|
10271
|
+
} else {
|
|
10272
|
+
route.unusedMethods = route.unusedMethods.filter((m) => !sortedMethods.includes(m));
|
|
10273
|
+
}
|
|
10258
10274
|
}
|
|
10259
10275
|
console.log("");
|
|
10260
10276
|
}
|
|
10277
|
+
if (result.unusedFiles && result.unusedFiles.files.length > 0) {
|
|
10278
|
+
console.log(source_default.yellow.bold(`\uD83D\uDDD1️ Deleting unused source files...
|
|
10279
|
+
`));
|
|
10280
|
+
for (const file of result.unusedFiles.files) {
|
|
10281
|
+
try {
|
|
10282
|
+
const fullPath = join8(config.dir, file.path);
|
|
10283
|
+
rmSync(fullPath, { force: true });
|
|
10284
|
+
console.log(source_default.red(` Deleted: ${file.path}`));
|
|
10285
|
+
fixedSomething = true;
|
|
10286
|
+
} catch (_err) {
|
|
10287
|
+
console.log(source_default.yellow(` Failed to delete: ${file.path}`));
|
|
10288
|
+
}
|
|
10289
|
+
}
|
|
10290
|
+
result.unusedFiles.files = [];
|
|
10291
|
+
result.unusedFiles.unused = 0;
|
|
10292
|
+
console.log("");
|
|
10293
|
+
}
|
|
10261
10294
|
if (result.unusedExports && result.unusedExports.exports.length > 0) {
|
|
10262
10295
|
console.log(source_default.yellow.bold(`\uD83D\uDD27 Fixing unused exports (removing "export" keyword)...
|
|
10263
10296
|
`));
|
|
@@ -10275,6 +10308,12 @@ program2.action(async (options) => {
|
|
|
10275
10308
|
if (removeExportFromLine(config.dir, exp)) {
|
|
10276
10309
|
console.log(source_default.green(` Fixed: ${exp.name} in ${exp.file}`));
|
|
10277
10310
|
fixedCount++;
|
|
10311
|
+
fixedSomething = true;
|
|
10312
|
+
const expIdx = result.unusedExports.exports.indexOf(exp);
|
|
10313
|
+
if (expIdx !== -1) {
|
|
10314
|
+
result.unusedExports.exports.splice(expIdx, 1);
|
|
10315
|
+
result.unusedExports.unused--;
|
|
10316
|
+
}
|
|
10278
10317
|
}
|
|
10279
10318
|
}
|
|
10280
10319
|
}
|
|
@@ -10284,8 +10323,13 @@ program2.action(async (options) => {
|
|
|
10284
10323
|
`));
|
|
10285
10324
|
}
|
|
10286
10325
|
}
|
|
10287
|
-
|
|
10288
|
-
|
|
10326
|
+
if (fixedSomething) {
|
|
10327
|
+
result.unused = result.routes.filter((r) => !r.used).length;
|
|
10328
|
+
result.used = result.routes.filter((r) => r.used).length;
|
|
10329
|
+
result.total = result.routes.length;
|
|
10330
|
+
}
|
|
10331
|
+
} else if (unusedRoutes.length > 0 || result.unusedExports && result.unusedExports.exports.length > 0 || result.unusedFiles && result.unusedFiles.files.length > 0) {
|
|
10332
|
+
console.log(source_default.dim(`\uD83D\uDCA1 Run with --fix to automatically clean up unused routes, files, and exports.
|
|
10289
10333
|
`));
|
|
10290
10334
|
}
|
|
10291
10335
|
console.log(source_default.bold(`\uD83D\uDCCA Summary Report
|