knip 5.83.0 → 5.84.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 (124) hide show
  1. package/dist/ConfigurationChief.d.ts +24 -0
  2. package/dist/IssueCollector.d.ts +15 -2
  3. package/dist/IssueCollector.js +59 -9
  4. package/dist/ProjectPrincipal.d.ts +2 -1
  5. package/dist/ProjectPrincipal.js +2 -1
  6. package/dist/WorkspaceWorker.d.ts +4 -1
  7. package/dist/WorkspaceWorker.js +69 -13
  8. package/dist/binaries/bash-parser.d.ts +0 -1
  9. package/dist/binaries/bash-parser.js +2 -3
  10. package/dist/binaries/fallback.js +1 -1
  11. package/dist/binaries/package-manager/npm.js +1 -1
  12. package/dist/binaries/package-manager/pnpm.js +3 -2
  13. package/dist/binaries/package-manager/yarn.js +1 -1
  14. package/dist/binaries/plugins.js +1 -0
  15. package/dist/compilers/compilers.d.ts +3 -3
  16. package/dist/compilers/index.d.ts +45 -4
  17. package/dist/compilers/index.js +6 -20
  18. package/dist/compilers/scss.d.ts +2 -2
  19. package/dist/compilers/types.d.ts +6 -5
  20. package/dist/constants.js +1 -0
  21. package/dist/graph/analyze.js +11 -0
  22. package/dist/graph/build.js +29 -15
  23. package/dist/plugins/astro/compiler-mdx.d.ts +2 -0
  24. package/dist/{compilers/astro-mdx.js → plugins/astro/compiler-mdx.js} +2 -4
  25. package/dist/plugins/astro/compiler.d.ts +2 -0
  26. package/dist/{compilers/astro.js → plugins/astro/compiler.js} +2 -3
  27. package/dist/plugins/astro/index.js +10 -0
  28. package/dist/plugins/bun/index.js +14 -5
  29. package/dist/plugins/bun/types.d.ts +5 -0
  30. package/dist/plugins/bun/types.js +1 -0
  31. package/dist/plugins/c8/index.js +1 -1
  32. package/dist/plugins/convex/index.js +1 -1
  33. package/dist/plugins/dotenv/index.js +8 -1
  34. package/dist/plugins/execa/index.d.ts +3 -0
  35. package/dist/plugins/execa/index.js +15 -0
  36. package/dist/{typescript/visitors/scripts → plugins/execa/visitors}/execa.js +3 -3
  37. package/dist/plugins/index.d.ts +4 -0
  38. package/dist/plugins/index.js +8 -0
  39. package/dist/plugins/jest/index.js +2 -2
  40. package/dist/plugins/metro/index.js +8 -2
  41. package/dist/plugins/nx/index.js +1 -1
  42. package/dist/plugins/pm2/index.d.ts +3 -0
  43. package/dist/plugins/pm2/index.js +34 -0
  44. package/dist/plugins/pm2/types.d.ts +9 -0
  45. package/dist/plugins/pm2/types.js +1 -0
  46. package/dist/plugins/prettier/index.js +2 -0
  47. package/dist/plugins/prisma/compiler.d.ts +2 -0
  48. package/dist/{compilers/prisma.js → plugins/prisma/compiler.js} +1 -2
  49. package/dist/plugins/prisma/index.js +6 -0
  50. package/dist/plugins/react-native/index.d.ts +3 -0
  51. package/dist/plugins/react-native/index.js +38 -0
  52. package/dist/plugins/react-native/types.d.ts +7 -0
  53. package/dist/plugins/react-native/types.js +1 -0
  54. package/dist/plugins/svelte/compiler.d.ts +2 -0
  55. package/dist/plugins/svelte/compiler.js +3 -0
  56. package/dist/plugins/svelte/index.js +6 -0
  57. package/dist/plugins/tailwind/compiler.d.ts +2 -0
  58. package/dist/{compilers/tailwind.js → plugins/tailwind/compiler.js} +2 -3
  59. package/dist/plugins/tailwind/index.js +6 -0
  60. package/dist/plugins/typescript/index.js +2 -2
  61. package/dist/plugins/vite/helpers.d.ts +2 -0
  62. package/dist/plugins/vite/helpers.js +23 -0
  63. package/dist/plugins/vite/index.js +10 -1
  64. package/dist/plugins/vite/visitors/importMetaGlob.d.ts +2 -0
  65. package/dist/plugins/vite/visitors/importMetaGlob.js +32 -0
  66. package/dist/plugins/vitest/index.js +24 -9
  67. package/dist/plugins/vue/compiler.d.ts +2 -0
  68. package/dist/plugins/vue/compiler.js +3 -0
  69. package/dist/plugins/vue/index.js +6 -0
  70. package/dist/plugins/webpack/index.js +15 -6
  71. package/dist/plugins/webpack/visitors/requireContext.d.ts +2 -0
  72. package/dist/plugins/webpack/visitors/requireContext.js +29 -0
  73. package/dist/plugins/yarn/index.js +18 -0
  74. package/dist/plugins/zx/index.d.ts +3 -0
  75. package/dist/plugins/zx/index.js +15 -0
  76. package/dist/{typescript/visitors/scripts → plugins/zx/visitors}/zx.js +2 -2
  77. package/dist/reporters/util/configuration-hints.js +3 -0
  78. package/dist/reporters/util/util.js +2 -2
  79. package/dist/run.d.ts +1 -1
  80. package/dist/schema/configuration.d.ts +60 -0
  81. package/dist/schema/plugins.d.ts +20 -0
  82. package/dist/schema/plugins.js +4 -0
  83. package/dist/session/session.d.ts +1 -1
  84. package/dist/types/PluginNames.d.ts +2 -2
  85. package/dist/types/PluginNames.js +4 -0
  86. package/dist/types/config.d.ts +26 -4
  87. package/dist/types/issues.d.ts +1 -1
  88. package/dist/typescript/ast-helpers.d.ts +2 -0
  89. package/dist/typescript/ast-helpers.js +55 -6
  90. package/dist/typescript/get-imports-and-exports.d.ts +2 -2
  91. package/dist/typescript/get-imports-and-exports.js +5 -5
  92. package/dist/typescript/visitors/dynamic-imports/index.d.ts +2 -1
  93. package/dist/typescript/visitors/dynamic-imports/index.js +3 -2
  94. package/dist/typescript/visitors/dynamic-imports/moduleRegister.d.ts +3 -0
  95. package/dist/typescript/visitors/dynamic-imports/moduleRegister.js +25 -0
  96. package/dist/typescript/visitors/index.d.ts +2 -0
  97. package/dist/typescript/visitors/scripts/index.d.ts +2 -1
  98. package/dist/typescript/visitors/scripts/index.js +2 -4
  99. package/dist/util/cli-arguments.d.ts +1 -1
  100. package/dist/util/cli-arguments.js +5 -3
  101. package/dist/util/create-input-handler.js +8 -4
  102. package/dist/util/create-options.d.ts +40 -0
  103. package/dist/util/jiti.d.ts +1 -5
  104. package/dist/util/jiti.js +2 -7
  105. package/dist/util/loader.js +1 -1
  106. package/dist/util/modules.d.ts +1 -0
  107. package/dist/util/modules.js +1 -0
  108. package/dist/util/watch.d.ts +1 -1
  109. package/dist/util/watch.js +9 -2
  110. package/dist/util/workspace-selectors.d.ts +1 -1
  111. package/dist/version.d.ts +1 -1
  112. package/dist/version.js +1 -1
  113. package/package.json +1 -1
  114. package/schema.json +19 -0
  115. package/dist/compilers/astro-mdx.d.ts +0 -6
  116. package/dist/compilers/astro.d.ts +0 -6
  117. package/dist/compilers/prisma.d.ts +0 -6
  118. package/dist/compilers/svelte.d.ts +0 -6
  119. package/dist/compilers/svelte.js +0 -4
  120. package/dist/compilers/tailwind.d.ts +0 -6
  121. package/dist/compilers/vue.d.ts +0 -6
  122. package/dist/compilers/vue.js +0 -4
  123. /package/dist/{typescript/visitors/scripts → plugins/execa/visitors}/execa.d.ts +0 -0
  124. /package/dist/{typescript/visitors/scripts → plugins/zx/visitors}/zx.d.ts +0 -0
