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.
Files changed (97) hide show
  1. package/README.md +27 -7
  2. package/dist/ConfigurationChief.d.ts +1 -0
  3. package/dist/ConfigurationChief.js +13 -1
  4. package/dist/ConfigurationValidator.d.ts +56 -0
  5. package/dist/ConfigurationValidator.js +1 -0
  6. package/dist/WorkspaceWorker.d.ts +1 -1
  7. package/dist/WorkspaceWorker.js +12 -17
  8. package/dist/binaries/bash-parser.js +1 -1
  9. package/dist/cli.js +1 -1
  10. package/dist/index.js +17 -16
  11. package/dist/plugins/_template/index.js +14 -3
  12. package/dist/plugins/_template/types.d.ts +1 -0
  13. package/dist/plugins/angular/index.js +11 -11
  14. package/dist/plugins/astro/index.d.ts +7 -0
  15. package/dist/plugins/astro/index.js +10 -0
  16. package/dist/plugins/ava/index.js +13 -12
  17. package/dist/plugins/babel/index.js +8 -5
  18. package/dist/plugins/capacitor/index.js +4 -2
  19. package/dist/plugins/changesets/index.js +7 -5
  20. package/dist/plugins/commitizen/index.js +4 -3
  21. package/dist/plugins/commitizen/types.d.ts +1 -1
  22. package/dist/plugins/commitlint/index.js +4 -2
  23. package/dist/plugins/cspell/index.js +4 -2
  24. package/dist/plugins/cspell/types.d.ts +1 -1
  25. package/dist/plugins/cypress/index.js +7 -4
  26. package/dist/plugins/drizzle/index.js +4 -4
  27. package/dist/plugins/eslint/fallback.js +6 -1
  28. package/dist/plugins/eslint/helpers.d.ts +2 -2
  29. package/dist/plugins/eslint/helpers.js +7 -7
  30. package/dist/plugins/eslint/index.d.ts +0 -1
  31. package/dist/plugins/eslint/index.js +3 -4
  32. package/dist/plugins/gatsby/index.js +5 -8
  33. package/dist/plugins/github-actions/index.d.ts +1 -1
  34. package/dist/plugins/github-actions/index.js +5 -4
  35. package/dist/plugins/husky/index.js +4 -2
  36. package/dist/plugins/index.d.ts +1 -0
  37. package/dist/plugins/index.js +1 -0
  38. package/dist/plugins/jest/index.js +8 -8
  39. package/dist/plugins/jest/types.d.ts +3 -0
  40. package/dist/plugins/jest/types.js +1 -0
  41. package/dist/plugins/lefthook/index.js +5 -4
  42. package/dist/plugins/lint-staged/index.js +7 -7
  43. package/dist/plugins/markdownlint/index.js +5 -4
  44. package/dist/plugins/mocha/index.js +8 -7
  45. package/dist/plugins/mocha/types.d.ts +4 -0
  46. package/dist/plugins/mocha/types.js +1 -0
  47. package/dist/plugins/npm-package-json-lint/index.js +4 -3
  48. package/dist/plugins/nx/index.js +6 -5
  49. package/dist/plugins/nyc/index.js +4 -3
  50. package/dist/plugins/nyc/types.d.ts +3 -0
  51. package/dist/plugins/nyc/types.js +1 -0
  52. package/dist/plugins/playwright/index.d.ts +1 -1
  53. package/dist/plugins/playwright/index.js +7 -6
  54. package/dist/plugins/playwright-ct/index.js +11 -6
  55. package/dist/plugins/postcss/index.js +6 -5
  56. package/dist/plugins/prettier/index.js +3 -3
  57. package/dist/plugins/prettier/types.d.ts +8 -0
  58. package/dist/plugins/prettier/types.js +1 -0
  59. package/dist/plugins/release-it/index.js +10 -9
  60. package/dist/plugins/remark/index.js +6 -5
  61. package/dist/plugins/remix/index.js +1 -5
  62. package/dist/plugins/rollup/index.js +1 -1
  63. package/dist/plugins/semantic-release/index.js +5 -4
  64. package/dist/plugins/semantic-release/types.d.ts +1 -1
  65. package/dist/plugins/storybook/index.js +13 -11
  66. package/dist/plugins/stryker/index.js +9 -6
  67. package/dist/plugins/stylelint/index.js +6 -5
  68. package/dist/plugins/typedoc/index.js +4 -3
  69. package/dist/plugins/typedoc/types.d.ts +1 -1
  70. package/dist/plugins/typescript/index.js +13 -10
  71. package/dist/plugins/vite/index.js +4 -2
  72. package/dist/plugins/vitest/index.d.ts +1 -1
  73. package/dist/plugins/vitest/index.js +8 -8
  74. package/dist/plugins/webpack/index.js +25 -15
  75. package/dist/plugins/webpack/types.d.ts +2 -1
  76. package/dist/types/config.d.ts +1 -1
  77. package/dist/types/plugins.d.ts +1 -1
  78. package/dist/typescript/SourceFileManager.js +3 -3
  79. package/dist/typescript/ast-helpers.d.ts +2 -1
  80. package/dist/typescript/ast-helpers.js +3 -0
  81. package/dist/typescript/visitors/exports/exportKeyword.js +5 -2
  82. package/dist/util/cli-arguments.d.ts +2 -1
  83. package/dist/util/cli-arguments.js +2 -0
  84. package/dist/util/compilers.d.ts +10 -0
  85. package/dist/util/debug.d.ts +3 -3
  86. package/dist/util/debug.js +10 -8
  87. package/dist/util/glob.js +1 -1
  88. package/dist/util/modules.js +1 -1
  89. package/dist/util/path.js +4 -2
  90. package/dist/util/plugin.js +7 -1
  91. package/dist/util/require.js +1 -1
  92. package/dist/util/unwrapFunction.d.ts +1 -0
  93. package/dist/util/unwrapFunction.js +13 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/package.json +1 -1
  97. 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, { manifest, isProduction }) => {
7
+ const findPostCSSDependencies = async (configFilePath, options) => {
8
+ const { manifest, isProduction } = options;
8
9
  if (isProduction)
9
10
  return [];
10
- const config = configFilePath.endsWith('package.json')
11
+ const localConfig = configFilePath.endsWith('package.json')
11
12
  ? manifest?.postcss
12
13
  : await load(configFilePath);
13
- if (!config)
14
+ if (!localConfig)
14
15
  return [];
15
- return config.plugins
16
- ? (Array.isArray(config.plugins) ? config.plugins : Object.keys(config.plugins)).flatMap(plugin => {
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 config = configFilePath.endsWith('package.json')
15
+ const localConfig = configFilePath.endsWith('package.json')
16
16
  ? manifest.prettier
17
17
  : await load(configFilePath);
18
- return config && Array.isArray(config.plugins)
19
- ? config.plugins.filter((plugin) => typeof plugin === 'string')
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,8 @@
1
+ export type PrettierConfig = {
2
+ plugins?: (string | {
3
+ parsers?: Record<string, unknown>;
4
+ printers?: Record<string, unknown>;
5
+ languages?: unknown[];
6
+ options?: Record<string, unknown>;
7
+ })[];
8
+ };
@@ -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, { cwd, manifest, isProduction }) => {
14
+ const findReleaseItDependencies = async (configFilePath, options) => {
15
+ const { cwd, manifest, isProduction } = options;
15
16
  if (isProduction)
16
17
  return [];
17
- const config = configFilePath.endsWith('package.json')
18
+ const localConfig = configFilePath.endsWith('package.json')
18
19
  ? manifest[PACKAGE_JSON_PATH]
19
20
  : await load(configFilePath);
20
- if (!config)
21
+ if (!localConfig)
21
22
  return [];
22
- const plugins = config.plugins ? Object.keys(config.plugins) : [];
23
- const scripts = config.hooks ? Object.values(config.hooks).flat() : [];
24
- if (typeof config.github?.releaseNotes === 'string') {
25
- scripts.push(config.github.releaseNotes);
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 config.gitlab?.releaseNotes === 'string') {
28
- scripts.push(config.gitlab.releaseNotes);
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, { manifest, isProduction }) => {
14
+ const findRemarkDependencies = async (configFilePath, options) => {
15
+ const { manifest, isProduction } = options;
15
16
  if (isProduction)
16
17
  return [];
17
- const config = configFilePath.endsWith('package.json')
18
+ const localConfig = configFilePath.endsWith('package.json')
18
19
  ? manifest[PACKAGE_JSON_PATH]
19
20
  : await load(configFilePath);
20
- if (!config)
21
+ if (!localConfig)
21
22
  return [];
22
- const plugins = config.plugins?.map(plugin => `remark-${plugin}`) ?? [];
23
- return [...plugins];
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
- const entryPatterns = [
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, { manifest, isProduction }) => {
13
+ const findSemanticReleaseDependencies = async (configFilePath, options) => {
14
+ const { manifest, isProduction } = options;
14
15
  if (isProduction)
15
16
  return [];
16
- const config = configFilePath.endsWith('package.json')
17
+ const localConfig = configFilePath.endsWith('package.json')
17
18
  ? manifest[PACKAGE_JSON_PATH]
18
19
  : await load(configFilePath);
19
- const plugins = config?.plugins ?? [];
20
- return plugins.map(plugin => (Array.isArray(plugin) ? plugin[0] : plugin));
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);
@@ -1,3 +1,3 @@
1
- export type PluginConfig = {
1
+ export type SemanticReleaseConfig = {
2
2
  plugins?: (string | [string, Record<string, unknown>])[];
3
3
  };
@@ -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, { isProduction, config }) => {
13
- const cfg = await load(configFilePath);
14
- const stories = (typeof cfg.stories === 'function' ? await cfg.stories(STORIES_FILE_PATTERNS) : cfg.stories)?.map(pattern => relative(join(dirname(configFilePath), pattern)));
15
- const cfgPatterns = [...(config?.entry ?? []), ...(stories ?? [])];
16
- const entryPatterns = (cfgPatterns.length > 0 ? cfgPatterns : ENTRY_FILE_PATTERNS).map(toEntryPattern);
17
- if (isProduction)
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
- if (!cfg)
20
- return [];
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 = cfg.framework?.name ? [cfg.framework.name] : [];
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, { isProduction }) => {
7
+ const findStrykerDependencies = async (configFilePath, options) => {
8
+ const { isProduction } = options;
8
9
  if (isProduction)
9
10
  return [];
10
- const config = await load(configFilePath);
11
- if (!config)
11
+ const localConfig = await load(configFilePath);
12
+ if (!localConfig)
12
13
  return [];
13
- const runners = config.testRunner ? [`@stryker-mutator/${config.testRunner}-runner`] : [];
14
- const checkers = config.checkers ? config.checkers.map(checker => `@stryker-mutator/${checker}-checker`) : [];
15
- const plugins = config.plugins ?? [];
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, { manifest, isProduction }) => {
12
+ const findPluginDependencies = async (configFilePath, options) => {
13
+ const { manifest, isProduction } = options;
13
14
  if (isProduction)
14
15
  return [];
15
- const config = configFilePath.endsWith('package.json')
16
+ const localConfig = configFilePath.endsWith('package.json')
16
17
  ? manifest.stylelint
17
18
  : await load(configFilePath);
18
- if (!config)
19
+ if (!localConfig)
19
20
  return [];
20
- const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(extend)) : [];
21
- const plugins = config.plugins ? [config.plugins].flat().filter(plugin => !isInternal(plugin)) : [];
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, { manifest, isProduction }) => {
15
+ const findTypeDocDependencies = async (configFilePath, options) => {
16
+ const { manifest, isProduction } = options;
16
17
  if (isProduction)
17
18
  return [];
18
- const config = configFilePath.endsWith('package.json')
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 config?.plugin ?? [];
24
+ return localConfig?.plugin ?? [];
24
25
  };
25
26
  export const findDependencies = timerify(findTypeDocDependencies);
@@ -1,3 +1,3 @@
1
- export type PluginConfig = {
1
+ export type TypeDocConfig = {
2
2
  plugin?: string[];
3
3
  };
@@ -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 config = await load(configFilePath);
12
- config.extends = config.extends ? [config.extends].flat() : [];
13
- if (config?.extends) {
14
- for (const extend of [config.extends].flat()) {
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
- config.extends.push(...(presetConfig.extends ? [presetConfig.extends].flat() : []));
20
+ localConfig.extends.push(...(presetConfig?.extends ? [presetConfig.extends].flat() : []));
19
21
  }
20
22
  }
21
23
  }
22
- return config;
24
+ return localConfig;
23
25
  };
24
- export const findTypeScriptDependencies = async (configFilePath, { isProduction }) => {
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 config = await resolveExtensibleConfig(configFilePath);
29
- if (!compilerOptions || !config)
31
+ const localConfig = await resolveExtensibleConfig(configFilePath);
32
+ if (!compilerOptions || !localConfig)
30
33
  return [];
31
- const extend = config.extends ? [config.extends].flat().filter(extend => !isInternal(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 config = await load(configFilePath);
10
- return findVitestDeps(config, options);
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: (config: VitestConfigOrFn, options: GenericPluginCallbackOptions) => any[];
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 = (config, options) => {
11
+ export const findVitestDeps = (localConfig, options) => {
12
12
  const { isProduction } = options;
13
- if (!config)
13
+ localConfig = typeof localConfig === 'function' ? localConfig() : localConfig;
14
+ if (!localConfig || !localConfig.test)
14
15
  return [];
15
- config = typeof config === 'function' ? config() : config;
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 config = await load(configFilePath);
31
- return compact([config].flat().flatMap(cfg => (!cfg || typeof cfg === 'string' ? [] : findVitestDeps(cfg, options))));
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, { manifest, isProduction }) => {
47
- if (isProduction)
48
- return [];
49
- const config = await load(configFilePath);
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 config === 'function' ? [false, true] : [false];
53
- const dependencies = passes.flatMap(isProduction => {
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 config === 'function' ? config(env, argv) : config;
57
- return [resolvedConfig].flat().flatMap(options => {
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
- return [...dependencies, ...entries.map(entry => (options.context ? join(options.context, entry) : entry))];
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
- export type WebpackConfig = Configuration | ((env: Env, argv: Argv) => Configuration);
9
+ type Configurations = Configuration | Configuration[];
10
+ export type WebpackConfig = Configurations | ((env: Env, argv: Argv) => Configurations) | (() => Promise<Configuration>);
10
11
  export {};
@@ -12,7 +12,7 @@ export type EnsuredPluginConfiguration = {
12
12
  entry: NormalizedGlob | null;
13
13
  project: NormalizedGlob | null;
14
14
  };
15
- export type PluginConfiguration = EnsuredPluginConfiguration | boolean;
15
+ type PluginConfiguration = EnsuredPluginConfiguration | boolean;
16
16
  export type PluginsConfiguration = Record<PluginName, PluginConfiguration>;
17
17
  interface BaseWorkspaceConfiguration {
18
18
  entry: NormalizedGlob;
@@ -12,7 +12,7 @@ export type IsPluginEnabledCallback = (options: IsPluginEnabledCallbackOptions)
12
12
  export type GenericPluginCallbackOptions = {
13
13
  cwd: string;
14
14
  manifest: PackageJsonWithPlugins;
15
- config?: EnsuredPluginConfiguration;
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 isPrivateMember(node: ts.MethodDeclaration | ts.PropertyDeclaration): boolean;
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) || ts.isMethodDeclaration(member)) && !isPrivateMember(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' },
@@ -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;
@@ -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: (name: string, sourceFiles: string[] | Set<string>) => void;
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;