knip 2.30.1 → 2.32.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 (103) hide show
  1. package/README.md +15 -24
  2. package/dist/ConfigurationChief.d.ts +2 -0
  3. package/dist/ConfigurationChief.js +57 -61
  4. package/dist/ConfigurationValidator.d.ts +377 -321
  5. package/dist/ConfigurationValidator.js +2 -1
  6. package/dist/WorkspaceWorker.d.ts +8 -6
  7. package/dist/WorkspaceWorker.js +41 -62
  8. package/dist/binaries/index.js +1 -1
  9. package/dist/binaries/resolvers/c8.js +2 -1
  10. package/dist/binaries/resolvers/dotenv.js +2 -1
  11. package/dist/binaries/resolvers/fallback.js +2 -1
  12. package/dist/binaries/resolvers/nodemon.js +2 -1
  13. package/dist/binaries/resolvers/npx.js +2 -1
  14. package/dist/binaries/resolvers/nx.js +1 -1
  15. package/dist/binaries/resolvers/pnpm.js +1 -1
  16. package/dist/binaries/resolvers/rollup.js +2 -1
  17. package/dist/binaries/resolvers/yarn.js +1 -1
  18. package/dist/binaries/util.d.ts +0 -3
  19. package/dist/binaries/util.js +1 -3
  20. package/dist/constants.d.ts +0 -1
  21. package/dist/constants.js +0 -4
  22. package/dist/index.js +27 -20
  23. package/dist/plugins/ava/index.d.ts +1 -1
  24. package/dist/plugins/ava/index.js +23 -5
  25. package/dist/plugins/ava/types.d.ts +1 -0
  26. package/dist/plugins/babel/index.js +3 -1
  27. package/dist/plugins/capacitor/index.js +3 -1
  28. package/dist/plugins/changesets/index.js +3 -1
  29. package/dist/plugins/commitizen/index.d.ts +1 -0
  30. package/dist/plugins/commitizen/index.js +4 -1
  31. package/dist/plugins/commitlint/index.js +3 -1
  32. package/dist/plugins/cspell/index.js +3 -1
  33. package/dist/plugins/cypress/index.d.ts +3 -1
  34. package/dist/plugins/cypress/index.js +14 -4
  35. package/dist/plugins/drizzle/index.js +3 -5
  36. package/dist/plugins/eslint/helpers.js +2 -1
  37. package/dist/plugins/eslint/index.d.ts +1 -0
  38. package/dist/plugins/eslint/index.js +4 -1
  39. package/dist/plugins/gatsby/index.js +10 -2
  40. package/dist/plugins/github-actions/index.js +3 -1
  41. package/dist/plugins/husky/index.js +3 -1
  42. package/dist/plugins/index.d.ts +1 -0
  43. package/dist/plugins/index.js +1 -0
  44. package/dist/plugins/jest/index.d.ts +1 -1
  45. package/dist/plugins/jest/index.js +16 -7
  46. package/dist/plugins/lefthook/index.js +4 -2
  47. package/dist/plugins/lint-staged/index.d.ts +1 -0
  48. package/dist/plugins/lint-staged/index.js +4 -1
  49. package/dist/plugins/markdownlint/index.js +3 -1
  50. package/dist/plugins/mocha/index.d.ts +1 -0
  51. package/dist/plugins/mocha/index.js +10 -6
  52. package/dist/plugins/next/index.d.ts +2 -1
  53. package/dist/plugins/next/index.js +4 -0
  54. package/dist/plugins/node-test-runner/index.d.ts +6 -0
  55. package/dist/plugins/node-test-runner/index.js +17 -0
  56. package/dist/plugins/npm-package-json-lint/index.d.ts +1 -0
  57. package/dist/plugins/npm-package-json-lint/index.js +5 -2
  58. package/dist/plugins/nx/index.js +3 -1
  59. package/dist/plugins/nyc/index.js +3 -1
  60. package/dist/plugins/playwright/index.d.ts +3 -1
  61. package/dist/plugins/playwright/index.js +22 -2
  62. package/dist/plugins/playwright-ct/index.d.ts +3 -1
  63. package/dist/plugins/playwright-ct/index.js +13 -2
  64. package/dist/plugins/postcss/index.js +8 -6
  65. package/dist/plugins/prettier/index.js +3 -1
  66. package/dist/plugins/release-it/index.d.ts +1 -0
  67. package/dist/plugins/release-it/index.js +5 -2
  68. package/dist/plugins/remark/index.d.ts +1 -0
  69. package/dist/plugins/remark/index.js +10 -3
  70. package/dist/plugins/remix/index.d.ts +2 -1
  71. package/dist/plugins/remix/index.js +10 -0
  72. package/dist/plugins/rollup/index.d.ts +2 -1
  73. package/dist/plugins/rollup/index.js +7 -0
  74. package/dist/plugins/semantic-release/index.d.ts +1 -0
  75. package/dist/plugins/semantic-release/index.js +7 -2
  76. package/dist/plugins/sentry/index.d.ts +2 -1
  77. package/dist/plugins/sentry/index.js +7 -0
  78. package/dist/plugins/storybook/index.js +6 -2
  79. package/dist/plugins/stryker/index.js +9 -8
  80. package/dist/plugins/stylelint/index.js +3 -1
  81. package/dist/plugins/svelte/index.d.ts +2 -1
  82. package/dist/plugins/svelte/index.js +6 -0
  83. package/dist/plugins/typedoc/index.d.ts +1 -0
  84. package/dist/plugins/typedoc/index.js +5 -2
  85. package/dist/plugins/typescript/index.js +3 -1
  86. package/dist/plugins/vite/index.js +2 -2
  87. package/dist/plugins/vitest/index.d.ts +3 -3
  88. package/dist/plugins/vitest/index.js +16 -23
  89. package/dist/plugins/vitest/types.d.ts +1 -0
  90. package/dist/plugins/webpack/index.js +3 -1
  91. package/dist/types/config.d.ts +5 -3
  92. package/dist/types/plugins.d.ts +3 -3
  93. package/dist/util/compilers.d.ts +90 -80
  94. package/dist/util/object.d.ts +1 -0
  95. package/dist/util/object.js +1 -0
  96. package/dist/util/plugin.d.ts +2 -2
  97. package/dist/util/plugin.js +2 -2
  98. package/dist/util/protocols.d.ts +9 -0
  99. package/dist/util/protocols.js +9 -0
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.js +1 -1
  102. package/package.json +2 -1
  103. package/schema.json +4 -0
