deslop-js 0.0.2
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/LICENSE +21 -0
- package/dist/cli.cjs +141 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +142 -0
- package/dist/index.cjs +4953 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.mts +44 -0
- package/dist/index.mjs +4922 -0
- package/dist/src-BIp8ek0h.mjs +4922 -0
- package/dist/src-BuniDJsj.cjs +4970 -0
- package/dist/src-OVMbJnkL.mjs +4924 -0
- package/dist/src-wbNpmldQ.cjs +4968 -0
- package/package.json +64 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Million Software, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const require_src = require('./src-wbNpmldQ.cjs');
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
const HELP_TEXT = `
|
|
7
|
+
deslop - Dead code detector for TypeScript/JavaScript
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
deslop [options] [rootDir]
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--entry <pattern> Entry point glob pattern (can be repeated)
|
|
14
|
+
--ignore <pattern> Ignore glob pattern (can be repeated)
|
|
15
|
+
--tsconfig <path> Path to tsconfig.json
|
|
16
|
+
--include-types Include type-only exports in results
|
|
17
|
+
--include-entry-exports Include entry file exports in results
|
|
18
|
+
--json Output as JSON
|
|
19
|
+
--help Show this help message
|
|
20
|
+
--version Show version
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
deslop
|
|
24
|
+
deslop ./my-project
|
|
25
|
+
deslop --entry "src/main.ts" --ignore "**/*.test.ts"
|
|
26
|
+
deslop --json > results.json
|
|
27
|
+
`;
|
|
28
|
+
const parseArguments = (argv) => {
|
|
29
|
+
const entries = [];
|
|
30
|
+
const ignores = [];
|
|
31
|
+
let rootDir = ".";
|
|
32
|
+
let tsconfig;
|
|
33
|
+
let includeTypes = false;
|
|
34
|
+
let includeEntryExports = false;
|
|
35
|
+
let outputJson = false;
|
|
36
|
+
let showHelp = false;
|
|
37
|
+
let showVersion = false;
|
|
38
|
+
let argumentIndex = 0;
|
|
39
|
+
while (argumentIndex < argv.length) {
|
|
40
|
+
const argument = argv[argumentIndex];
|
|
41
|
+
if (argument === "--help" || argument === "-h") showHelp = true;
|
|
42
|
+
else if (argument === "--version" || argument === "-v") showVersion = true;
|
|
43
|
+
else if (argument === "--entry" || argument === "-e") {
|
|
44
|
+
argumentIndex++;
|
|
45
|
+
if (argumentIndex < argv.length) entries.push(argv[argumentIndex]);
|
|
46
|
+
} else if (argument === "--ignore" || argument === "-i") {
|
|
47
|
+
argumentIndex++;
|
|
48
|
+
if (argumentIndex < argv.length) ignores.push(argv[argumentIndex]);
|
|
49
|
+
} else if (argument === "--tsconfig") {
|
|
50
|
+
argumentIndex++;
|
|
51
|
+
if (argumentIndex < argv.length) tsconfig = argv[argumentIndex];
|
|
52
|
+
} else if (argument === "--include-types") includeTypes = true;
|
|
53
|
+
else if (argument === "--include-entry-exports") includeEntryExports = true;
|
|
54
|
+
else if (argument === "--json") outputJson = true;
|
|
55
|
+
else if (!argument.startsWith("-")) rootDir = argument;
|
|
56
|
+
argumentIndex++;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
rootDir,
|
|
60
|
+
entries,
|
|
61
|
+
ignores,
|
|
62
|
+
tsconfig,
|
|
63
|
+
includeTypes,
|
|
64
|
+
includeEntryExports,
|
|
65
|
+
outputJson,
|
|
66
|
+
showHelp,
|
|
67
|
+
showVersion
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const formatResults = (analysisResult, rootDir) => {
|
|
71
|
+
const outputLines = [];
|
|
72
|
+
outputLines.push(`\n deslop analysis complete\n`);
|
|
73
|
+
outputLines.push(` Scanned ${analysisResult.totalFiles} files with ${analysisResult.totalExports} exports in ${analysisResult.analysisTimeMs.toFixed(0)}ms\n`);
|
|
74
|
+
if (analysisResult.unusedFiles.length > 0) {
|
|
75
|
+
outputLines.push(` Unused files (${analysisResult.unusedFiles.length}):`);
|
|
76
|
+
for (const unusedFile of analysisResult.unusedFiles) outputLines.push(` ${(0, node_path.relative)(rootDir, unusedFile.path)}`);
|
|
77
|
+
outputLines.push("");
|
|
78
|
+
}
|
|
79
|
+
if (analysisResult.unusedExports.length > 0) {
|
|
80
|
+
outputLines.push(` Unused exports (${analysisResult.unusedExports.length}):`);
|
|
81
|
+
for (const unusedExport of analysisResult.unusedExports) {
|
|
82
|
+
const relativePath = (0, node_path.relative)(rootDir, unusedExport.path);
|
|
83
|
+
const typeLabel = unusedExport.isTypeOnly ? " (type)" : "";
|
|
84
|
+
outputLines.push(` ${relativePath}:${unusedExport.line} ${unusedExport.name}${typeLabel}`);
|
|
85
|
+
}
|
|
86
|
+
outputLines.push("");
|
|
87
|
+
}
|
|
88
|
+
if (analysisResult.unusedDependencies.length > 0) {
|
|
89
|
+
outputLines.push(` Unused dependencies (${analysisResult.unusedDependencies.length}):`);
|
|
90
|
+
for (const unusedDependency of analysisResult.unusedDependencies) {
|
|
91
|
+
const devLabel = unusedDependency.isDevDependency ? " (dev)" : "";
|
|
92
|
+
outputLines.push(` ${unusedDependency.name}${devLabel}`);
|
|
93
|
+
}
|
|
94
|
+
outputLines.push("");
|
|
95
|
+
}
|
|
96
|
+
if (analysisResult.circularDependencies.length > 0) {
|
|
97
|
+
outputLines.push(` Circular dependencies (${analysisResult.circularDependencies.length}):`);
|
|
98
|
+
for (const cycle of analysisResult.circularDependencies) {
|
|
99
|
+
const relativePaths = cycle.files.map((filePath) => (0, node_path.relative)(rootDir, filePath));
|
|
100
|
+
outputLines.push(` ${relativePaths.join(" → ")} → ${relativePaths[0]}`);
|
|
101
|
+
}
|
|
102
|
+
outputLines.push("");
|
|
103
|
+
}
|
|
104
|
+
const totalIssueCount = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length;
|
|
105
|
+
if (totalIssueCount === 0) outputLines.push(" No dead code found!\n");
|
|
106
|
+
else outputLines.push(` Total issues: ${totalIssueCount}\n`);
|
|
107
|
+
return outputLines.join("\n");
|
|
108
|
+
};
|
|
109
|
+
const main = async () => {
|
|
110
|
+
const cliArguments = parseArguments(process.argv.slice(2));
|
|
111
|
+
if (cliArguments.showHelp) {
|
|
112
|
+
process.stdout.write(HELP_TEXT);
|
|
113
|
+
process.exit(0);
|
|
114
|
+
}
|
|
115
|
+
if (cliArguments.showVersion) {
|
|
116
|
+
process.stdout.write("deslop 0.1.0\n");
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
const rootDir = (0, node_path.resolve)(cliArguments.rootDir);
|
|
120
|
+
const config = require_src.createConfig({
|
|
121
|
+
rootDir,
|
|
122
|
+
entryPatterns: cliArguments.entries.length > 0 ? cliArguments.entries : void 0,
|
|
123
|
+
ignorePatterns: cliArguments.ignores.length > 0 ? cliArguments.ignores : void 0,
|
|
124
|
+
tsConfigPath: cliArguments.tsconfig,
|
|
125
|
+
reportTypes: cliArguments.includeTypes,
|
|
126
|
+
includeEntryExports: cliArguments.includeEntryExports
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
const analysisResult = await require_src.analyze(config);
|
|
130
|
+
const outputContent = cliArguments.outputJson ? JSON.stringify(analysisResult, null, 2) + "\n" : formatResults(analysisResult, rootDir);
|
|
131
|
+
const exitCode = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length > 0 ? 1 : 0;
|
|
132
|
+
if (process.stdout.write(outputContent)) process.exit(exitCode);
|
|
133
|
+
else process.stdout.once("drain", () => process.exit(exitCode));
|
|
134
|
+
} catch (error) {
|
|
135
|
+
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
136
|
+
process.exit(2);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
main();
|
|
140
|
+
|
|
141
|
+
//#endregion
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as createConfig, t as analyze } from "./src-BIp8ek0h.mjs";
|
|
3
|
+
import { relative, resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
const HELP_TEXT = `
|
|
7
|
+
deslop - Dead code detector for TypeScript/JavaScript
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
deslop [options] [rootDir]
|
|
11
|
+
|
|
12
|
+
Options:
|
|
13
|
+
--entry <pattern> Entry point glob pattern (can be repeated)
|
|
14
|
+
--ignore <pattern> Ignore glob pattern (can be repeated)
|
|
15
|
+
--tsconfig <path> Path to tsconfig.json
|
|
16
|
+
--include-types Include type-only exports in results
|
|
17
|
+
--include-entry-exports Include entry file exports in results
|
|
18
|
+
--json Output as JSON
|
|
19
|
+
--help Show this help message
|
|
20
|
+
--version Show version
|
|
21
|
+
|
|
22
|
+
Examples:
|
|
23
|
+
deslop
|
|
24
|
+
deslop ./my-project
|
|
25
|
+
deslop --entry "src/main.ts" --ignore "**/*.test.ts"
|
|
26
|
+
deslop --json > results.json
|
|
27
|
+
`;
|
|
28
|
+
const parseArguments = (argv) => {
|
|
29
|
+
const entries = [];
|
|
30
|
+
const ignores = [];
|
|
31
|
+
let rootDir = ".";
|
|
32
|
+
let tsconfig;
|
|
33
|
+
let includeTypes = false;
|
|
34
|
+
let includeEntryExports = false;
|
|
35
|
+
let outputJson = false;
|
|
36
|
+
let showHelp = false;
|
|
37
|
+
let showVersion = false;
|
|
38
|
+
let argumentIndex = 0;
|
|
39
|
+
while (argumentIndex < argv.length) {
|
|
40
|
+
const argument = argv[argumentIndex];
|
|
41
|
+
if (argument === "--help" || argument === "-h") showHelp = true;
|
|
42
|
+
else if (argument === "--version" || argument === "-v") showVersion = true;
|
|
43
|
+
else if (argument === "--entry" || argument === "-e") {
|
|
44
|
+
argumentIndex++;
|
|
45
|
+
if (argumentIndex < argv.length) entries.push(argv[argumentIndex]);
|
|
46
|
+
} else if (argument === "--ignore" || argument === "-i") {
|
|
47
|
+
argumentIndex++;
|
|
48
|
+
if (argumentIndex < argv.length) ignores.push(argv[argumentIndex]);
|
|
49
|
+
} else if (argument === "--tsconfig") {
|
|
50
|
+
argumentIndex++;
|
|
51
|
+
if (argumentIndex < argv.length) tsconfig = argv[argumentIndex];
|
|
52
|
+
} else if (argument === "--include-types") includeTypes = true;
|
|
53
|
+
else if (argument === "--include-entry-exports") includeEntryExports = true;
|
|
54
|
+
else if (argument === "--json") outputJson = true;
|
|
55
|
+
else if (!argument.startsWith("-")) rootDir = argument;
|
|
56
|
+
argumentIndex++;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
rootDir,
|
|
60
|
+
entries,
|
|
61
|
+
ignores,
|
|
62
|
+
tsconfig,
|
|
63
|
+
includeTypes,
|
|
64
|
+
includeEntryExports,
|
|
65
|
+
outputJson,
|
|
66
|
+
showHelp,
|
|
67
|
+
showVersion
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const formatResults = (analysisResult, rootDir) => {
|
|
71
|
+
const outputLines = [];
|
|
72
|
+
outputLines.push(`\n deslop analysis complete\n`);
|
|
73
|
+
outputLines.push(` Scanned ${analysisResult.totalFiles} files with ${analysisResult.totalExports} exports in ${analysisResult.analysisTimeMs.toFixed(0)}ms\n`);
|
|
74
|
+
if (analysisResult.unusedFiles.length > 0) {
|
|
75
|
+
outputLines.push(` Unused files (${analysisResult.unusedFiles.length}):`);
|
|
76
|
+
for (const unusedFile of analysisResult.unusedFiles) outputLines.push(` ${relative(rootDir, unusedFile.path)}`);
|
|
77
|
+
outputLines.push("");
|
|
78
|
+
}
|
|
79
|
+
if (analysisResult.unusedExports.length > 0) {
|
|
80
|
+
outputLines.push(` Unused exports (${analysisResult.unusedExports.length}):`);
|
|
81
|
+
for (const unusedExport of analysisResult.unusedExports) {
|
|
82
|
+
const relativePath = relative(rootDir, unusedExport.path);
|
|
83
|
+
const typeLabel = unusedExport.isTypeOnly ? " (type)" : "";
|
|
84
|
+
outputLines.push(` ${relativePath}:${unusedExport.line} ${unusedExport.name}${typeLabel}`);
|
|
85
|
+
}
|
|
86
|
+
outputLines.push("");
|
|
87
|
+
}
|
|
88
|
+
if (analysisResult.unusedDependencies.length > 0) {
|
|
89
|
+
outputLines.push(` Unused dependencies (${analysisResult.unusedDependencies.length}):`);
|
|
90
|
+
for (const unusedDependency of analysisResult.unusedDependencies) {
|
|
91
|
+
const devLabel = unusedDependency.isDevDependency ? " (dev)" : "";
|
|
92
|
+
outputLines.push(` ${unusedDependency.name}${devLabel}`);
|
|
93
|
+
}
|
|
94
|
+
outputLines.push("");
|
|
95
|
+
}
|
|
96
|
+
if (analysisResult.circularDependencies.length > 0) {
|
|
97
|
+
outputLines.push(` Circular dependencies (${analysisResult.circularDependencies.length}):`);
|
|
98
|
+
for (const cycle of analysisResult.circularDependencies) {
|
|
99
|
+
const relativePaths = cycle.files.map((filePath) => relative(rootDir, filePath));
|
|
100
|
+
outputLines.push(` ${relativePaths.join(" → ")} → ${relativePaths[0]}`);
|
|
101
|
+
}
|
|
102
|
+
outputLines.push("");
|
|
103
|
+
}
|
|
104
|
+
const totalIssueCount = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length;
|
|
105
|
+
if (totalIssueCount === 0) outputLines.push(" No dead code found!\n");
|
|
106
|
+
else outputLines.push(` Total issues: ${totalIssueCount}\n`);
|
|
107
|
+
return outputLines.join("\n");
|
|
108
|
+
};
|
|
109
|
+
const main = async () => {
|
|
110
|
+
const cliArguments = parseArguments(process.argv.slice(2));
|
|
111
|
+
if (cliArguments.showHelp) {
|
|
112
|
+
process.stdout.write(HELP_TEXT);
|
|
113
|
+
process.exit(0);
|
|
114
|
+
}
|
|
115
|
+
if (cliArguments.showVersion) {
|
|
116
|
+
process.stdout.write("deslop 0.1.0\n");
|
|
117
|
+
process.exit(0);
|
|
118
|
+
}
|
|
119
|
+
const rootDir = resolve(cliArguments.rootDir);
|
|
120
|
+
const config = createConfig({
|
|
121
|
+
rootDir,
|
|
122
|
+
entryPatterns: cliArguments.entries.length > 0 ? cliArguments.entries : void 0,
|
|
123
|
+
ignorePatterns: cliArguments.ignores.length > 0 ? cliArguments.ignores : void 0,
|
|
124
|
+
tsConfigPath: cliArguments.tsconfig,
|
|
125
|
+
reportTypes: cliArguments.includeTypes,
|
|
126
|
+
includeEntryExports: cliArguments.includeEntryExports
|
|
127
|
+
});
|
|
128
|
+
try {
|
|
129
|
+
const analysisResult = await analyze(config);
|
|
130
|
+
const outputContent = cliArguments.outputJson ? JSON.stringify(analysisResult, null, 2) + "\n" : formatResults(analysisResult, rootDir);
|
|
131
|
+
const exitCode = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length > 0 ? 1 : 0;
|
|
132
|
+
if (process.stdout.write(outputContent)) process.exit(exitCode);
|
|
133
|
+
else process.stdout.once("drain", () => process.exit(exitCode));
|
|
134
|
+
} catch (error) {
|
|
135
|
+
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
136
|
+
process.exit(2);
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
main();
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
export { };
|