knip 0.11.2 → 0.12.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.
- package/README.md +1 -0
- package/dist/cli.js +15 -38
- package/dist/help.js +2 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.js +42 -49
- package/dist/log.js +2 -7
- package/dist/progress.d.ts +1 -1
- package/dist/progress.js +14 -19
- package/dist/reporters/codeowners.d.ts +1 -1
- package/dist/reporters/codeowners.js +11 -16
- package/dist/reporters/compact.d.ts +1 -1
- package/dist/reporters/compact.js +6 -8
- package/dist/reporters/constants.js +1 -4
- package/dist/reporters/index.d.ts +4 -4
- package/dist/reporters/index.js +9 -14
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.js +8 -13
- package/dist/reporters/symbols.d.ts +1 -1
- package/dist/reporters/symbols.js +6 -8
- package/dist/runner.d.ts +1 -1
- package/dist/runner.js +46 -54
- package/dist/types.js +1 -2
- package/dist/util/config.d.ts +1 -1
- package/dist/util/config.js +19 -16
- package/dist/util/debug.js +6 -15
- package/dist/util/dependencies.d.ts +2 -2
- package/dist/util/dependencies.js +15 -17
- package/dist/util/errors.js +1 -5
- package/dist/util/fs.d.ts +1 -0
- package/dist/util/fs.js +12 -17
- package/dist/util/glob.d.ts +1 -1
- package/dist/util/glob.js +8 -20
- package/dist/util/parseArgs.d.ts +24 -0
- package/dist/util/parseArgs.js +23 -0
- package/dist/util/path.js +2 -9
- package/dist/util/performance.d.ts +22 -0
- package/dist/util/performance.js +81 -0
- package/dist/util/project.d.ts +9 -3
- package/dist/util/project.js +16 -9
- package/dist/util/type.js +5 -9
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -91,6 +91,7 @@ Knip works by creating two sets of files:
|
|
|
91
91
|
--jsdoc Enable JSDoc parsing, with options: public
|
|
92
92
|
--debug Show debug output
|
|
93
93
|
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
94
|
+
--performance Measure running time of expensive functions and display stats table
|
|
94
95
|
|
|
95
96
|
Issue types: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
96
97
|
|
package/dist/cli.js
CHANGED
|
@@ -1,47 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const help_1 = require("./help");
|
|
11
|
-
const reporters_1 = __importDefault(require("./reporters"));
|
|
12
|
-
const errors_1 = require("./util/errors");
|
|
13
|
-
const { values: { help, dir, config: configFilePath, tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'include-entry-files': isIncludeEntryFiles = false, 'no-progress': noProgress = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = (0, node_util_1.parseArgs)({
|
|
14
|
-
options: {
|
|
15
|
-
help: { type: 'boolean' },
|
|
16
|
-
config: { type: 'string', short: 'c' },
|
|
17
|
-
tsConfig: { type: 'string', short: 't' },
|
|
18
|
-
dir: { type: 'string' },
|
|
19
|
-
include: { type: 'string', multiple: true },
|
|
20
|
-
exclude: { type: 'string', multiple: true },
|
|
21
|
-
ignore: { type: 'string', multiple: true },
|
|
22
|
-
'no-gitignore': { type: 'boolean' },
|
|
23
|
-
dev: { type: 'boolean' },
|
|
24
|
-
'include-entry-files': { type: 'boolean' },
|
|
25
|
-
'no-progress': { type: 'boolean' },
|
|
26
|
-
'max-issues': { type: 'string' },
|
|
27
|
-
reporter: { type: 'string' },
|
|
28
|
-
'reporter-options': { type: 'string' },
|
|
29
|
-
jsdoc: { type: 'string', multiple: true },
|
|
30
|
-
debug: { type: 'boolean' },
|
|
31
|
-
'debug-level': { type: 'string' },
|
|
32
|
-
},
|
|
33
|
-
});
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import parsedArgs from './util/parseArgs.js';
|
|
4
|
+
import { main } from './index.js';
|
|
5
|
+
import { printHelp } from './help.js';
|
|
6
|
+
import reporters from './reporters/index.js';
|
|
7
|
+
import { ConfigurationError } from './util/errors.js';
|
|
8
|
+
import { measure } from './util/performance.js';
|
|
9
|
+
const { values: { help, dir, config: configFilePath, tsConfig: tsConfigFilePath, include = [], exclude = [], ignore = [], 'no-gitignore': isNoGitIgnore = false, dev: isDev = false, 'include-entry-files': isIncludeEntryFiles = false, 'no-progress': noProgress = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', 'max-issues': maxIssues = '0', jsdoc: jsDoc = [], debug: isDebug = false, 'debug-level': debugLevel = '1', }, } = parsedArgs;
|
|
34
10
|
if (help) {
|
|
35
|
-
|
|
11
|
+
printHelp();
|
|
36
12
|
process.exit(0);
|
|
37
13
|
}
|
|
38
14
|
const cwd = process.cwd();
|
|
39
|
-
const workingDir = dir ?
|
|
15
|
+
const workingDir = dir ? path.resolve(dir) : cwd;
|
|
40
16
|
const isShowProgress = !isDebug && noProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
|
|
41
|
-
const printReport = reporter in
|
|
17
|
+
const printReport = reporter in reporters ? reporters[reporter] : await import(path.join(workingDir, reporter));
|
|
42
18
|
const run = async () => {
|
|
43
19
|
try {
|
|
44
|
-
const { report, issues, counters } = await
|
|
20
|
+
const { report, issues, counters } = await main({
|
|
45
21
|
cwd,
|
|
46
22
|
workingDir,
|
|
47
23
|
configFilePath,
|
|
@@ -63,13 +39,14 @@ const run = async () => {
|
|
|
63
39
|
const totalErrorCount = Object.keys(report)
|
|
64
40
|
.filter(reportGroup => report[reportGroup])
|
|
65
41
|
.reduce((errorCount, reportGroup) => errorCount + counters[reportGroup], 0);
|
|
42
|
+
await measure.print();
|
|
66
43
|
if (totalErrorCount > Number(maxIssues))
|
|
67
44
|
process.exit(totalErrorCount);
|
|
68
45
|
}
|
|
69
46
|
catch (error) {
|
|
70
|
-
if (error instanceof
|
|
47
|
+
if (error instanceof ConfigurationError) {
|
|
71
48
|
console.error(error.message + '\n');
|
|
72
|
-
|
|
49
|
+
printHelp();
|
|
73
50
|
process.exit(1);
|
|
74
51
|
}
|
|
75
52
|
throw error;
|
package/dist/help.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.printHelp = void 0;
|
|
4
|
-
const printHelp = () => {
|
|
1
|
+
export const printHelp = () => {
|
|
5
2
|
console.log(`knip [options]
|
|
6
3
|
|
|
7
4
|
Options:
|
|
@@ -21,6 +18,7 @@ Options:
|
|
|
21
18
|
--jsdoc Enable JSDoc parsing, with options: public
|
|
22
19
|
--debug Show debug output
|
|
23
20
|
--debug-level Set verbosity of debug output (default: 1, max: 2)
|
|
21
|
+
--performance Measure running time of expensive functions and display stats table
|
|
24
22
|
|
|
25
23
|
Issue types: files, dependencies, unlisted, exports, nsExports, types, nsTypes, duplicates
|
|
26
24
|
|
|
@@ -34,4 +32,3 @@ $ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
|
34
32
|
|
|
35
33
|
More info: https://github.com/webpro/knip`);
|
|
36
34
|
};
|
|
37
|
-
exports.printHelp = printHelp;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { UnresolvedConfiguration } from './types';
|
|
1
|
+
import type { UnresolvedConfiguration } from './types.js';
|
|
2
2
|
export declare const main: (unresolvedConfiguration: UnresolvedConfiguration) => Promise<{
|
|
3
|
-
report: import("./types").Report;
|
|
4
|
-
issues: import("./types").Issues;
|
|
5
|
-
counters: import("./types").Counters;
|
|
3
|
+
report: import("./types.js").Report;
|
|
4
|
+
issues: import("./types.js").Issues;
|
|
5
|
+
counters: import("./types.js").Counters;
|
|
6
6
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const project_1 = require("./util/project");
|
|
13
|
-
const runner_1 = require("./runner");
|
|
14
|
-
const errors_1 = require("./util/errors");
|
|
15
|
-
const debug_1 = require("./util/debug");
|
|
16
|
-
const progress_1 = require("./progress");
|
|
17
|
-
const main = async (unresolvedConfiguration) => {
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { resolveConfig, resolveIncludedIssueTypes } from './util/config.js';
|
|
3
|
+
import { findFile, loadJSON } from './util/fs.js';
|
|
4
|
+
import { relative } from './util/path.js';
|
|
5
|
+
import { _glob } from './util/glob.js';
|
|
6
|
+
import { _createProject, _resolveSourceFileDependencies, _removeExternalSourceFiles } from './util/project.js';
|
|
7
|
+
import { findIssues } from './runner.js';
|
|
8
|
+
import { ConfigurationError } from './util/errors.js';
|
|
9
|
+
import { debugLogObject, debugLogFiles, debugLogSourceFiles } from './util/debug.js';
|
|
10
|
+
import { getMessageUpdater } from './progress.js';
|
|
11
|
+
export const main = async (unresolvedConfiguration) => {
|
|
18
12
|
const { cwd, workingDir, configFilePath: configFilePathArg, tsConfigFilePath: tsConfigFilePathArg, include, exclude, ignore, gitignore, isIncludeEntryFiles, isDev, isShowProgress, jsDoc, debug, } = unresolvedConfiguration;
|
|
19
|
-
const updateMessage =
|
|
20
|
-
|
|
13
|
+
const updateMessage = getMessageUpdater(unresolvedConfiguration);
|
|
14
|
+
debugLogObject(debug, 1, 'Unresolved configuration', unresolvedConfiguration);
|
|
21
15
|
updateMessage('Reading configuration and manifest files...');
|
|
22
|
-
const manifestPath = await
|
|
23
|
-
const manifest = manifestPath &&
|
|
16
|
+
const manifestPath = await findFile(cwd, workingDir, 'package.json');
|
|
17
|
+
const manifest = manifestPath && (await loadJSON(manifestPath));
|
|
24
18
|
if (!manifestPath || !manifest) {
|
|
25
|
-
throw new
|
|
19
|
+
throw new ConfigurationError('Unable to find package.json');
|
|
26
20
|
}
|
|
27
21
|
const configFilePath = configFilePathArg ?? 'knip.json';
|
|
28
|
-
const resolvedConfigFilePath = await
|
|
29
|
-
const localConfig = resolvedConfigFilePath &&
|
|
22
|
+
const resolvedConfigFilePath = await findFile(cwd, workingDir, configFilePath);
|
|
23
|
+
const localConfig = resolvedConfigFilePath && (await loadJSON(resolvedConfigFilePath));
|
|
30
24
|
if (configFilePathArg && !resolvedConfigFilePath) {
|
|
31
|
-
throw new
|
|
25
|
+
throw new ConfigurationError(`Unable to find ${configFilePathArg}`);
|
|
32
26
|
}
|
|
33
27
|
const tsConfigFilePath = tsConfigFilePathArg ?? 'tsconfig.json';
|
|
34
|
-
const resolvedTsConfigFilePath = await
|
|
28
|
+
const resolvedTsConfigFilePath = await findFile(cwd, workingDir, tsConfigFilePath);
|
|
35
29
|
if (tsConfigFilePathArg && !resolvedTsConfigFilePath) {
|
|
36
|
-
throw new
|
|
30
|
+
throw new ConfigurationError(`Unable to find ${tsConfigFilePathArg}`);
|
|
37
31
|
}
|
|
38
32
|
let tsConfigPathGlobs = [];
|
|
39
33
|
if (resolvedTsConfigFilePath) {
|
|
40
|
-
const config =
|
|
34
|
+
const config = ts.readConfigFile(resolvedTsConfigFilePath, ts.sys.readFile);
|
|
41
35
|
tsConfigPathGlobs = config.config.compilerOptions?.paths
|
|
42
36
|
? Object.keys(config.config.compilerOptions.paths).map(p => p.replace(/\*/g, '**'))
|
|
43
37
|
: [];
|
|
44
38
|
if (config.error) {
|
|
45
|
-
throw new
|
|
39
|
+
throw new ConfigurationError(`Unable to read ${relative(resolvedTsConfigFilePath)}`);
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
|
-
const dir =
|
|
49
|
-
const resolvedConfig =
|
|
50
|
-
|
|
42
|
+
const dir = relative(workingDir);
|
|
43
|
+
const resolvedConfig = resolveConfig(manifest.knip ?? localConfig, { workingDir: dir, isDev });
|
|
44
|
+
debugLogObject(debug, 1, 'Resolved configuration', resolvedConfig);
|
|
51
45
|
if (!resolvedConfigFilePath && !manifest.knip && !resolvedTsConfigFilePath) {
|
|
52
|
-
throw new
|
|
46
|
+
throw new ConfigurationError(`Unable to find ${configFilePath} or package.json#knip or ${tsConfigFilePath}`);
|
|
53
47
|
}
|
|
54
48
|
const { entryFiles, productionFiles, projectFiles } = await (async () => {
|
|
55
49
|
if (resolvedConfig) {
|
|
@@ -58,42 +52,42 @@ const main = async (unresolvedConfiguration) => {
|
|
|
58
52
|
? { tsConfigFilePath: resolvedTsConfigFilePath }
|
|
59
53
|
: { compilerOptions: { allowJs: true } };
|
|
60
54
|
updateMessage('Resolving entry files...');
|
|
61
|
-
const entryPaths = await (
|
|
55
|
+
const entryPaths = await _glob({
|
|
62
56
|
cwd,
|
|
63
57
|
workingDir,
|
|
64
58
|
patterns: resolvedConfig.entryFiles,
|
|
65
59
|
ignore,
|
|
66
60
|
gitignore,
|
|
67
61
|
});
|
|
68
|
-
|
|
69
|
-
const production = (
|
|
62
|
+
debugLogFiles(debug, 1, 'Globbed entry paths', entryPaths);
|
|
63
|
+
const production = _createProject({ ...projectOptions, ...skipAddFiles }, entryPaths);
|
|
70
64
|
const entryFiles = production.getSourceFiles();
|
|
71
|
-
|
|
72
|
-
production
|
|
73
|
-
const productionFiles = (
|
|
74
|
-
|
|
65
|
+
debugLogSourceFiles(debug, 1, 'Resolved entry source files', entryFiles);
|
|
66
|
+
_resolveSourceFileDependencies(production);
|
|
67
|
+
const productionFiles = _removeExternalSourceFiles(production);
|
|
68
|
+
debugLogSourceFiles(debug, 1, 'Resolved production source files', productionFiles);
|
|
75
69
|
updateMessage('Resolving project files...');
|
|
76
|
-
const projectPaths = await (
|
|
70
|
+
const projectPaths = await _glob({
|
|
77
71
|
cwd,
|
|
78
72
|
workingDir,
|
|
79
73
|
patterns: resolvedConfig.projectFiles,
|
|
80
74
|
ignore,
|
|
81
75
|
gitignore,
|
|
82
76
|
});
|
|
83
|
-
|
|
84
|
-
const project = (
|
|
77
|
+
debugLogFiles(debug, 1, 'Globbed project paths', projectPaths);
|
|
78
|
+
const project = _createProject({ ...projectOptions, ...skipAddFiles }, projectPaths);
|
|
85
79
|
const projectFiles = project.getSourceFiles();
|
|
86
|
-
|
|
80
|
+
debugLogSourceFiles(debug, 1, 'Resolved project source files', projectFiles);
|
|
87
81
|
return { entryFiles, productionFiles, projectFiles };
|
|
88
82
|
}
|
|
89
83
|
else {
|
|
90
84
|
updateMessage('Resolving project files...');
|
|
91
|
-
const project = (
|
|
85
|
+
const project = _createProject({ tsConfigFilePath: resolvedTsConfigFilePath });
|
|
92
86
|
const files = project.getSourceFiles();
|
|
93
87
|
return { entryFiles: files, productionFiles: files, projectFiles: files };
|
|
94
88
|
}
|
|
95
89
|
})();
|
|
96
|
-
const report =
|
|
90
|
+
const report = resolveIncludedIssueTypes(include, resolvedConfig ? exclude : ['files'], resolvedConfig);
|
|
97
91
|
const config = {
|
|
98
92
|
workingDir,
|
|
99
93
|
report,
|
|
@@ -114,8 +108,7 @@ const main = async (unresolvedConfiguration) => {
|
|
|
114
108
|
},
|
|
115
109
|
debug,
|
|
116
110
|
};
|
|
117
|
-
const { issues, counters } = await
|
|
118
|
-
|
|
111
|
+
const { issues, counters } = await findIssues(config);
|
|
112
|
+
debugLogObject(debug, 2, 'Issues', issues);
|
|
119
113
|
return { report, issues, counters };
|
|
120
114
|
};
|
|
121
|
-
exports.main = main;
|
package/dist/log.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.LineRewriter = exports.getLine = void 0;
|
|
4
|
-
const getLine = (value, text) => `${String(value).padStart(5)} ${text}`;
|
|
5
|
-
exports.getLine = getLine;
|
|
6
|
-
class LineRewriter {
|
|
1
|
+
export const getLine = (value, text) => `${String(value).padStart(5)} ${text}`;
|
|
2
|
+
export class LineRewriter {
|
|
7
3
|
lines = 0;
|
|
8
4
|
clearLines(count) {
|
|
9
5
|
if (count > 0) {
|
|
@@ -23,4 +19,3 @@ class LineRewriter {
|
|
|
23
19
|
this.lines = messages.length;
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
exports.LineRewriter = LineRewriter;
|
package/dist/progress.d.ts
CHANGED
package/dist/progress.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const path_1 = require("./util/path");
|
|
6
|
-
const lineRewriter = new log_1.LineRewriter();
|
|
7
|
-
const getMessageUpdater = (configuration) => {
|
|
1
|
+
import { getLine, LineRewriter } from './log.js';
|
|
2
|
+
import { relative } from './util/path.js';
|
|
3
|
+
const lineRewriter = new LineRewriter();
|
|
4
|
+
export const getMessageUpdater = (configuration) => {
|
|
8
5
|
const { isShowProgress } = configuration;
|
|
9
6
|
if (!isShowProgress)
|
|
10
7
|
return () => { };
|
|
11
8
|
return (message) => lineRewriter.update([message]);
|
|
12
9
|
};
|
|
13
|
-
|
|
14
|
-
const getCountersUpdater = (configuration, counters) => {
|
|
10
|
+
export const getCountersUpdater = (configuration, counters) => {
|
|
15
11
|
const { isShowProgress, report } = configuration;
|
|
16
12
|
if (!isShowProgress)
|
|
17
13
|
return () => { };
|
|
@@ -20,19 +16,18 @@ const getCountersUpdater = (configuration, counters) => {
|
|
|
20
16
|
return lineRewriter.resetLines();
|
|
21
17
|
const { processed, total } = counters;
|
|
22
18
|
const percentage = Math.floor((processed / total) * 100);
|
|
23
|
-
const messages = [
|
|
24
|
-
report.files && messages.push(
|
|
25
|
-
report.unlisted && messages.push(
|
|
26
|
-
report.exports && messages.push(
|
|
27
|
-
report.nsExports && messages.push(
|
|
28
|
-
report.types && messages.push(
|
|
29
|
-
report.nsTypes && messages.push(
|
|
30
|
-
report.duplicates && messages.push(
|
|
19
|
+
const messages = [getLine(`${percentage}%`, `of files processed (${processed} of ${total})`)];
|
|
20
|
+
report.files && messages.push(getLine(counters.files, 'unused files'));
|
|
21
|
+
report.unlisted && messages.push(getLine(counters.unlisted, 'unlisted dependencies'));
|
|
22
|
+
report.exports && messages.push(getLine(counters.exports, 'unused exports'));
|
|
23
|
+
report.nsExports && messages.push(getLine(counters.nsExports, 'unused exports in namespace'));
|
|
24
|
+
report.types && messages.push(getLine(counters.types, 'unused types'));
|
|
25
|
+
report.nsTypes && messages.push(getLine(counters.nsTypes, 'unused types in namespace'));
|
|
26
|
+
report.duplicates && messages.push(getLine(counters.duplicates, 'duplicate exports'));
|
|
31
27
|
if (processed < total) {
|
|
32
28
|
messages.push('');
|
|
33
|
-
messages.push(`Processing: ${
|
|
29
|
+
messages.push(`Processing: ${relative(issue.filePath)}`);
|
|
34
30
|
}
|
|
35
31
|
lineRewriter.update(messages);
|
|
36
32
|
};
|
|
37
33
|
};
|
|
38
|
-
exports.getCountersUpdater = getCountersUpdater;
|
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const ownership_1 = require("@snyk/github-codeowners/dist/lib/ownership");
|
|
8
|
-
const path_1 = require("../util/path");
|
|
9
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { OwnershipEngine } from '@snyk/github-codeowners/dist/lib/ownership/index.js';
|
|
3
|
+
import { relative } from '../util/path.js';
|
|
4
|
+
import { ISSUE_TYPE_TITLE } from './constants.js';
|
|
10
5
|
const logIssueLine = (owner, filePath, symbols) => {
|
|
11
|
-
console.log(`${owner} ${
|
|
6
|
+
console.log(`${owner} ${relative(filePath)}${symbols ? `: ${symbols.join(', ')}` : ''}`);
|
|
12
7
|
};
|
|
13
8
|
const logIssueSet = (issues, title) => {
|
|
14
9
|
title && console.log(`--- ${title} (${issues.length})`);
|
|
15
10
|
if (issues.length) {
|
|
16
11
|
issues
|
|
17
12
|
.sort((a, b) => (a.owner < b.owner ? -1 : 1))
|
|
18
|
-
.forEach(issue => console.log(issue.owner, issue.symbol.startsWith('/') ?
|
|
13
|
+
.forEach(issue => console.log(issue.owner, issue.symbol.startsWith('/') ? relative(issue.symbol) : issue.symbol));
|
|
19
14
|
}
|
|
20
15
|
else {
|
|
21
16
|
console.log('Not found');
|
|
@@ -31,7 +26,7 @@ const logIssueRecord = (issues, title) => {
|
|
|
31
26
|
console.log('Not found');
|
|
32
27
|
}
|
|
33
28
|
};
|
|
34
|
-
|
|
29
|
+
export default ({ report, issues, options }) => {
|
|
35
30
|
let opts = {};
|
|
36
31
|
try {
|
|
37
32
|
opts = options ? JSON.parse(options) : opts;
|
|
@@ -39,16 +34,16 @@ exports.default = ({ report, issues, options }) => {
|
|
|
39
34
|
catch (error) {
|
|
40
35
|
console.error(error);
|
|
41
36
|
}
|
|
42
|
-
const codeownersFilePath =
|
|
43
|
-
const codeownersEngine =
|
|
37
|
+
const codeownersFilePath = path.resolve(opts.path ?? '.github/CODEOWNERS');
|
|
38
|
+
const codeownersEngine = OwnershipEngine.FromCodeownersFile(codeownersFilePath);
|
|
44
39
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
45
40
|
const [dependenciesOwner = '[no-owner]'] = codeownersEngine.calcFileOwnership('package.json');
|
|
46
41
|
const fallbackOwner = dependenciesOwner;
|
|
47
|
-
const calcFileOwnership = (filePath) => codeownersEngine.calcFileOwnership(
|
|
42
|
+
const calcFileOwnership = (filePath) => codeownersEngine.calcFileOwnership(relative(filePath))[0] ?? fallbackOwner;
|
|
48
43
|
const addOwner = (issue) => ({ ...issue, owner: calcFileOwnership(issue.filePath) });
|
|
49
44
|
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
50
45
|
if (isReportType) {
|
|
51
|
-
const title = reportMultipleGroups &&
|
|
46
|
+
const title = reportMultipleGroups && ISSUE_TYPE_TITLE[reportType];
|
|
52
47
|
if (issues[reportType] instanceof Set) {
|
|
53
48
|
const toIssue = (filePath) => ({ filePath, symbol: filePath });
|
|
54
49
|
const issuesForType = Array.from(issues[reportType]).map(toIssue);
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path_1 = require("../util/path");
|
|
4
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { relative } from '../util/path.js';
|
|
2
|
+
import { ISSUE_TYPE_TITLE } from './constants.js';
|
|
5
3
|
const logIssueLine = (filePath, symbols) => {
|
|
6
|
-
console.log(`${
|
|
4
|
+
console.log(`${relative(filePath)}${symbols ? `: ${symbols.join(', ')}` : ''}`);
|
|
7
5
|
};
|
|
8
6
|
const logIssueSet = (issues, title) => {
|
|
9
7
|
title && console.log(`--- ${title} (${issues.length})`);
|
|
10
8
|
if (issues.length) {
|
|
11
|
-
issues.sort().forEach(value => console.log(value.startsWith('/') ?
|
|
9
|
+
issues.sort().forEach(value => console.log(value.startsWith('/') ? relative(value) : value));
|
|
12
10
|
}
|
|
13
11
|
else {
|
|
14
12
|
console.log('Not found');
|
|
@@ -24,11 +22,11 @@ const logIssueRecord = (issues, title) => {
|
|
|
24
22
|
console.log('Not found');
|
|
25
23
|
}
|
|
26
24
|
};
|
|
27
|
-
|
|
25
|
+
export default ({ report, issues }) => {
|
|
28
26
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
29
27
|
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
30
28
|
if (isReportType) {
|
|
31
|
-
const title = reportMultipleGroups &&
|
|
29
|
+
const title = reportMultipleGroups && ISSUE_TYPE_TITLE[reportType];
|
|
32
30
|
if (issues[reportType] instanceof Set) {
|
|
33
31
|
logIssueSet(Array.from(issues[reportType]), title);
|
|
34
32
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ISSUE_TYPE_TITLE = void 0;
|
|
4
|
-
exports.ISSUE_TYPE_TITLE = {
|
|
1
|
+
export const ISSUE_TYPE_TITLE = {
|
|
5
2
|
files: 'UNUSED FILES',
|
|
6
3
|
dependencies: 'UNUSED DEPENDENCIES',
|
|
7
4
|
devDependencies: 'UNUSED DEV DEPENDENCIES',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
symbols: ({ report, issues }: import("../types").ReporterOptions) => void;
|
|
3
|
-
compact: ({ report, issues }: import("../types").ReporterOptions) => void;
|
|
4
|
-
codeowners: ({ report, issues, options }: import("../types").ReporterOptions) => void;
|
|
5
|
-
json: ({ report, issues, options }: import("../types").ReporterOptions) => Promise<void>;
|
|
2
|
+
symbols: ({ report, issues }: import("../types.js").ReporterOptions) => void;
|
|
3
|
+
compact: ({ report, issues }: import("../types.js").ReporterOptions) => void;
|
|
4
|
+
codeowners: ({ report, issues, options }: import("../types.js").ReporterOptions) => void;
|
|
5
|
+
json: ({ report, issues, options }: import("../types.js").ReporterOptions) => Promise<void>;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
package/dist/reporters/index.js
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.default = {
|
|
11
|
-
symbols: symbols_1.default,
|
|
12
|
-
compact: compact_1.default,
|
|
13
|
-
codeowners: codeowners_1.default,
|
|
14
|
-
json: json_1.default,
|
|
1
|
+
import symbols from './symbols.js';
|
|
2
|
+
import compact from './compact.js';
|
|
3
|
+
import codeowners from './codeowners.js';
|
|
4
|
+
import json from './json.js';
|
|
5
|
+
export default {
|
|
6
|
+
symbols,
|
|
7
|
+
compact,
|
|
8
|
+
codeowners,
|
|
9
|
+
json,
|
|
15
10
|
};
|
package/dist/reporters/json.d.ts
CHANGED
package/dist/reporters/json.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
7
|
-
const fs_1 = require("../util/fs");
|
|
8
|
-
const path_1 = require("../util/path");
|
|
9
|
-
const ownership_1 = require("@snyk/github-codeowners/dist/lib/ownership");
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { isFile } from '../util/fs.js';
|
|
3
|
+
import { relative } from '../util/path.js';
|
|
4
|
+
import { OwnershipEngine } from '@snyk/github-codeowners/dist/lib/ownership/index.js';
|
|
10
5
|
const mergeTypes = (type) => type === 'exports' || type === 'nsExports' ? 'exports' : type === 'types' || type === 'nsTypes' ? 'types' : type;
|
|
11
|
-
|
|
6
|
+
export default async ({ report, issues, options }) => {
|
|
12
7
|
let opts = {};
|
|
13
8
|
try {
|
|
14
9
|
opts = options ? JSON.parse(options) : opts;
|
|
@@ -17,11 +12,11 @@ exports.default = async ({ report, issues, options }) => {
|
|
|
17
12
|
console.error(error);
|
|
18
13
|
}
|
|
19
14
|
const json = {};
|
|
20
|
-
const codeownersFilePath =
|
|
21
|
-
const codeownersEngine = (await
|
|
15
|
+
const codeownersFilePath = path.resolve(opts.codeowners ?? '.github/CODEOWNERS');
|
|
16
|
+
const codeownersEngine = (await isFile(codeownersFilePath)) && OwnershipEngine.FromCodeownersFile(codeownersFilePath);
|
|
22
17
|
const flatten = (issues) => Object.values(issues).map(Object.values).flat();
|
|
23
18
|
const initRow = (filePath) => {
|
|
24
|
-
const file =
|
|
19
|
+
const file = relative(filePath);
|
|
25
20
|
const row = {
|
|
26
21
|
file,
|
|
27
22
|
...(codeownersEngine && { owners: codeownersEngine.calcFileOwnership(file) }),
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const path_1 = require("../util/path");
|
|
4
|
-
const constants_1 = require("./constants");
|
|
1
|
+
import { relative } from '../util/path.js';
|
|
2
|
+
import { ISSUE_TYPE_TITLE } from './constants.js';
|
|
5
3
|
const TRUNCATE_WIDTH = 40;
|
|
6
4
|
const logIssueLine = (issue, maxWidth) => {
|
|
7
5
|
const symbols = issue.symbols ? issue.symbols.join(', ') : issue.symbol;
|
|
8
6
|
const truncatedSymbol = symbols.length > maxWidth ? symbols.slice(0, maxWidth - 3) + '...' : symbols;
|
|
9
|
-
const filePath =
|
|
7
|
+
const filePath = relative(issue.filePath);
|
|
10
8
|
console.log(`${truncatedSymbol.padEnd(maxWidth + 2)}${issue.symbolType?.padEnd(11) || ''}${filePath}`);
|
|
11
9
|
};
|
|
12
10
|
const logIssueSet = (issues, title) => {
|
|
13
11
|
title && console.log(`--- ${title} (${issues.length})`);
|
|
14
12
|
if (issues.length) {
|
|
15
|
-
issues.sort().forEach(value => console.log(value.startsWith('/') ?
|
|
13
|
+
issues.sort().forEach(value => console.log(value.startsWith('/') ? relative(value) : value));
|
|
16
14
|
}
|
|
17
15
|
else {
|
|
18
16
|
console.log('Not found');
|
|
@@ -29,11 +27,11 @@ const logIssueRecord = (issues, title, isTruncate = false) => {
|
|
|
29
27
|
console.log('Not found');
|
|
30
28
|
}
|
|
31
29
|
};
|
|
32
|
-
|
|
30
|
+
export default ({ report, issues }) => {
|
|
33
31
|
const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
|
|
34
32
|
for (const [reportType, isReportType] of Object.entries(report)) {
|
|
35
33
|
if (isReportType) {
|
|
36
|
-
const title = reportMultipleGroups &&
|
|
34
|
+
const title = reportMultipleGroups && ISSUE_TYPE_TITLE[reportType];
|
|
37
35
|
if (issues[reportType] instanceof Set) {
|
|
38
36
|
logIssueSet(Array.from(issues[reportType]), title);
|
|
39
37
|
}
|
package/dist/runner.d.ts
CHANGED