@@ -51,7 +51,7 @@ const reportConfigSchema = z.object({
51
51
  exclude: z.array(z.string()).optional(),
52
52
  });
53
53
  export const pluginSchema = z.union([
54
- z.literal(false),
54
+ z.boolean(),
55
55
  globSchema,
56
56
  z.object({
57
57
  config: globSchema.optional(),
@@ -79,6 +79,7 @@ const pluginsSchema = z.object({
79
79
  markdownlint: pluginSchema,
80
80
  mocha: pluginSchema,
81
81
  next: pluginSchema,
82
+ 'node-test-runner': pluginSchema,
82
83
  'npm-package-json-lint': pluginSchema,
83
84
  nx: pluginSchema,
84
85
  nyc: pluginSchema,
@@ -31,19 +31,19 @@ export declare class WorkspaceWorker {
31
31
  hostDependencies: HostDependencies;
32
32
  installedBinaries: InstalledBinaries;
33
33
  hasTypesIncluded: Set<string>;
34
+ entryFilePatterns: Set<string>;
35
+ productionEntryFilePatterns: Set<string>;
34
36
  constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }: WorkspaceManagerOptions);
35
37
  init(): Promise<void>;
36
38
  private setEnabledPlugins;
37
39
  private initReferencedDependencies;
38
40
  private getConfigForPlugin;
39
41
  getEntryFilePatterns(): string[];
40
- getProjectFilePatterns(): string[];
41
- getPluginEntryFilePatterns(isIncludeProductionEntryFiles?: boolean): string[];
42
+ getProjectFilePatterns(testFilePatterns: string[]): string[];
42
43
  getPluginProjectFilePatterns(): string[];
43
44
  getPluginConfigPatterns(): string[];
44
- getProductionEntryFilePatterns(): string[];
45
- getProductionProjectFilePatterns(): string[];
46
- getProductionPluginEntryFilePatterns(): string[];
45
+ getProductionEntryFilePatterns(negatedTestFilePatterns: string[]): string[];
46
+ getProductionProjectFilePatterns(negatedTestFilePatterns: string[]): string[];
47
47
  private getConfigurationFilePatterns;
48
48
  getIgnorePatterns(): string[];
49
49
  private findDependenciesByPlugins;
@@ -52,7 +52,9 @@ export declare class WorkspaceWorker {
52
52
  installedBinaries: InstalledBinaries;
53
53
  referencedDependencies: ReferencedDependencies;
54
54
  hasTypesIncluded: Set<string>;
55
- enabledPlugins: ("angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "drizzle" | "githubActions" | "lintStaged" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
55
+ enabledPlugins: ("angular" | "ava" | "babel" | "capacitor" | "changesets" | "commitizen" | "commitlint" | "cspell" | "cypress" | "eslint" | "gatsby" | "husky" | "jest" | "lefthook" | "markdownlint" | "mocha" | "next" | "nx" | "nyc" | "playwright" | "postcss" | "prettier" | "remark" | "remix" | "rollup" | "sentry" | "storybook" | "stryker" | "stylelint" | "tailwind" | "typedoc" | "typescript" | "vite" | "vitest" | "webpack" | "drizzle" | "githubActions" | "lintStaged" | "nodeTestRunner" | "npmPackageJsonLint" | "playwrightCt" | "releaseIt" | "semanticRelease" | "svelte")[];
56
+ entryFilePatterns: string[];
57
+ productionEntryFilePatterns: string[];
56
58
  }>;
57
59
  }
58
60
  export {};
@@ -1,11 +1,11 @@
1
- import { TEST_FILE_PATTERNS } from './constants.js';
2
1
  import * as npm from './manifest/index.js';
3
2
  import * as plugins from './plugins/index.js';
4
3
  import { debugLogArray, debugLogObject } from './util/debug.js';
5
4
  import { _pureGlob, negate, hasProductionSuffix, hasNoProductionSuffix, prependDirToPattern } from './util/glob.js';
6
- import { getKeysByValue } from './util/object.js';
5
+ import { get, getKeysByValue } from './util/object.js';
7
6
  import { join, toPosix } from './util/path.js';
8
- const negatedTestFilePatterns = TEST_FILE_PATTERNS.map(negate);
7
+ import { fromEntryPattern, fromProductionEntryPattern, isEntryPattern, isProductionEntryPattern, } from './util/protocols.js';
8
+ const nullConfig = { config: null, entry: null, project: null };
9
9
  export class WorkspaceWorker {
10
10
  name;
11
11
  dir;
@@ -23,6 +23,8 @@ export class WorkspaceWorker {
23
23
  hostDependencies = new Map();
24
24
  installedBinaries = new Map();
25
25
  hasTypesIncluded = new Set();
26
+ entryFilePatterns = new Set();
27
+ productionEntryFilePatterns = new Set();
26
28
  constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
27
29
  this.name = name;
28
30
  this.dir = dir;
@@ -49,6 +51,10 @@ export class WorkspaceWorker {
49
51
  for (const [pluginName, plugin] of pluginEntries) {
50
52
  if (this.config[pluginName] === false)
51
53
  continue;
54
+ if (this.config[pluginName]) {
55
+ this.enabled[pluginName] = true;
56
+ continue;
57
+ }
52
58
  const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
53
59
  if (isEnabledInAncestor ||
54
60
  (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies, config: this.config }))) {
@@ -72,61 +78,38 @@ export class WorkspaceWorker {
72
78
  this.hostDependencies = hostDependencies;
73
79
  this.installedBinaries = installedBinaries;
74
80
  this.hasTypesIncluded = hasTypesIncluded;
81
+ this.hasTypesIncluded = hasTypesIncluded;
75
82
  }
76
83
  getConfigForPlugin(pluginName) {
77
- return this.config[pluginName] ?? { config: null, entry: null, project: null };
84
+ return this.config[pluginName] !== true ? this.config[pluginName] ?? nullConfig : nullConfig;
78
85
  }
79
86
  getEntryFilePatterns() {
80
87
  const { entry } = this.config;
81
88
  if (entry.length === 0)
82
89
  return [];
83
- return [entry, TEST_FILE_PATTERNS, this.negatedWorkspacePatterns].flat();
90
+ return [entry, this.negatedWorkspacePatterns].flat();
84
91
  }
85
- getProjectFilePatterns() {
92
+ getProjectFilePatterns(testFilePatterns) {
86
93
  const { project } = this.config;
87
94
  if (project.length === 0)
88
95
  return [];
89
96
  const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
90
- const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
91
97
  const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
92
98
  return [
93
99
  project,
94
100
  negatedPluginConfigPatterns,
95
- negatedPluginEntryFilePatterns,
96
101
  negatedPluginProjectFilePatterns,
97
- TEST_FILE_PATTERNS,
102
+ testFilePatterns,
98
103
  this.negatedWorkspacePatterns,
99
104
  ].flat();
100
105
  }
101
- getPluginEntryFilePatterns(isIncludeProductionEntryFiles = true) {
102
- const patterns = [];
103
- for (const [pluginName, plugin] of Object.entries(plugins)) {
104
- const pluginConfig = this.getConfigForPlugin(pluginName);
105
- if (this.enabled[pluginName] && pluginConfig) {
106
- const { entry } = pluginConfig;
107
- const defaultEntryFiles = 'ENTRY_FILE_PATTERNS' in plugin ? plugin.ENTRY_FILE_PATTERNS : [];
108
- patterns.push(...(entry ?? defaultEntryFiles));
109
- if (isIncludeProductionEntryFiles) {
110
- const entry = 'PRODUCTION_ENTRY_FILE_PATTERNS' in plugin ? plugin.PRODUCTION_ENTRY_FILE_PATTERNS : [];
111
- patterns.push(...entry);
112
- }
113
- }
114
- }
115
- return [patterns, this.negatedWorkspacePatterns].flat();
116
- }
117
106
  getPluginProjectFilePatterns() {
118
107
  const patterns = [];
119
108
  for (const [pluginName, plugin] of Object.entries(plugins)) {
120
109
  const pluginConfig = this.getConfigForPlugin(pluginName);
121
110
  if (this.enabled[pluginName] && pluginConfig) {
122
- const { entry, project } = pluginConfig;
123
- patterns.push(...(project ??
124
- entry ??
125
- ('PROJECT_FILE_PATTERNS' in plugin
126
- ? plugin.PROJECT_FILE_PATTERNS
127
- : 'ENTRY_FILE_PATTERNS' in plugin
128
- ? plugin.ENTRY_FILE_PATTERNS
129
- : [])));
111
+ const { entry, project } = pluginConfig === true ? nullConfig : pluginConfig;
112
+ patterns.push(...(project ?? entry ?? ('PROJECT_FILE_PATTERNS' in plugin ? plugin.PROJECT_FILE_PATTERNS : [])));
130
113
  }
131
114
  }
132
115
  return [patterns, this.negatedWorkspacePatterns].flat();
@@ -136,24 +119,24 @@ export class WorkspaceWorker {
136
119
  for (const [pluginName, plugin] of Object.entries(plugins)) {
137
120
  const pluginConfig = this.getConfigForPlugin(pluginName);
138
121
  if (this.enabled[pluginName] && pluginConfig) {
139
- const { config } = pluginConfig;
122
+ const { config } = pluginConfig === true ? nullConfig : pluginConfig;
140
123
  const defaultConfigFiles = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
141
124
  patterns.push(...(config ?? defaultConfigFiles));
142
125
  }
143
126
  }
144
127
  return patterns;
145
128
  }
146
- getProductionEntryFilePatterns() {
129
+ getProductionEntryFilePatterns(negatedTestFilePatterns) {
147
130
  const entry = this.config.entry.filter(hasProductionSuffix);
148
131
  if (entry.length === 0)
149
132
  return [];
150
133
  const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
151
134
  return [entry, negatedEntryFiles, negatedTestFilePatterns, this.negatedWorkspacePatterns].flat();
152
135
  }
153
- getProductionProjectFilePatterns() {
136
+ getProductionProjectFilePatterns(negatedTestFilePatterns) {
154
137
  const project = this.config.project;
155
138
  if (project.length === 0)
156
- return this.getProductionEntryFilePatterns();
139
+ return this.getProductionEntryFilePatterns(negatedTestFilePatterns);
157
140
  const _project = this.config.project.map(pattern => {
158
141
  if (!pattern.endsWith('!') && !pattern.startsWith('!'))
159
142
  return negate(pattern);
@@ -161,38 +144,22 @@ export class WorkspaceWorker {
161
144
  });
162
145
  const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
163
146
  const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
164
- const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
165
147
  const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
166
148
  return [
167
149
  _project,
168
150
  negatedEntryFiles,
169
151
  negatedPluginConfigPatterns,
170
- negatedPluginEntryFilePatterns,
171
152
  negatedPluginProjectFilePatterns,
172
153
  negatedTestFilePatterns,
173
154
  this.negatedWorkspacePatterns,
174
155
  ].flat();
175
156
  }
176
- getProductionPluginEntryFilePatterns() {
177
- const patterns = [];
178
- for (const [pluginName, plugin] of Object.entries(plugins)) {
179
- const pluginConfig = this.getConfigForPlugin(pluginName);
180
- if (this.enabled[pluginName] && pluginConfig) {
181
- if ('PRODUCTION_ENTRY_FILE_PATTERNS' in plugin) {
182
- patterns.push(...(pluginConfig.entry ?? plugin.PRODUCTION_ENTRY_FILE_PATTERNS));
183
- }
184
- }
185
- }
186
- if (patterns.length === 0)
187
- return [];
188
- return [patterns.flat(), negatedTestFilePatterns].flat();
189
- }
190
157
  getConfigurationFilePatterns(pluginName) {
191
158
  const plugin = plugins[pluginName];
192
159
  const pluginConfig = this.getConfigForPlugin(pluginName);
193
160
  if (pluginConfig) {
194
161
  const defaultConfig = 'CONFIG_FILE_PATTERNS' in plugin ? plugin.CONFIG_FILE_PATTERNS : [];
195
- return pluginConfig.config ?? defaultConfig;
162
+ return (pluginConfig === true ? null : pluginConfig.config) ?? defaultConfig;
196
163
  }
197
164
  return [];
198
165
  }
@@ -203,31 +170,41 @@ export class WorkspaceWorker {
203
170
  const cwd = this.dir;
204
171
  const ignore = this.getIgnorePatterns();
205
172
  for (const [pluginName, plugin] of Object.entries(plugins)) {
206
- const isIncludePlugin = this.isProduction ? `PRODUCTION_ENTRY_FILE_PATTERNS` in plugin : true;
207
- if (this.enabled[pluginName] && isIncludePlugin) {
173
+ if (this.enabled[pluginName]) {
208
174
  const hasDependencyFinder = 'findDependencies' in plugin && typeof plugin.findDependencies === 'function';
209
175
  if (hasDependencyFinder) {
210
176
  const pluginConfig = this.getConfigForPlugin(pluginName);
211
177
  if (!pluginConfig)
212
178
  continue;
213
179
  const patterns = this.getConfigurationFilePatterns(pluginName);
214
- const configFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
180
+ const allConfigFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
181
+ const configFilePaths = allConfigFilePaths.filter(filePath => !filePath.endsWith('package.json') ||
182
+ get(this.manifest, 'PACKAGE_JSON_PATH' in plugin ? plugin.PACKAGE_JSON_PATH : pluginName));
215
183
  debugLogArray(`Found ${plugin.NAME} config file paths`, configFilePaths);
216
- if (configFilePaths.length === 0)
184
+ if (patterns.length > 0 && configFilePaths.length === 0)
217
185
  continue;
186
+ if (patterns.length === 0)
187
+ configFilePaths.push('__FAKE__');
218
188
  const pluginDependencies = new Set();
219
189
  for (const configFilePath of configFilePaths) {
220
190
  const dependencies = await plugin.findDependencies(configFilePath, {
221
191
  cwd,
222
192
  manifest: this.manifest,
223
- config: pluginConfig,
193
+ config: pluginConfig === true ? nullConfig : pluginConfig,
224
194
  isProduction: this.isProduction,
225
195
  });
226
- dependencies.map(toPosix).forEach(specifier => {
196
+ dependencies.forEach(specifier => {
227
197
  pluginDependencies.add(specifier);
228
- this.referencedDependencies.add([configFilePath, specifier]);
198
+ if (isEntryPattern(specifier)) {
199
+ this.entryFilePatterns.add(fromEntryPattern(specifier));
200
+ }
201
+ else if (isProductionEntryPattern(specifier)) {
202
+ this.productionEntryFilePatterns.add(fromProductionEntryPattern(specifier));
203
+ }
204
+ else {
205
+ this.referencedDependencies.add([configFilePath, toPosix(specifier)]);
206
+ }
229
207
  });
230
- dependencies.forEach(dependency => pluginDependencies.add(dependency));
231
208
  }
232
209
  debugLogArray(`Dependencies referenced in ${plugin.NAME}`, pluginDependencies);
233
210
  }
@@ -242,6 +219,8 @@ export class WorkspaceWorker {
242
219
  referencedDependencies: this.referencedDependencies,
243
220
  hasTypesIncluded: this.hasTypesIncluded,
244
221
  enabledPlugins: this.enabledPlugins,
222
+ entryFilePatterns: Array.from(this.entryFilePatterns),
223
+ productionEntryFilePatterns: Array.from(this.productionEntryFilePatterns),
245
224
  };
246
225
  }
247
226
  }
@@ -2,8 +2,8 @@ import { compact } from '../util/array.js';
2
2
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
3
3
  import { isInternal } from '../util/path.js';
4
4
  import { timerify } from '../util/Performance.js';
5
+ import { isBinary } from '../util/protocols.js';
5
6
  import { getBinariesFromScript } from './bash-parser.js';
6
- import { isBinary } from './util.js';
7
7
  const defaultCwd = process.cwd();
8
8
  const getDependenciesFromScripts = (npmScripts, options = {}) => {
9
9
  const { cwd = defaultCwd, manifest = {}, knownGlobalsOnly = false } = options;
@@ -1,5 +1,6 @@
1
1
  import parseArgs from 'minimist';
2
- import { toBinary, argsFrom } from '../util.js';
2
+ import { toBinary } from '../../util/protocols.js';
3
+ import { argsFrom } from '../util.js';
3
4
  export const resolve = (binary, args, { fromArgs }) => {
4
5
  const parsed = parseArgs(args, {
5
6
  boolean: ['all', 'check-coverage', 'clean', 'exclude-after-remap', 'per-file', 'skip-full'],
@@ -1,5 +1,6 @@
1
1
  import parseArgs from 'minimist';
2
- import { toBinary, argsFrom } from '../util.js';
2
+ import { toBinary } from '../../util/protocols.js';
3
+ import { argsFrom } from '../util.js';
3
4
  export const resolve = (binary, args, { fromArgs }) => {
4
5
  const parsed = parseArgs(args);
5
6
  return [toBinary(binary), ...fromArgs(argsFrom(args, parsed._[0]))];
@@ -1,6 +1,7 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { compact } from '../../util/array.js';
3
- import { toBinary, tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
3
+ import { toBinary } from '../../util/protocols.js';
4
+ import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
4
5
  const withPositional = parsed => [parsed._[0], parsed.require].flat();
5
6
  const withoutPositional = parsed => [parsed.require].flat();
6
7
  const argFilters = {
@@ -1,6 +1,7 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { compact } from '../../util/array.js';
3
- import { toBinary, tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
3
+ import { toBinary } from '../../util/protocols.js';
4
+ import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
4
5
  export const resolve = (binary, args, { cwd, fromArgs }) => {
5
6
  const parsed = parseArgs(args, {
6
7
  string: ['r', 'exec'],
@@ -1,7 +1,8 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { isInternal } from '../../util/path.js';
3
+ import { toBinary } from '../../util/protocols.js';
3
4
  import { getBinariesFromScript } from '../bash-parser.js';
4
- import { argsFrom, stripVersionFromSpecifier, toBinary } from '../util.js';
5
+ import { argsFrom, stripVersionFromSpecifier } from '../util.js';
5
6
  export const resolve = (binary, args, { cwd, fromArgs, manifest }) => {
6
7
  const parsed = parseArgs(args, {
7
8
  boolean: ['yes', 'no'],
@@ -1,5 +1,5 @@
1
1
  import parseArgs from 'minimist';
2
- import { toBinary } from '../util.js';
2
+ import { toBinary } from '../../util/protocols.js';
3
3
  export const resolve = (binary, args, { fromArgs }) => {
4
4
  const parsed = parseArgs(args);
5
5
  const [command] = parsed._;
@@ -1,5 +1,5 @@
1
1
  import parseArgs from 'minimist';
2
- import { toBinary } from '../util.js';
2
+ import { toBinary } from '../../util/protocols.js';
3
3
  const commands = [
4
4
  'add',
5
5
  'audit',
@@ -1,6 +1,7 @@
1
1
  import parseArgs from 'minimist';
2
2
  import { compact } from '../../util/array.js';
3
- import { toBinary, tryResolveSpecifiers } from '../util.js';
3
+ import { toBinary } from '../../util/protocols.js';
4
+ import { tryResolveSpecifiers } from '../util.js';
4
5
  export const resolve = (binary, args, { cwd, fromArgs }) => {
5
6
  const safeArgs = args.filter(arg => arg !== '--watch');
6
7
  const parsed = parseArgs(safeArgs, { alias: { plugin: 'p' } });
@@ -1,5 +1,5 @@
1
1
  import parseArgs from 'minimist';
2
- import { toBinary } from '../util.js';
2
+ import { toBinary } from '../../util/protocols.js';
3
3
  const commands = [
4
4
  'add',
5
5
  'bin',
@@ -1,8 +1,5 @@
1
1
  export declare const tryResolveFilePath: (cwd: string, specifier: string, acceptModuleSpecifier?: boolean) => string | undefined;
2
2
  export declare const tryResolveSpecifiers: (cwd: string, specifiers: string[]) => (string | undefined)[];
3
- export declare const toBinary: (specifier: string) => string;
4
- export declare const fromBinary: (specifier: string) => string;
5
- export declare const isBinary: (specifier: string) => boolean;
6
3
  export declare const stripVersionFromSpecifier: (specifier: string) => string;
7
4
  export declare const stripBinaryPath: (command: string) => string;
8
5
  export declare const argsFrom: (args: string[], from: string) => string[];
@@ -1,5 +1,6 @@
1
1
  import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier } from '../util/modules.js';
2
2
  import { isInNodeModules, join } from '../util/path.js';
3
+ import { toBinary } from '../util/protocols.js';
3
4
  import { _tryResolve } from '../util/require.js';
4
5
  export const tryResolveFilePath = (cwd, specifier, acceptModuleSpecifier) => {
5
6
  if (specifier) {
@@ -22,9 +23,6 @@ export const tryResolveFilePath = (cwd, specifier, acceptModuleSpecifier) => {
22
23
  }
23
24
  };
24
25
  export const tryResolveSpecifiers = (cwd, specifiers) => specifiers.map(specifier => tryResolveFilePath(cwd, specifier, true));
25
- export const toBinary = (specifier) => specifier.replace(/^(bin:)?/, 'bin:');
26
- export const fromBinary = (specifier) => specifier.replace(/^(bin:)?/, '');
27
- export const isBinary = (specifier) => specifier.startsWith('bin:');
28
26
  export const stripVersionFromSpecifier = (specifier) => specifier.replace(/(\S+)@.*/, '$1');
29
27
  const stripNodeModulesFromPath = (command) => command.replace(/^(\.\/)?node_modules\//, '');
30
28
  export const stripBinaryPath = (command) => stripVersionFromSpecifier(stripNodeModulesFromPath(command)
@@ -2,7 +2,6 @@ import type { IssueType } from './types/issues.js';
2
2
  export declare const ROOT_WORKSPACE_NAME = ".";
3
3
  export declare const KNIP_CONFIG_LOCATIONS: string[];
4
4
  export declare const DEFAULT_EXTENSIONS: string[];
5
- export declare const TEST_FILE_PATTERNS: string[];
6
5
  export declare const GLOBAL_IGNORE_PATTERNS: string[];
7
6
  export declare const IGNORED_GLOBAL_BINARIES: string[];
8
7
  export declare const IGNORED_DEPENDENCIES: string[];
package/dist/constants.js CHANGED
@@ -1,10 +1,6 @@
1
1
  export const ROOT_WORKSPACE_NAME = '.';
2
2
  export const KNIP_CONFIG_LOCATIONS = ['knip.json', 'knip.jsonc', '.knip.json', '.knip.jsonc', 'knip.ts', 'knip.js'];
3
3
  export const DEFAULT_EXTENSIONS = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.tsx', '.mts', '.cts'];
4
- export const TEST_FILE_PATTERNS = [
5
- '**/*{.,-}{test,spec}.{js,jsx,ts,tsx,mjs,cjs}',
6
- '**/{test,__tests__}/**/*.{js,jsx,ts,tsx,mjs,cjs}',
7
- ];
8
4
  export const GLOBAL_IGNORE_PATTERNS = ['**/node_modules/**', '.yarn'];
9
5
  export const IGNORED_GLOBAL_BINARIES = [
10
6
  'bash',
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import micromatch from 'micromatch';
2
2
  import { _getDependenciesFromScripts } from './binaries/index.js';
3
- import { fromBinary, isBinary } from './binaries/util.js';
4
3
  import { ConfigurationChief } from './ConfigurationChief.js';
5
4
  import { ConsoleStreamer } from './ConsoleStreamer.js';
6
5
  import { ROOT_WORKSPACE_NAME } from './constants.js';
@@ -12,9 +11,10 @@ import { compact } from './util/array.js';
12
11
  import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
13
12
  import { LoaderError } from './util/errors.js';
14
13
  import { findFile } from './util/fs.js';
15
- import { _glob } from './util/glob.js';
14
+ import { _glob, negate } from './util/glob.js';
16
15
  import { getEntryPathFromManifest, getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, } from './util/modules.js';
17
16
  import { dirname, isInNodeModules, join, isInternal, toAbsolute } from './util/path.js';
17
+ import { fromBinary, isBinary } from './util/protocols.js';
18
18
  import { _resolveSpecifier, _tryResolve } from './util/require.js';
19
19
  import { _require } from './util/require.js';
20
20
  import { loadTSConfig } from './util/tsconfig-loader.js';
@@ -113,21 +113,30 @@ export const main = async (unresolvedConfiguration) => {
113
113
  const entryPathsFromManifest = await getEntryPathFromManifest(cwd, dir, manifest);
114
114
  debugLogArray(`Found entry paths in package.json (${name})`, entryPathsFromManifest);
115
115
  principal.addEntryPaths(entryPathsFromManifest);
116
+ const dependencies = await worker.findAllDependencies();
117
+ const { referencedDependencies, hostDependencies, installedBinaries, hasTypesIncluded, enabledPlugins, entryFilePatterns, productionEntryFilePatterns, } = dependencies;
118
+ deputy.addHostDependencies(name, hostDependencies);
119
+ deputy.setInstalledBinaries(name, installedBinaries);
120
+ deputy.setHasTypesIncluded(name, hasTypesIncluded);
121
+ enabledPluginsStore.set(name, enabledPlugins);
122
+ referencedDependencies.forEach(([containingFilePath, specifier]) => {
123
+ handleReferencedDependency({ specifier, containingFilePath, principal, workspace });
124
+ });
116
125
  if (isProduction) {
126
+ const negatedEntryPatterns = entryFilePatterns.map(negate);
117
127
  {
118
- const patterns = worker.getProductionEntryFilePatterns();
128
+ const patterns = worker.getProductionEntryFilePatterns(negatedEntryPatterns);
119
129
  const workspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
120
130
  debugLogArray(`Found entry paths (${name})`, workspaceEntryPaths);
121
131
  principal.addEntryPaths(workspaceEntryPaths);
122
132
  }
123
133
  {
124
- const patterns = worker.getProductionPluginEntryFilePatterns();
125
- const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
134
+ const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns: productionEntryFilePatterns });
126
135
  debugLogArray(`Found production plugin entry paths (${name})`, pluginWorkspaceEntryPaths);
127
136
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
128
137
  }
129
138
  {
130
- const patterns = worker.getProductionProjectFilePatterns();
139
+ const patterns = worker.getProductionProjectFilePatterns(negatedEntryPatterns);
131
140
  const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
132
141
  debugLogArray(`Found project paths (${name})`, workspaceProjectPaths);
133
142
  workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
@@ -141,13 +150,13 @@ export const main = async (unresolvedConfiguration) => {
141
150
  principal.addEntryPaths(workspaceEntryPaths);
142
151
  }
143
152
  {
144
- const patterns = worker.getProjectFilePatterns();
153
+ const patterns = worker.getProjectFilePatterns([...productionEntryFilePatterns]);
145
154
  const workspaceProjectPaths = await _glob({ ...sharedGlobOptions, patterns });
146
155
  debugLogArray(`Found project paths (${name})`, workspaceProjectPaths);
147
156
  workspaceProjectPaths.forEach(projectPath => principal.addProjectPath(projectPath));
148
157
  }
149
158
  {
150
- const patterns = worker.getPluginEntryFilePatterns();
159
+ const patterns = [...entryFilePatterns, ...productionEntryFilePatterns];
151
160
  const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns });
152
161
  debugLogArray(`Found plugin entry paths (${name})`, pluginWorkspaceEntryPaths);
153
162
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
@@ -165,17 +174,9 @@ export const main = async (unresolvedConfiguration) => {
165
174
  principal.addEntryPaths(configurationEntryPaths, { skipExportsAnalysis: true });
166
175
  }
167
176
  }
168
- if (chief.resolvedConfigFilePath)
177
+ if (chief.resolvedConfigFilePath) {
169
178
  principal.addEntryPath(chief.resolvedConfigFilePath, { skipExportsAnalysis: true });
170
- const dependencies = await worker.findAllDependencies();
171
- const { referencedDependencies, hostDependencies, installedBinaries, enabledPlugins, hasTypesIncluded } = dependencies;
172
- deputy.addHostDependencies(name, hostDependencies);
173
- deputy.setInstalledBinaries(name, installedBinaries);
174
- deputy.setHasTypesIncluded(name, hasTypesIncluded);
175
- enabledPluginsStore.set(name, enabledPlugins);
176
- referencedDependencies.forEach(([containingFilePath, specifier]) => {
177
- handleReferencedDependency({ specifier, containingFilePath, principal, workspace });
178
- });
179
+ }
179
180
  }
180
181
  const principals = factory.getPrincipals();
181
182
  debugLog(`Installed ${principals.length} principals for ${workspaces.length} workspaces`);
@@ -183,6 +184,7 @@ export const main = async (unresolvedConfiguration) => {
183
184
  const exportedSymbols = new Map();
184
185
  const importedSymbols = new Map();
185
186
  for (const principal of principals) {
187
+ const specifierFilePaths = new Set();
186
188
  const analyzeSourceFile = (filePath, _principal = principal) => {
187
189
  const workspace = chief.findWorkspaceByFilePath(filePath);
188
190
  if (workspace) {
@@ -200,8 +202,7 @@ export const main = async (unresolvedConfiguration) => {
200
202
  if (workspace) {
201
203
  const principal = factory.getPrincipalByPackageName(workspace.pkgName);
202
204
  if (principal && !principal.isGitIgnored(specifierFilePath)) {
203
- analyzeSourceFile(specifierFilePath, principal);
204
- analyzedFiles.add(specifierFilePath);
205
+ specifierFilePaths.add(specifierFilePath);
205
206
  }
206
207
  }
207
208
  }
@@ -257,6 +258,12 @@ export const main = async (unresolvedConfiguration) => {
257
258
  analyzedFiles.add(filePath);
258
259
  });
259
260
  } while (size !== principal.entryPaths.size);
261
+ specifierFilePaths.forEach(specifierFilePath => {
262
+ if (!analyzedFiles.has(specifierFilePath)) {
263
+ analyzedFiles.add(specifierFilePath);
264
+ analyzeSourceFile(specifierFilePath, principal);
265
+ }
266
+ });
260
267
  }
261
268
  const isSymbolImported = (symbol, importingModule) => {
262
269
  if (!importingModule)
@@ -3,5 +3,5 @@ export declare const NAME = "Ava";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
- export declare const ENTRY_FILE_PATTERNS: never[];
6
+ export declare const ENTRY_FILE_PATTERNS: string[];
7
7
  export declare const findDependencies: GenericPluginCallback;
@@ -1,20 +1,38 @@
1
1
  import { _getDependenciesFromScripts } from '../../binaries/index.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
+ import { toEntryPattern } from '../../util/protocols.js';
4
5
  export const NAME = 'Ava';
5
6
  export const ENABLERS = ['ava'];
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
8
  export const CONFIG_FILE_PATTERNS = ['ava.config.{js,cjs,mjs}', 'package.json'];
8
- export const ENTRY_FILE_PATTERNS = [];
9
- const findAvaDependencies = async (configFilePath, { cwd, manifest }) => {
9
+ export const ENTRY_FILE_PATTERNS = [
10
+ `test.{js,cjs,mjs}`,
11
+ `{src,source}/test.{js,cjs,mjs}`,
12
+ `**/__tests__/**/*.{js,cjs,mjs}`,
13
+ `**/*.spec.{js,cjs,mjs}`,
14
+ `**/*.test.{js,cjs,mjs}`,
15
+ `**/test-*.{js,cjs,mjs}`,
16
+ `**/test/**/*.{js,cjs,mjs}`,
17
+ `**/tests/**/*.{js,cjs,mjs}`,
18
+ '!**/__tests__/**/__{helper,fixture}?(s)__/**/*',
19
+ '!**/test?(s)/**/{helper,fixture}?(s)/**/*',
20
+ ];
21
+ const findAvaDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
10
22
  const config = configFilePath.endsWith('package.json') ? manifest.ava : await load(configFilePath);
11
- const requireArgs = (config?.require ?? []).map(require => `--require ${require}`);
12
- const otherArgs = config?.nodeArguments ?? [];
23
+ const entryPatterns = (config?.files ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
24
+ if (isProduction)
25
+ return entryPatterns;
26
+ if (!config)
27
+ return [];
28
+ const requireArgs = (config.require ?? []).map(require => `--require ${require}`);
29
+ const otherArgs = config.nodeArguments ?? [];
13
30
  const cmd = `node ${otherArgs.join(' ')} ${requireArgs.join(' ')}`;
14
- return _getDependenciesFromScripts([cmd], {
31
+ const dependencies = _getDependenciesFromScripts([cmd], {
15
32
  cwd,
16
33
  manifest,
17
34
  knownGlobalsOnly: true,
18
35
  });
36
+ return [...entryPatterns, ...dependencies];
19
37
  };
20
38
  export const findDependencies = timerify(findAvaDependencies);
@@ -1,4 +1,5 @@
1
1
  export type PluginConfig = {
2
+ files?: string[];
2
3
  require?: string[];
3
4
  nodeArguments?: string[];
4
5
  };
@@ -20,7 +20,9 @@ export const getDependenciesFromConfig = (config) => {
20
20
  const nested = config.env ? Object.values(config.env).flatMap(getDependenciesFromConfig) : [];
21
21
  return compact([...presets, ...plugins, ...nested]);
22
22
  };
23
- const findBabelDependencies = async (configFilePath, { manifest }) => {
23
+ const findBabelDependencies = async (configFilePath, { manifest, isProduction }) => {
24
+ if (isProduction)
25
+ return [];
24
26
  let config = configFilePath.endsWith('package.json') ? manifest.babel : await load(configFilePath);
25
27
  if (typeof config === 'function') {
26
28
  config = config(api);
@@ -4,7 +4,9 @@ export const NAME = 'Capacitor';
4
4
  export const ENABLERS = [/^@capacitor\//];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const CONFIG_FILE_PATTERNS = ['capacitor.config.ts'];
7
- const findCapacitorDependencies = async (configFilePath) => {
7
+ const findCapacitorDependencies = async (configFilePath, { isProduction }) => {
8
+ if (isProduction)
9
+ return [];
8
10
  const config = await load(configFilePath);
9
11
  return config.includePlugins ?? [];
10
12
  };