knip 2.16.2 → 2.17.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/README.md +2 -2
- package/dist/binaries/resolvers/c8.js +3 -2
- package/dist/binaries/resolvers/dotenv.js +2 -2
- package/dist/binaries/resolvers/node.js +4 -1
- package/dist/binaries/util.d.ts +1 -0
- package/dist/binaries/util.js +1 -0
- package/dist/index.js +0 -2
- package/dist/plugins/svelte/index.js +1 -1
- package/dist/types/compilers.d.ts +2 -2
- package/dist/types/imports.d.ts +0 -1
- package/dist/typescript/SourceFileManager.js +2 -2
- package/dist/typescript/getImportsAndExports.d.ts +0 -1
- package/dist/typescript/getImportsAndExports.js +4 -7
- package/dist/util/cli-arguments.d.ts +1 -1
- package/dist/util/cli-arguments.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -152,8 +152,8 @@ Using workspaces in a monorepo? Please see [workspaces][1] for more details abou
|
|
|
152
152
|
-d, --debug Show debug output
|
|
153
153
|
--debug-file-filter Filter for files in debug output (regex as string)
|
|
154
154
|
--performance Measure count and running time of expensive functions and display stats table
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
-h, --help Print this help text
|
|
156
|
+
-V, --version Print version
|
|
157
157
|
|
|
158
158
|
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
|
|
159
159
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import parseArgs from 'minimist';
|
|
2
|
-
import { toBinary } from '../util.js';
|
|
2
|
+
import { toBinary, argsFrom } from '../util.js';
|
|
3
3
|
export const resolve = (binary, args, { fromArgs }) => {
|
|
4
4
|
const parsed = parseArgs(args, {
|
|
5
5
|
boolean: ['all', 'check-coverage', 'clean', 'exclude-after-remap', 'per-file', 'skip-full'],
|
|
6
6
|
});
|
|
7
7
|
parsed._ = parsed._.filter(a => a !== 'check-coverage');
|
|
8
|
-
|
|
8
|
+
const rest = argsFrom(args, parsed._[0]);
|
|
9
|
+
return [toBinary(binary), ...fromArgs(rest)];
|
|
9
10
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import parseArgs from 'minimist';
|
|
2
|
-
import { toBinary } from '../util.js';
|
|
2
|
+
import { toBinary, argsFrom } from '../util.js';
|
|
3
3
|
export const resolve = (binary, args, { fromArgs }) => {
|
|
4
4
|
const parsed = parseArgs(args);
|
|
5
|
-
return [toBinary(binary), ...fromArgs(parsed._)];
|
|
5
|
+
return [toBinary(binary), ...fromArgs(argsFrom(args, parsed._[0]))];
|
|
6
6
|
};
|
|
@@ -2,6 +2,9 @@ import parseArgs from 'minimist';
|
|
|
2
2
|
import { compact } from '../../util/array.js';
|
|
3
3
|
import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
|
|
4
4
|
export const resolve = (binary, args, { cwd }) => {
|
|
5
|
-
const parsed = parseArgs(args, {
|
|
5
|
+
const parsed = parseArgs(args, {
|
|
6
|
+
string: ['r'],
|
|
7
|
+
alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter'] },
|
|
8
|
+
});
|
|
6
9
|
return compact([tryResolveFilePath(cwd, parsed._[0]), ...tryResolveSpecifiers(cwd, [parsed.require].flat())]);
|
|
7
10
|
};
|
package/dist/binaries/util.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export declare const toBinary: (specifier: string) => string;
|
|
|
4
4
|
export declare const fromBinary: (specifier: string) => string;
|
|
5
5
|
export declare const isBinary: (specifier: string) => boolean;
|
|
6
6
|
export declare const stripBinaryPath: (command: string) => string;
|
|
7
|
+
export declare const argsFrom: (args: string[], from: string) => string[];
|
package/dist/binaries/util.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -202,8 +202,6 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
202
202
|
importedModule.isReExport = importItems.isReExport;
|
|
203
203
|
importedModule.isReExportedBy.add(filePath);
|
|
204
204
|
}
|
|
205
|
-
if (importItems.isDynamic)
|
|
206
|
-
importedModule.isDynamic = importItems.isDynamic;
|
|
207
205
|
if (importItems.isStar)
|
|
208
206
|
importedModule.isStar = importItems.isStar;
|
|
209
207
|
}
|
|
@@ -4,6 +4,6 @@ export const ENABLERS = ['svelte'];
|
|
|
4
4
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
5
5
|
export const ENTRY_FILE_PATTERNS = ['svelte.config.js', 'vite.config.ts'];
|
|
6
6
|
export const PRODUCTION_ENTRY_FILE_PATTERNS = [
|
|
7
|
-
'src/routes/**/+{page,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
|
|
7
|
+
'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
|
|
8
8
|
];
|
|
9
9
|
export const PROJECT_FILE_PATTERNS = ['src/**/*.{js,ts,svelte}'];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type FileExtension = string;
|
|
2
|
-
export type SyncCompilerFn = (source: string) => string;
|
|
3
|
-
export type AsyncCompilerFn = (source: string) => Promise<string>;
|
|
2
|
+
export type SyncCompilerFn = (source: string, path: string) => string;
|
|
3
|
+
export type AsyncCompilerFn = (source: string, path: string) => Promise<string>;
|
|
4
4
|
export type SyncCompilers = Map<FileExtension, SyncCompilerFn>;
|
|
5
5
|
export type AsyncCompilers = Map<FileExtension, AsyncCompilerFn>;
|
|
6
6
|
export {};
|
package/dist/types/imports.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export class SourceFileManager {
|
|
|
23
23
|
throw new Error(`Unable to read ${filePath}`);
|
|
24
24
|
const ext = extname(filePath);
|
|
25
25
|
const compiler = this.syncCompilers?.get(ext);
|
|
26
|
-
const compiled = compiler ? compiler(contents) : contents;
|
|
26
|
+
const compiled = compiler ? compiler(contents, filePath) : contents;
|
|
27
27
|
if (compiler)
|
|
28
28
|
debugLog(`Compiled ${filePath}`);
|
|
29
29
|
return this.createSourceFile(filePath, compiled);
|
|
@@ -45,7 +45,7 @@ export class SourceFileManager {
|
|
|
45
45
|
const ext = extname(filePath);
|
|
46
46
|
const compiler = this.asyncCompilers?.get(ext);
|
|
47
47
|
if (compiler) {
|
|
48
|
-
const compiled = await compiler(contents);
|
|
48
|
+
const compiled = await compiler(contents, filePath);
|
|
49
49
|
debugLog(`Compiled ${filePath}`);
|
|
50
50
|
this.createSourceFile(filePath, compiled);
|
|
51
51
|
}
|
|
@@ -22,7 +22,7 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
22
22
|
const importedInternalSymbols = new Map();
|
|
23
23
|
const visitors = getVisitors(sourceFile);
|
|
24
24
|
const addInternalImport = (options) => {
|
|
25
|
-
const { identifier, specifier, symbol, filePath,
|
|
25
|
+
const { identifier, specifier, symbol, filePath, isReExport } = options;
|
|
26
26
|
const isStar = identifier === '*';
|
|
27
27
|
const internalImport = getOrSet(internalImports, filePath, {
|
|
28
28
|
specifier,
|
|
@@ -30,7 +30,6 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
30
30
|
isReExport,
|
|
31
31
|
isReExportedBy: new Set(),
|
|
32
32
|
symbols: new Set(),
|
|
33
|
-
isDynamic,
|
|
34
33
|
});
|
|
35
34
|
if (isReExport) {
|
|
36
35
|
internalImport.isReExport = isReExport;
|
|
@@ -42,11 +41,9 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
42
41
|
internalImport.symbols.add(identifier);
|
|
43
42
|
if (isStar && symbol)
|
|
44
43
|
importedInternalSymbols.set(symbol, filePath);
|
|
45
|
-
if (isDynamic)
|
|
46
|
-
internalImport.isDynamic = isDynamic;
|
|
47
44
|
};
|
|
48
45
|
const addImport = (options) => {
|
|
49
|
-
const { specifier, symbol, identifier = '__anonymous',
|
|
46
|
+
const { specifier, symbol, identifier = '__anonymous', isReExport = false } = options;
|
|
50
47
|
if (isBuiltin(specifier))
|
|
51
48
|
return;
|
|
52
49
|
const module = sourceFile.resolvedModules?.get(specifier, undefined);
|
|
@@ -55,7 +52,7 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
55
52
|
if (filePath) {
|
|
56
53
|
if (module.resolvedModule.isExternalLibraryImport) {
|
|
57
54
|
if (!isInNodeModules(filePath)) {
|
|
58
|
-
addInternalImport({ identifier, specifier, symbol, filePath,
|
|
55
|
+
addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
|
|
59
56
|
}
|
|
60
57
|
if (!isMaybePackageName(specifier))
|
|
61
58
|
return;
|
|
@@ -67,7 +64,7 @@ export const getImportsAndExports = (sourceFile, options) => {
|
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
else {
|
|
70
|
-
addInternalImport({ identifier, specifier, symbol, filePath,
|
|
67
|
+
addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
}
|
|
@@ -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 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\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
|
|
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 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\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";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
config: string | undefined;
|
|
4
4
|
debug: boolean | undefined;
|
|
@@ -24,8 +24,8 @@ Options:
|
|
|
24
24
|
-d, --debug Show debug output
|
|
25
25
|
--debug-file-filter Filter for files in debug output (regex as string)
|
|
26
26
|
--performance Measure count and running time of expensive functions and display stats table
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
-h, --help Print this help text
|
|
28
|
+
-V, --version Print version
|
|
29
29
|
|
|
30
30
|
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates
|
|
31
31
|
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "2.
|
|
1
|
+
export declare const version = "2.17.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.17.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.1",
|
|
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",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"format": "prettier scripts src tests schema.json --with-node-modules --write --config .prettierrc",
|
|
25
25
|
"pretest": "node rmdir.js tmp && swc src -d tmp/src && swc tests -d tmp/tests",
|
|
26
26
|
"test": "node --no-warnings --test tmp",
|
|
27
|
-
"coverage": "c8
|
|
27
|
+
"coverage": "c8 --reporter html node --no-warnings --loader tsx --test tests/*.test.ts tests/*/*.test.ts",
|
|
28
28
|
"watch": "tsc --watch",
|
|
29
29
|
"prebuild": "node rmdir.js dist",
|
|
30
30
|
"build": "tsc",
|