knip 5.9.0 → 5.9.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/dist/ConfigurationChief.d.ts +6 -6
- package/dist/ConfigurationChief.js +10 -8
- package/dist/ConsoleStreamer.js +1 -1
- package/dist/DependencyDeputy.d.ts +1 -1
- package/dist/DependencyDeputy.js +22 -18
- package/dist/IssueCollector.js +10 -9
- package/dist/IssueFixer.js +9 -7
- package/dist/PrincipalFactory.d.ts +2 -2
- package/dist/PrincipalFactory.js +3 -5
- package/dist/ProjectPrincipal.d.ts +6 -6
- package/dist/ProjectPrincipal.js +12 -10
- package/dist/WorkspaceWorker.d.ts +2 -2
- package/dist/WorkspaceWorker.js +13 -9
- package/dist/binaries/index.js +1 -1
- package/dist/binaries/resolvers/bun.js +1 -1
- package/dist/binaries/resolvers/index.d.ts +12 -12
- package/dist/binaries/util.js +1 -1
- package/dist/cli.js +10 -9
- package/dist/compilers/index.d.ts +1 -1
- package/dist/index.js +65 -57
- package/dist/issues/initializers.d.ts +1 -1
- package/dist/manifest/helpers.js +1 -1
- package/dist/manifest/index.d.ts +1 -1
- package/dist/manifest/index.js +4 -4
- package/dist/plugins/ava/index.js +8 -8
- package/dist/plugins/babel/index.js +2 -2
- package/dist/plugins/babel/types.d.ts +1 -1
- package/dist/plugins/babel/types.js +1 -1
- package/dist/plugins/commitlint/index.d.ts +1 -1
- package/dist/plugins/cspell/index.d.ts +1 -1
- package/dist/plugins/drizzle/index.d.ts +1 -1
- package/dist/plugins/eleventy/helpers.d.ts +0 -1
- package/dist/plugins/eleventy/helpers.js +1 -2
- package/dist/plugins/eleventy/index.d.ts +1 -1
- package/dist/plugins/eslint/helpers.d.ts +1 -1
- package/dist/plugins/eslint/helpers.js +5 -2
- package/dist/plugins/eslint/index.d.ts +0 -1
- package/dist/plugins/eslint/index.js +1 -1
- package/dist/plugins/github-actions/index.js +1 -1
- package/dist/plugins/graphql-codegen/index.d.ts +1 -1
- package/dist/plugins/jest/index.js +5 -4
- package/dist/plugins/lint-staged/index.d.ts +1 -1
- package/dist/plugins/lint-staged/index.js +2 -1
- package/dist/plugins/linthtml/index.d.ts +1 -1
- package/dist/plugins/markdownlint/index.d.ts +1 -1
- package/dist/plugins/npm-package-json-lint/index.d.ts +1 -1
- package/dist/plugins/nyc/index.d.ts +1 -1
- package/dist/plugins/playwright/index.d.ts +1 -1
- package/dist/plugins/playwright-ct/index.js +1 -1
- package/dist/plugins/postcss/index.d.ts +1 -1
- package/dist/plugins/prettier/index.d.ts +1 -1
- package/dist/plugins/release-it/index.d.ts +1 -1
- package/dist/plugins/remark/index.d.ts +1 -1
- package/dist/plugins/semantic-release/index.d.ts +1 -1
- package/dist/plugins/stryker/index.d.ts +1 -1
- package/dist/plugins/stylelint/index.d.ts +1 -1
- package/dist/plugins/tsup/index.d.ts +1 -1
- package/dist/plugins/typescript/index.d.ts +0 -1
- package/dist/plugins/typescript/index.js +4 -3
- package/dist/plugins/unbuild/index.d.ts +1 -1
- package/dist/plugins/vite/index.d.ts +2 -2
- package/dist/plugins/vite/index.js +1 -1
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +8 -4
- package/dist/plugins/vue/index.d.ts +1 -1
- package/dist/plugins/vue/index.js +2 -1
- package/dist/plugins/vue/types.d.ts +1 -1
- package/dist/plugins/webpack/index.js +4 -4
- package/dist/plugins/wireit/index.d.ts +1 -1
- package/dist/plugins/yorkie/index.d.ts +1 -1
- package/dist/plugins/yorkie/index.js +2 -1
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +6 -3
- package/dist/reporters/codeowners.js +9 -7
- package/dist/reporters/compact.js +1 -1
- package/dist/reporters/index.d.ts +5 -5
- package/dist/reporters/json.js +3 -3
- package/dist/reporters/markdown.js +7 -7
- package/dist/reporters/symbols.js +8 -8
- package/dist/reporters/util.js +3 -2
- package/dist/types/config.d.ts +5 -5
- package/dist/types/config.js +1 -3
- package/dist/types/exports.d.ts +1 -1
- package/dist/types/exports.js +1 -1
- package/dist/types/imports.d.ts +1 -1
- package/dist/types/imports.js +1 -1
- package/dist/typescript/SourceFile.d.ts +1 -1
- package/dist/typescript/SourceFile.js +1 -1
- package/dist/typescript/SourceFileManager.d.ts +1 -1
- package/dist/typescript/ast-helpers.js +2 -2
- package/dist/typescript/createHosts.d.ts +1 -1
- package/dist/typescript/createHosts.js +1 -1
- package/dist/typescript/getImportsAndExports.d.ts +1 -1
- package/dist/typescript/getImportsAndExports.js +15 -12
- package/dist/typescript/resolveModuleNames.js +2 -2
- package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/importCall.js +24 -30
- package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/index.d.ts +2 -2
- package/dist/typescript/visitors/dynamic-imports/index.js +0 -1
- package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/requireCall.js +14 -22
- package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
- package/dist/typescript/visitors/exports/exportKeyword.js +10 -12
- package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/exports/index.d.ts +2 -2
- package/dist/typescript/visitors/exports/index.js +0 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +2 -4
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/importDeclaration.js +18 -20
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/index.d.ts +2 -2
- package/dist/typescript/visitors/imports/index.js +0 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.js +14 -16
- package/dist/typescript/visitors/index.d.ts +1 -1
- package/dist/typescript/visitors/index.js +0 -1
- package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
- package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
- package/dist/typescript/visitors/scripts/index.d.ts +2 -2
- package/dist/typescript/visitors/scripts/index.js +0 -1
- package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
- package/dist/util/Performance.d.ts +1 -1
- package/dist/util/Performance.js +5 -5
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/debug.js +1 -1
- package/dist/util/fs.d.ts +2 -2
- package/dist/util/fs.js +3 -3
- package/dist/util/get-included-issue-types.js +8 -5
- package/dist/util/get-reexporting-entry-file.js +12 -16
- package/dist/util/git.js +5 -5
- package/dist/util/glob.js +2 -2
- package/dist/util/globby.d.ts +1 -1
- package/dist/util/globby.js +11 -12
- package/dist/util/handle-dependency.d.ts +1 -1
- package/dist/util/handle-dependency.js +1 -2
- package/dist/util/is-identifier-referenced.js +4 -4
- package/dist/util/loader.js +3 -5
- package/dist/util/modules.js +7 -5
- package/dist/util/object.js +1 -1
- package/dist/util/plugin.d.ts +1 -1
- package/dist/util/plugin.js +12 -14
- package/dist/util/regex.js +1 -1
- package/dist/util/require.js +2 -2
- package/dist/util/tag.js +4 -2
- package/dist/util/type.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -23
package/dist/util/Performance.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PerformanceObserver, performance } from 'node:perf_hooks';
|
|
2
2
|
import { constants } from 'node:perf_hooks';
|
|
3
3
|
import { memoryUsage } from 'node:process';
|
|
4
4
|
import EasyTable from 'easy-table';
|
|
@@ -27,9 +27,9 @@ export class Performance {
|
|
|
27
27
|
this.startTime = performance.now();
|
|
28
28
|
this.instanceId = Math.floor(performance.now() * 100);
|
|
29
29
|
this.fnObserver = new PerformanceObserver(items => {
|
|
30
|
-
items.getEntries()
|
|
30
|
+
for (const entry of items.getEntries()) {
|
|
31
31
|
this.entries.push(entry);
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
});
|
|
34
34
|
this.fnObserver.observe({ entryTypes: ['function'] });
|
|
35
35
|
this.gcObserver = new PerformanceObserver(items => {
|
|
@@ -71,7 +71,7 @@ export class Performance {
|
|
|
71
71
|
getTable() {
|
|
72
72
|
const entriesByName = this.getEntriesByName();
|
|
73
73
|
const table = new EasyTable();
|
|
74
|
-
|
|
74
|
+
for (const [name, values] of Object.entries(entriesByName)) {
|
|
75
75
|
const stats = new Summary(values);
|
|
76
76
|
table.cell('Name', name);
|
|
77
77
|
table.cell('size', stats.size(), EasyTable.number(0));
|
|
@@ -80,7 +80,7 @@ export class Performance {
|
|
|
80
80
|
table.cell('median', stats.median(), EasyTable.number(2));
|
|
81
81
|
table.cell('sum', stats.sum(), EasyTable.number(2));
|
|
82
82
|
table.newRow();
|
|
83
|
-
}
|
|
83
|
+
}
|
|
84
84
|
table.sort(['sum|des']);
|
|
85
85
|
return table.toString().trim();
|
|
86
86
|
}
|
package/dist/util/debug.js
CHANGED
|
@@ -34,7 +34,7 @@ const levels = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨'];
|
|
|
34
34
|
export const exportLookupLog = IS_TRACE_ENABLED
|
|
35
35
|
? (depth, message, filePath) => {
|
|
36
36
|
if (depth === -1)
|
|
37
|
-
console.log(
|
|
37
|
+
console.log(`\n${message}`, relative(filePath));
|
|
38
38
|
else
|
|
39
39
|
console.log(new Array(depth + 1).join(' '), levels[depth], message, relative(filePath));
|
|
40
40
|
}
|
package/dist/util/fs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const isDirectory: (filePath: string) => boolean;
|
|
2
|
-
export declare const isFile: (filePath: string) => boolean;
|
|
1
|
+
export declare const isDirectory: (filePath: string) => boolean | undefined;
|
|
2
|
+
export declare const isFile: (filePath: string) => boolean | undefined;
|
|
3
3
|
export declare const findFile: (workingDir: string, fileName: string) => string | undefined;
|
|
4
4
|
export declare const loadFile: (filePath: string) => Promise<string>;
|
|
5
5
|
export declare const loadJSON: (filePath: string) => Promise<any>;
|
package/dist/util/fs.js
CHANGED
|
@@ -3,16 +3,16 @@ import { readFile } from 'node:fs/promises';
|
|
|
3
3
|
import yaml from 'js-yaml';
|
|
4
4
|
import { parse as parseTOML } from 'smol-toml';
|
|
5
5
|
import stripJsonComments from 'strip-json-comments';
|
|
6
|
+
import { timerify } from './Performance.js';
|
|
6
7
|
import { LoaderError } from './errors.js';
|
|
7
8
|
import { dirname, join } from './path.js';
|
|
8
|
-
import { timerify } from './Performance.js';
|
|
9
9
|
export const isDirectory = (filePath) => {
|
|
10
10
|
const stat = statSync(filePath, { throwIfNoEntry: false });
|
|
11
|
-
return stat
|
|
11
|
+
return stat?.isDirectory();
|
|
12
12
|
};
|
|
13
13
|
export const isFile = (filePath) => {
|
|
14
14
|
const stat = statSync(filePath, { throwIfNoEntry: false });
|
|
15
|
-
return stat
|
|
15
|
+
return stat?.isFile();
|
|
16
16
|
};
|
|
17
17
|
export const findFile = (workingDir, fileName) => {
|
|
18
18
|
const filePath = join(workingDir, fileName);
|
|
@@ -2,14 +2,14 @@ import { ISSUE_TYPES } from '../constants.js';
|
|
|
2
2
|
import { ConfigurationError } from './errors.js';
|
|
3
3
|
export const defaultExcludedIssueTypes = ['classMembers', 'nsExports', 'nsTypes'];
|
|
4
4
|
const defaultIssueTypes = ISSUE_TYPES.filter(type => !defaultExcludedIssueTypes.includes(type));
|
|
5
|
-
const normalize = (values) => values.
|
|
5
|
+
const normalize = (values) => values.flatMap(value => value.split(','));
|
|
6
6
|
export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isProduction = false } = {}) => {
|
|
7
7
|
let incl = normalize(cliArgs.include);
|
|
8
|
-
|
|
9
|
-
[...incl, ...excl, ...include, ...exclude]
|
|
8
|
+
const excl = normalize(cliArgs.exclude);
|
|
9
|
+
for (const type of [...incl, ...excl, ...include, ...exclude]) {
|
|
10
10
|
if (!ISSUE_TYPES.includes(type))
|
|
11
11
|
throw new ConfigurationError(`Invalid issue type: ${type}`);
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
const excludes = exclude.filter(exclude => !incl.includes(exclude));
|
|
14
14
|
const includes = include.filter(include => !excl.includes(include));
|
|
15
15
|
if (cliArgs.dependencies) {
|
|
@@ -37,5 +37,8 @@ export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isP
|
|
|
37
37
|
? _include
|
|
38
38
|
: [..._include, ...defaultIssueTypes]
|
|
39
39
|
: defaultIssueTypes).filter(group => !_exclude.includes(group));
|
|
40
|
-
return ISSUE_TYPES.reduce((types, group) =>
|
|
40
|
+
return ISSUE_TYPES.reduce((types, group) => {
|
|
41
|
+
types[group] = included.includes(group);
|
|
42
|
+
return types;
|
|
43
|
+
}, {});
|
|
41
44
|
};
|
|
@@ -9,16 +9,16 @@ export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, impo
|
|
|
9
9
|
for (const filePath of importedModule.isReExportedBy) {
|
|
10
10
|
if (entryPaths.has(filePath)) {
|
|
11
11
|
if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
|
|
12
|
-
exportLookupLog(depth,
|
|
12
|
+
exportLookupLog(depth, 're-exported by entry', filePath);
|
|
13
13
|
return filePath;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
exportLookupLog(depth,
|
|
15
|
+
if (importedModule.hasStar) {
|
|
16
|
+
exportLookupLog(depth, 're-exported (*) by entry', filePath);
|
|
17
17
|
return filePath;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
exportLookupLog(depth,
|
|
21
|
+
exportLookupLog(depth, 're-exported by', filePath);
|
|
22
22
|
const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
|
|
23
23
|
if (file)
|
|
24
24
|
return file;
|
|
@@ -29,24 +29,20 @@ export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, impo
|
|
|
29
29
|
exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
|
|
30
30
|
return filePath;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return file;
|
|
37
|
-
}
|
|
32
|
+
exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
|
|
33
|
+
const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
|
|
34
|
+
if (file)
|
|
35
|
+
return file;
|
|
38
36
|
}
|
|
39
37
|
for (const [filePath, alias] of importedModule.isReExportedAs) {
|
|
40
38
|
if (entryPaths.has(filePath)) {
|
|
41
39
|
exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
|
|
42
40
|
return filePath;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return file;
|
|
49
|
-
}
|
|
42
|
+
exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
|
|
43
|
+
const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
|
|
44
|
+
if (file)
|
|
45
|
+
return file;
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
48
|
exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
|
package/dist/util/git.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
2
|
import { join } from './path.js';
|
|
3
3
|
const hookFileNames = [
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
'prepare-commit-msg',
|
|
5
|
+
'commit-msg',
|
|
6
|
+
'pre-{applypatch,commit,merge-commit,push,rebase,receive}',
|
|
7
|
+
'post-{checkout,commit,merge,rewrite}',
|
|
8
8
|
];
|
|
9
9
|
const getGitHooksPath = (defaultPath = '.git/hooks') => {
|
|
10
10
|
try {
|
package/dist/util/glob.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import fg from 'fast-glob';
|
|
2
2
|
import { GLOBAL_IGNORE_PATTERNS } from '../constants.js';
|
|
3
|
+
import { timerify } from './Performance.js';
|
|
3
4
|
import { compact } from './array.js';
|
|
4
5
|
import { globby } from './globby.js';
|
|
5
6
|
import { join, relative } from './path.js';
|
|
6
|
-
import { timerify } from './Performance.js';
|
|
7
7
|
export const prependDirToPattern = (workingDir, pattern) => {
|
|
8
8
|
if (pattern.startsWith('!'))
|
|
9
|
-
return
|
|
9
|
+
return `!${join(workingDir, pattern.slice(1))}`;
|
|
10
10
|
return join(workingDir, pattern);
|
|
11
11
|
};
|
|
12
12
|
export const negate = (pattern) => pattern.replace(/^!?/, '!');
|
package/dist/util/globby.d.ts
CHANGED
package/dist/util/globby.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
3
|
import { walk as _walk } from '@nodelib/fs.walk';
|
|
4
|
-
import {} from 'fast-glob';
|
|
5
4
|
import fastGlob from 'fast-glob';
|
|
6
5
|
import picomatch from 'picomatch';
|
|
7
6
|
import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
|
|
7
|
+
import { timerify } from './Performance.js';
|
|
8
8
|
import { debugLogObject } from './debug.js';
|
|
9
9
|
import { dirname, join, relative, toPosix } from './path.js';
|
|
10
|
-
import { timerify } from './Performance.js';
|
|
11
10
|
const walk = promisify(_walk);
|
|
12
11
|
const _picomatch = timerify(picomatch);
|
|
13
12
|
const cachedIgnores = new Map();
|
|
14
13
|
function convertGitignoreToMicromatch(pattern) {
|
|
15
|
-
|
|
14
|
+
const negated = pattern[0] === '!';
|
|
16
15
|
if (negated) {
|
|
17
16
|
pattern = pattern.slice(1);
|
|
18
17
|
}
|
|
@@ -22,20 +21,20 @@ function convertGitignoreToMicromatch(pattern) {
|
|
|
22
21
|
if (pattern.startsWith('/'))
|
|
23
22
|
pattern = pattern.slice(1);
|
|
24
23
|
else if (!pattern.startsWith('**/'))
|
|
25
|
-
pattern =
|
|
24
|
+
pattern = `**/${pattern}`;
|
|
26
25
|
if (pattern.endsWith('/*'))
|
|
27
26
|
extPattern = pattern;
|
|
28
27
|
else if (pattern.endsWith('/'))
|
|
29
|
-
extPattern = pattern
|
|
28
|
+
extPattern = `${pattern}**`;
|
|
30
29
|
else
|
|
31
|
-
extPattern = pattern
|
|
30
|
+
extPattern = `${pattern}/**`;
|
|
32
31
|
return { negated, patterns: [pattern, extPattern] };
|
|
33
32
|
}
|
|
34
33
|
function parseGitignoreFile(filePath) {
|
|
35
34
|
const file = fs.readFileSync(filePath, 'utf8');
|
|
36
35
|
return file
|
|
37
36
|
.split(/\r?\n/)
|
|
38
|
-
.filter(line => line && !line.startsWith('#'))
|
|
37
|
+
.filter(line => line.trim() && !line.startsWith('#'))
|
|
39
38
|
.map(pattern => convertGitignoreToMicromatch(pattern.replace(/(?<!\\)#.*/, '').trim()));
|
|
40
39
|
}
|
|
41
40
|
async function parseFindGitignores(options) {
|
|
@@ -67,7 +66,7 @@ async function parseFindGitignores(options) {
|
|
|
67
66
|
dirUnignores.push(...rule.patterns);
|
|
68
67
|
}
|
|
69
68
|
else {
|
|
70
|
-
if (!unignores.includes(ext.startsWith('**/') ? ext :
|
|
69
|
+
if (!unignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
|
|
71
70
|
dirUnignores.push(join(base, p), join(base, ext));
|
|
72
71
|
}
|
|
73
72
|
}
|
|
@@ -78,7 +77,7 @@ async function parseFindGitignores(options) {
|
|
|
78
77
|
dirIgnores.push(...rule.patterns);
|
|
79
78
|
}
|
|
80
79
|
else {
|
|
81
|
-
if (!ignores.includes(ext.startsWith('**/') ? ext :
|
|
80
|
+
if (!ignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
|
|
82
81
|
dirIgnores.push(join(base, p), join(base, ext));
|
|
83
82
|
}
|
|
84
83
|
}
|
|
@@ -109,7 +108,7 @@ export async function globby(patterns, options) {
|
|
|
109
108
|
const i = cachedIgnores.get(dir);
|
|
110
109
|
if (i) {
|
|
111
110
|
ignore.push(...i.ignores);
|
|
112
|
-
ignore.push(...i.unignores.map(e =>
|
|
111
|
+
ignore.push(...i.unignores.map(e => `!${e}`));
|
|
113
112
|
}
|
|
114
113
|
dir = dirname(dir);
|
|
115
114
|
}
|
|
@@ -118,7 +117,7 @@ export async function globby(patterns, options) {
|
|
|
118
117
|
ignore.push(...i.ignores);
|
|
119
118
|
}
|
|
120
119
|
const { dir, ...fastGlobOptions } = { ...options, ignore };
|
|
121
|
-
debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME,
|
|
120
|
+
debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...options });
|
|
122
121
|
return fastGlob(patterns, fastGlobOptions);
|
|
123
122
|
}
|
|
124
123
|
export async function getGitIgnoredFn(options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ProjectPrincipal } from '../ProjectPrincipal.js';
|
|
2
1
|
import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
|
|
3
2
|
import type { DependencyDeputy } from '../DependencyDeputy.js';
|
|
4
3
|
import type { IssueCollector } from '../IssueCollector.js';
|
|
4
|
+
import type { ProjectPrincipal } from '../ProjectPrincipal.js';
|
|
5
5
|
export declare const getHandler: (collector: IssueCollector, deputy: DependencyDeputy, chief: ConfigurationChief) => (specifier: string, containingFilePath: string, workspace: Workspace, principal: ProjectPrincipal) => void;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import micromatch from 'micromatch';
|
|
2
|
-
import { ProjectPrincipal } from '../ProjectPrincipal.js';
|
|
3
2
|
import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, normalizeSpecifierFromFilePath, } from './modules.js';
|
|
4
|
-
import { isInNodeModules,
|
|
3
|
+
import { isInNodeModules, isInternal, join } from './path.js';
|
|
5
4
|
import { fromBinary, isBinary } from './protocols.js';
|
|
6
5
|
import { _resolveSpecifier } from './require.js';
|
|
7
6
|
export const getHandler = (collector, deputy, chief) => (specifier, containingFilePath, workspace, principal) => {
|
|
@@ -4,11 +4,11 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
|
|
|
4
4
|
if (depth === 0)
|
|
5
5
|
exportLookupLog(-1, `Looking up export "${id}" from`, filePath);
|
|
6
6
|
if (!importsForExport) {
|
|
7
|
-
exportLookupLog(depth,
|
|
7
|
+
exportLookupLog(depth, 'no imports found from', filePath);
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
10
|
if (importsForExport.identifiers.has(id)) {
|
|
11
|
-
exportLookupLog(depth,
|
|
11
|
+
exportLookupLog(depth, 'imported from', filePath);
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
14
|
for (const ns of importsForExport.importedNs) {
|
|
@@ -20,7 +20,7 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
|
|
|
20
20
|
if (importsForExport.isReExport) {
|
|
21
21
|
for (const filePath of importsForExport.isReExportedBy) {
|
|
22
22
|
if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
|
|
23
|
-
exportLookupLog(depth,
|
|
23
|
+
exportLookupLog(depth, 're-exported by', filePath);
|
|
24
24
|
return true;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -37,7 +37,7 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
exportLookupLog(depth,
|
|
40
|
+
exportLookupLog(depth, 'not imported from', filePath);
|
|
41
41
|
return false;
|
|
42
42
|
};
|
|
43
43
|
return isIdentifierReferenced;
|
package/dist/util/loader.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { timerify } from './Performance.js';
|
|
2
3
|
import { LoaderError } from './errors.js';
|
|
3
|
-
import {
|
|
4
|
+
import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js';
|
|
4
5
|
import { isTypeModule } from './fs.js';
|
|
5
6
|
import { extname, isInternal } from './path.js';
|
|
6
|
-
import { timerify } from './Performance.js';
|
|
7
7
|
import { jitiCJS, jitiESM } from './register.js';
|
|
8
8
|
const load = async (filePath) => {
|
|
9
9
|
try {
|
|
@@ -44,9 +44,7 @@ const load = async (filePath) => {
|
|
|
44
44
|
if (ext === '.mts' || ((ext === '.ts' || ext === '.tsx') && isTypeModule(filePath))) {
|
|
45
45
|
return await jitiESM(filePath);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
return await jitiCJS(filePath);
|
|
49
|
-
}
|
|
47
|
+
return await jitiCJS(filePath);
|
|
50
48
|
}
|
|
51
49
|
catch (error) {
|
|
52
50
|
throw new LoaderError(`Error loading ${filePath}`, { cause: error });
|
package/dist/util/modules.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isBuiltin } from 'module';
|
|
1
|
+
import { isBuiltin } from 'node:module';
|
|
2
2
|
import { _glob } from './glob.js';
|
|
3
3
|
import { getStringValues } from './object.js';
|
|
4
4
|
import { isAbsolute, toPosix } from './path.js';
|
|
@@ -26,8 +26,8 @@ export const getDefinitelyTypedFor = (packageName) => {
|
|
|
26
26
|
if (isDefinitelyTyped(packageName))
|
|
27
27
|
return packageName;
|
|
28
28
|
if (packageName.startsWith('@'))
|
|
29
|
-
return
|
|
30
|
-
return
|
|
29
|
+
return `@types/${packageName.slice(1).replace('/', '__')}`;
|
|
30
|
+
return `@types/${packageName}`;
|
|
31
31
|
};
|
|
32
32
|
export const getPackageFromDefinitelyTyped = (typedDependency) => {
|
|
33
33
|
if (typedDependency.includes('__')) {
|
|
@@ -45,10 +45,12 @@ export const getEntryPathFromManifest = (manifest, sharedGlobOptions) => {
|
|
|
45
45
|
if (typeof bin === 'string')
|
|
46
46
|
entryPaths.add(bin);
|
|
47
47
|
if (typeof bin === 'object')
|
|
48
|
-
|
|
48
|
+
for (const id of Object.values(bin))
|
|
49
|
+
entryPaths.add(id);
|
|
49
50
|
}
|
|
50
51
|
if (exports) {
|
|
51
|
-
|
|
52
|
+
for (const item of getStringValues(exports))
|
|
53
|
+
entryPaths.add(item);
|
|
52
54
|
}
|
|
53
55
|
return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
|
|
54
56
|
};
|
package/dist/util/object.js
CHANGED
package/dist/util/plugin.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { _loadJSON as loadJSON } from './fs.js';
|
|
|
3
3
|
export { _tryResolve as tryResolve } from './require.js';
|
|
4
4
|
export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
|
|
5
5
|
import type { RawPluginConfiguration } from '../types/config.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Plugin, PluginOptions } from '../types/plugins.js';
|
|
7
7
|
export declare const toCamelCase: (name: string) => string;
|
|
8
8
|
export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
|
|
9
9
|
export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguration) => boolean | {
|
package/dist/util/plugin.js
CHANGED
|
@@ -13,7 +13,7 @@ export const hasDependency = (dependencies, values) => values.some(value => {
|
|
|
13
13
|
if (typeof value === 'string') {
|
|
14
14
|
return dependencies.has(value);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
if (value instanceof RegExp) {
|
|
17
17
|
for (const dependency of dependencies) {
|
|
18
18
|
if (value.test(dependency))
|
|
19
19
|
return true;
|
|
@@ -25,19 +25,17 @@ export const normalizePluginConfig = (pluginConfig) => {
|
|
|
25
25
|
if (typeof pluginConfig === 'boolean') {
|
|
26
26
|
return pluginConfig;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
?
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return { config, entry, project };
|
|
40
|
-
}
|
|
28
|
+
const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
|
|
29
|
+
const config = isObject
|
|
30
|
+
? 'config' in pluginConfig
|
|
31
|
+
? arrayify(pluginConfig.config)
|
|
32
|
+
: null
|
|
33
|
+
: pluginConfig
|
|
34
|
+
? arrayify(pluginConfig)
|
|
35
|
+
: null;
|
|
36
|
+
const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
|
|
37
|
+
const project = isObject && 'project' in pluginConfig ? arrayify(pluginConfig.project) : entry;
|
|
38
|
+
return { config, entry, project };
|
|
41
39
|
};
|
|
42
40
|
export const loadConfigForPlugin = async (configFilePath, plugin, options, pluginName) => {
|
|
43
41
|
const { packageJsonPath } = plugin;
|
package/dist/util/regex.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export const toRegexOrString = (value) => typeof value === 'string' && /[*+\\(|{^$]/.test(value) ? new RegExp(value) : value;
|
|
2
|
-
export const hasMatch = (haystack, needle) => haystack
|
|
2
|
+
export const hasMatch = (haystack, needle) => haystack?.some(n => (typeof n === 'string' ? n === needle : n.test(needle)));
|
|
3
3
|
export const hasMatchInSet = (haystack, needle) => haystack && (typeof needle === 'string' ? haystack.has(needle) : [...haystack].some(n => needle.test(n)));
|
|
4
4
|
export const findKey = (map, key) => [...map.keys()].find(k => k instanceof RegExp && k.source === key.source);
|
package/dist/util/require.js
CHANGED
|
@@ -2,10 +2,10 @@ import { createRequire as nodeCreateRequire } from 'node:module';
|
|
|
2
2
|
import { pathToFileURL } from 'node:url';
|
|
3
3
|
import createJITI from 'jiti';
|
|
4
4
|
import transform from 'jiti/dist/babel.js';
|
|
5
|
+
import { timerify } from './Performance.js';
|
|
5
6
|
import { debugLog } from './debug.js';
|
|
6
7
|
import { getPackageNameFromModuleSpecifier } from './modules.js';
|
|
7
|
-
import { cwd,
|
|
8
|
-
import { timerify } from './Performance.js';
|
|
8
|
+
import { cwd, join, toPosix } from './path.js';
|
|
9
9
|
import { jitiCJS } from './register.js';
|
|
10
10
|
const createRequire = (path) => nodeCreateRequire(pathToFileURL(path ?? cwd));
|
|
11
11
|
const require = createRequire();
|
package/dist/util/tag.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export const splitTags = (tags) => tags
|
|
2
2
|
.flatMap(tag => tag.split(','))
|
|
3
3
|
.reduce(([incl, excl], tag) => {
|
|
4
|
-
|
|
4
|
+
const match = tag.match(/[a-zA-Z]+/);
|
|
5
|
+
if (match)
|
|
6
|
+
(tag.startsWith('-') ? excl : incl).push(match[0]);
|
|
5
7
|
return [incl, excl];
|
|
6
8
|
}, [[], []]);
|
|
7
|
-
const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.includes(
|
|
9
|
+
const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.includes(`@${tag}`));
|
|
8
10
|
export const shouldIgnore = (jsDocTags, tags) => {
|
|
9
11
|
const [includeJSDocTags, excludeJSDocTags] = tags;
|
|
10
12
|
if (includeJSDocTags.length > 0 && !hasTag(includeJSDocTags, jsDocTags))
|
package/dist/util/type.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const getHasStrictlyNsReferences = (importsForExport) => {
|
|
2
|
-
if (!importsForExport
|
|
2
|
+
if (!importsForExport?.hasStar || importsForExport.importedNs.size === 0)
|
|
3
3
|
return [false];
|
|
4
4
|
let namespace;
|
|
5
5
|
for (const ns of importsForExport.importedNs) {
|
|
@@ -7,7 +7,7 @@ export const getHasStrictlyNsReferences = (importsForExport) => {
|
|
|
7
7
|
if (!hasNs)
|
|
8
8
|
return [false, ns];
|
|
9
9
|
for (const id of importsForExport.identifiers)
|
|
10
|
-
if (id.startsWith(ns
|
|
10
|
+
if (id.startsWith(`${ns}.`))
|
|
11
11
|
return [false, ns];
|
|
12
12
|
namespace = ns;
|
|
13
13
|
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.9.
|
|
1
|
+
export declare const version = "5.9.2";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.9.
|
|
1
|
+
export const version = '5.9.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "5.9.
|
|
3
|
+
"version": "5.9.2",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://knip.dev",
|
|
6
6
|
"repository": {
|
|
@@ -37,19 +37,17 @@
|
|
|
37
37
|
"scripts": {
|
|
38
38
|
"knip": "node ./dist/cli.js --directory ../..",
|
|
39
39
|
"knip:production": "node ./dist/cli.js --directory ../.. --production --strict",
|
|
40
|
-
"lint": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"test": "node --no-warnings --test tmp",
|
|
45
|
-
"coverage": "c8 --reporter html node --no-warnings --import tsx --test test/*.test.ts test/*/*.test.ts",
|
|
40
|
+
"lint": "biome lint .",
|
|
41
|
+
"format": "biome format --write .",
|
|
42
|
+
"test": "bun test test/**/*.test.ts",
|
|
43
|
+
"test:node": "glob -c \"tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
|
|
46
44
|
"watch": "npm link && tsc --watch",
|
|
47
45
|
"prebuild": "node rmdir.js dist",
|
|
48
46
|
"build": "tsc",
|
|
49
|
-
"
|
|
47
|
+
"ci": "bun run lint && bun run build && bun run knip && bun run knip:production && npm test",
|
|
50
48
|
"release": "release-it",
|
|
51
|
-
"create-plugin": "
|
|
52
|
-
"postcreate-plugin": "
|
|
49
|
+
"create-plugin": "bun ./scripts/create-new-plugin.ts",
|
|
50
|
+
"postcreate-plugin": "biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts"
|
|
53
51
|
},
|
|
54
52
|
"files": [
|
|
55
53
|
"dist",
|
|
@@ -61,8 +59,7 @@
|
|
|
61
59
|
"@nodelib/fs.walk": "2.0.0",
|
|
62
60
|
"@npmcli/map-workspaces": "3.0.4",
|
|
63
61
|
"@npmcli/package-json": "5.0.0",
|
|
64
|
-
"@pnpm/
|
|
65
|
-
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
|
62
|
+
"@pnpm/workspace.pkgs-graph": "2.0.14",
|
|
66
63
|
"@snyk/github-codeowners": "1.1.0",
|
|
67
64
|
"@types/picomatch": "2.3.3",
|
|
68
65
|
"easy-table": "1.2.0",
|
|
@@ -87,11 +84,8 @@
|
|
|
87
84
|
},
|
|
88
85
|
"devDependencies": {
|
|
89
86
|
"@jest/types": "^29.6.3",
|
|
90
|
-
"@knip/eslint-config": "0.0.0",
|
|
91
87
|
"@release-it/bumper": "^6.0.1",
|
|
92
|
-
"@
|
|
93
|
-
"@swc/core": "^1.4.6",
|
|
94
|
-
"@types/bun": "^1.0.8",
|
|
88
|
+
"@types/bun": "^1.0.12",
|
|
95
89
|
"@types/js-yaml": "^4.0.9",
|
|
96
90
|
"@types/micromatch": "^4.0.6",
|
|
97
91
|
"@types/minimist": "^1.2.5",
|
|
@@ -99,14 +93,12 @@
|
|
|
99
93
|
"@types/npmcli__package-json": "^4.0.4",
|
|
100
94
|
"@types/resolve": "^1.20.6",
|
|
101
95
|
"@types/webpack": "^5.28.5",
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"playwright": "^1.42.1",
|
|
105
|
-
"prettier": "^3.2.5",
|
|
96
|
+
"glob": "^10.3.12",
|
|
97
|
+
"playwright": "^1.43.0",
|
|
106
98
|
"release-it": "^17.1.1",
|
|
107
|
-
"tsx": "^4.7.
|
|
108
|
-
"type-fest": "^4.
|
|
109
|
-
"typescript": "5.4.2"
|
|
99
|
+
"tsx": "^4.7.2",
|
|
100
|
+
"type-fest": "^4.15.0",
|
|
101
|
+
"typescript": "^5.4.2"
|
|
110
102
|
},
|
|
111
103
|
"engines": {
|
|
112
104
|
"node": ">=18.6.0"
|