knip 1.1.0 → 1.2.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 -1
- package/dist/configuration-chief.js +10 -9
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +6 -0
- package/dist/util/cli-arguments.d.ts +1 -1
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/loader.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ Use `npm run knip` to analyze the project and output unused files, dependencies
|
|
|
87
87
|
knip [options]
|
|
88
88
|
|
|
89
89
|
Options:
|
|
90
|
-
-c/--config [file] Configuration file path (default: knip.json, knip.
|
|
90
|
+
-c/--config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
|
|
91
91
|
-t/--tsConfig [file] TypeScript configuration path (default: tsconfig.json)
|
|
92
92
|
--production Analyze only production source files (e.g. no tests, devDependencies, exported types)
|
|
93
93
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
@@ -2,21 +2,18 @@ import path from 'node:path';
|
|
|
2
2
|
import mapWorkspaces from '@npmcli/map-workspaces';
|
|
3
3
|
import micromatch from 'micromatch';
|
|
4
4
|
import { ConfigurationValidator } from './configuration-validator.js';
|
|
5
|
-
import { ROOT_WORKSPACE_NAME } from './constants.js';
|
|
5
|
+
import { ROOT_WORKSPACE_NAME, DEFAULT_WORKSPACE_CONFIG, KNIP_CONFIG_LOCATIONS } from './constants.js';
|
|
6
6
|
import * as plugins from './plugins/index.js';
|
|
7
7
|
import { arrayify } from './util/array.js';
|
|
8
8
|
import parsedArgs from './util/cli-arguments.js';
|
|
9
9
|
import { ConfigurationError } from './util/errors.js';
|
|
10
10
|
import { findFile, loadJSON } from './util/fs.js';
|
|
11
11
|
import { ensurePosixPath } from './util/glob.js';
|
|
12
|
+
import { _load } from './util/loader.js';
|
|
12
13
|
import { resolveIncludedIssueTypes } from './util/resolve-included-issue-types.js';
|
|
13
14
|
import { byPathDepth } from './util/workspace.js';
|
|
14
15
|
const { values: { config: rawConfigArg, workspace: rawWorkspaceArg, include = [], exclude = [], dependencies = false, exports = false, }, } = parsedArgs;
|
|
15
|
-
const defaultWorkspaceConfig =
|
|
16
|
-
entry: ['index.{js,ts,tsx}!', 'src/index.{js,ts,tsx}!'],
|
|
17
|
-
project: ['**/*.{js,ts,tsx}!'],
|
|
18
|
-
ignore: [],
|
|
19
|
-
};
|
|
16
|
+
const defaultWorkspaceConfig = DEFAULT_WORKSPACE_CONFIG;
|
|
20
17
|
const defaultConfig = {
|
|
21
18
|
include: [],
|
|
22
19
|
exclude: [],
|
|
@@ -49,12 +46,16 @@ export default class ConfigurationChief {
|
|
|
49
46
|
}
|
|
50
47
|
this.manifestPath = manifestPath;
|
|
51
48
|
this.manifest = manifest;
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
let resolvedConfigFilePath;
|
|
50
|
+
for (const configPath of rawConfigArg ? [rawConfigArg] : KNIP_CONFIG_LOCATIONS) {
|
|
51
|
+
resolvedConfigFilePath = await findFile(this.cwd, configPath);
|
|
52
|
+
if (resolvedConfigFilePath)
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
54
55
|
if (rawConfigArg && !resolvedConfigFilePath && !manifest.knip) {
|
|
55
56
|
throw new ConfigurationError(`Unable to find ${rawConfigArg} or package.json#knip`);
|
|
56
57
|
}
|
|
57
|
-
const rawLocalConfig = resolvedConfigFilePath ? await
|
|
58
|
+
const rawLocalConfig = resolvedConfigFilePath ? await _load(resolvedConfigFilePath) : manifest.knip;
|
|
58
59
|
if (rawLocalConfig) {
|
|
59
60
|
this.config = this.normalize(ConfigurationValidator.parse(rawLocalConfig));
|
|
60
61
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { IssueType } from './types/issues.js';
|
|
2
2
|
export declare const ROOT_WORKSPACE_NAME = ".";
|
|
3
|
+
export declare const KNIP_CONFIG_LOCATIONS: string[];
|
|
4
|
+
export declare const DEFAULT_WORKSPACE_CONFIG: {
|
|
5
|
+
entry: string[];
|
|
6
|
+
project: string[];
|
|
7
|
+
ignore: never[];
|
|
8
|
+
};
|
|
3
9
|
export declare const TEST_FILE_PATTERNS: string[];
|
|
4
10
|
export declare const IGNORED_GLOBAL_BINARIES: string[];
|
|
5
11
|
export declare const IGNORE_DEFINITELY_TYPED: string[];
|
package/dist/constants.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
export const ROOT_WORKSPACE_NAME = '.';
|
|
2
|
+
export const KNIP_CONFIG_LOCATIONS = ['knip.json', 'knip.jsonc', '.knip.json', '.knip.jsonc', 'knip.ts', 'knip.js'];
|
|
3
|
+
export const DEFAULT_WORKSPACE_CONFIG = {
|
|
4
|
+
entry: ['index.{js,ts,tsx}!', 'src/index.{js,ts,tsx}!'],
|
|
5
|
+
project: ['**/*.{js,ts,tsx}!'],
|
|
6
|
+
ignore: [],
|
|
7
|
+
};
|
|
2
8
|
export const TEST_FILE_PATTERNS = ['**/*.{test,spec}.{js,jsx,ts,tsx}', '**/__tests__/**/*.{js,jsx,ts,tsx}'];
|
|
3
9
|
export const IGNORED_GLOBAL_BINARIES = ['npm', 'npx', 'node', 'yarn', 'pnpm', 'deno', 'git'];
|
|
4
10
|
export const IGNORE_DEFINITELY_TYPED = ['node'];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const helpText = "knip [options]\n\nOptions:\n -c/--config [file] Configuration file path (default: knip.json, knip.
|
|
1
|
+
export declare const helpText = "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 Analyze a single workspace (default: analyze all configured workspaces)\n --include-entry-exports Include unused exports in entry files (without `@public`)\n --ignore Ignore files matching this glob pattern, can be repeated\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\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --no-progress Don't show dynamic progress updates\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-exit-code Always exit with code zero (0)\n --max-issues Maximum number of issues before non-zero exit code (default: 0)\n --debug Show debug output\n --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure running time of expensive functions and display stats table\n\n(1) Issue types: files, dependencies, unlisted, 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 info: https://github.com/webpro/knip";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
values: {
|
|
4
4
|
config: string | undefined;
|
|
@@ -2,7 +2,7 @@ import { parseArgs } from 'node:util';
|
|
|
2
2
|
export const helpText = `knip [options]
|
|
3
3
|
|
|
4
4
|
Options:
|
|
5
|
-
-c/--config [file] Configuration file path (default: knip.json, knip.
|
|
5
|
+
-c/--config [file] Configuration file path (default: [.]knip.json[c], knip.js, knip.ts or package.json#knip)
|
|
6
6
|
-t/--tsConfig [file] TypeScript configuration path (default: tsconfig.json)
|
|
7
7
|
--production Analyze only production source files (e.g. no tests, devDependencies, exported types)
|
|
8
8
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
package/dist/util/loader.js
CHANGED
|
@@ -8,7 +8,7 @@ import { logIfDebug } from './log.js';
|
|
|
8
8
|
import { timerify } from './performance.js';
|
|
9
9
|
const load = async (filePath) => {
|
|
10
10
|
try {
|
|
11
|
-
if (
|
|
11
|
+
if (/\.jsonc?$/.test(filePath) || /rc$/.test(filePath)) {
|
|
12
12
|
return loadJSON(filePath);
|
|
13
13
|
}
|
|
14
14
|
if (path.extname(filePath) === '.yaml' || path.extname(filePath) === '.yml') {
|
package/package.json
CHANGED