knip 3.4.0 → 3.5.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/ProjectPrincipal.js +2 -2
- package/dist/WorkspaceWorker.js +3 -2
- package/dist/constants.js +1 -0
- package/dist/plugins/_template/index.js +2 -4
- package/dist/plugins/astro/index.js +1 -1
- package/dist/plugins/ava/index.js +4 -6
- package/dist/plugins/babel/index.js +2 -3
- package/dist/plugins/commitizen/index.js +2 -3
- package/dist/plugins/commitlint/index.js +2 -3
- package/dist/plugins/eslint/helpers.js +2 -2
- package/dist/plugins/eslint/index.js +2 -1
- package/dist/plugins/github-actions/index.js +2 -3
- package/dist/plugins/graphql-codegen/index.js +2 -4
- package/dist/plugins/husky/index.js +2 -3
- package/dist/plugins/jest/index.js +4 -4
- package/dist/plugins/lefthook/index.js +5 -5
- package/dist/plugins/lint-staged/index.js +4 -6
- package/dist/plugins/mocha/index.js +2 -3
- package/dist/plugins/node-test-runner/index.js +1 -5
- package/dist/plugins/npm-package-json-lint/index.js +2 -3
- package/dist/plugins/nx/index.js +2 -3
- package/dist/plugins/postcss/index.js +2 -3
- package/dist/plugins/prettier/index.js +2 -3
- package/dist/plugins/release-it/index.js +4 -6
- package/dist/plugins/remark/index.js +2 -3
- package/dist/plugins/semantic-release/index.js +2 -3
- package/dist/plugins/stylelint/index.js +2 -4
- package/dist/plugins/typedoc/index.js +3 -2
- package/dist/plugins/vite/index.js +1 -1
- package/dist/plugins/vitest/index.js +12 -6
- package/dist/plugins/webpack/index.js +2 -2
- package/dist/types/plugins.d.ts +1 -0
- package/dist/typescript/getImportsAndExports.js +3 -2
- package/dist/util/cli-arguments.d.ts +1 -1
- package/dist/util/cli-arguments.js +1 -1
- package/dist/util/modules.d.ts +1 -1
- package/dist/util/modules.js +2 -2
- package/dist/util/path.d.ts +1 -0
- package/dist/util/path.js +1 -0
- package/dist/util/plugin.d.ts +1 -0
- package/dist/util/plugin.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getImportsAndExports } from './typescript/getImportsAndExports.js';
|
|
|
7
7
|
import { createCustomModuleResolver } from './typescript/resolveModuleNames.js';
|
|
8
8
|
import { SourceFileManager } from './typescript/SourceFileManager.js';
|
|
9
9
|
import { compact } from './util/array.js';
|
|
10
|
-
import {
|
|
10
|
+
import { isStartsLikePackageName, sanitizeSpecifier } from './util/modules.js';
|
|
11
11
|
import { dirname, extname, isInNodeModules, join } from './util/path.js';
|
|
12
12
|
import { timerify } from './util/Performance.js';
|
|
13
13
|
const baseCompilerOptions = {
|
|
@@ -145,7 +145,7 @@ export class ProjectPrincipal {
|
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
147
|
const sanitizedSpecifier = sanitizeSpecifier(specifier);
|
|
148
|
-
if (
|
|
148
|
+
if (isStartsLikePackageName(sanitizedSpecifier)) {
|
|
149
149
|
external.add(sanitizedSpecifier);
|
|
150
150
|
}
|
|
151
151
|
else {
|
package/dist/WorkspaceWorker.js
CHANGED
|
@@ -4,7 +4,7 @@ import { debugLogArray, debugLogObject } from './util/debug.js';
|
|
|
4
4
|
import { _pureGlob, negate, hasProductionSuffix, hasNoProductionSuffix, prependDirToPattern } from './util/glob.js';
|
|
5
5
|
import { FAKE_PATH } from './util/loader.js';
|
|
6
6
|
import { get, getKeysByValue } from './util/object.js';
|
|
7
|
-
import { join, toPosix } from './util/path.js';
|
|
7
|
+
import { basename, join, toPosix } from './util/path.js';
|
|
8
8
|
import { fromEntryPattern, fromProductionEntryPattern, isEntryPattern, isProductionEntryPattern, } from './util/protocols.js';
|
|
9
9
|
const nullConfig = { config: null, entry: null, project: null };
|
|
10
10
|
export class WorkspaceWorker {
|
|
@@ -183,7 +183,7 @@ export class WorkspaceWorker {
|
|
|
183
183
|
continue;
|
|
184
184
|
const patterns = this.getConfigurationFilePatterns(pluginName);
|
|
185
185
|
const allConfigFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
|
|
186
|
-
const configFilePaths = allConfigFilePaths.filter(filePath =>
|
|
186
|
+
const configFilePaths = allConfigFilePaths.filter(filePath => basename(filePath) !== 'package.json' ||
|
|
187
187
|
get(this.manifest, 'PACKAGE_JSON_PATH' in plugin ? plugin.PACKAGE_JSON_PATH : pluginName));
|
|
188
188
|
debugLogArray([name, plugin.NAME], 'config file paths', configFilePaths);
|
|
189
189
|
if (configFilePaths.length === 0)
|
|
@@ -195,6 +195,7 @@ export class WorkspaceWorker {
|
|
|
195
195
|
manifest: this.manifest,
|
|
196
196
|
config: pluginConfig,
|
|
197
197
|
isProduction: this.isProduction,
|
|
198
|
+
enabledPlugins: this.enabledPlugins,
|
|
198
199
|
});
|
|
199
200
|
dependencies.forEach(specifier => {
|
|
200
201
|
pluginDependencies.add(specifier);
|
package/dist/constants.js
CHANGED
|
@@ -33,6 +33,7 @@ export const IGNORED_GLOBAL_BINARIES = [
|
|
|
33
33
|
'test',
|
|
34
34
|
'true',
|
|
35
35
|
'yarn',
|
|
36
|
+
'xargs',
|
|
36
37
|
];
|
|
37
38
|
export const IGNORED_DEPENDENCIES = ['knip', 'typescript'];
|
|
38
39
|
export const DUMMY_VIRTUAL_FILE_EXTENSIONS = new Set(['.html', '.jpeg', '.jpg', '.png', '.svg', '.webp']);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
|
|
@@ -10,10 +11,7 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [];
|
|
|
10
11
|
export const PROJECT_FILE_PATTERNS = [];
|
|
11
12
|
const findPluginDependencies = async (configFilePath, options) => {
|
|
12
13
|
const { manifest, config, isProduction } = options;
|
|
13
|
-
const localConfig = configFilePath
|
|
14
|
-
?
|
|
15
|
-
manifest.plugin
|
|
16
|
-
: await load(configFilePath);
|
|
14
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.plugin : await load(configFilePath);
|
|
17
15
|
if (!localConfig)
|
|
18
16
|
return [];
|
|
19
17
|
const entryPatterns = (config?.entry ?? localConfig.entryPathsOrPatterns ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
@@ -12,7 +12,7 @@ export const findDependencies = async (configFilePath, options) => {
|
|
|
12
12
|
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
|
|
13
13
|
if (!isProduction &&
|
|
14
14
|
manifest.scripts &&
|
|
15
|
-
Object.values(manifest.scripts).some(script => /astro
|
|
15
|
+
Object.values(manifest.scripts).some(script => /(?<=^|\s)astro(\s|\s.+\s)check(?=\s|$)/.test(script))) {
|
|
16
16
|
dependencies.push('@astrojs/check');
|
|
17
17
|
}
|
|
18
18
|
return dependencies;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
|
-
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
5
5
|
export const NAME = 'Ava';
|
|
6
6
|
export const ENABLERS = ['ava'];
|
|
@@ -20,9 +20,7 @@ export const ENTRY_FILE_PATTERNS = [
|
|
|
20
20
|
];
|
|
21
21
|
const findAvaDependencies = async (configFilePath, options) => {
|
|
22
22
|
const { cwd, manifest, isProduction, config } = options;
|
|
23
|
-
let localConfig = configFilePath
|
|
24
|
-
? manifest.ava
|
|
25
|
-
: await load(configFilePath);
|
|
23
|
+
let localConfig = basename(configFilePath) === 'package.json' ? manifest.ava : await load(configFilePath);
|
|
26
24
|
if (typeof localConfig === 'function')
|
|
27
25
|
localConfig = localConfig();
|
|
28
26
|
const entryPatterns = (config.entry ?? localConfig?.files ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
@@ -31,7 +29,7 @@ const findAvaDependencies = async (configFilePath, options) => {
|
|
|
31
29
|
const nodeArgs = localConfig.nodeArguments ?? [];
|
|
32
30
|
const requireArgs = (localConfig.require ?? []).map(require => `--require ${require}`);
|
|
33
31
|
const fakeCommand = `node ${nodeArgs.join(' ')} ${requireArgs.join(' ')}`;
|
|
34
|
-
const dependencies =
|
|
32
|
+
const dependencies = getDependenciesFromScripts([fakeCommand], {
|
|
35
33
|
cwd,
|
|
36
34
|
manifest,
|
|
37
35
|
knownGlobalsOnly: true,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
+
import { basename } from '../../util/path.js';
|
|
2
3
|
import { timerify } from '../../util/Performance.js';
|
|
3
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
5
|
import { resolveName, api } from './helpers.js';
|
|
@@ -21,9 +22,7 @@ export const getDependenciesFromConfig = (config) => {
|
|
|
21
22
|
const findBabelDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
22
23
|
if (isProduction)
|
|
23
24
|
return [];
|
|
24
|
-
let localConfig = configFilePath
|
|
25
|
-
? manifest.babel
|
|
26
|
-
: await load(configFilePath);
|
|
25
|
+
let localConfig = basename(configFilePath) === 'package.json' ? manifest.babel : await load(configFilePath);
|
|
27
26
|
if (typeof localConfig === 'function')
|
|
28
27
|
localConfig = localConfig(api);
|
|
29
28
|
if (!localConfig)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'Commitizen';
|
|
@@ -8,9 +9,7 @@ export const CONFIG_FILE_PATTERNS = ['.czrc', '.cz.json', 'package.json'];
|
|
|
8
9
|
const findPluginDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
9
10
|
if (isProduction)
|
|
10
11
|
return [];
|
|
11
|
-
const localConfig = configFilePath
|
|
12
|
-
? manifest.config?.commitizen
|
|
13
|
-
: await load(configFilePath);
|
|
12
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.config?.commitizen : await load(configFilePath);
|
|
14
13
|
if (!localConfig)
|
|
15
14
|
return [];
|
|
16
15
|
return localConfig.path ? [localConfig.path] : [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'commitlint';
|
|
@@ -12,9 +13,7 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
13
|
const findCommitLintDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
13
14
|
if (isProduction)
|
|
14
15
|
return [];
|
|
15
|
-
const localConfig = configFilePath
|
|
16
|
-
? manifest.commitlint
|
|
17
|
-
: await load(configFilePath);
|
|
16
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.commitlint : await load(configFilePath);
|
|
18
17
|
if (!localConfig)
|
|
19
18
|
return [];
|
|
20
19
|
return localConfig.extends ? [localConfig.extends].flat() : [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
2
|
import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
|
|
3
|
-
import { isInternal, dirname, toAbsolute } from '../../util/path.js';
|
|
3
|
+
import { basename, isInternal, dirname, toAbsolute } from '../../util/path.js';
|
|
4
4
|
import { load } from '../../util/plugin.js';
|
|
5
5
|
import { _resolve } from '../../util/require.js';
|
|
6
6
|
import { getDependenciesFromConfig } from '../babel/index.js';
|
|
@@ -21,7 +21,7 @@ const getDependencies = (config) => {
|
|
|
21
21
|
};
|
|
22
22
|
export const getDependenciesDeep = async (configFilePath, options, dependencies = new Set()) => {
|
|
23
23
|
const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
|
|
24
|
-
const localConfig = configFilePath
|
|
24
|
+
const localConfig = basename(configFilePath) === 'package.json'
|
|
25
25
|
? options.manifest[PACKAGE_JSON_PATH]
|
|
26
26
|
: /(\.(jsonc?|ya?ml)|rc)$/.test(configFilePath)
|
|
27
27
|
? await load(configFilePath)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency } from '../../util/plugin.js';
|
|
3
4
|
import { getDependenciesDeep } from './helpers.js';
|
|
@@ -17,7 +18,7 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
17
18
|
const findESLintDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
|
|
18
19
|
if (isProduction)
|
|
19
20
|
return [];
|
|
20
|
-
if (configFilePath
|
|
21
|
+
if (basename(configFilePath) === 'eslint.config.js')
|
|
21
22
|
return [];
|
|
22
23
|
const dependencies = await getDependenciesDeep(configFilePath, { cwd, manifest });
|
|
23
24
|
return Array.from(dependencies);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
1
|
import { _firstGlob } from '../../util/glob.js';
|
|
3
2
|
import { getValuesByKeyDeep } from '../../util/object.js';
|
|
4
3
|
import { timerify } from '../../util/Performance.js';
|
|
5
|
-
import { load } from '../../util/plugin.js';
|
|
4
|
+
import { getDependenciesFromScripts, load } from '../../util/plugin.js';
|
|
6
5
|
export const NAME = 'GitHub Actions';
|
|
7
6
|
export const ENABLERS = 'This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.';
|
|
8
7
|
export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.{yml,yaml}'] }));
|
|
@@ -15,7 +14,7 @@ const findGithubActionsDependencies = async (configFilePath, options) => {
|
|
|
15
14
|
if (!config)
|
|
16
15
|
return [];
|
|
17
16
|
const scripts = getValuesByKeyDeep(config, 'run').filter((value) => typeof value === 'string');
|
|
18
|
-
return
|
|
17
|
+
return getDependenciesFromScripts(scripts, {
|
|
19
18
|
cwd,
|
|
20
19
|
manifest,
|
|
21
20
|
knownGlobalsOnly: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isInternal } from '../../util/path.js';
|
|
1
|
+
import { basename, isInternal } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
@@ -17,9 +17,7 @@ const findPluginDependencies = async (configFilePath, options) => {
|
|
|
17
17
|
const { manifest, isProduction } = options;
|
|
18
18
|
if (isProduction)
|
|
19
19
|
return [];
|
|
20
|
-
const localConfig = configFilePath
|
|
21
|
-
? manifest[PACKAGE_JSON_PATH]
|
|
22
|
-
: await load(configFilePath);
|
|
20
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
|
|
23
21
|
if (!localConfig)
|
|
24
22
|
return [];
|
|
25
23
|
const generateSet = Object.values(localConfig.generates);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
1
|
import { getGitHookPaths } from '../../util/git.js';
|
|
3
2
|
import { FAKE_PATH } from '../../util/loader.js';
|
|
4
3
|
import { timerify } from '../../util/Performance.js';
|
|
5
|
-
import { hasDependency, loadFile } from '../../util/plugin.js';
|
|
4
|
+
import { getDependenciesFromScripts, hasDependency, loadFile } from '../../util/plugin.js';
|
|
6
5
|
export const NAME = 'husky';
|
|
7
6
|
export const ENABLERS = ['husky'];
|
|
8
7
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
@@ -15,7 +14,7 @@ const findHuskyDependencies = async (configFilePath, options) => {
|
|
|
15
14
|
const script = await loadFile(configFilePath);
|
|
16
15
|
if (!script)
|
|
17
16
|
return [];
|
|
18
|
-
return
|
|
17
|
+
return getDependenciesFromScripts(String(script), {
|
|
19
18
|
cwd,
|
|
20
19
|
manifest,
|
|
21
20
|
knownGlobalsOnly: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, isInternal, toAbsolute, dirname } from '../../util/path.js';
|
|
1
|
+
import { basename, join, isInternal, toAbsolute, dirname } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
@@ -46,6 +46,7 @@ const resolveDependencies = (config, options) => {
|
|
|
46
46
|
? Object.values(config.moduleNameMapper).map(mapper => (typeof mapper === 'string' ? mapper : mapper[0]))
|
|
47
47
|
: []).filter(value => !/\$[0-9]/.test(value));
|
|
48
48
|
const testResultsProcessor = config.testResultsProcessor ? [config.testResultsProcessor] : [];
|
|
49
|
+
const snapshotResolver = config.snapshotResolver ? [config.snapshotResolver] : [];
|
|
49
50
|
return [
|
|
50
51
|
...entryPatterns,
|
|
51
52
|
...presets,
|
|
@@ -60,13 +61,12 @@ const resolveDependencies = (config, options) => {
|
|
|
60
61
|
...transform,
|
|
61
62
|
...moduleNameMapper,
|
|
62
63
|
...testResultsProcessor,
|
|
64
|
+
...snapshotResolver,
|
|
63
65
|
];
|
|
64
66
|
};
|
|
65
67
|
const findJestDependencies = async (configFilePath, options) => {
|
|
66
68
|
const { manifest, cwd } = options;
|
|
67
|
-
let localConfig = configFilePath
|
|
68
|
-
? manifest.jest
|
|
69
|
-
: await resolveExtensibleConfig(configFilePath);
|
|
69
|
+
let localConfig = basename(configFilePath) === 'package.json' ? manifest.jest : await resolveExtensibleConfig(configFilePath);
|
|
70
70
|
if (typeof localConfig === 'function')
|
|
71
71
|
localConfig = await localConfig();
|
|
72
72
|
if (!localConfig)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
1
|
import { getGitHookPaths } from '../../util/git.js';
|
|
3
2
|
import { getValuesByKeyDeep } from '../../util/object.js';
|
|
3
|
+
import { extname } from '../../util/path.js';
|
|
4
4
|
import { timerify } from '../../util/Performance.js';
|
|
5
|
-
import { hasDependency, load, loadFile } from '../../util/plugin.js';
|
|
5
|
+
import { getDependenciesFromScripts, hasDependency, load, loadFile } from '../../util/plugin.js';
|
|
6
6
|
import { fromBinary } from '../../util/protocols.js';
|
|
7
7
|
export const NAME = 'Lefthook';
|
|
8
8
|
export const ENABLERS = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthook'];
|
|
@@ -14,18 +14,18 @@ const findLefthookDependencies = async (configFilePath, options) => {
|
|
|
14
14
|
if (isProduction)
|
|
15
15
|
return [];
|
|
16
16
|
const dependencies = manifest.devDependencies ? Object.keys(manifest.devDependencies) : [];
|
|
17
|
-
if (configFilePath
|
|
17
|
+
if (extname(configFilePath) === '.yml') {
|
|
18
18
|
const localConfig = await load(configFilePath);
|
|
19
19
|
if (!localConfig)
|
|
20
20
|
return [];
|
|
21
21
|
const scripts = getValuesByKeyDeep(localConfig, 'run').filter((run) => typeof run === 'string');
|
|
22
22
|
const lefthook = process.env.CI ? ENABLERS.filter(dependency => dependencies.includes(dependency)) : [];
|
|
23
|
-
return [...lefthook, ...
|
|
23
|
+
return [...lefthook, ...getDependenciesFromScripts(scripts, { cwd, manifest, knownGlobalsOnly: true })];
|
|
24
24
|
}
|
|
25
25
|
const script = await loadFile(configFilePath);
|
|
26
26
|
if (!script)
|
|
27
27
|
return [];
|
|
28
|
-
const scriptDependencies =
|
|
28
|
+
const scriptDependencies = getDependenciesFromScripts([script], { cwd, manifest, knownGlobalsOnly: false });
|
|
29
29
|
const matches = scriptDependencies.find(dep => dependencies.includes(fromBinary(dep)));
|
|
30
30
|
return matches ? [matches] : [];
|
|
31
31
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
|
-
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'lint-staged';
|
|
5
5
|
export const ENABLERS = ['lint-staged'];
|
|
6
6
|
export const PACKAGE_JSON_PATH = 'lint-staged';
|
|
@@ -17,9 +17,7 @@ const findLintStagedDependencies = async (configFilePath, options) => {
|
|
|
17
17
|
const { cwd, manifest, isProduction } = options;
|
|
18
18
|
if (isProduction)
|
|
19
19
|
return [];
|
|
20
|
-
let localConfig = configFilePath
|
|
21
|
-
? manifest['lint-staged']
|
|
22
|
-
: await load(configFilePath);
|
|
20
|
+
let localConfig = basename(configFilePath) === 'package.json' ? manifest['lint-staged'] : await load(configFilePath);
|
|
23
21
|
if (typeof localConfig === 'function')
|
|
24
22
|
localConfig = localConfig();
|
|
25
23
|
if (!localConfig)
|
|
@@ -28,7 +26,7 @@ const findLintStagedDependencies = async (configFilePath, options) => {
|
|
|
28
26
|
for (const entry of Object.values(localConfig).flat()) {
|
|
29
27
|
const scripts = [typeof entry === 'function' ? await entry([]) : entry].flat();
|
|
30
28
|
const options = { cwd, manifest };
|
|
31
|
-
|
|
29
|
+
getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
|
|
32
30
|
}
|
|
33
31
|
return Array.from(dependencies);
|
|
34
32
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
@@ -8,9 +9,7 @@ export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'p
|
|
|
8
9
|
export const ENTRY_FILE_PATTERNS = ['**/test/*.{js,cjs,mjs}'];
|
|
9
10
|
const findMochaDependencies = async (configFilePath, options) => {
|
|
10
11
|
const { config, manifest, isProduction } = options;
|
|
11
|
-
const localConfig = configFilePath
|
|
12
|
-
? manifest.mocha
|
|
13
|
-
: await load(configFilePath);
|
|
12
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.mocha : await load(configFilePath);
|
|
14
13
|
const entryPatterns = (config.entry ?? (localConfig?.spec ? [localConfig.spec].flat() : ENTRY_FILE_PATTERNS)).map(toEntryPattern);
|
|
15
14
|
if (isProduction || !localConfig)
|
|
16
15
|
return entryPatterns;
|
|
@@ -2,11 +2,7 @@ import { timerify } from '../../util/Performance.js';
|
|
|
2
2
|
import { toEntryPattern } from '../../util/protocols.js';
|
|
3
3
|
export const NAME = 'Node.js Test Runner';
|
|
4
4
|
export const ENABLERS = 'This plugin is enabled when any script in `package.json` includes `node --test`';
|
|
5
|
-
export const isEnabled = ({ manifest }) => {
|
|
6
|
-
return Object.keys(manifest.scripts ?? {})
|
|
7
|
-
.filter(s => /test/.test(s))
|
|
8
|
-
.some(s => manifest.scripts && /node (.*)--test/.test(manifest.scripts[s]));
|
|
9
|
-
};
|
|
5
|
+
export const isEnabled = ({ manifest }) => Object.keys(manifest.scripts ?? {}).some(script => manifest.scripts && /(?<=^|\s)node (.*)--test/.test(manifest.scripts[script]));
|
|
10
6
|
export const ENTRY_FILE_PATTERNS = [
|
|
11
7
|
'**/*{.,-,_}test.?(c|m)js',
|
|
12
8
|
'**/test-*.?(c|m)js',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'npm-package-json-lint';
|
|
@@ -9,9 +10,7 @@ const findNpmPkgJsonLintConfigDependencies = async (configFilePath, options) =>
|
|
|
9
10
|
const { manifest, isProduction } = options;
|
|
10
11
|
if (isProduction)
|
|
11
12
|
return [];
|
|
12
|
-
const localConfig = configFilePath
|
|
13
|
-
? manifest[PACKAGE_JSON_PATH]
|
|
14
|
-
: await load(configFilePath);
|
|
13
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
|
|
15
14
|
return localConfig?.extends ? [localConfig.extends] : [];
|
|
16
15
|
};
|
|
17
16
|
export const findDependencies = timerify(findNpmPkgJsonLintConfigDependencies);
|
package/dist/plugins/nx/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { _getDependenciesFromScripts } from '../../binaries/index.js';
|
|
2
1
|
import { compact } from '../../util/array.js';
|
|
3
2
|
import { timerify } from '../../util/Performance.js';
|
|
4
|
-
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
|
|
5
4
|
export const NAME = 'Nx';
|
|
6
5
|
export const ENABLERS = ['nx', /^@nrwl\//, /^@nx\//];
|
|
7
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
@@ -21,7 +20,7 @@ const findNxDependencies = async (configFilePath, options) => {
|
|
|
21
20
|
const scripts = targets
|
|
22
21
|
.filter(target => target.executor === 'nx:run-commands')
|
|
23
22
|
.flatMap(target => target.options?.commands ?? (target.options?.command ? [target.options.command] : []));
|
|
24
|
-
const dependencies =
|
|
23
|
+
const dependencies = getDependenciesFromScripts(scripts, { cwd, manifest });
|
|
25
24
|
return compact([...executors, ...dependencies]);
|
|
26
25
|
};
|
|
27
26
|
export const findDependencies = timerify(findNxDependencies);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'PostCSS';
|
|
@@ -8,9 +9,7 @@ const findPostCSSDependencies = async (configFilePath, options) => {
|
|
|
8
9
|
const { manifest, isProduction } = options;
|
|
9
10
|
if (isProduction)
|
|
10
11
|
return [];
|
|
11
|
-
const localConfig = configFilePath
|
|
12
|
-
? manifest?.postcss
|
|
13
|
-
: await load(configFilePath);
|
|
12
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest?.postcss : await load(configFilePath);
|
|
14
13
|
if (!localConfig)
|
|
15
14
|
return [];
|
|
16
15
|
return localConfig.plugins
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'Prettier';
|
|
@@ -12,9 +13,7 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
13
|
const findPrettierDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
13
14
|
if (isProduction)
|
|
14
15
|
return [];
|
|
15
|
-
const localConfig = configFilePath
|
|
16
|
-
? manifest.prettier
|
|
17
|
-
: await load(configFilePath);
|
|
16
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.prettier : await load(configFilePath);
|
|
18
17
|
if (typeof localConfig === 'string') {
|
|
19
18
|
return [localConfig];
|
|
20
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
|
-
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
|
+
import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Release It';
|
|
5
5
|
export const ENABLERS = ['release-it'];
|
|
6
6
|
export const PACKAGE_JSON_PATH = 'release-it';
|
|
@@ -15,9 +15,7 @@ const findReleaseItDependencies = async (configFilePath, options) => {
|
|
|
15
15
|
const { cwd, manifest, isProduction } = options;
|
|
16
16
|
if (isProduction)
|
|
17
17
|
return [];
|
|
18
|
-
const localConfig = configFilePath
|
|
19
|
-
? manifest[PACKAGE_JSON_PATH]
|
|
20
|
-
: await load(configFilePath);
|
|
18
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
|
|
21
19
|
if (!localConfig)
|
|
22
20
|
return [];
|
|
23
21
|
const plugins = localConfig.plugins ? Object.keys(localConfig.plugins) : [];
|
|
@@ -28,7 +26,7 @@ const findReleaseItDependencies = async (configFilePath, options) => {
|
|
|
28
26
|
if (typeof localConfig.gitlab?.releaseNotes === 'string') {
|
|
29
27
|
scripts.push(localConfig.gitlab.releaseNotes);
|
|
30
28
|
}
|
|
31
|
-
const dependencies =
|
|
29
|
+
const dependencies = getDependenciesFromScripts(scripts, { cwd, manifest });
|
|
32
30
|
return [...plugins, ...dependencies];
|
|
33
31
|
};
|
|
34
32
|
export const findDependencies = timerify(findReleaseItDependencies);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'Remark';
|
|
@@ -15,9 +16,7 @@ const findRemarkDependencies = async (configFilePath, options) => {
|
|
|
15
16
|
const { manifest, isProduction } = options;
|
|
16
17
|
if (isProduction)
|
|
17
18
|
return [];
|
|
18
|
-
const localConfig = configFilePath
|
|
19
|
-
? manifest[PACKAGE_JSON_PATH]
|
|
20
|
-
: await load(configFilePath);
|
|
19
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
|
|
21
20
|
if (!localConfig)
|
|
22
21
|
return [];
|
|
23
22
|
const plugins = localConfig.plugins
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'Semantic Release';
|
|
@@ -14,9 +15,7 @@ const findSemanticReleaseDependencies = async (configFilePath, options) => {
|
|
|
14
15
|
const { manifest, isProduction } = options;
|
|
15
16
|
if (isProduction)
|
|
16
17
|
return [];
|
|
17
|
-
const localConfig = configFilePath
|
|
18
|
-
? manifest[PACKAGE_JSON_PATH]
|
|
19
|
-
: await load(configFilePath);
|
|
18
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
|
|
20
19
|
const plugins = (localConfig?.plugins ?? []).map(plugin => (Array.isArray(plugin) ? plugin[0] : plugin));
|
|
21
20
|
return plugins;
|
|
22
21
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isInternal } from '../../util/path.js';
|
|
1
|
+
import { basename, isInternal } from '../../util/path.js';
|
|
2
2
|
import { timerify } from '../../util/Performance.js';
|
|
3
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
4
4
|
export const NAME = 'Stylelint';
|
|
@@ -13,9 +13,7 @@ const findPluginDependencies = async (configFilePath, options) => {
|
|
|
13
13
|
const { manifest, isProduction } = options;
|
|
14
14
|
if (isProduction)
|
|
15
15
|
return [];
|
|
16
|
-
const localConfig = configFilePath
|
|
17
|
-
? manifest.stylelint
|
|
18
|
-
: await load(configFilePath);
|
|
16
|
+
const localConfig = basename(configFilePath) === 'package.json' ? manifest.stylelint : await load(configFilePath);
|
|
19
17
|
if (!localConfig)
|
|
20
18
|
return [];
|
|
21
19
|
const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { basename } from '../../util/path.js';
|
|
1
2
|
import { timerify } from '../../util/Performance.js';
|
|
2
3
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
3
4
|
export const NAME = 'TypeDoc';
|
|
@@ -16,9 +17,9 @@ const findTypeDocDependencies = async (configFilePath, options) => {
|
|
|
16
17
|
const { manifest, isProduction } = options;
|
|
17
18
|
if (isProduction)
|
|
18
19
|
return [];
|
|
19
|
-
const localConfig = configFilePath
|
|
20
|
+
const localConfig = basename(configFilePath) === 'package.json'
|
|
20
21
|
? manifest[PACKAGE_JSON_PATH]
|
|
21
|
-
: configFilePath
|
|
22
|
+
: basename(configFilePath) === 'tsconfig.json'
|
|
22
23
|
? (await load(configFilePath)).typedocOptions
|
|
23
24
|
: await load(configFilePath);
|
|
24
25
|
return localConfig?.plugin ?? [];
|
|
@@ -4,7 +4,7 @@ import { findVitestDependencies } from '../vitest/index.js';
|
|
|
4
4
|
export const NAME = 'Vite';
|
|
5
5
|
export const ENABLERS = ['vite'];
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
|
-
export const CONFIG_FILE_PATTERNS = ['vite
|
|
7
|
+
export const CONFIG_FILE_PATTERNS = ['vite*.config.{js,mjs,ts,cjs,mts,cts}'];
|
|
8
8
|
const findViteDependencies = async (configFilePath, options) => {
|
|
9
9
|
const localConfig = await load(configFilePath);
|
|
10
10
|
if (!localConfig)
|
|
@@ -8,7 +8,7 @@ export const NAME = 'Vitest';
|
|
|
8
8
|
export const ENABLERS = ['vitest'];
|
|
9
9
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
10
10
|
export const CONFIG_FILE_PATTERNS = [
|
|
11
|
-
'vitest
|
|
11
|
+
'vitest*.config.{js,mjs,ts,cjs,mts,cts}',
|
|
12
12
|
'vitest.{workspace,projects}.{ts,js,json}',
|
|
13
13
|
];
|
|
14
14
|
export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
|
|
@@ -19,17 +19,23 @@ const resolveEntry = (containingFilePath, specifier) => {
|
|
|
19
19
|
return toEntryPattern(relative(dir, resolvedPath));
|
|
20
20
|
return specifier;
|
|
21
21
|
};
|
|
22
|
+
const enablesCoverageInScript = /vitest(.+)--coverage(?:\.enabled(?:=true)?)?/;
|
|
23
|
+
const hasScriptWithCoverage = (scripts) => {
|
|
24
|
+
return Object.values(scripts).some(script => {
|
|
25
|
+
return enablesCoverageInScript.test(script);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
22
28
|
const findConfigDependencies = (configFilePath, localConfig, options) => {
|
|
23
|
-
const { isProduction, config } = options;
|
|
29
|
+
const { isProduction, config, manifest } = options;
|
|
24
30
|
const testConfig = localConfig.test;
|
|
25
31
|
const entryPatterns = (config?.entry ?? testConfig?.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
26
32
|
if (!testConfig || isProduction)
|
|
27
33
|
return entryPatterns;
|
|
28
34
|
const environments = testConfig.environment ? [getEnvPackageName(testConfig.environment)] : [];
|
|
29
35
|
const reporters = getExternalReporters(testConfig.reporters);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
const hasCoverageEnabled = (testConfig.coverage && testConfig.coverage.enabled !== false) ||
|
|
37
|
+
(manifest.scripts !== undefined && hasScriptWithCoverage(manifest.scripts));
|
|
38
|
+
const coverage = hasCoverageEnabled ? [`@vitest/coverage-${testConfig.coverage?.provider ?? 'v8'}`] : [];
|
|
33
39
|
const setupFiles = [testConfig.setupFiles ?? []].flat().map(v => resolveEntry(configFilePath, v));
|
|
34
40
|
const globalSetup = [testConfig.globalSetup ?? []].flat().map(v => resolveEntry(configFilePath, v));
|
|
35
41
|
return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
|
|
@@ -49,7 +55,7 @@ export const findVitestDependencies = async (configFilePath, localConfig, option
|
|
|
49
55
|
}
|
|
50
56
|
const entry = localConfig.build?.lib?.entry ?? [];
|
|
51
57
|
const dependencies = (typeof entry === 'string' ? [entry] : Object.values(entry)).map(specifier => resolveEntry(configFilePath, specifier));
|
|
52
|
-
if (!
|
|
58
|
+
if (!options.enabledPlugins.includes('vitest'))
|
|
53
59
|
return dependencies;
|
|
54
60
|
return [...dependencies, ...findConfigDependencies(configFilePath, localConfig, options)];
|
|
55
61
|
};
|
|
@@ -7,7 +7,7 @@ import { getDependenciesFromConfig } from '../babel/index.js';
|
|
|
7
7
|
export const NAME = 'Webpack';
|
|
8
8
|
export const ENABLERS = ['webpack'];
|
|
9
9
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
10
|
-
export const CONFIG_FILE_PATTERNS = ['webpack.config*.{js,ts}'];
|
|
10
|
+
export const CONFIG_FILE_PATTERNS = ['webpack.config*.{js,ts,mjs,cjs,mts,cts}'];
|
|
11
11
|
const hasBabelOptions = (use) => Boolean(use) &&
|
|
12
12
|
typeof use !== 'string' &&
|
|
13
13
|
'loader' in use &&
|
|
@@ -87,7 +87,7 @@ const findWebpackDependencies = async (configFilePath, options) => {
|
|
|
87
87
|
if (isProduction)
|
|
88
88
|
return [...entryPatterns];
|
|
89
89
|
const scripts = Object.values(manifest.scripts ?? {});
|
|
90
|
-
const webpackCLI = scripts.some(script => script
|
|
90
|
+
const webpackCLI = scripts.some(script => script && /(?<=^|\s)webpack(?=\s|$)/.test(script)) ? ['webpack-cli'] : [];
|
|
91
91
|
const webpackDevServer = scripts.some(script => script?.includes('webpack serve')) ? ['webpack-dev-server'] : [];
|
|
92
92
|
return compact([...entryPatterns, ...dependencies, ...webpackCLI, ...webpackDevServer]);
|
|
93
93
|
};
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export type GenericPluginCallbackOptions = {
|
|
|
12
12
|
manifest: PackageJsonWithPlugins;
|
|
13
13
|
config: EnsuredPluginConfiguration;
|
|
14
14
|
isProduction: boolean;
|
|
15
|
+
enabledPlugins: string[];
|
|
15
16
|
};
|
|
16
17
|
export type GenericPluginCallback = (configFilePath: string, options: GenericPluginCallbackOptions) => Promise<string[]> | string[];
|
|
17
18
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isBuiltin } from 'node:module';
|
|
2
2
|
import ts from 'typescript';
|
|
3
3
|
import { getOrSet } from '../util/map.js';
|
|
4
|
-
import {
|
|
4
|
+
import { isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
|
|
5
5
|
import { isInNodeModules } from '../util/path.js';
|
|
6
6
|
import { isDeclarationFileExtension, isAccessExpression, getAccessExpressionName, getJSDocTags, getLineAndCharacterOfPosition, } from './ast-helpers.js';
|
|
7
7
|
import getExportVisitors from './visitors/exports/index.js';
|
|
@@ -59,8 +59,9 @@ export const getImportsAndExports = (sourceFile, getResolvedModule, options) =>
|
|
|
59
59
|
addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
|
|
60
60
|
}
|
|
61
61
|
const sanitizedSpecifier = sanitizeSpecifier(specifier);
|
|
62
|
-
if (!
|
|
62
|
+
if (!isStartsLikePackageName(sanitizedSpecifier)) {
|
|
63
63
|
return;
|
|
64
|
+
}
|
|
64
65
|
if (isDeclarationFileExtension(module.resolvedModule.extension)) {
|
|
65
66
|
externalImports.add(sanitizedSpecifier);
|
|
66
67
|
}
|
|
@@ -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 -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\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,binaries,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 --isolate-workspaces Isolated workspaces in monorepo\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 --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\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 --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\
|
|
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 -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --directory [dir] Run process from a different directory (default: cwd)\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,binaries,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 --isolate-workspaces Isolated workspaces in monorepo\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 --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\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 --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\nWebsite: https://knip.dev";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
config: string | undefined;
|
|
4
4
|
debug: boolean | undefined;
|
|
@@ -40,7 +40,7 @@ $ knip --workspace packages/client --include files,dependencies
|
|
|
40
40
|
$ knip -c ./config/knip.json --reporter compact
|
|
41
41
|
$ knip --reporter codeowners --reporter-options '{"path":".github/CODEOWNERS"}'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
Website: https://knip.dev`;
|
|
44
44
|
let parsedArgs;
|
|
45
45
|
try {
|
|
46
46
|
parsedArgs = parseArgs({
|
package/dist/util/modules.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { PackageJson } from '@npmcli/package-json';
|
|
|
2
2
|
export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
|
|
3
3
|
export declare const getPackageNameFromFilePath: (value: string) => string;
|
|
4
4
|
export declare const normalizeSpecifierFromFilePath: (value: string) => string;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const isStartsLikePackageName: (specifier: string) => boolean;
|
|
6
6
|
export declare const isDefinitelyTyped: (packageName: string) => boolean;
|
|
7
7
|
export declare const getDefinitelyTypedFor: (packageName: string) => string;
|
|
8
8
|
export declare const getPackageFromDefinitelyTyped: (typedDependency: string) => string;
|
package/dist/util/modules.js
CHANGED
|
@@ -3,7 +3,7 @@ import { _glob } from './glob.js';
|
|
|
3
3
|
import { getStringValues } from './object.js';
|
|
4
4
|
import { isAbsolute, toPosix } from './path.js';
|
|
5
5
|
export const getPackageNameFromModuleSpecifier = (moduleSpecifier) => {
|
|
6
|
-
if (!
|
|
6
|
+
if (!isStartsLikePackageName(moduleSpecifier))
|
|
7
7
|
return;
|
|
8
8
|
const parts = moduleSpecifier.split('/').slice(0, 2);
|
|
9
9
|
return moduleSpecifier.startsWith('@') ? parts.join('/') : parts[0];
|
|
@@ -20,7 +20,7 @@ export const normalizeSpecifierFromFilePath = (value) => {
|
|
|
20
20
|
return match[match.length - 1];
|
|
21
21
|
return value;
|
|
22
22
|
};
|
|
23
|
-
export const
|
|
23
|
+
export const isStartsLikePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
|
|
24
24
|
export const isDefinitelyTyped = (packageName) => packageName.startsWith('@types/');
|
|
25
25
|
export const getDefinitelyTypedFor = (packageName) => {
|
|
26
26
|
if (isDefinitelyTyped(packageName))
|
package/dist/util/path.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const isAbsolute: (path: string) => boolean;
|
|
2
2
|
export declare const dirname: (path: string) => string;
|
|
3
3
|
export declare const extname: (path: string) => string;
|
|
4
|
+
export declare const basename: (path: string, suffix?: string | undefined) => string;
|
|
4
5
|
export declare const join: (...paths: string[]) => string;
|
|
5
6
|
export declare const toPosix: (value: string) => string;
|
|
6
7
|
export declare const cwd: string;
|
package/dist/util/path.js
CHANGED
|
@@ -4,6 +4,7 @@ const { directory } = parsedArgValues;
|
|
|
4
4
|
export const isAbsolute = path.isAbsolute;
|
|
5
5
|
export const dirname = path.posix.dirname;
|
|
6
6
|
export const extname = path.posix.extname;
|
|
7
|
+
export const basename = path.posix.basename;
|
|
7
8
|
export const join = path.posix.join;
|
|
8
9
|
export const toPosix = (value) => value.split(path.sep).join(path.posix.sep);
|
|
9
10
|
export const cwd = directory ? path.posix.resolve(directory) : toPosix(process.cwd());
|
package/dist/util/plugin.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { _load as load, _loadFile as loadFile } from './loader.js';
|
|
2
2
|
export { _tryResolve as tryResolve } from './require.js';
|
|
3
|
+
export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
|
|
3
4
|
import type { RawPluginConfiguration } from '../types/config.js';
|
|
4
5
|
export declare const toCamelCase: (name: string) => string;
|
|
5
6
|
export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
|
package/dist/util/plugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { _load as load, _loadFile as loadFile } from './loader.js';
|
|
2
2
|
export { _tryResolve as tryResolve } from './require.js';
|
|
3
|
+
export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
|
|
3
4
|
import { arrayify } from './array.js';
|
|
4
5
|
export const toCamelCase = (name) => name.toLowerCase().replace(/(-[a-z])/g, group => group.toUpperCase().replace('-', ''));
|
|
5
6
|
export const hasDependency = (dependencies, values) => values.some(value => {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.
|
|
1
|
+
export declare const version = "3.5.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '3.
|
|
1
|
+
export const version = '3.5.1';
|