knip 5.26.0 → 5.27.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/dist/CacheConsultant.d.ts +8 -2
- package/dist/CacheConsultant.js +9 -16
- package/dist/ConfigurationChief.d.ts +11 -4
- package/dist/ConfigurationChief.js +22 -21
- package/dist/ConfigurationValidator.d.ts +224 -0
- package/dist/ConfigurationValidator.js +4 -0
- package/dist/DependencyDeputy.d.ts +3 -2
- package/dist/DependencyDeputy.js +4 -4
- package/dist/PrincipalFactory.d.ts +4 -0
- package/dist/PrincipalFactory.js +3 -2
- package/dist/ProjectPrincipal.d.ts +5 -4
- package/dist/ProjectPrincipal.js +8 -6
- package/dist/WorkspaceWorker.d.ts +5 -3
- package/dist/WorkspaceWorker.js +2 -2
- package/dist/binaries/resolvers/bun.js +1 -1
- package/dist/binaries/util.js +2 -2
- package/dist/cli.js +23 -12
- package/dist/compilers/index.d.ts +40 -0
- package/dist/index.js +55 -134
- package/dist/plugins/babel/index.js +2 -1
- package/dist/plugins/babel/types.d.ts +1 -0
- package/dist/plugins/cypress/helpers.d.ts +3 -0
- package/dist/plugins/cypress/helpers.js +23 -0
- package/dist/plugins/cypress/index.d.ts +3 -1
- package/dist/plugins/cypress/index.js +5 -0
- package/dist/plugins/cypress/types.d.ts +6 -0
- package/dist/plugins/cypress/types.js +1 -0
- package/dist/plugins/eslint/helpers.js +8 -7
- package/dist/plugins/husky/index.d.ts +1 -1
- package/dist/plugins/husky/index.js +9 -2
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/ladle/index.d.ts +13 -0
- package/dist/plugins/ladle/index.js +36 -0
- package/dist/plugins/ladle/types.d.ts +4 -0
- package/dist/plugins/ladle/types.js +1 -0
- package/dist/plugins/playwright/index.d.ts +1 -1
- package/dist/plugins/playwright/types.d.ts +36 -0
- package/dist/plugins/playwright/types.js +1 -0
- package/dist/plugins/playwright-ct/index.d.ts +2 -2
- package/dist/plugins/react-cosmos/index.d.ts +12 -0
- package/dist/plugins/react-cosmos/index.js +33 -0
- package/dist/plugins/react-cosmos/types.d.ts +5 -0
- package/dist/plugins/react-cosmos/types.js +1 -0
- package/dist/plugins/rsbuild/index.d.ts +10 -0
- package/dist/plugins/rsbuild/index.js +15 -0
- package/dist/plugins/rsbuild/types.d.ts +3 -0
- package/dist/plugins/rsbuild/types.js +1 -0
- package/dist/plugins/rspack/index.d.ts +10 -0
- package/dist/plugins/rspack/index.js +22 -0
- package/dist/plugins/vitest/index.js +1 -1
- package/dist/types/cli.d.ts +16 -9
- package/dist/typescript/{createHosts.js → create-hosts.js} +1 -1
- package/dist/typescript/{resolveModuleNames.js → resolve-module-names.js} +3 -2
- package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/importCall.js +25 -31
- package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
- package/dist/typescript/visitors/dynamic-imports/index.d.ts +1 -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 +8 -4
- 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/exportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/exports/index.d.ts +1 -1
- package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
- package/dist/typescript/visitors/helpers.js +1 -1
- package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/imports/index.d.ts +1 -1
- package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
- package/dist/typescript/visitors/index.d.ts +1 -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 +1 -1
- package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
- package/dist/util/create-workspace-graph.d.ts +8 -0
- package/dist/util/{pkgs-graph.js → create-workspace-graph.js} +3 -3
- package/dist/util/dependency-graph.d.ts +3 -4
- package/dist/util/dependency-graph.js +35 -3
- package/dist/util/get-included-issue-types.d.ts +6 -6
- package/dist/util/get-included-issue-types.js +5 -5
- package/dist/util/globby.js +2 -2
- package/dist/util/handle-dependency.d.ts +1 -1
- package/dist/util/handle-dependency.js +7 -9
- package/dist/util/loader.js +1 -1
- package/dist/util/modules.d.ts +0 -1
- package/dist/util/modules.js +0 -7
- package/dist/util/plugin.d.ts +1 -0
- package/dist/util/plugin.js +7 -6
- package/dist/util/reporter.d.ts +2 -2
- package/dist/util/reporter.js +12 -10
- package/dist/util/require.d.ts +0 -3
- package/dist/util/require.js +3 -34
- package/dist/util/resolve.d.ts +2 -1
- package/dist/util/resolve.js +21 -12
- package/dist/util/to-source-path.d.ts +2 -2
- package/dist/util/watch.d.ts +25 -0
- package/dist/util/watch.js +85 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -5
- package/schema.json +16 -0
- package/dist/util/pkgs-graph.d.ts +0 -8
- /package/dist/typescript/{createHosts.d.ts → create-hosts.d.ts} +0 -0
- /package/dist/typescript/{getImportsAndExports.d.ts → get-imports-and-exports.d.ts} +0 -0
- /package/dist/typescript/{getImportsAndExports.js → get-imports-and-exports.js} +0 -0
- /package/dist/typescript/{resolveModuleNames.d.ts → resolve-module-names.d.ts} +0 -0
- /package/dist/util/{register.d.ts → jiti.d.ts} +0 -0
- /package/dist/util/{register.js → jiti.js} +0 -0
|
@@ -4,21 +4,21 @@ export const defaultExcludedIssueTypes = ['classMembers', 'nsExports', 'nsTypes'
|
|
|
4
4
|
const defaultIssueTypes = ISSUE_TYPES.filter(type => !defaultExcludedIssueTypes.includes(type));
|
|
5
5
|
const normalize = (values) => values.flatMap(value => value.split(','));
|
|
6
6
|
export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isProduction = false } = {}) => {
|
|
7
|
-
let incl = normalize(cliArgs.
|
|
8
|
-
const excl = normalize(cliArgs.
|
|
7
|
+
let incl = normalize(cliArgs.includedIssueTypes);
|
|
8
|
+
const excl = normalize(cliArgs.excludedIssueTypes);
|
|
9
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
|
-
if (cliArgs.
|
|
15
|
+
if (cliArgs.isDependenciesShorthand) {
|
|
16
16
|
incl = [...incl, 'dependencies', 'optionalPeerDependencies', 'unlisted', 'binaries', 'unresolved'];
|
|
17
17
|
}
|
|
18
|
-
if (cliArgs.
|
|
18
|
+
if (cliArgs.isExportsShorthand) {
|
|
19
19
|
incl = [...incl, 'exports', 'types', 'enumMembers', 'duplicates'];
|
|
20
20
|
}
|
|
21
|
-
if (cliArgs.
|
|
21
|
+
if (cliArgs.isFilesShorthand) {
|
|
22
22
|
incl = [...incl, 'files'];
|
|
23
23
|
}
|
|
24
24
|
const _include = [...incl, ...includes];
|
package/dist/util/globby.js
CHANGED
|
@@ -7,7 +7,7 @@ import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
|
|
|
7
7
|
import { timerify } from './Performance.js';
|
|
8
8
|
import { debugLogObject } from './debug.js';
|
|
9
9
|
import { isFile } from './fs.js';
|
|
10
|
-
import { dirname, join, relative, toPosix } from './path.js';
|
|
10
|
+
import { dirname, join, relative, toPosix, toRelative } from './path.js';
|
|
11
11
|
const walk = promisify(_walk);
|
|
12
12
|
const _picomatch = timerify(picomatch);
|
|
13
13
|
const cachedIgnores = new Map();
|
|
@@ -53,7 +53,7 @@ async function parseFindGitignores(options) {
|
|
|
53
53
|
return false;
|
|
54
54
|
};
|
|
55
55
|
const addFile = (filePath) => {
|
|
56
|
-
gitignoreFiles.push(filePath);
|
|
56
|
+
gitignoreFiles.push(toRelative(filePath));
|
|
57
57
|
const dir = dirname(toPosix(filePath));
|
|
58
58
|
const base = relative(options.cwd, dir);
|
|
59
59
|
const dirIgnores = base === '' ? ['.git', ...GLOBAL_IGNORE_PATTERNS] : [];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
|
|
2
2
|
import type { DependencyDeputy } from '../DependencyDeputy.js';
|
|
3
3
|
import type { IssueCollector } from '../IssueCollector.js';
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const getReferencedDependencyHandler: (collector: IssueCollector, deputy: DependencyDeputy, chief: ConfigurationChief) => (specifier: string, containingFilePath: string, workspace: Workspace) => string | undefined;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier
|
|
2
|
-
import { isInNodeModules, isInternal } from './path.js';
|
|
1
|
+
import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from './modules.js';
|
|
2
|
+
import { dirname, isInNodeModules, isInternal } from './path.js';
|
|
3
3
|
import { fromBinary, isBinary } from './protocols.js';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export const getHandler = (collector, deputy, chief) => (specifier, containingFilePath, workspace) => {
|
|
4
|
+
import { _resolveSync } from './resolve.js';
|
|
5
|
+
export const getReferencedDependencyHandler = (collector, deputy, chief) => (specifier, containingFilePath, workspace) => {
|
|
7
6
|
if (isBinary(specifier)) {
|
|
8
7
|
const binaryName = fromBinary(specifier);
|
|
9
8
|
const isHandled = deputy.maybeAddReferencedBinary(workspace, binaryName);
|
|
@@ -17,7 +16,7 @@ export const getHandler = (collector, deputy, chief) => (specifier, containingFi
|
|
|
17
16
|
}
|
|
18
17
|
else {
|
|
19
18
|
if (isInternal(specifier)) {
|
|
20
|
-
const resolvedFilePath =
|
|
19
|
+
const resolvedFilePath = _resolveSync(specifier, dirname(containingFilePath));
|
|
21
20
|
if (resolvedFilePath)
|
|
22
21
|
return resolvedFilePath;
|
|
23
22
|
collector.addIssue({
|
|
@@ -40,9 +39,8 @@ export const getHandler = (collector, deputy, chief) => (specifier, containingFi
|
|
|
40
39
|
symbol: specifier,
|
|
41
40
|
});
|
|
42
41
|
if (packageName && specifier !== packageName) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const filePath = _resolveSpecifier(otherWorkspace.dir, normalizeSpecifierFromFilePath(specifier));
|
|
42
|
+
if (chief.workspacePackagesByName.get(packageName)) {
|
|
43
|
+
const filePath = _resolveSync(specifier, dirname(containingFilePath));
|
|
46
44
|
if (filePath)
|
|
47
45
|
return filePath;
|
|
48
46
|
collector.addIssue({
|
package/dist/util/loader.js
CHANGED
|
@@ -3,8 +3,8 @@ import { timerify } from './Performance.js';
|
|
|
3
3
|
import { LoaderError } from './errors.js';
|
|
4
4
|
import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js';
|
|
5
5
|
import { isTypeModule } from './fs.js';
|
|
6
|
+
import { jitiCJS, jitiESM } from './jiti.js';
|
|
6
7
|
import { extname, isInternal } from './path.js';
|
|
7
|
-
import { jitiCJS, jitiESM } from './register.js';
|
|
8
8
|
const load = async (filePath) => {
|
|
9
9
|
try {
|
|
10
10
|
const ext = extname(filePath);
|
package/dist/util/modules.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PackageJson } from '../types/package-json.js';
|
|
2
2
|
export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
|
|
3
3
|
export declare const getPackageNameFromFilePath: (value: string) => string;
|
|
4
|
-
export declare const normalizeSpecifierFromFilePath: (value: string) => string;
|
|
5
4
|
export declare const isStartsLikePackageName: (specifier: string) => boolean;
|
|
6
5
|
export declare const isDefinitelyTyped: (packageName: string) => boolean;
|
|
7
6
|
export declare const getDefinitelyTypedFor: (packageName: string) => string;
|
package/dist/util/modules.js
CHANGED
|
@@ -16,13 +16,6 @@ export const getPackageNameFromFilePath = (value) => {
|
|
|
16
16
|
return match[match.length - 1];
|
|
17
17
|
return value;
|
|
18
18
|
};
|
|
19
|
-
const packageNameMatch = /.*\/node_modules\/(.+)/;
|
|
20
|
-
export const normalizeSpecifierFromFilePath = (value) => {
|
|
21
|
-
const match = toPosix(value).match(packageNameMatch);
|
|
22
|
-
if (match)
|
|
23
|
-
return match[match.length - 1];
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
19
|
export const isStartsLikePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
|
|
27
20
|
export const isDefinitelyTyped = (packageName) => packageName.startsWith(`${DT_SCOPE}/`);
|
|
28
21
|
export const getDefinitelyTypedFor = (packageName) => {
|
package/dist/util/plugin.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
|
|
2
2
|
export { _loadJSON as loadJSON } from './fs.js';
|
|
3
3
|
export { _load as load } from './loader.js';
|
|
4
|
+
export { _resolveSync as resolve } from './resolve.js';
|
|
4
5
|
import type { RawPluginConfiguration } from '../types/config.js';
|
|
5
6
|
import type { Plugin, PluginOptions } from '../types/plugins.js';
|
|
6
7
|
export declare const toCamelCase: (name: string) => string;
|
package/dist/util/plugin.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
|
|
2
2
|
export { _loadJSON as loadJSON } from './fs.js';
|
|
3
3
|
export { _load as load } from './loader.js';
|
|
4
|
+
export { _resolveSync as resolve } from './resolve.js';
|
|
4
5
|
import { arrayify } from './array.js';
|
|
5
6
|
import { _load as load } from './loader.js';
|
|
6
7
|
import { get } from './object.js';
|
|
7
8
|
import { basename, isAbsolute, join, relative } from './path.js';
|
|
8
9
|
import { toEntryPattern, toProductionEntryPattern } from './protocols.js';
|
|
9
|
-
import {
|
|
10
|
+
import { _resolveSync } from './resolve.js';
|
|
10
11
|
export const toCamelCase = (name) => name.toLowerCase().replace(/(-[a-z])/g, group => group.toUpperCase().replace('-', ''));
|
|
11
12
|
export const hasDependency = (dependencies, values) => values.some(value => {
|
|
12
13
|
if (typeof value === 'string') {
|
|
@@ -77,9 +78,9 @@ const toConfigMap = (defaultExtensions, builderConfig) => (moduleName, options)
|
|
|
77
78
|
];
|
|
78
79
|
const rcFiles = `${rcPrefix}${moduleName}${rcSuffix}.{${extensions.join(',')}}`;
|
|
79
80
|
const configExtensions = extensions.filter(ext => config.configFilesAllExtensions || jsTypeExtensions.includes(ext));
|
|
80
|
-
const configFiles =
|
|
81
|
-
const configDirFiles =
|
|
82
|
-
return [...baseFiles, rcFiles, configFiles, configDirFiles]
|
|
81
|
+
const configFiles = config.configFiles ? [`${moduleName}.config.{${configExtensions.join(',')}}`] : [];
|
|
82
|
+
const configDirFiles = config.configDir ? [`.config/${moduleName}${rcSuffix}.{${extensions.join(',')}}`] : [];
|
|
83
|
+
return [...baseFiles, rcFiles, ...configFiles, ...configDirFiles];
|
|
83
84
|
};
|
|
84
85
|
export const toCosmiconfig = toConfigMap(['json', 'yaml', 'yml', 'js', 'ts', 'cjs', 'mjs'], { configDir: true });
|
|
85
86
|
export const toLilconfig = toConfigMap(['json', 'js', 'cjs', 'mjs'], { configDir: true });
|
|
@@ -90,10 +91,10 @@ export const toUnconfig = toConfigMap(['json', 'ts', 'mts', 'cts', 'js', 'mjs',
|
|
|
90
91
|
configFiles: false,
|
|
91
92
|
});
|
|
92
93
|
export const resolveEntry = (options, specifier, rootDir = '.') => {
|
|
93
|
-
const { configFileDir
|
|
94
|
+
const { configFileDir } = options;
|
|
94
95
|
const resolvedPath = isAbsolute(specifier)
|
|
95
96
|
? specifier
|
|
96
|
-
:
|
|
97
|
+
: _resolveSync(join(configFileDir, rootDir, specifier), join(configFileDir, rootDir));
|
|
97
98
|
if (resolvedPath)
|
|
98
99
|
return toEntryPattern(relative(configFileDir, resolvedPath));
|
|
99
100
|
return specifier;
|
package/dist/util/reporter.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ReporterOptions } from '../types/issues.js';
|
|
2
|
-
export declare const runPreprocessors: (
|
|
3
|
-
export declare const runReporters: (options: ReporterOptions) => Promise<void>;
|
|
2
|
+
export declare const runPreprocessors: (processors: string[], data: ReporterOptions) => Promise<ReporterOptions>;
|
|
3
|
+
export declare const runReporters: (reporter: string[], options: ReporterOptions) => Promise<void>;
|
package/dist/util/reporter.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import internalReporters from '../reporters/index.js';
|
|
2
|
-
import parsedArgValues from '../util/cli-arguments.js';
|
|
3
2
|
import { _load } from './loader.js';
|
|
4
3
|
import { isInternal, resolve } from './path.js';
|
|
5
|
-
const
|
|
6
|
-
const preprocessors = await Promise.all(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
export const runPreprocessors = async (processors, data) => {
|
|
5
|
+
const preprocessors = await Promise.all(processors.map(proc => _load(isInternal(proc) ? resolve(proc) : proc)));
|
|
6
|
+
return preprocessors.length === 0
|
|
7
|
+
? Promise.resolve(data)
|
|
8
|
+
: runPreprocessors(preprocessors.slice(1), preprocessors[0](data));
|
|
9
|
+
};
|
|
10
|
+
export const runReporters = async (reporter, options) => {
|
|
11
|
+
const reporters = await Promise.all(reporter.map(async (reporter) => {
|
|
12
|
+
return reporter in internalReporters
|
|
13
|
+
? internalReporters[reporter]
|
|
14
|
+
: await _load(isInternal(reporter) ? resolve(reporter) : reporter);
|
|
15
|
+
}));
|
|
14
16
|
for (const reporter of reporters)
|
|
15
17
|
await reporter(options);
|
|
16
18
|
};
|
package/dist/util/require.d.ts
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
1
|
export declare const _require: NodeRequire;
|
|
2
|
-
export declare const _resolve: (specifier: string) => string;
|
|
3
|
-
export declare const _tryResolve: (specifier: string, from: string) => string | undefined;
|
|
4
|
-
export declare const _resolveSpecifier: (dir: string, specifier: string) => string | undefined;
|
package/dist/util/require.js
CHANGED
|
@@ -1,36 +1,5 @@
|
|
|
1
|
-
import { createRequire
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
import createJITI from 'jiti';
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
4
2
|
import { timerify } from './Performance.js';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { cwd, join, toPosix } from './path.js';
|
|
8
|
-
import { jitiCJS } from './register.js';
|
|
9
|
-
const createRequire = (path) => nodeCreateRequire(pathToFileURL(path ?? cwd));
|
|
10
|
-
const require = createRequire();
|
|
3
|
+
import { cwd } from './path.js';
|
|
4
|
+
const require = createRequire(cwd);
|
|
11
5
|
export const _require = timerify(require);
|
|
12
|
-
const resolve = (specifier) => toPosix(jitiCJS.resolve(specifier));
|
|
13
|
-
const tryResolve = (specifier, from) => {
|
|
14
|
-
try {
|
|
15
|
-
return resolve(specifier);
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
debugLog('*', `Unable to resolve ${specifier} (from ${from})`);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const resolveSpecifier = (dir, specifier) => {
|
|
22
|
-
try {
|
|
23
|
-
const jiti = createJITI(dir);
|
|
24
|
-
return toPosix(jiti.resolve(specifier));
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
const packageName = getPackageNameFromModuleSpecifier(specifier);
|
|
28
|
-
if (packageName) {
|
|
29
|
-
const relativeSpecifier = specifier.replace(packageName, '.');
|
|
30
|
-
return tryResolve(join(dir, relativeSpecifier), dir);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export const _resolve = timerify(resolve);
|
|
35
|
-
export const _tryResolve = timerify(tryResolve);
|
|
36
|
-
export const _resolveSpecifier = timerify(resolveSpecifier);
|
package/dist/util/resolve.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const createSyncResolver: (extensions: string[]) => (specifier: string, baseDir: string) => string | undefined;
|
|
2
|
+
export declare const _resolveSync: (specifier: string, baseDir: string) => string | undefined;
|
package/dist/util/resolve.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import ER from 'enhanced-resolve';
|
|
2
3
|
import { DEFAULT_EXTENSIONS } from '../constants.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import { timerify } from './Performance.js';
|
|
5
|
+
import { toPosix } from './path.js';
|
|
6
|
+
const fileSystem = new ER.CachedInputFileSystem(fs, 9999999);
|
|
7
|
+
export const createSyncResolver = (extensions) => {
|
|
8
|
+
const resolver = ER.create.sync({
|
|
9
|
+
fileSystem,
|
|
10
|
+
extensions,
|
|
11
|
+
conditionNames: ['require', 'import', 'node', 'default'],
|
|
12
|
+
});
|
|
13
|
+
return function resolveSync(specifier, baseDir) {
|
|
14
|
+
try {
|
|
15
|
+
const resolved = resolver({}, baseDir, specifier);
|
|
16
|
+
if (resolved)
|
|
17
|
+
return toPosix(resolved);
|
|
18
|
+
}
|
|
19
|
+
catch (_error) { }
|
|
20
|
+
};
|
|
14
21
|
};
|
|
22
|
+
const resolveSync = createSyncResolver([...DEFAULT_EXTENSIONS, '.json']);
|
|
23
|
+
export const _resolveSync = timerify(resolveSync);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CompilerOptions } from 'typescript';
|
|
2
2
|
import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
|
|
3
|
-
export type ToSourceFilePath = (filePath: string) => undefined | string;
|
|
4
3
|
export declare const augmentWorkspace: (workspace: Workspace, dir: string, compilerOptions: CompilerOptions) => void;
|
|
5
|
-
export declare const getToSourcePathHandler: (chief: ConfigurationChief) =>
|
|
4
|
+
export declare const getToSourcePathHandler: (chief: ConfigurationChief) => (filePath: string) => string | undefined;
|
|
5
|
+
export type ToSourceFilePath = ReturnType<typeof getToSourcePathHandler>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { WatchListener } from 'node:fs';
|
|
2
|
+
import type { ConfigurationChief } from '../ConfigurationChief.js';
|
|
3
|
+
import type { ConsoleStreamer } from '../ConsoleStreamer.js';
|
|
4
|
+
import type { IssueCollector } from '../IssueCollector.js';
|
|
5
|
+
import type { PrincipalFactory } from '../PrincipalFactory.js';
|
|
6
|
+
import type { ProjectPrincipal } from '../ProjectPrincipal.js';
|
|
7
|
+
import type { DependencyGraph } from '../types/dependency-graph.js';
|
|
8
|
+
import type { Report } from '../types/issues.js';
|
|
9
|
+
type Watch = {
|
|
10
|
+
analyzedFiles: Set<string>;
|
|
11
|
+
analyzeSourceFile: (filePath: string, principal: ProjectPrincipal) => void;
|
|
12
|
+
chief: ConfigurationChief;
|
|
13
|
+
collector: IssueCollector;
|
|
14
|
+
collectUnusedExports: () => Promise<void>;
|
|
15
|
+
cwd: string;
|
|
16
|
+
factory: PrincipalFactory;
|
|
17
|
+
graph: DependencyGraph;
|
|
18
|
+
isDebug: boolean;
|
|
19
|
+
isIgnored: (path: string) => boolean;
|
|
20
|
+
report: Report;
|
|
21
|
+
streamer: ConsoleStreamer;
|
|
22
|
+
unreferencedFiles: Set<string>;
|
|
23
|
+
};
|
|
24
|
+
export declare const getWatchHandler: ({ analyzedFiles, analyzeSourceFile, chief, collector, collectUnusedExports, cwd, factory, graph, isDebug, isIgnored, report, streamer, unreferencedFiles, }: Watch) => Promise<WatchListener<string | Buffer>>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import watchReporter from '../reporters/watch.js';
|
|
2
|
+
import { debugLog } from './debug.js';
|
|
3
|
+
import { updateImportMap } from './dependency-graph.js';
|
|
4
|
+
import { isFile } from './fs.js';
|
|
5
|
+
import { join, toPosix } from './path.js';
|
|
6
|
+
export const getWatchHandler = async ({ analyzedFiles, analyzeSourceFile, chief, collector, collectUnusedExports, cwd, factory, graph, isDebug, isIgnored, report, streamer, unreferencedFiles, }) => {
|
|
7
|
+
const reportIssues = async (startTime) => {
|
|
8
|
+
const { issues } = collector.getIssues();
|
|
9
|
+
watchReporter({ report, issues, streamer, startTime, size: analyzedFiles.size, isDebug });
|
|
10
|
+
};
|
|
11
|
+
const listener = async (eventType, filename) => {
|
|
12
|
+
debugLog('*', `(raw) ${eventType} ${filename}`);
|
|
13
|
+
if (typeof filename === 'string') {
|
|
14
|
+
const startTime = performance.now();
|
|
15
|
+
const filePath = join(cwd, toPosix(filename));
|
|
16
|
+
if (isIgnored(filePath)) {
|
|
17
|
+
debugLog('*', `ignoring ${eventType} ${filename}`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const workspace = chief.findWorkspaceByFilePath(filePath);
|
|
21
|
+
if (workspace) {
|
|
22
|
+
const principal = factory.getPrincipalByPackageName(workspace.pkgName);
|
|
23
|
+
if (principal) {
|
|
24
|
+
const event = eventType === 'rename' ? (isFile(filePath) ? 'added' : 'deleted') : 'modified';
|
|
25
|
+
principal.invalidateFile(filePath);
|
|
26
|
+
unreferencedFiles.clear();
|
|
27
|
+
const cachedUnusedFiles = collector.purge();
|
|
28
|
+
switch (event) {
|
|
29
|
+
case 'added':
|
|
30
|
+
principal.addProjectPath(filePath);
|
|
31
|
+
principal.deletedFiles.delete(filePath);
|
|
32
|
+
cachedUnusedFiles.add(filePath);
|
|
33
|
+
debugLog(workspace.name, `Watcher: + ${filename}`);
|
|
34
|
+
break;
|
|
35
|
+
case 'deleted':
|
|
36
|
+
analyzedFiles.delete(filePath);
|
|
37
|
+
principal.removeProjectPath(filePath);
|
|
38
|
+
cachedUnusedFiles.delete(filePath);
|
|
39
|
+
debugLog(workspace.name, `Watcher: - ${filename}`);
|
|
40
|
+
break;
|
|
41
|
+
case 'modified':
|
|
42
|
+
debugLog(workspace.name, `Watcher: ± ${filename}`);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
const filePaths = principal.getUsedResolvedFiles();
|
|
46
|
+
if (event === 'added' || event === 'deleted') {
|
|
47
|
+
graph.clear();
|
|
48
|
+
for (const filePath of filePaths)
|
|
49
|
+
analyzeSourceFile(filePath, principal);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
for (const [filePath, file] of graph) {
|
|
53
|
+
if (filePaths.includes(filePath)) {
|
|
54
|
+
file.imported = undefined;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
graph.delete(filePath);
|
|
58
|
+
analyzedFiles.delete(filePath);
|
|
59
|
+
cachedUnusedFiles.add(filePath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const filePath of filePaths)
|
|
63
|
+
if (!graph.has(filePath))
|
|
64
|
+
analyzeSourceFile(filePath, principal);
|
|
65
|
+
if (!cachedUnusedFiles.has(filePath))
|
|
66
|
+
analyzeSourceFile(filePath, principal);
|
|
67
|
+
for (const filePath of filePaths) {
|
|
68
|
+
const file = graph.get(filePath);
|
|
69
|
+
if (file?.internalImportCache)
|
|
70
|
+
updateImportMap(file, file.internalImportCache, graph);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
await collectUnusedExports();
|
|
74
|
+
const unusedFiles = [...cachedUnusedFiles].filter(filePath => !analyzedFiles.has(filePath));
|
|
75
|
+
collector.addFilesIssues(unusedFiles);
|
|
76
|
+
collector.addFileCounts({ processed: analyzedFiles.size, unused: unusedFiles.length });
|
|
77
|
+
await reportIssues(startTime);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
await collectUnusedExports();
|
|
83
|
+
await reportIssues();
|
|
84
|
+
return listener;
|
|
85
|
+
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.27.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.27.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "knip",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.27.1",
|
|
4
4
|
"description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
|
|
5
5
|
"homepage": "https://knip.dev",
|
|
6
6
|
"repository": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"lint": "biome lint ../..",
|
|
46
46
|
"format": "biome format --write .",
|
|
47
47
|
"test": "bun test test/*.test.ts test/**/*.test.ts",
|
|
48
|
-
"test:node": "glob -c \"npx -y tsx
|
|
48
|
+
"test:node": "glob -c \"npx -y tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
|
|
49
49
|
"watch": "npm link && tsc --watch",
|
|
50
50
|
"prebuild": "node rmdir.js dist",
|
|
51
51
|
"build": "tsc",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"@nodelib/fs.walk": "1.2.8",
|
|
65
65
|
"@snyk/github-codeowners": "1.1.0",
|
|
66
66
|
"easy-table": "1.2.0",
|
|
67
|
+
"enhanced-resolve": "^5.17.1",
|
|
67
68
|
"fast-glob": "^3.3.2",
|
|
68
69
|
"jiti": "^1.21.6",
|
|
69
70
|
"js-yaml": "^4.1.0",
|
|
@@ -71,7 +72,6 @@
|
|
|
71
72
|
"picocolors": "^1.0.0",
|
|
72
73
|
"picomatch": "^4.0.1",
|
|
73
74
|
"pretty-ms": "^9.0.0",
|
|
74
|
-
"resolve": "^1.22.8",
|
|
75
75
|
"smol-toml": "^1.1.4",
|
|
76
76
|
"strip-json-comments": "5.0.1",
|
|
77
77
|
"summary": "2.1.0",
|
|
@@ -89,11 +89,9 @@
|
|
|
89
89
|
"@types/js-yaml": "^4.0.9",
|
|
90
90
|
"@types/minimist": "^1.2.5",
|
|
91
91
|
"@types/picomatch": "2.3.4",
|
|
92
|
-
"@types/resolve": "^1.20.6",
|
|
93
92
|
"@types/webpack": "^5.28.5",
|
|
94
93
|
"@wdio/types": "^8.39.0",
|
|
95
94
|
"glob": "^10.4.2",
|
|
96
|
-
"playwright": "^1.44.1",
|
|
97
95
|
"release-it": "^17.4.1",
|
|
98
96
|
"type-fest": "^4.20.0",
|
|
99
97
|
"typescript": "^5.5.2"
|
package/schema.json
CHANGED
|
@@ -356,6 +356,10 @@
|
|
|
356
356
|
"title": "Jest plugin configuration (https://knip.dev/reference/plugins/jest)",
|
|
357
357
|
"$ref": "#/definitions/plugin"
|
|
358
358
|
},
|
|
359
|
+
"ladle": {
|
|
360
|
+
"title": "ladle plugin configuration (https://knip.dev/reference/plugins/ladle)",
|
|
361
|
+
"$ref": "#/definitions/plugin"
|
|
362
|
+
},
|
|
359
363
|
"lefthook": {
|
|
360
364
|
"title": "lefthook plugin configuration (https://knip.dev/reference/plugins/lefthook)",
|
|
361
365
|
"$ref": "#/definitions/plugin"
|
|
@@ -436,6 +440,10 @@
|
|
|
436
440
|
"title": "Prettier plugin configuration (https://knip.dev/reference/plugins/prettier)",
|
|
437
441
|
"$ref": "#/definitions/plugin"
|
|
438
442
|
},
|
|
443
|
+
"react-cosmos": {
|
|
444
|
+
"title": "react-cosmos plugin configuration (https://knip.dev/reference/plugins/react-cosmos)",
|
|
445
|
+
"$ref": "#/definitions/plugin"
|
|
446
|
+
},
|
|
439
447
|
"release-it": {
|
|
440
448
|
"title": "Release It plugin configuration (https://knip.dev/reference/plugins/release-it)",
|
|
441
449
|
"$ref": "#/definitions/plugin"
|
|
@@ -452,6 +460,14 @@
|
|
|
452
460
|
"title": "Rollup plugin configuration (https://knip.dev/reference/plugins/rollup)",
|
|
453
461
|
"$ref": "#/definitions/plugin"
|
|
454
462
|
},
|
|
463
|
+
"rsbuild": {
|
|
464
|
+
"title": "rsbuild plugin configuration (https://knip.dev/reference/plugins/rsbuild)",
|
|
465
|
+
"$ref": "#/definitions/plugin"
|
|
466
|
+
},
|
|
467
|
+
"rspack": {
|
|
468
|
+
"title": "rspack plugin configuration (https://knip.dev/reference/plugins/rspack)",
|
|
469
|
+
"$ref": "#/definitions/plugin"
|
|
470
|
+
},
|
|
455
471
|
"semantic-release": {
|
|
456
472
|
"title": "semantic-release plugin configuration (https://knip.dev/reference/plugins/semantic-release)",
|
|
457
473
|
"$ref": "#/definitions/plugin"
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PackageJson } from '../types/package-json.js';
|
|
2
|
-
interface Package {
|
|
3
|
-
manifest: PackageJson;
|
|
4
|
-
dir: string;
|
|
5
|
-
}
|
|
6
|
-
export type Graph = Record<string, Set<string>>;
|
|
7
|
-
export declare function createPkgGraph(cwd: string, wsNames: string[], wsPkgNames: Set<string>, byPkgName: Map<string, Package>, byName: Map<string, Package>): Graph;
|
|
8
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|