knip 2.33.3 → 2.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -7
- package/dist/ConfigurationChief.d.ts +1 -0
- package/dist/ConfigurationChief.js +13 -1
- package/dist/ConfigurationValidator.d.ts +56 -0
- package/dist/ConfigurationValidator.js +1 -0
- package/dist/WorkspaceWorker.d.ts +1 -1
- package/dist/WorkspaceWorker.js +12 -17
- package/dist/binaries/bash-parser.js +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.js +17 -16
- package/dist/plugins/_template/index.js +14 -3
- package/dist/plugins/_template/types.d.ts +1 -0
- package/dist/plugins/angular/index.js +11 -11
- package/dist/plugins/astro/index.d.ts +7 -0
- package/dist/plugins/astro/index.js +10 -0
- package/dist/plugins/ava/index.js +13 -12
- package/dist/plugins/babel/index.js +8 -5
- package/dist/plugins/capacitor/index.js +4 -2
- package/dist/plugins/changesets/index.js +7 -5
- package/dist/plugins/commitizen/index.js +4 -3
- package/dist/plugins/commitizen/types.d.ts +1 -1
- package/dist/plugins/commitlint/index.js +4 -2
- package/dist/plugins/cspell/index.js +4 -2
- package/dist/plugins/cspell/types.d.ts +1 -1
- package/dist/plugins/cypress/index.js +7 -4
- package/dist/plugins/drizzle/index.js +4 -4
- package/dist/plugins/eslint/fallback.js +6 -1
- package/dist/plugins/eslint/helpers.d.ts +2 -2
- package/dist/plugins/eslint/helpers.js +7 -7
- package/dist/plugins/eslint/index.d.ts +0 -1
- package/dist/plugins/eslint/index.js +3 -4
- package/dist/plugins/gatsby/index.js +5 -8
- package/dist/plugins/github-actions/index.d.ts +1 -1
- package/dist/plugins/github-actions/index.js +5 -4
- package/dist/plugins/husky/index.js +4 -2
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/jest/index.js +8 -8
- package/dist/plugins/jest/types.d.ts +3 -0
- package/dist/plugins/jest/types.js +1 -0
- package/dist/plugins/lefthook/index.js +5 -4
- package/dist/plugins/lint-staged/index.js +7 -7
- package/dist/plugins/markdownlint/index.js +5 -4
- package/dist/plugins/mocha/index.js +8 -7
- package/dist/plugins/mocha/types.d.ts +4 -0
- package/dist/plugins/mocha/types.js +1 -0
- package/dist/plugins/npm-package-json-lint/index.js +4 -3
- package/dist/plugins/nx/index.js +6 -5
- package/dist/plugins/nyc/index.js +4 -3
- package/dist/plugins/nyc/types.d.ts +3 -0
- package/dist/plugins/nyc/types.js +1 -0
- package/dist/plugins/playwright/index.d.ts +1 -1
- package/dist/plugins/playwright/index.js +7 -6
- package/dist/plugins/playwright-ct/index.js +11 -6
- package/dist/plugins/postcss/index.js +6 -5
- package/dist/plugins/prettier/index.js +3 -3
- package/dist/plugins/prettier/types.d.ts +8 -0
- package/dist/plugins/prettier/types.js +1 -0
- package/dist/plugins/release-it/index.js +10 -9
- package/dist/plugins/remark/index.js +6 -5
- package/dist/plugins/remix/index.js +1 -5
- package/dist/plugins/rollup/index.js +1 -1
- package/dist/plugins/semantic-release/index.js +5 -4
- package/dist/plugins/semantic-release/types.d.ts +1 -1
- package/dist/plugins/storybook/index.js +13 -11
- package/dist/plugins/stryker/index.js +9 -6
- package/dist/plugins/stylelint/index.js +6 -5
- package/dist/plugins/typedoc/index.js +4 -3
- package/dist/plugins/typedoc/types.d.ts +1 -1
- package/dist/plugins/typescript/index.js +13 -10
- package/dist/plugins/vite/index.js +4 -2
- package/dist/plugins/vitest/index.d.ts +1 -1
- package/dist/plugins/vitest/index.js +8 -8
- package/dist/plugins/webpack/index.js +25 -15
- package/dist/plugins/webpack/types.d.ts +2 -1
- package/dist/types/config.d.ts +1 -1
- package/dist/types/plugins.d.ts +1 -1
- package/dist/typescript/SourceFileManager.js +3 -3
- package/dist/typescript/ast-helpers.d.ts +2 -1
- package/dist/typescript/ast-helpers.js +3 -0
- package/dist/typescript/visitors/exports/exportKeyword.js +5 -2
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +2 -0
- package/dist/util/compilers.d.ts +10 -0
- package/dist/util/debug.d.ts +3 -3
- package/dist/util/debug.js +10 -8
- package/dist/util/glob.js +1 -1
- package/dist/util/modules.js +1 -1
- package/dist/util/path.js +4 -2
- package/dist/util/plugin.js +7 -1
- package/dist/util/require.js +1 -1
- package/dist/util/unwrapFunction.d.ts +1 -0
- package/dist/util/unwrapFunction.js +13 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +4 -0
|
@@ -4,16 +4,17 @@ export const NAME = 'PostCSS';
|
|
|
4
4
|
export const ENABLERS = ['postcss', 'next'];
|
|
5
5
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
6
6
|
export const CONFIG_FILE_PATTERNS = ['postcss.config.js', 'postcss.config.json', 'package.json'];
|
|
7
|
-
const findPostCSSDependencies = async (configFilePath,
|
|
7
|
+
const findPostCSSDependencies = async (configFilePath, options) => {
|
|
8
|
+
const { manifest, isProduction } = options;
|
|
8
9
|
if (isProduction)
|
|
9
10
|
return [];
|
|
10
|
-
const
|
|
11
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
11
12
|
? manifest?.postcss
|
|
12
13
|
: await load(configFilePath);
|
|
13
|
-
if (!
|
|
14
|
+
if (!localConfig)
|
|
14
15
|
return [];
|
|
15
|
-
return
|
|
16
|
-
? (Array.isArray(
|
|
16
|
+
return localConfig.plugins
|
|
17
|
+
? (Array.isArray(localConfig.plugins) ? localConfig.plugins : Object.keys(localConfig.plugins)).flatMap(plugin => {
|
|
17
18
|
if (typeof plugin === 'string')
|
|
18
19
|
return plugin;
|
|
19
20
|
if (Array.isArray(plugin) && typeof plugin[0] === 'string')
|
|
@@ -12,11 +12,11 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
const findPrettierDependencies = async (configFilePath, { manifest, isProduction }) => {
|
|
13
13
|
if (isProduction)
|
|
14
14
|
return [];
|
|
15
|
-
const
|
|
15
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
16
16
|
? manifest.prettier
|
|
17
17
|
: await load(configFilePath);
|
|
18
|
-
return
|
|
19
|
-
?
|
|
18
|
+
return localConfig && Array.isArray(localConfig.plugins)
|
|
19
|
+
? localConfig.plugins.filter((plugin) => typeof plugin === 'string')
|
|
20
20
|
: [];
|
|
21
21
|
};
|
|
22
22
|
export const findDependencies = timerify(findPrettierDependencies);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -11,21 +11,22 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
11
11
|
'.release-it.{yml,yaml}',
|
|
12
12
|
'package.json',
|
|
13
13
|
];
|
|
14
|
-
const findReleaseItDependencies = async (configFilePath,
|
|
14
|
+
const findReleaseItDependencies = async (configFilePath, options) => {
|
|
15
|
+
const { cwd, manifest, isProduction } = options;
|
|
15
16
|
if (isProduction)
|
|
16
17
|
return [];
|
|
17
|
-
const
|
|
18
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
18
19
|
? manifest[PACKAGE_JSON_PATH]
|
|
19
20
|
: await load(configFilePath);
|
|
20
|
-
if (!
|
|
21
|
+
if (!localConfig)
|
|
21
22
|
return [];
|
|
22
|
-
const plugins =
|
|
23
|
-
const scripts =
|
|
24
|
-
if (typeof
|
|
25
|
-
scripts.push(
|
|
23
|
+
const plugins = localConfig.plugins ? Object.keys(localConfig.plugins) : [];
|
|
24
|
+
const scripts = localConfig.hooks ? Object.values(localConfig.hooks).flat() : [];
|
|
25
|
+
if (typeof localConfig.github?.releaseNotes === 'string') {
|
|
26
|
+
scripts.push(localConfig.github.releaseNotes);
|
|
26
27
|
}
|
|
27
|
-
if (typeof
|
|
28
|
-
scripts.push(
|
|
28
|
+
if (typeof localConfig.gitlab?.releaseNotes === 'string') {
|
|
29
|
+
scripts.push(localConfig.gitlab.releaseNotes);
|
|
29
30
|
}
|
|
30
31
|
const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest });
|
|
31
32
|
return [...plugins, ...dependencies];
|
|
@@ -11,15 +11,16 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
11
11
|
'.remarkrc.{js,cjs,mjs}',
|
|
12
12
|
'.remarkrc.{yml,yaml}',
|
|
13
13
|
];
|
|
14
|
-
const findRemarkDependencies = async (configFilePath,
|
|
14
|
+
const findRemarkDependencies = async (configFilePath, options) => {
|
|
15
|
+
const { manifest, isProduction } = options;
|
|
15
16
|
if (isProduction)
|
|
16
17
|
return [];
|
|
17
|
-
const
|
|
18
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
18
19
|
? manifest[PACKAGE_JSON_PATH]
|
|
19
20
|
: await load(configFilePath);
|
|
20
|
-
if (!
|
|
21
|
+
if (!localConfig)
|
|
21
22
|
return [];
|
|
22
|
-
const plugins =
|
|
23
|
-
return
|
|
23
|
+
const plugins = localConfig.plugins?.map(plugin => `remark-${plugin}`) ?? [];
|
|
24
|
+
return plugins;
|
|
24
25
|
};
|
|
25
26
|
export const findDependencies = timerify(findRemarkDependencies);
|
|
@@ -12,10 +12,6 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
|
|
|
12
12
|
'server.{js,ts}',
|
|
13
13
|
];
|
|
14
14
|
const findRemixDependencies = async () => {
|
|
15
|
-
|
|
16
|
-
...ENTRY_FILE_PATTERNS.map(toEntryPattern),
|
|
17
|
-
...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern),
|
|
18
|
-
];
|
|
19
|
-
return entryPatterns;
|
|
15
|
+
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
|
|
20
16
|
};
|
|
21
17
|
export const findDependencies = timerify(findRemixDependencies);
|
|
@@ -4,7 +4,7 @@ import { toEntryPattern } from '../../util/protocols.js';
|
|
|
4
4
|
export const NAME = 'Rollup';
|
|
5
5
|
export const ENABLERS = ['rollup'];
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
|
-
export const ENTRY_FILE_PATTERNS = ['rollup.config.{js,mjs,ts}'];
|
|
7
|
+
export const ENTRY_FILE_PATTERNS = ['rollup.config.{js,cjs,mjs,ts}'];
|
|
8
8
|
const findRollupDependencies = async () => {
|
|
9
9
|
const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
|
|
10
10
|
return entryPatterns;
|
|
@@ -10,13 +10,14 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
10
10
|
'release.config.{js,cjs}',
|
|
11
11
|
'package.json',
|
|
12
12
|
];
|
|
13
|
-
const findSemanticReleaseDependencies = async (configFilePath,
|
|
13
|
+
const findSemanticReleaseDependencies = async (configFilePath, options) => {
|
|
14
|
+
const { manifest, isProduction } = options;
|
|
14
15
|
if (isProduction)
|
|
15
16
|
return [];
|
|
16
|
-
const
|
|
17
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
17
18
|
? manifest[PACKAGE_JSON_PATH]
|
|
18
19
|
: await load(configFilePath);
|
|
19
|
-
const plugins =
|
|
20
|
-
return plugins
|
|
20
|
+
const plugins = (localConfig?.plugins ?? []).map(plugin => (Array.isArray(plugin) ? plugin[0] : plugin));
|
|
21
|
+
return plugins;
|
|
21
22
|
};
|
|
22
23
|
export const findDependencies = timerify(findSemanticReleaseDependencies);
|
|
@@ -9,19 +9,21 @@ export const CONFIG_FILE_PATTERNS = ['.storybook/{main,test-runner}.{js,ts}'];
|
|
|
9
9
|
export const STORIES_FILE_PATTERNS = ['**/*.stories.{js,jsx,ts,tsx}'];
|
|
10
10
|
export const ENTRY_FILE_PATTERNS = ['.storybook/{manager,preview}.{js,jsx,ts,tsx}', ...STORIES_FILE_PATTERNS];
|
|
11
11
|
export const PROJECT_FILE_PATTERNS = ['.storybook/**/*.{js,jsx,ts,tsx}'];
|
|
12
|
-
const findStorybookDependencies = async (configFilePath,
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const findStorybookDependencies = async (configFilePath, options) => {
|
|
13
|
+
const { isProduction, cwd, config } = options;
|
|
14
|
+
const localConfig = await load(configFilePath);
|
|
15
|
+
const stories = typeof localConfig?.stories === 'function'
|
|
16
|
+
? await localConfig.stories(STORIES_FILE_PATTERNS)
|
|
17
|
+
: localConfig?.stories;
|
|
18
|
+
const relativePatterns = stories?.map(pattern => relative(cwd, join(dirname(configFilePath), pattern)));
|
|
19
|
+
const patterns = [...(config?.entry ?? []), ...(relativePatterns ?? [])];
|
|
20
|
+
const entryPatterns = (patterns.length > 0 ? patterns : ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
21
|
+
if (!localConfig || isProduction)
|
|
18
22
|
return entryPatterns;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const addons = cfg.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
|
|
22
|
-
const builder = cfg?.core?.builder;
|
|
23
|
+
const addons = localConfig.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
|
|
24
|
+
const builder = localConfig?.core?.builder;
|
|
23
25
|
const builderPackages = builder && /webpack/.test(builder) ? [`@storybook/builder-${builder}`, `@storybook/manager-${builder}`] : [];
|
|
24
|
-
const frameworks =
|
|
26
|
+
const frameworks = localConfig.framework?.name ? [localConfig.framework.name] : [];
|
|
25
27
|
return [...entryPatterns, ...addons, ...builderPackages, ...frameworks];
|
|
26
28
|
};
|
|
27
29
|
export const findDependencies = timerify(findStorybookDependencies);
|
|
@@ -4,15 +4,18 @@ export const NAME = 'Stryker';
|
|
|
4
4
|
export const ENABLERS = ['@stryker-mutator/core'];
|
|
5
5
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
6
6
|
export const CONFIG_FILE_PATTERNS = ['?(.)stryker.{conf,config}.{js,mjs,cjs,json}'];
|
|
7
|
-
const findStrykerDependencies = async (configFilePath,
|
|
7
|
+
const findStrykerDependencies = async (configFilePath, options) => {
|
|
8
|
+
const { isProduction } = options;
|
|
8
9
|
if (isProduction)
|
|
9
10
|
return [];
|
|
10
|
-
const
|
|
11
|
-
if (!
|
|
11
|
+
const localConfig = await load(configFilePath);
|
|
12
|
+
if (!localConfig)
|
|
12
13
|
return [];
|
|
13
|
-
const runners =
|
|
14
|
-
const checkers =
|
|
15
|
-
|
|
14
|
+
const runners = localConfig.testRunner ? [`@stryker-mutator/${localConfig.testRunner}-runner`] : [];
|
|
15
|
+
const checkers = localConfig.checkers
|
|
16
|
+
? localConfig.checkers.map(checker => `@stryker-mutator/${checker}-checker`)
|
|
17
|
+
: [];
|
|
18
|
+
const plugins = localConfig.plugins ?? [];
|
|
16
19
|
return [...runners, ...checkers, ...plugins];
|
|
17
20
|
};
|
|
18
21
|
export const findDependencies = timerify(findStrykerDependencies);
|
|
@@ -9,16 +9,17 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
9
9
|
'.stylelintrc.{cjs,js,json,yaml,yml}',
|
|
10
10
|
'stylelint.config.{cjs,mjs,js}',
|
|
11
11
|
];
|
|
12
|
-
const findPluginDependencies = async (configFilePath,
|
|
12
|
+
const findPluginDependencies = async (configFilePath, options) => {
|
|
13
|
+
const { manifest, isProduction } = options;
|
|
13
14
|
if (isProduction)
|
|
14
15
|
return [];
|
|
15
|
-
const
|
|
16
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
16
17
|
? manifest.stylelint
|
|
17
18
|
: await load(configFilePath);
|
|
18
|
-
if (!
|
|
19
|
+
if (!localConfig)
|
|
19
20
|
return [];
|
|
20
|
-
const extend =
|
|
21
|
-
const plugins =
|
|
21
|
+
const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
|
|
22
|
+
const plugins = localConfig.plugins ? [localConfig.plugins].flat().filter(plugin => !isInternal(plugin)) : [];
|
|
22
23
|
return [...extend, ...plugins];
|
|
23
24
|
};
|
|
24
25
|
export const findDependencies = timerify(findPluginDependencies);
|
|
@@ -12,14 +12,15 @@ export const CONFIG_FILE_PATTERNS = [
|
|
|
12
12
|
'package.json',
|
|
13
13
|
'tsconfig.json',
|
|
14
14
|
];
|
|
15
|
-
const findTypeDocDependencies = async (configFilePath,
|
|
15
|
+
const findTypeDocDependencies = async (configFilePath, options) => {
|
|
16
|
+
const { manifest, isProduction } = options;
|
|
16
17
|
if (isProduction)
|
|
17
18
|
return [];
|
|
18
|
-
const
|
|
19
|
+
const localConfig = configFilePath.endsWith('package.json')
|
|
19
20
|
? manifest[PACKAGE_JSON_PATH]
|
|
20
21
|
: configFilePath.endsWith('tsconfig.json')
|
|
21
22
|
? (await load(configFilePath)).typedocOptions
|
|
22
23
|
: await load(configFilePath);
|
|
23
|
-
return
|
|
24
|
+
return localConfig?.plugin ?? [];
|
|
24
25
|
};
|
|
25
26
|
export const findDependencies = timerify(findTypeDocDependencies);
|
|
@@ -8,27 +8,30 @@ export const ENABLERS = ['typescript'];
|
|
|
8
8
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
9
9
|
export const CONFIG_FILE_PATTERNS = ['tsconfig.json', 'tsconfig.*.json'];
|
|
10
10
|
const resolveExtensibleConfig = async (configFilePath) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const localConfig = await load(configFilePath);
|
|
12
|
+
if (!localConfig)
|
|
13
|
+
return;
|
|
14
|
+
localConfig.extends = localConfig.extends ? [localConfig.extends].flat() : [];
|
|
15
|
+
if (localConfig?.extends) {
|
|
16
|
+
for (const extend of [localConfig.extends].flat()) {
|
|
15
17
|
if (isInternal(extend)) {
|
|
16
18
|
const presetConfigPath = toAbsolute(extend, dirname(configFilePath));
|
|
17
19
|
const presetConfig = await resolveExtensibleConfig(presetConfigPath);
|
|
18
|
-
|
|
20
|
+
localConfig.extends.push(...(presetConfig?.extends ? [presetConfig.extends].flat() : []));
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
return
|
|
24
|
+
return localConfig;
|
|
23
25
|
};
|
|
24
|
-
export const findTypeScriptDependencies = async (configFilePath,
|
|
26
|
+
export const findTypeScriptDependencies = async (configFilePath, options) => {
|
|
27
|
+
const { isProduction } = options;
|
|
25
28
|
if (isProduction)
|
|
26
29
|
return [];
|
|
27
30
|
const { compilerOptions } = await loadTSConfig(configFilePath);
|
|
28
|
-
const
|
|
29
|
-
if (!compilerOptions || !
|
|
31
|
+
const localConfig = await resolveExtensibleConfig(configFilePath);
|
|
32
|
+
if (!compilerOptions || !localConfig)
|
|
30
33
|
return [];
|
|
31
|
-
const extend =
|
|
34
|
+
const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
|
|
32
35
|
const types = compilerOptions.types ?? [];
|
|
33
36
|
const plugins = Array.isArray(compilerOptions?.plugins)
|
|
34
37
|
? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : ''))
|
|
@@ -6,7 +6,9 @@ export const ENABLERS = ['vite'];
|
|
|
6
6
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
7
7
|
export const CONFIG_FILE_PATTERNS = ['vite.config.{js,ts}'];
|
|
8
8
|
const findViteDependencies = async (configFilePath, options) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const localConfig = await load(configFilePath);
|
|
10
|
+
if (!localConfig)
|
|
11
|
+
return [];
|
|
12
|
+
return findVitestDeps(localConfig, options);
|
|
11
13
|
};
|
|
12
14
|
export const findDependencies = timerify(findViteDependencies);
|
|
@@ -5,5 +5,5 @@ export declare const ENABLERS: string[];
|
|
|
5
5
|
export declare const isEnabled: IsPluginEnabledCallback;
|
|
6
6
|
export declare const CONFIG_FILE_PATTERNS: string[];
|
|
7
7
|
export declare const ENTRY_FILE_PATTERNS: string[];
|
|
8
|
-
export declare const findVitestDeps: (
|
|
8
|
+
export declare const findVitestDeps: (localConfig: VitestConfigOrFn, options: GenericPluginCallbackOptions) => any[];
|
|
9
9
|
export declare const findDependencies: GenericPluginCallback;
|
|
@@ -8,14 +8,12 @@ export const ENABLERS = ['vitest'];
|
|
|
8
8
|
export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
|
|
9
9
|
export const CONFIG_FILE_PATTERNS = ['vitest.config.ts', 'vitest.{workspace,projects}.{ts,js,json}'];
|
|
10
10
|
export const ENTRY_FILE_PATTERNS = ['**/*.{test,spec}.?(c|m)[jt]s?(x)'];
|
|
11
|
-
export const findVitestDeps = (
|
|
11
|
+
export const findVitestDeps = (localConfig, options) => {
|
|
12
12
|
const { isProduction } = options;
|
|
13
|
-
|
|
13
|
+
localConfig = typeof localConfig === 'function' ? localConfig() : localConfig;
|
|
14
|
+
if (!localConfig || !localConfig.test)
|
|
14
15
|
return [];
|
|
15
|
-
|
|
16
|
-
if (!config.test)
|
|
17
|
-
return [];
|
|
18
|
-
const testConfig = config.test;
|
|
16
|
+
const testConfig = localConfig.test;
|
|
19
17
|
const entryPatterns = (options.config?.entry ?? testConfig.include ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
|
|
20
18
|
if (isProduction)
|
|
21
19
|
return entryPatterns;
|
|
@@ -27,7 +25,9 @@ export const findVitestDeps = (config, options) => {
|
|
|
27
25
|
return [...entryPatterns, ...environments, ...reporters, ...coverage, ...setupFiles, ...globalSetup];
|
|
28
26
|
};
|
|
29
27
|
const findVitestDependencies = async (configFilePath, options) => {
|
|
30
|
-
const
|
|
31
|
-
return compact([
|
|
28
|
+
const localConfig = await load(configFilePath);
|
|
29
|
+
return compact([localConfig]
|
|
30
|
+
.flat()
|
|
31
|
+
.flatMap(config => (!config || typeof config === 'string' ? [] : findVitestDeps(config, options))));
|
|
32
32
|
};
|
|
33
33
|
export const findDependencies = timerify(findVitestDependencies);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { compact } from '../../util/array.js';
|
|
2
|
-
import { join } from '../../util/path.js';
|
|
2
|
+
import { join, relative } from '../../util/path.js';
|
|
3
3
|
import { timerify } from '../../util/Performance.js';
|
|
4
4
|
import { hasDependency, load } from '../../util/plugin.js';
|
|
5
|
+
import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
|
|
5
6
|
import { getDependenciesFromConfig } from '../babel/index.js';
|
|
6
7
|
export const NAME = 'Webpack';
|
|
7
8
|
export const ENABLERS = ['webpack'];
|
|
@@ -43,20 +44,23 @@ const resolveUseItem = (use) => {
|
|
|
43
44
|
return [use.loader];
|
|
44
45
|
return [];
|
|
45
46
|
};
|
|
46
|
-
const findWebpackDependencies = async (configFilePath,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!config)
|
|
47
|
+
const findWebpackDependencies = async (configFilePath, options) => {
|
|
48
|
+
const { manifest, isProduction, cwd } = options;
|
|
49
|
+
const localConfig = await load(configFilePath);
|
|
50
|
+
if (!localConfig)
|
|
51
51
|
return [];
|
|
52
|
-
const passes = typeof
|
|
53
|
-
const dependencies =
|
|
52
|
+
const passes = typeof localConfig === 'function' ? [false, true] : [false];
|
|
53
|
+
const dependencies = new Set();
|
|
54
|
+
const entryPatterns = new Set();
|
|
55
|
+
for (const isProduction of passes) {
|
|
54
56
|
const env = { production: isProduction };
|
|
55
57
|
const argv = { mode: isProduction ? 'production' : 'development' };
|
|
56
|
-
const resolvedConfig = typeof
|
|
57
|
-
|
|
58
|
-
const dependencies = (options.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []).map(loader => loader.replace(/\?.*/, ''));
|
|
58
|
+
const resolvedConfig = typeof localConfig === 'function' ? await localConfig(env, argv) : localConfig;
|
|
59
|
+
for (const options of [resolvedConfig].flat()) {
|
|
59
60
|
const entries = [];
|
|
61
|
+
for (const loader of options.module?.rules?.flatMap(resolveRuleSetDependencies) ?? []) {
|
|
62
|
+
dependencies.add(loader.replace(/\?.*/, ''));
|
|
63
|
+
}
|
|
60
64
|
if (typeof options.entry === 'string')
|
|
61
65
|
entries.push(options.entry);
|
|
62
66
|
else if (Array.isArray(options.entry))
|
|
@@ -73,12 +77,18 @@ const findWebpackDependencies = async (configFilePath, { manifest, isProduction
|
|
|
73
77
|
entries.push(entry['filename']);
|
|
74
78
|
});
|
|
75
79
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
entries.forEach(entry => {
|
|
81
|
+
const item = relative(cwd, join(options.context ? options.context : cwd, entry));
|
|
82
|
+
const value = options.mode === 'development' ? toEntryPattern(item) : toProductionEntryPattern(item);
|
|
83
|
+
entryPatterns.add(value);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (isProduction)
|
|
88
|
+
return [...entryPatterns];
|
|
79
89
|
const scripts = Object.values(manifest.scripts ?? {});
|
|
80
90
|
const webpackCLI = scripts.some(script => script?.includes('webpack ')) ? ['webpack-cli'] : [];
|
|
81
91
|
const webpackDevServer = scripts.some(script => script?.includes('webpack serve')) ? ['webpack-dev-server'] : [];
|
|
82
|
-
return compact([...dependencies, ...webpackCLI, ...webpackDevServer]);
|
|
92
|
+
return compact([...entryPatterns, ...dependencies, ...webpackCLI, ...webpackDevServer]);
|
|
83
93
|
};
|
|
84
94
|
export const findDependencies = timerify(findWebpackDependencies);
|
|
@@ -6,5 +6,6 @@ export type Env = {
|
|
|
6
6
|
export type Argv = {
|
|
7
7
|
mode: Mode;
|
|
8
8
|
};
|
|
9
|
-
|
|
9
|
+
type Configurations = Configuration | Configuration[];
|
|
10
|
+
export type WebpackConfig = Configurations | ((env: Env, argv: Argv) => Configurations) | (() => Promise<Configuration>);
|
|
10
11
|
export {};
|
package/dist/types/config.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type EnsuredPluginConfiguration = {
|
|
|
12
12
|
entry: NormalizedGlob | null;
|
|
13
13
|
project: NormalizedGlob | null;
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
type PluginConfiguration = EnsuredPluginConfiguration | boolean;
|
|
16
16
|
export type PluginsConfiguration = Record<PluginName, PluginConfiguration>;
|
|
17
17
|
interface BaseWorkspaceConfiguration {
|
|
18
18
|
entry: NormalizedGlob;
|
package/dist/types/plugins.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions)
|
|
|
12
12
|
export type GenericPluginCallbackOptions = {
|
|
13
13
|
cwd: string;
|
|
14
14
|
manifest: PackageJsonWithPlugins;
|
|
15
|
-
config
|
|
15
|
+
config: EnsuredPluginConfiguration;
|
|
16
16
|
isProduction: boolean;
|
|
17
17
|
};
|
|
18
18
|
export type GenericPluginCallback = (configFilePath: string, options: GenericPluginCallbackOptions) => Promise<string[]> | string[];
|
|
@@ -22,14 +22,14 @@ export class SourceFileManager {
|
|
|
22
22
|
const contents = ts.sys.readFile(filePath);
|
|
23
23
|
if (typeof contents !== 'string') {
|
|
24
24
|
if (isInternal(filePath))
|
|
25
|
-
debugLog(`Unable to read ${filePath}`);
|
|
25
|
+
debugLog('*', `Unable to read ${filePath}`);
|
|
26
26
|
return this.createSourceFile(filePath, '');
|
|
27
27
|
}
|
|
28
28
|
const ext = extname(filePath);
|
|
29
29
|
const compiler = this.syncCompilers?.get(ext);
|
|
30
30
|
const compiled = compiler ? compiler(contents, filePath) : contents;
|
|
31
31
|
if (compiler)
|
|
32
|
-
debugLog(`Compiled ${filePath}`);
|
|
32
|
+
debugLog('*', `Compiled ${filePath}`);
|
|
33
33
|
return this.createSourceFile(filePath, compiled);
|
|
34
34
|
}
|
|
35
35
|
getSnapshot(filePath) {
|
|
@@ -50,7 +50,7 @@ export class SourceFileManager {
|
|
|
50
50
|
const compiler = this.asyncCompilers?.get(ext);
|
|
51
51
|
if (compiler) {
|
|
52
52
|
const compiled = await compiler(contents, filePath);
|
|
53
|
-
debugLog(`Compiled ${filePath}`);
|
|
53
|
+
debugLog('*', `Compiled ${filePath}`);
|
|
54
54
|
this.createSourceFile(filePath, compiled);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -5,7 +5,8 @@ interface ValidImportTypeNode extends ts.ImportTypeNode {
|
|
|
5
5
|
};
|
|
6
6
|
}
|
|
7
7
|
export declare function isValidImportTypeNode(node: ts.Node): node is ValidImportTypeNode;
|
|
8
|
-
export declare function
|
|
8
|
+
export declare function isGetOrSetAccessorDeclaration(node: ts.Node): node is ts.AccessorDeclaration;
|
|
9
|
+
export declare function isPrivateMember(node: ts.MethodDeclaration | ts.PropertyDeclaration | ts.SetAccessorDeclaration | ts.GetAccessorDeclaration): boolean;
|
|
9
10
|
export declare function isDefaultImport(node: ts.ImportDeclaration | ts.ImportEqualsDeclaration | ts.ExportDeclaration): boolean;
|
|
10
11
|
export declare function isAccessExpression(node: ts.Node): node is ts.PropertyAccessExpression | ts.ElementAccessExpression;
|
|
11
12
|
export declare function isImportCall(node: ts.Node): node is ts.ImportCall;
|
|
@@ -2,6 +2,9 @@ import ts from 'typescript';
|
|
|
2
2
|
export function isValidImportTypeNode(node) {
|
|
3
3
|
return ts.isImportTypeNode(node);
|
|
4
4
|
}
|
|
5
|
+
export function isGetOrSetAccessorDeclaration(node) {
|
|
6
|
+
return node.kind === ts.SyntaxKind.SetAccessor || node.kind === ts.SyntaxKind.GetAccessor;
|
|
7
|
+
}
|
|
5
8
|
export function isPrivateMember(node) {
|
|
6
9
|
return node.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword) ?? false;
|
|
7
10
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { SymbolType } from '../../../types/issues.js';
|
|
3
3
|
import { compact } from '../../../util/array.js';
|
|
4
|
-
import { isPrivateMember, stripQuotes } from '../../ast-helpers.js';
|
|
4
|
+
import { isGetOrSetAccessorDeclaration, isPrivateMember, stripQuotes } from '../../ast-helpers.js';
|
|
5
5
|
import { exportVisitor as visit } from '../index.js';
|
|
6
6
|
export default visit(() => true, node => {
|
|
7
7
|
const modifierKinds = node.modifiers?.map(modifier => modifier.kind) ?? [];
|
|
@@ -47,7 +47,10 @@ export default visit(() => true, node => {
|
|
|
47
47
|
const identifier = modifierKinds.includes(ts.SyntaxKind.DefaultKeyword) ? 'default' : node.name.getText();
|
|
48
48
|
const pos = (node.name ?? node).getStart();
|
|
49
49
|
const members = node.members
|
|
50
|
-
.filter((member) => (ts.isPropertyDeclaration(member) ||
|
|
50
|
+
.filter((member) => (ts.isPropertyDeclaration(member) ||
|
|
51
|
+
ts.isMethodDeclaration(member) ||
|
|
52
|
+
isGetOrSetAccessorDeclaration(member)) &&
|
|
53
|
+
!isPrivateMember(member))
|
|
51
54
|
.map(member => ({
|
|
52
55
|
node: member,
|
|
53
56
|
identifier: member.name.getText(),
|
|
@@ -1,9 +1,10 @@
|
|
|
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 --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\n -W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)\n --no-gitignore Don't use .gitignore\n --include Report only provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (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 --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
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 --ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)\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,unresolved\n --exports Shortcut for --include exports,nsExports,classMembers,types,nsTypes,enumMembers,duplicates\n --include-entry-exports Include entry files when reporting unused exports\n -n, --no-progress Don't show dynamic progress updates (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 --debug-file-filter Filter for files in debug output (regex as string)\n --performance Measure count and running time of expensive functions and display stats table\n -h, --help Print this help text\n -V, --version Print version\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, classMembers, types, nsTypes, enumMembers, duplicates\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --debug --debug-file-filter '(specific|particular)-module'\n\nMore documentation and bug reports: https://github.com/webpro/knip";
|
|
2
2
|
declare const _default: {
|
|
3
3
|
config: string | undefined;
|
|
4
4
|
debug: boolean | undefined;
|
|
5
5
|
'debug-file-filter': string | undefined;
|
|
6
6
|
dependencies: boolean | undefined;
|
|
7
|
+
directory: string | undefined;
|
|
7
8
|
exclude: string[] | undefined;
|
|
8
9
|
exports: boolean | undefined;
|
|
9
10
|
help: boolean | undefined;
|
|
@@ -10,6 +10,7 @@ Options:
|
|
|
10
10
|
--strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)
|
|
11
11
|
--ignore-internal Ignore exports with tag @internal (JSDoc/TSDoc)
|
|
12
12
|
-W, --workspace [dir] Analyze a single workspace (default: analyze all configured workspaces)
|
|
13
|
+
--directory [dir] Run process from a different directory (default: cwd)
|
|
13
14
|
--no-gitignore Don't use .gitignore
|
|
14
15
|
--include Report only provided issue type(s), can be comma-separated or repeated (1)
|
|
15
16
|
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
@@ -50,6 +51,7 @@ try {
|
|
|
50
51
|
debug: { type: 'boolean', short: 'd' },
|
|
51
52
|
'debug-file-filter': { type: 'string' },
|
|
52
53
|
dependencies: { type: 'boolean' },
|
|
54
|
+
directory: { type: 'string' },
|
|
53
55
|
exclude: { type: 'string', multiple: true },
|
|
54
56
|
exports: { type: 'boolean' },
|
|
55
57
|
help: { type: 'boolean', short: 'h' },
|
package/dist/util/compilers.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
22
22
|
ignore?: string | string[] | undefined;
|
|
23
23
|
ignoreBinaries?: string[] | undefined;
|
|
24
24
|
ignoreDependencies?: string[] | undefined;
|
|
25
|
+
astro?: string | boolean | string[] | {
|
|
26
|
+
config?: string | string[] | undefined;
|
|
27
|
+
entry?: string | string[] | undefined;
|
|
28
|
+
project?: string | string[] | undefined;
|
|
29
|
+
} | undefined;
|
|
25
30
|
angular?: string | boolean | string[] | {
|
|
26
31
|
config?: string | string[] | undefined;
|
|
27
32
|
entry?: string | string[] | undefined;
|
|
@@ -228,6 +233,11 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
|
|
|
228
233
|
project?: string | string[] | undefined;
|
|
229
234
|
} | undefined;
|
|
230
235
|
}> | undefined;
|
|
236
|
+
astro?: string | boolean | string[] | {
|
|
237
|
+
config?: string | string[] | undefined;
|
|
238
|
+
entry?: string | string[] | undefined;
|
|
239
|
+
project?: string | string[] | undefined;
|
|
240
|
+
} | undefined;
|
|
231
241
|
angular?: string | boolean | string[] | {
|
|
232
242
|
config?: string | string[] | undefined;
|
|
233
243
|
entry?: string | string[] | undefined;
|
package/dist/util/debug.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const debugLog: (message: string) => void;
|
|
2
|
-
export declare const debugLogObject: (name: string, obj: unknown) => void;
|
|
3
|
-
export declare const debugLogArray: (
|
|
1
|
+
export declare const debugLog: (context: string, message: string) => void;
|
|
2
|
+
export declare const debugLogObject: (context: string, name: string, obj: unknown | (() => unknown)) => void;
|
|
3
|
+
export declare const debugLogArray: (context: string | [string, string], message: string, elements: string[] | Set<string>) => void;
|