@@ -1,4 +1,3 @@
1
- const condition = (hasDependency) => hasDependency('prisma');
2
1
  const directiveMatcher = /generator\s+(?!client)\w+\s*\{\s*provider\s*=\s*"([^"]+)"[^}]*\}/g;
3
2
  const compiler = (text) => {
4
3
  const imports = [];
@@ -10,4 +9,4 @@ const compiler = (text) => {
10
9
  }
11
10
  return imports.join('\n');
12
11
  };
13
- export default { condition, compiler };
12
+ export default compiler;
@@ -2,6 +2,7 @@ import { isDirectory } from '../../util/fs.js';
2
2
  import { toEntry } from '../../util/input.js';
3
3
  import { join } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
+ import compiler from './compiler.js';
5
6
  const title = 'Prisma';
6
7
  const enablers = ['prisma', /^@prisma\/.*/];
7
8
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -30,6 +31,10 @@ const resolveConfig = async (config, options) => {
30
31
  }
31
32
  return inputs;
32
33
  };
34
+ const registerCompilers = ({ registerCompiler, hasDependency }) => {
35
+ if (hasDependency('prisma'))
36
+ registerCompiler({ extension: '.prisma', compiler });
37
+ };
33
38
  const args = {
34
39
  config: true,
35
40
  resolveInputs: (parsed, { cwd }) => {
@@ -48,5 +53,6 @@ const plugin = {
48
53
  config,
49
54
  args,
50
55
  resolveConfig,
56
+ registerCompilers,
51
57
  };
52
58
  export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,38 @@
1
+ import { toDependency } from '../../util/input.js';
2
+ import { hasDependency } from '../../util/plugin.js';
3
+ const title = 'React Native';
4
+ const enablers = ['react-native'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['react-native.config.js'];
7
+ const RN_CLI_PACKAGES = [
8
+ '@react-native-community/cli',
9
+ '@react-native-community/cli-platform-android',
10
+ '@react-native-community/cli-platform-ios',
11
+ ];
12
+ const resolveConfig = async (config) => {
13
+ const inputs = [];
14
+ if (config.dependencies) {
15
+ for (const name of Object.keys(config.dependencies)) {
16
+ inputs.push(toDependency(name));
17
+ }
18
+ }
19
+ if (config.platforms) {
20
+ for (const platform of Object.values(config.platforms)) {
21
+ if (platform.npmPackageName)
22
+ inputs.push(toDependency(platform.npmPackageName));
23
+ }
24
+ }
25
+ return inputs;
26
+ };
27
+ const resolve = () => {
28
+ return RN_CLI_PACKAGES.map(pkg => toDependency(pkg, { optional: true }));
29
+ };
30
+ const plugin = {
31
+ title,
32
+ enablers,
33
+ isEnabled,
34
+ config,
35
+ resolveConfig,
36
+ resolve,
37
+ };
38
+ export default plugin;
@@ -0,0 +1,7 @@
1
+ export type ReactNativeConfig = {
2
+ reactNativePath?: string;
3
+ dependencies?: Record<string, unknown>;
4
+ platforms?: Record<string, {
5
+ npmPackageName?: string;
6
+ }>;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const compiler: import("../../compilers/types.js").CompilerSync;
2
+ export default compiler;
@@ -0,0 +1,3 @@
1
+ import { importsWithinScripts } from '../../compilers/compilers.js';
2
+ const compiler = importsWithinScripts;
3
+ export default compiler;
@@ -1,13 +1,19 @@
1
1
  import { hasDependency } from '../../util/plugin.js';
2
2
  import { config as viteConfig } from '../vite/index.js';
3
+ import compiler from './compiler.js';
3
4
  const title = 'Svelte';
4
5
  const enablers = ['svelte'];
5
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
7
  const entry = ['svelte.config.js', ...viteConfig];
8
+ const registerCompilers = ({ registerCompiler, hasDependency }) => {
9
+ if (hasDependency('svelte'))
10
+ registerCompiler({ extension: '.svelte', compiler });
11
+ };
7
12
  const plugin = {
8
13
  title,
9
14
  enablers,
10
15
  isEnabled,
11
16
  entry,
17
+ registerCompilers,
12
18
  };
13
19
  export default plugin;
@@ -0,0 +1,2 @@
1
+ declare const compiler: (text: string) => string;
2
+ export default compiler;
@@ -1,5 +1,4 @@
1
- const condition = (hasDependency) => hasDependency('tailwindcss');
2
- const directiveMatcher = /@(?:import|config|source|plugin)\s+['"]([^'"]+)['"][^;]*;/g;
1
+ const directiveMatcher = /@(?:import|config|plugin)\s+['"]([^'"]+)['"][^;]*;/g;
3
2
  const compiler = (text) => {
4
3
  const imports = [];
5
4
  let match;
@@ -9,4 +8,4 @@ const compiler = (text) => {
9
8
  imports.push(`import _$${index++} from '${match[1]}';`);
10
9
  return imports.join('\n');
11
10
  };
12
- export default { condition, compiler };
11
+ export default compiler;
@@ -1,12 +1,18 @@
1
1
  import { hasDependency } from '../../util/plugin.js';
2
+ import compiler from './compiler.js';
2
3
  const title = 'Tailwind';
3
4
  const enablers = ['tailwindcss'];
4
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
6
  const entry = ['tailwind.config.{js,cjs,mjs,ts}'];
7
+ const registerCompilers = ({ registerCompiler, hasDependency }) => {
8
+ if (hasDependency('tailwindcss'))
9
+ registerCompiler({ extension: '.css', compiler });
10
+ };
6
11
  const plugin = {
7
12
  title,
8
13
  enablers,
9
14
  isEnabled,
10
15
  entry,
16
+ registerCompilers,
11
17
  };
12
18
  export default plugin;
@@ -3,7 +3,7 @@ import { toConfig, toDeferResolve, toProductionDependency } from '../../util/inp
3
3
  import { join } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  const title = 'TypeScript';
6
- const enablers = ['typescript'];
6
+ const enablers = ['typescript', '@typescript/native-preview'];
7
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
8
  const config = ['tsconfig.json'];
9
9
  const resolveConfig = async (localConfig, options) => {
@@ -32,7 +32,7 @@ const resolveConfig = async (localConfig, options) => {
32
32
  ]);
33
33
  };
34
34
  const args = {
35
- binaries: ['tsc'],
35
+ binaries: ['tsc', 'tsgo'],
36
36
  string: ['project'],
37
37
  alias: { project: ['p'] },
38
38
  config: [['project', (p) => (p.endsWith('.json') ? p : join(p, 'tsconfig.json'))]],
@@ -1,2 +1,4 @@
1
1
  import ts from 'typescript';
2
+ import { type Input } from '../../util/input.js';
2
3
  export declare const getReactBabelPlugins: (sourceFile: ts.SourceFile) => string[];
4
+ export declare const getIndexHtmlEntries: (rootDir: string) => Promise<Input[]>;
@@ -1,5 +1,8 @@
1
1
  import ts from 'typescript';
2
2
  import { findDescendants, getDefaultImportName, getImportMap, stripQuotes } from '../../typescript/ast-helpers.js';
3
+ import { isFile, loadFile } from '../../util/fs.js';
4
+ import { toProductionEntry } from '../../util/input.js';
5
+ import { join } from '../../util/path.js';
3
6
  export const getReactBabelPlugins = (sourceFile) => {
4
7
  const babelPlugins = [];
5
8
  const importMap = getImportMap(sourceFile);
@@ -74,3 +77,23 @@ export const getReactBabelPlugins = (sourceFile) => {
74
77
  }
75
78
  return babelPlugins;
76
79
  };
80
+ const moduleScriptPattern = /<script\b(?=[^>]*\btype\s*=\s*["']?module["']?)(?=[^>]*\bsrc\s*=\s*["']?([^"' >]+)["']?)[^>]*>/gi;
81
+ const normalizeModuleScriptSrc = (value) => value.trim().replace(/^\//, '');
82
+ const getModuleScriptSources = (html) => {
83
+ const matches = html.matchAll(moduleScriptPattern);
84
+ const sources = [];
85
+ for (const match of matches) {
86
+ const src = normalizeModuleScriptSrc(match[1]);
87
+ if (src)
88
+ sources.push(src);
89
+ }
90
+ return sources;
91
+ };
92
+ export const getIndexHtmlEntries = async (rootDir) => {
93
+ const indexPath = join(rootDir, 'index.html');
94
+ if (!isFile(indexPath))
95
+ return [];
96
+ const html = await loadFile(indexPath);
97
+ const entries = getModuleScriptSources(html).map(src => join(rootDir, src));
98
+ return entries.map(entry => toProductionEntry(entry));
99
+ };
@@ -1,7 +1,8 @@
1
1
  import { toDependency } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import { resolveConfig } from '../vitest/index.js';
4
- import { getReactBabelPlugins } from './helpers.js';
4
+ import { getIndexHtmlEntries, getReactBabelPlugins } from './helpers.js';
5
+ import { importMetaGlobCall } from './visitors/importMetaGlob.js';
5
6
  const title = 'Vite';
6
7
  const enablers = ['vite', 'vitest'];
7
8
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -10,6 +11,12 @@ const resolveFromAST = (sourceFile) => {
10
11
  const babelPlugins = getReactBabelPlugins(sourceFile);
11
12
  return babelPlugins.map(plugin => toDependency(plugin));
12
13
  };
14
+ const resolve = async (options) => {
15
+ return getIndexHtmlEntries(options.cwd);
16
+ };
17
+ const registerVisitors = ({ registerVisitors }) => {
18
+ registerVisitors({ dynamicImport: [importMetaGlobCall] });
19
+ };
13
20
  const args = {
14
21
  config: true,
15
22
  };
@@ -20,6 +27,8 @@ const plugin = {
20
27
  config,
21
28
  resolveConfig,
22
29
  resolveFromAST,
30
+ resolve,
31
+ registerVisitors,
23
32
  args,
24
33
  };
25
34
  export default plugin;
@@ -0,0 +1,2 @@
1
+ import type { ImportVisitor } from '../../../typescript/visitors/index.js';
2
+ export declare const importMetaGlobCall: ImportVisitor;
@@ -0,0 +1,32 @@
1
+ import ts from 'typescript';
2
+ import { IMPORT_FLAGS } from '../../../constants.js';
3
+ import { isPropertyAccessCall } from '../../../typescript/ast-helpers.js';
4
+ import { _syncGlob } from '../../../util/glob.js';
5
+ import { dirname, isAbsolute, join } from '../../../util/path.js';
6
+ export const importMetaGlobCall = sourceFile => {
7
+ return node => {
8
+ if (!isPropertyAccessCall(node, 'import.meta.glob'))
9
+ return;
10
+ const arg = node.arguments[0];
11
+ if (!arg)
12
+ return;
13
+ const dir = dirname(sourceFile.fileName);
14
+ const patterns = ts.isStringLiteralLike(arg)
15
+ ? [arg.text]
16
+ : ts.isArrayLiteralExpression(arg)
17
+ ? arg.elements.filter(ts.isStringLiteralLike).map(e => e.text)
18
+ : undefined;
19
+ if (!patterns?.length)
20
+ return;
21
+ const files = _syncGlob({ patterns, cwd: dir });
22
+ return files.map(filePath => ({
23
+ specifier: isAbsolute(filePath) ? filePath : join(dir, filePath),
24
+ identifier: undefined,
25
+ pos: arg.pos,
26
+ modifiers: IMPORT_FLAGS.ENTRY,
27
+ alias: undefined,
28
+ namespace: undefined,
29
+ symbol: undefined,
30
+ }));
31
+ };
32
+ };
@@ -10,10 +10,8 @@ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
10
10
  const config = ['vitest.config.{js,mjs,ts,cjs,mts,cts}', 'vitest.{workspace,projects}.{js,mjs,ts,cjs,mts,cts,json}'];
11
11
  const mocks = ['**/__mocks__/**/*.[jt]s?(x)'];
12
12
  const entry = ['**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)', ...mocks];
13
- const isVitestCoverageCommand = /vitest(.+)--coverage(?:\.enabled(?:=true)?)?/;
14
- const hasScriptWithCoverage = (scripts) => scripts ? Object.values(scripts).some(script => isVitestCoverageCommand.test(script)) : false;
15
- const findConfigDependencies = (localConfig, options) => {
16
- const { manifest, configFileDir: dir } = options;
13
+ const findConfigDependencies = (localConfig, options, vitestRoot) => {
14
+ const { configFileDir: dir } = options;
17
15
  const testConfig = localConfig.test;
18
16
  if (!testConfig)
19
17
  return [];
@@ -24,21 +22,23 @@ const findConfigDependencies = (localConfig, options) => {
24
22
  : [toDependency(getEnvSpecifier(env))]
25
23
  : [];
26
24
  const reporters = getExternalReporters(testConfig.reporters);
27
- const hasCoverageEnabled = (testConfig.coverage && testConfig.coverage.enabled !== false) || hasScriptWithCoverage(manifest.scripts);
25
+ const hasCoverageEnabled = testConfig.coverage && testConfig.coverage.enabled !== false;
28
26
  const coverage = hasCoverageEnabled ? [`@vitest/coverage-${testConfig.coverage?.provider ?? 'v8'}`] : [];
29
- const setupFiles = [testConfig.setupFiles ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));
27
+ const setupFiles = [testConfig.setupFiles ?? []]
28
+ .flat()
29
+ .map(specifier => ({ ...toDeferResolve(specifier), dir: vitestRoot }));
30
30
  const globalSetup = [testConfig.globalSetup ?? []].flat().map(specifier => ({ ...toDeferResolve(specifier), dir }));
31
31
  const workspaceDependencies = [];
32
32
  if (testConfig.workspace !== undefined) {
33
33
  for (const workspaceConfig of testConfig.workspace) {
34
- workspaceDependencies.push(...findConfigDependencies(workspaceConfig, options));
34
+ workspaceDependencies.push(...findConfigDependencies(workspaceConfig, options, vitestRoot));
35
35
  }
36
36
  }
37
37
  const projectsDependencies = [];
38
38
  if (testConfig.projects !== undefined) {
39
39
  for (const projectConfig of testConfig.projects) {
40
40
  if (typeof projectConfig !== 'string') {
41
- projectsDependencies.push(...findConfigDependencies(projectConfig, options));
41
+ projectsDependencies.push(...findConfigDependencies(projectConfig, options, vitestRoot));
42
42
  }
43
43
  }
44
44
  }
@@ -148,7 +148,7 @@ export const resolveConfig = async (localConfig, options) => {
148
148
  inputs.add(toEntry(`src/**/*${ext}`));
149
149
  }
150
150
  }
151
- for (const dependency of findConfigDependencies(cfg, options))
151
+ for (const dependency of findConfigDependencies(cfg, options, dir))
152
152
  inputs.add(dependency);
153
153
  const _entry = cfg.build?.lib?.entry ?? [];
154
154
  const deps = (typeof _entry === 'string' ? [_entry] : Object.values(_entry))
@@ -165,6 +165,21 @@ const args = {
165
165
  const inputs = [];
166
166
  if (parsed['ui'])
167
167
  inputs.push(toDependency('@vitest/ui', { optional: true }));
168
+ if (parsed['coverage']) {
169
+ const provider = typeof parsed['coverage'] === 'object' ? parsed['coverage'].provider : undefined;
170
+ inputs.push(toDependency(`@vitest/coverage-${provider ?? 'v8'}`));
171
+ }
172
+ if (parsed['reporter']) {
173
+ for (const reporter of getExternalReporters([parsed['reporter']].flat())) {
174
+ inputs.push(toDependency(reporter));
175
+ }
176
+ }
177
+ if (parsed['environment'] && parsed['environment'] !== 'node') {
178
+ inputs.push(toDependency(getEnvSpecifier(parsed['environment'])));
179
+ }
180
+ if (typeof parsed['typecheck'] === 'object' && parsed['typecheck'].checker) {
181
+ inputs.push(toDependency(parsed['typecheck'].checker === 'tsc' ? 'typescript' : parsed['typecheck'].checker));
182
+ }
168
183
  return inputs;
169
184
  },
170
185
  };
@@ -0,0 +1,2 @@
1
+ declare const compiler: import("../../compilers/types.js").CompilerSync;
2
+ export default compiler;
@@ -0,0 +1,3 @@
1
+ import { scriptBodies } from '../../compilers/compilers.js';
2
+ const compiler = scriptBodies;
3
+ export default compiler;
@@ -1,6 +1,7 @@
1
1
  import { toDependency } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
3
  import { findWebpackDependenciesFromConfig } from '../webpack/index.js';
4
+ import compiler from './compiler.js';
4
5
  const title = 'Vue';
5
6
  const enablers = ['vue'];
6
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -27,11 +28,16 @@ const resolveConfig = async (config, options) => {
27
28
  }
28
29
  return inputs;
29
30
  };
31
+ const registerCompilers = ({ registerCompiler, hasDependency }) => {
32
+ if (hasDependency('vue') || hasDependency('nuxt'))
33
+ registerCompiler({ extension: '.vue', compiler });
34
+ };
30
35
  const plugin = {
31
36
  title,
32
37
  enablers,
33
38
  isEnabled,
34
39
  config,
35
40
  resolveConfig,
41
+ registerCompilers,
36
42
  };
37
43
  export default plugin;
@@ -1,8 +1,8 @@
1
- import { compact } from '../../util/array.js';
2
1
  import { toAlias, toDeferResolve, toDeferResolveEntry, toDeferResolveProductionEntry, toDependency, } from '../../util/input.js';
3
2
  import { isInternal, join, toAbsolute } from '../../util/path.js';
4
3
  import { hasDependency } from '../../util/plugin.js';
5
4
  import { getDependenciesFromConfig } from '../babel/index.js';
5
+ import { requireContextCall } from './visitors/requireContext.js';
6
6
  const title = 'webpack';
7
7
  const enablers = ['webpack', 'webpack-cli'];
8
8
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
@@ -140,16 +140,23 @@ export const findWebpackDependenciesFromConfig = async (config, options) => {
140
140
  return Array.from(inputs);
141
141
  };
142
142
  const resolveConfig = async (localConfig, options) => {
143
- const { manifest } = options;
144
143
  const inputs = await findWebpackDependenciesFromConfig(localConfig, options);
145
- const scripts = Object.values(manifest.scripts ?? {});
146
- const webpackCLI = scripts.some(script => script && /(?<=^|\s)webpack(?=\s|$)/.test(script)) ? ['webpack-cli'] : [];
147
- const webpackDevServer = scripts.some(script => script?.includes('webpack serve')) ? ['webpack-dev-server'] : [];
148
- return compact([...inputs, ...[...webpackCLI, ...webpackDevServer].map(id => toDependency(id))]);
144
+ inputs.push(toDependency('webpack-cli', { optional: true }));
145
+ return inputs;
149
146
  };
147
+ const registerVisitors = ({ registerVisitors }) => {
148
+ registerVisitors({ dynamicImport: [requireContextCall] });
149
+ };
150
+ const isFilterTransitiveDependencies = true;
150
151
  const args = {
151
152
  binaries: ['webpack', 'webpack-dev-server'],
152
153
  config: true,
154
+ resolveInputs: (parsed) => {
155
+ const inputs = [toDependency('webpack-cli')];
156
+ if (parsed._[0] === 'serve')
157
+ inputs.push(toDependency('webpack-dev-server'));
158
+ return inputs;
159
+ },
153
160
  };
154
161
  const plugin = {
155
162
  title,
@@ -157,6 +164,8 @@ const plugin = {
157
164
  isEnabled,
158
165
  config,
159
166
  resolveConfig,
167
+ registerVisitors,
168
+ isFilterTransitiveDependencies,
160
169
  args,
161
170
  };
162
171
  export default plugin;
@@ -0,0 +1,2 @@
1
+ import type { ImportVisitor } from '../../../typescript/visitors/index.js';
2
+ export declare const requireContextCall: ImportVisitor;
@@ -0,0 +1,29 @@
1
+ import ts from 'typescript';
2
+ import { IMPORT_FLAGS } from '../../../constants.js';
3
+ import { isPropertyAccessCall } from '../../../typescript/ast-helpers.js';
4
+ import { _syncGlob } from '../../../util/glob.js';
5
+ import { dirname, isAbsolute, join } from '../../../util/path.js';
6
+ export const requireContextCall = sourceFile => {
7
+ return node => {
8
+ if (!isPropertyAccessCall(node, 'require.context'))
9
+ return;
10
+ const [dirArg, recursiveArg, regExpArg] = node.arguments;
11
+ if (!dirArg || !ts.isStringLiteralLike(dirArg))
12
+ return;
13
+ const cwd = join(dirname(sourceFile.fileName), dirArg.text);
14
+ const isRecursive = !recursiveArg || recursiveArg.kind !== ts.SyntaxKind.FalseKeyword;
15
+ const pattern = isRecursive ? '**/*' : '*';
16
+ const files = _syncGlob({ patterns: [pattern], cwd });
17
+ const filter = regExpArg && ts.isRegularExpressionLiteral(regExpArg) ? regExpArg.text.match(/^\/(.+)\/([gimsuy]*)$/) : null;
18
+ const matched = filter ? files.filter(file => new RegExp(filter[1], filter[2]).test(file)) : files;
19
+ return matched.map(filePath => ({
20
+ specifier: isAbsolute(filePath) ? filePath : join(cwd, filePath),
21
+ identifier: undefined,
22
+ pos: dirArg.pos,
23
+ modifiers: IMPORT_FLAGS.ENTRY,
24
+ alias: undefined,
25
+ namespace: undefined,
26
+ symbol: undefined,
27
+ }));
28
+ };
29
+ };
@@ -1,14 +1,32 @@
1
1
  import { isFile } from '../../util/fs.js';
2
+ import { toEntry } from '../../util/input.js';
2
3
  const title = 'Yarn';
3
4
  const enablers = 'This plugin is enabled when a `yarn.lock` file is found in the root folder.';
4
5
  const isEnabled = async ({ cwd }) => isFile(cwd, 'yarn.lock');
5
6
  const isRootOnly = true;
7
+ const config = ['.yarnrc.yml'];
6
8
  const entry = ['yarn.config.cjs'];
9
+ const resolveConfig = config => {
10
+ const inputs = entry.map(id => toEntry(id));
11
+ if (Array.isArray(config.plugins)) {
12
+ for (const plugin of config.plugins) {
13
+ if (plugin.path) {
14
+ inputs.push(toEntry(plugin.path));
15
+ }
16
+ }
17
+ }
18
+ if (config.yarnPath) {
19
+ inputs.push(toEntry(config.yarnPath));
20
+ }
21
+ return inputs;
22
+ };
7
23
  const plugin = {
8
24
  title,
9
25
  enablers,
10
26
  isEnabled,
11
27
  isRootOnly,
28
+ config,
12
29
  entry,
30
+ resolveConfig,
13
31
  };
14
32
  export default plugin;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.js';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,15 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ import zxVisitor from './visitors/zx.js';
3
+ const title = 'zx';
4
+ const enablers = ['zx'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const registerVisitors = ({ registerVisitors }) => {
7
+ registerVisitors({ script: [zxVisitor] });
8
+ };
9
+ const plugin = {
10
+ title,
11
+ enablers,
12
+ isEnabled,
13
+ registerVisitors,
14
+ };
15
+ export default plugin;
@@ -1,6 +1,6 @@
1
1
  import ts from 'typescript';
2
- import { stripQuotes } from '../../ast-helpers.js';
3
- import { scriptVisitor as visit } from '../index.js';
2
+ import { stripQuotes } from '../../../typescript/ast-helpers.js';
3
+ import { scriptVisitor as visit } from '../../../typescript/visitors/index.js';
4
4
  export default visit(sourceFile => ts.getShebang(sourceFile.text) === '#!/usr/bin/env zx', node => {
5
5
  if (ts.isTaggedTemplateExpression(node) && node.tag.getText() === '$') {
6
6
  return stripQuotes(node.template.getText());
@@ -40,6 +40,8 @@ const addWorkspace = (options) => options.configFilePath
40
40
  : `Create ${bright('knip.json')} configuration file with ${bright(`workspaces["${options.workspaceName}"]`)} object (${options.size} unused files)`;
41
41
  const packageEntry = () => 'Package entry file not found';
42
42
  const hintPrinters = new Map([
43
+ ['ignore', { print: unused }],
44
+ ['ignoreFiles', { print: unused }],
43
45
  ['ignoreBinaries', { print: unused }],
44
46
  ['ignoreDependencies', { print: unused }],
45
47
  ['ignoreUnresolved', { print: unused }],
@@ -58,6 +60,7 @@ export { hintPrinters };
58
60
  const hintTypesOrder = [
59
61
  ['top-level-unconfigured', 'workspace-unconfigured'],
60
62
  ['entry-top-level', 'project-top-level'],
63
+ ['ignore', 'ignoreFiles'],
61
64
  ['ignoreWorkspaces'],
62
65
  ['ignoreDependencies'],
63
66
  ['ignoreBinaries'],
@@ -45,8 +45,8 @@ export const getTableForType = (issues, cwd, options = { isUseColors: true }) =>
45
45
  const print = options.isUseColors && (issue.isFixed || issue.severity === 'warn') ? dim : plain;
46
46
  const isFileIssue = issue.type === 'files';
47
47
  const symbol = issue.symbols ? issue.symbols.map(s => s.symbol).join(', ') : issue.symbol;
48
- const displaySymbol = isFileIssue ? '' : symbol;
49
- table.cell('symbol', print(displaySymbol), options.isUseColors ? highlightSymbol(issue) : () => displaySymbol);
48
+ if (!isFileIssue)
49
+ table.cell('symbol', print(symbol), options.isUseColors ? highlightSymbol(issue) : () => symbol);
50
50
  table.cell('parentSymbol', issue.parentSymbol && print(issue.parentSymbol));
51
51
  table.cell('symbolType', issue.symbolType && issue.symbolType !== SYMBOL_TYPE.UNKNOWN && print(issue.symbolType));
52
52
  const pos = issue.line === undefined ? '' : `:${issue.line}${issue.col === undefined ? '' : `:${issue.col}`}`;
package/dist/run.d.ts CHANGED
@@ -18,7 +18,7 @@ export declare const run: (options: MainOptions) => Promise<{
18
18
  handleFileChanges: (changes: import("./util/watch.js").WatchChange[]) => Promise<{
19
19
  duration: number;
20
20
  mem: number;
21
- }>;
21
+ } | undefined>;
22
22
  getEntryPaths: () => Set<string>;
23
23
  getGraph: () => import("./types/module-graph.js").ModuleGraph;
24
24
  getIssues: () => {