knip 2.19.5 → 2.20.0-preprocess.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 CHANGED
@@ -637,7 +637,8 @@ for false positives, and how to handle them.
637
637
  --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
638
638
  --include-entry-exports Include entry files when reporting unused exports
639
639
  -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
640
- --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
640
+ --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
641
+ --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
641
642
  --reporter-options Pass extra options to the reporter (as JSON string, see example)
642
643
  --no-config-hints Suppress configuration hints
643
644
  --no-exit-code Always exit with code zero (0)
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import './util/register.js';
3
3
  import prettyMilliseconds from 'pretty-ms';
4
- import reporters from './reporters/index.js';
4
+ import internalReporters from './reporters/index.js';
5
5
  import parsedArgValues, { helpText } from './util/cli-arguments.js';
6
6
  import { isKnownError, getKnownError, isConfigurationError, hasCause } from './util/errors.js';
7
7
  import { _load } from './util/loader.js';
@@ -9,7 +9,7 @@ import { cwd, resolve } from './util/path.js';
9
9
  import { Performance } from './util/Performance.js';
10
10
  import { version } from './version.js';
11
11
  import { main } from './index.js';
12
- const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'include-entry-exports': isIncludeEntryExports = false, performance: isObservePerf = false, production: isProduction = false, reporter = 'symbols', 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
12
+ const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'include-entry-exports': isIncludeEntryExports = false, performance: isObservePerf = false, production: isProduction = false, preprocessor = [], reporter = ['symbols'], 'reporter-options': reporterOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
13
13
  if (isHelp) {
14
14
  console.log(helpText);
15
15
  process.exit(0);
@@ -19,7 +19,13 @@ if (isVersion) {
19
19
  process.exit(0);
20
20
  }
21
21
  const isShowProgress = !isDebug && isNoProgress === false && process.stdout.isTTY && typeof process.stdout.cursorTo === 'function';
22
- const printReport = reporter in reporters ? reporters[reporter] : await _load(resolve(reporter));
22
+ const preprocessors = await Promise.all(preprocessor.map(processor => _load(resolve(processor))));
23
+ const processAsync = (data, processors) => processors.length === 0 ? Promise.resolve(data) : processAsync(processors[0](data), processors.slice(1));
24
+ const reporters = await Promise.all(reporter.map(async (reporter) => {
25
+ return reporter in internalReporters
26
+ ? internalReporters[reporter]
27
+ : await _load(resolve(reporter));
28
+ }));
23
29
  const run = async () => {
24
30
  try {
25
31
  const perfObserver = new Performance(isObservePerf);
@@ -32,7 +38,7 @@ const run = async () => {
32
38
  isShowProgress,
33
39
  isIncludeEntryExports,
34
40
  });
35
- await printReport({
41
+ const initialData = {
36
42
  report,
37
43
  issues,
38
44
  configurationHints,
@@ -41,7 +47,10 @@ const run = async () => {
41
47
  isProduction,
42
48
  isShowProgress,
43
49
  options: reporterOptions,
44
- });
50
+ };
51
+ const finalData = await processAsync(initialData, preprocessors);
52
+ for (const reporter of reporters)
53
+ await reporter(finalData);
45
54
  const totalErrorCount = Object.keys(report)
46
55
  .filter(reportGroup => report[reportGroup] && rules[reportGroup] === 'error')
47
56
  .reduce((errorCount, reportGroup) => errorCount + counters[reportGroup], 0);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { CommandLineOptions } from './types/cli.js';
2
2
  export type { RawConfiguration as KnipConfig } from './types/config.js';
3
- export type { Reporter, ReporterOptions } from './types/issues.js';
3
+ export type { Preprocessor, Reporter, ReporterOptions } from './types/issues.js';
4
4
  export declare const main: (unresolvedConfiguration: CommandLineOptions) => Promise<{
5
5
  report: import("./types/issues.js").Report;
6
6
  issues: import("./types/issues.js").Issues;
@@ -45,12 +45,12 @@ export type ReporterOptions = {
45
45
  configurationHints: ConfigurationHints;
46
46
  noConfigHints: boolean;
47
47
  cwd: string;
48
- workingDir: string;
49
48
  isProduction: boolean;
50
49
  isShowProgress: boolean;
51
50
  options: string;
52
51
  };
53
52
  export type Reporter = (options: ReporterOptions) => void;
53
+ export type Preprocessor = (options: ReporterOptions) => ReporterOptions;
54
54
  export type IssueSeverity = 'error' | 'warn' | 'off';
55
55
  export type Rules = Record<IssueType, IssueSeverity>;
56
56
  export type ConfigurationHints = Set<ConfigurationHint>;
@@ -1,4 +1,4 @@
1
- export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
1
+ export declare const helpText = "\u2702\uFE0F Find unused files, dependencies and exports in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -c, --config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n --production Analyze only production source files (e.g. no tests, devDependencies, exported types)\n --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n -d, --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
2
2
  declare const _default: {
3
3
  config: string | undefined;
4
4
  debug: boolean | undefined;
@@ -16,7 +16,8 @@ declare const _default: {
16
16
  'no-progress': boolean | undefined;
17
17
  performance: boolean | undefined;
18
18
  production: boolean | undefined;
19
- reporter: string | undefined;
19
+ preprocessor: string[] | undefined;
20
+ reporter: string[] | undefined;
20
21
  'reporter-options': string | undefined;
21
22
  strict: boolean | undefined;
22
23
  tsConfig: string | undefined;
@@ -16,7 +16,8 @@ Options:
16
16
  --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates
17
17
  --include-entry-exports Include entry files when reporting unused exports
18
18
  -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)
19
- --reporter Select reporter: symbols, compact, codeowners, json (default: symbols)
19
+ --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated
20
+ --reporter Select reporter: symbols, compact, codeowners, json, can be repeated (default: symbols)
20
21
  --reporter-options Pass extra options to the reporter (as JSON string, see example)
21
22
  --no-config-hints Suppress configuration hints
22
23
  --no-exit-code Always exit with code zero (0)
@@ -59,7 +60,8 @@ try {
59
60
  'no-progress': { type: 'boolean', short: 'n' },
60
61
  performance: { type: 'boolean' },
61
62
  production: { type: 'boolean' },
62
- reporter: { type: 'string' },
63
+ preprocessor: { type: 'string', multiple: true },
64
+ reporter: { type: 'string', multiple: true },
63
65
  'reporter-options': { type: 'string' },
64
66
  strict: { type: 'boolean' },
65
67
  tsConfig: { type: 'string', short: 't' },
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "2.19.5";
1
+ export declare const version = "2.20.0-preprocess.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '2.19.5';
1
+ export const version = '2.20.0-preprocess.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "2.19.5",
3
+ "version": "2.20.0-preprocess.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://github.com/webpro/knip",
6
6
  "repository": "github:webpro/knip",