knip 0.0.0-graph.3 → 0.0.0-node-types.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 (214) hide show
  1. package/README.md +7 -915
  2. package/bin/knip.js +2 -0
  3. package/dist/ConfigurationChief.d.ts +14 -6
  4. package/dist/ConfigurationChief.js +104 -70
  5. package/dist/ConfigurationValidator.d.ts +553 -321
  6. package/dist/ConfigurationValidator.js +7 -1
  7. package/dist/DependencyDeputy.d.ts +4 -1
  8. package/dist/DependencyDeputy.js +13 -11
  9. package/dist/PrincipalFactory.d.ts +5 -2
  10. package/dist/PrincipalFactory.js +11 -7
  11. package/dist/ProjectPrincipal.d.ts +18 -15
  12. package/dist/ProjectPrincipal.js +43 -25
  13. package/dist/WorkspaceWorker.d.ts +9 -7
  14. package/dist/WorkspaceWorker.js +45 -63
  15. package/dist/binaries/bash-parser.js +1 -1
  16. package/dist/binaries/index.js +12 -3
  17. package/dist/binaries/resolvers/c8.js +2 -1
  18. package/dist/binaries/resolvers/dotenv.js +2 -1
  19. package/dist/binaries/resolvers/fallback.js +4 -2
  20. package/dist/binaries/resolvers/index.d.ts +1 -0
  21. package/dist/binaries/resolvers/index.js +1 -0
  22. package/dist/binaries/resolvers/node.js +1 -1
  23. package/dist/binaries/resolvers/nodemon.js +2 -1
  24. package/dist/binaries/resolvers/npx.js +2 -1
  25. package/dist/binaries/resolvers/nx.js +1 -1
  26. package/dist/binaries/resolvers/pnpm.js +1 -1
  27. package/dist/binaries/resolvers/rollup.js +2 -1
  28. package/dist/binaries/resolvers/tsx.d.ts +2 -0
  29. package/dist/binaries/resolvers/tsx.js +6 -0
  30. package/dist/binaries/resolvers/yarn.js +1 -1
  31. package/dist/binaries/util.d.ts +0 -3
  32. package/dist/binaries/util.js +1 -3
  33. package/dist/cli.d.ts +0 -1
  34. package/dist/cli.js +10 -9
  35. package/dist/constants.d.ts +0 -1
  36. package/dist/constants.js +5 -4
  37. package/dist/index.js +101 -65
  38. package/dist/manifest/index.js +8 -4
  39. package/dist/plugins/_template/index.js +15 -3
  40. package/dist/plugins/_template/types.d.ts +1 -0
  41. package/dist/plugins/angular/index.js +11 -11
  42. package/dist/plugins/astro/index.d.ts +7 -0
  43. package/dist/plugins/astro/index.js +19 -0
  44. package/dist/plugins/ava/index.d.ts +1 -1
  45. package/dist/plugins/ava/index.js +28 -7
  46. package/dist/plugins/ava/types.d.ts +5 -1
  47. package/dist/plugins/babel/helpers.d.ts +1 -2
  48. package/dist/plugins/babel/helpers.js +28 -20
  49. package/dist/plugins/babel/index.js +17 -14
  50. package/dist/plugins/capacitor/index.js +7 -3
  51. package/dist/plugins/changesets/index.js +10 -6
  52. package/dist/plugins/commitizen/index.d.ts +1 -0
  53. package/dist/plugins/commitizen/index.js +8 -4
  54. package/dist/plugins/commitizen/types.d.ts +1 -1
  55. package/dist/plugins/commitlint/index.js +7 -3
  56. package/dist/plugins/cspell/index.js +7 -3
  57. package/dist/plugins/cspell/types.d.ts +1 -1
  58. package/dist/plugins/cypress/index.d.ts +3 -1
  59. package/dist/plugins/cypress/index.js +17 -4
  60. package/dist/plugins/drizzle/index.js +5 -7
  61. package/dist/plugins/eslint/fallback.js +6 -1
  62. package/dist/plugins/eslint/helpers.d.ts +4 -11
  63. package/dist/plugins/eslint/helpers.js +24 -26
  64. package/dist/plugins/eslint/index.d.ts +1 -1
  65. package/dist/plugins/eslint/index.js +14 -4
  66. package/dist/plugins/gatsby/index.js +11 -5
  67. package/dist/plugins/github-actions/index.d.ts +1 -1
  68. package/dist/plugins/github-actions/index.js +7 -4
  69. package/dist/plugins/graphql-codegen/index.d.ts +7 -0
  70. package/dist/plugins/graphql-codegen/index.js +46 -0
  71. package/dist/plugins/graphql-codegen/types.d.ts +25 -0
  72. package/dist/plugins/graphql-codegen/types.js +3 -0
  73. package/dist/plugins/husky/index.js +9 -4
  74. package/dist/plugins/index.d.ts +4 -0
  75. package/dist/plugins/index.js +4 -0
  76. package/dist/plugins/jest/index.d.ts +1 -1
  77. package/dist/plugins/jest/index.js +21 -12
  78. package/dist/plugins/jest/types.d.ts +3 -0
  79. package/dist/plugins/lefthook/index.js +12 -8
  80. package/dist/plugins/lint-staged/index.d.ts +1 -0
  81. package/dist/plugins/lint-staged/index.js +10 -7
  82. package/dist/plugins/markdownlint/index.js +7 -4
  83. package/dist/plugins/mocha/index.d.ts +1 -0
  84. package/dist/plugins/mocha/index.js +12 -7
  85. package/dist/plugins/mocha/types.d.ts +4 -0
  86. package/dist/plugins/mocha/types.js +1 -0
  87. package/dist/plugins/next/index.d.ts +2 -1
  88. package/dist/plugins/next/index.js +7 -0
  89. package/dist/plugins/node-test-runner/index.d.ts +6 -0
  90. package/dist/plugins/node-test-runner/index.js +19 -0
  91. package/dist/plugins/npm-package-json-lint/index.d.ts +1 -0
  92. package/dist/plugins/npm-package-json-lint/index.js +8 -4
  93. package/dist/plugins/nx/index.js +13 -10
  94. package/dist/plugins/nyc/index.js +6 -3
  95. package/dist/plugins/nyc/types.d.ts +3 -0
  96. package/dist/plugins/nyc/types.js +1 -0
  97. package/dist/plugins/playwright/index.d.ts +5 -1
  98. package/dist/plugins/playwright/index.js +25 -2
  99. package/dist/plugins/playwright-ct/index.d.ts +3 -1
  100. package/dist/plugins/playwright-ct/index.js +18 -2
  101. package/dist/plugins/postcss/index.js +12 -9
  102. package/dist/plugins/prettier/index.js +11 -6
  103. package/dist/plugins/prettier/types.d.ts +8 -0
  104. package/dist/plugins/prettier/types.js +1 -0
  105. package/dist/plugins/release-it/index.d.ts +1 -0
  106. package/dist/plugins/release-it/index.js +14 -10
  107. package/dist/plugins/remark/index.d.ts +1 -0
  108. package/dist/plugins/remark/index.js +20 -4
  109. package/dist/plugins/remark/types.d.ts +3 -0
  110. package/dist/plugins/remark/types.js +1 -0
  111. package/dist/plugins/remix/index.d.ts +2 -1
  112. package/dist/plugins/remix/index.js +9 -0
  113. package/dist/plugins/rollup/index.d.ts +2 -1
  114. package/dist/plugins/rollup/index.js +8 -1
  115. package/dist/plugins/semantic-release/index.d.ts +1 -0
  116. package/dist/plugins/semantic-release/index.js +10 -4
  117. package/dist/plugins/semantic-release/types.d.ts +1 -1
  118. package/dist/plugins/sentry/index.d.ts +2 -1
  119. package/dist/plugins/sentry/index.js +7 -0
  120. package/dist/plugins/storybook/index.js +28 -10
  121. package/dist/plugins/storybook/types.d.ts +7 -0
  122. package/dist/plugins/stryker/index.js +13 -9
  123. package/dist/plugins/stylelint/index.js +8 -5
  124. package/dist/plugins/svelte/index.d.ts +2 -1
  125. package/dist/plugins/svelte/index.js +6 -0
  126. package/dist/plugins/tsup/index.d.ts +6 -0
  127. package/dist/plugins/tsup/index.js +23 -0
  128. package/dist/plugins/tsup/types.d.ts +7 -0
  129. package/dist/plugins/tsup/types.js +1 -0
  130. package/dist/plugins/typedoc/index.d.ts +1 -0
  131. package/dist/plugins/typedoc/index.js +8 -4
  132. package/dist/plugins/typedoc/types.d.ts +1 -1
  133. package/dist/plugins/typescript/index.js +16 -11
  134. package/dist/plugins/vite/index.js +7 -5
  135. package/dist/plugins/vitest/helpers.d.ts +2 -2
  136. package/dist/plugins/vitest/index.d.ts +4 -4
  137. package/dist/plugins/vitest/index.js +55 -26
  138. package/dist/plugins/vitest/types.d.ts +23 -2
  139. package/dist/plugins/webpack/index.js +31 -19
  140. package/dist/plugins/webpack/types.d.ts +2 -1
  141. package/dist/reporters/codeowners.js +2 -2
  142. package/dist/reporters/json.js +14 -9
  143. package/dist/reporters/symbols.js +3 -2
  144. package/dist/reporters/util.d.ts +8 -2
  145. package/dist/reporters/util.js +7 -1
  146. package/dist/types/cli.d.ts +1 -1
  147. package/dist/types/config.d.ts +9 -4
  148. package/dist/types/exports.d.ts +1 -0
  149. package/dist/types/imports.d.ts +6 -0
  150. package/dist/types/issues.d.ts +11 -1
  151. package/dist/types/package-json.d.ts +41 -0
  152. package/dist/types/package-json.js +1 -0
  153. package/dist/types/plugins.d.ts +5 -7
  154. package/dist/types/util.d.ts +16 -0
  155. package/dist/types/util.js +1 -0
  156. package/dist/types/workspace.d.ts +4 -1
  157. package/dist/typescript/SourceFile.d.ts +5 -0
  158. package/dist/typescript/SourceFileManager.js +3 -3
  159. package/dist/typescript/ast-helpers.d.ts +7 -14
  160. package/dist/typescript/ast-helpers.js +11 -9
  161. package/dist/typescript/createHosts.d.ts +1 -0
  162. package/dist/typescript/createHosts.js +1 -1
  163. package/dist/typescript/getImportsAndExports.d.ts +7 -5
  164. package/dist/typescript/getImportsAndExports.js +35 -18
  165. package/dist/typescript/resolveModuleNames.d.ts +1 -1
  166. package/dist/typescript/resolveModuleNames.js +38 -12
  167. package/dist/typescript/visitors/exports/exportDeclaration.js +14 -1
  168. package/dist/typescript/visitors/exports/exportKeyword.js +5 -2
  169. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +29 -21
  170. package/dist/typescript/visitors/imports/importCall.js +1 -1
  171. package/dist/typescript/visitors/imports/importDeclaration.js +3 -3
  172. package/dist/typescript/visitors/imports/importEqualsDeclaration.js +1 -1
  173. package/dist/typescript/visitors/imports/jsDocType.js +37 -5
  174. package/dist/typescript/visitors/imports/propertyAccessCall.js +1 -1
  175. package/dist/typescript/visitors/imports/reExportDeclaration.js +8 -3
  176. package/dist/typescript/visitors/imports/requireCall.js +5 -5
  177. package/dist/util/array.d.ts +3 -1
  178. package/dist/util/cli-arguments.d.ts +3 -2
  179. package/dist/util/cli-arguments.js +6 -6
  180. package/dist/util/compilers.d.ts +122 -80
  181. package/dist/util/debug.d.ts +3 -3
  182. package/dist/util/debug.js +12 -18
  183. package/dist/util/fs.d.ts +2 -0
  184. package/dist/util/fs.js +22 -3
  185. package/dist/util/get-included-issue-types.js +14 -18
  186. package/dist/util/git.js +1 -1
  187. package/dist/util/glob.js +1 -1
  188. package/dist/util/loader.d.ts +2 -0
  189. package/dist/util/loader.js +23 -3
  190. package/dist/util/modules.d.ts +7 -1
  191. package/dist/util/modules.js +20 -10
  192. package/dist/util/object.d.ts +1 -0
  193. package/dist/util/object.js +3 -0
  194. package/dist/util/parse-args.d.ts +3 -0
  195. package/dist/util/parse-args.js +8 -0
  196. package/dist/util/path.d.ts +1 -0
  197. package/dist/util/path.js +5 -3
  198. package/dist/util/plugin.d.ts +4 -3
  199. package/dist/util/plugin.js +11 -4
  200. package/dist/util/protocols.d.ts +9 -0
  201. package/dist/util/protocols.js +9 -0
  202. package/dist/util/register.d.ts +2 -1
  203. package/dist/util/register.js +9 -13
  204. package/dist/util/require.js +7 -5
  205. package/dist/util/tsconfig-loader.js +2 -1
  206. package/dist/util/unwrap-function.d.ts +1 -0
  207. package/dist/util/unwrap-function.js +13 -0
  208. package/dist/version.d.ts +1 -1
  209. package/dist/version.js +1 -1
  210. package/package.json +86 -85
  211. package/schema-jsonc.json +11 -0
  212. package/schema.json +27 -3
  213. package/dist/plugins/vite/types.d.ts +0 -4
  214. /package/dist/plugins/{vite → jest}/types.js +0 -0
@@ -1,11 +1,12 @@
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 { FAKE_PATH } from './util/loader.js';
6
+ import { get, getKeysByValue } from './util/object.js';
7
7
  import { join, toPosix } from './util/path.js';
8
- const negatedTestFilePatterns = TEST_FILE_PATTERNS.map(negate);
8
+ import { fromEntryPattern, fromProductionEntryPattern, isEntryPattern, isProductionEntryPattern, } from './util/protocols.js';
9
+ const nullConfig = { config: null, entry: null, project: null };
9
10
  export class WorkspaceWorker {
10
11
  name;
11
12
  dir;
@@ -23,6 +24,8 @@ export class WorkspaceWorker {
23
24
  hostDependencies = new Map();
24
25
  installedBinaries = new Map();
25
26
  hasTypesIncluded = new Set();
27
+ entryFilePatterns = new Set();
28
+ productionEntryFilePatterns = new Set();
26
29
  constructor({ name, dir, cwd, config, manifest, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, enabledPluginsInAncestors, }) {
27
30
  this.name = name;
28
31
  this.dir = dir;
@@ -49,6 +52,10 @@ export class WorkspaceWorker {
49
52
  for (const [pluginName, plugin] of pluginEntries) {
50
53
  if (this.config[pluginName] === false)
51
54
  continue;
55
+ if (this.config[pluginName]) {
56
+ this.enabled[pluginName] = true;
57
+ continue;
58
+ }
52
59
  const isEnabledInAncestor = this.enabledPluginsInAncestors.includes(pluginName);
53
60
  if (isEnabledInAncestor ||
54
61
  (await plugin.isEnabled({ cwd: this.dir, manifest, dependencies, config: this.config }))) {
@@ -57,7 +64,7 @@ export class WorkspaceWorker {
57
64
  }
58
65
  this.enabledPlugins = getKeysByValue(this.enabled, true);
59
66
  const enabledPluginNames = this.enabledPlugins.map(name => plugins[name].NAME);
60
- debugLogObject(`Enabled plugins (${this.name})`, enabledPluginNames);
67
+ debugLogObject(this.name, `Enabled plugins (${this.name})`, enabledPluginNames);
61
68
  }
62
69
  async initReferencedDependencies() {
63
70
  const { dependencies, hostDependencies, installedBinaries, hasTypesIncluded } = await npm.findDependencies({
@@ -72,61 +79,41 @@ export class WorkspaceWorker {
72
79
  this.hostDependencies = hostDependencies;
73
80
  this.installedBinaries = installedBinaries;
74
81
  this.hasTypesIncluded = hasTypesIncluded;
82
+ this.hasTypesIncluded = hasTypesIncluded;
75
83
  }
76
84
  getConfigForPlugin(pluginName) {
77
- return this.config[pluginName] ?? { config: null, entry: null, project: null };
85
+ const config = this.config[pluginName];
86
+ return typeof config === 'undefined' || typeof config === 'boolean' ? nullConfig : config;
78
87
  }
79
88
  getEntryFilePatterns() {
80
89
  const { entry } = this.config;
81
90
  if (entry.length === 0)
82
91
  return [];
83
- return [entry, TEST_FILE_PATTERNS, this.negatedWorkspacePatterns].flat();
92
+ const excludeProductionNegations = entry.filter(pattern => !(pattern.startsWith('!') && pattern.endsWith('!')));
93
+ return [excludeProductionNegations, this.negatedWorkspacePatterns].flat();
84
94
  }
85
- getProjectFilePatterns() {
95
+ getProjectFilePatterns(testFilePatterns) {
86
96
  const { project } = this.config;
87
97
  if (project.length === 0)
88
98
  return [];
99
+ const excludeProductionNegations = project.filter(pattern => !(pattern.startsWith('!') && pattern.endsWith('!')));
89
100
  const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
90
- const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
91
101
  const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
92
102
  return [
93
- project,
103
+ excludeProductionNegations,
94
104
  negatedPluginConfigPatterns,
95
- negatedPluginEntryFilePatterns,
96
105
  negatedPluginProjectFilePatterns,
97
- TEST_FILE_PATTERNS,
106
+ testFilePatterns,
98
107
  this.negatedWorkspacePatterns,
99
108
  ].flat();
100
109
  }
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
110
  getPluginProjectFilePatterns() {
118
111
  const patterns = [];
119
112
  for (const [pluginName, plugin] of Object.entries(plugins)) {
120
113
  const pluginConfig = this.getConfigForPlugin(pluginName);
121
- if (this.enabled[pluginName] && pluginConfig) {
114
+ if (this.enabled[pluginName]) {
122
115
  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
- : [])));
116
+ patterns.push(...(project ?? entry ?? ('PROJECT_FILE_PATTERNS' in plugin ? plugin.PROJECT_FILE_PATTERNS : [])));
130
117
  }
131
118
  }
132
119
  return [patterns, this.negatedWorkspacePatterns].flat();
@@ -143,17 +130,17 @@ export class WorkspaceWorker {
143
130
  }
144
131
  return patterns;
145
132
  }
146
- getProductionEntryFilePatterns() {
133
+ getProductionEntryFilePatterns(negatedTestFilePatterns) {
147
134
  const entry = this.config.entry.filter(hasProductionSuffix);
148
135
  if (entry.length === 0)
149
136
  return [];
150
137
  const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
151
138
  return [entry, negatedEntryFiles, negatedTestFilePatterns, this.negatedWorkspacePatterns].flat();
152
139
  }
153
- getProductionProjectFilePatterns() {
140
+ getProductionProjectFilePatterns(negatedTestFilePatterns) {
154
141
  const project = this.config.project;
155
142
  if (project.length === 0)
156
- return this.getProductionEntryFilePatterns();
143
+ return this.getProductionEntryFilePatterns(negatedTestFilePatterns);
157
144
  const _project = this.config.project.map(pattern => {
158
145
  if (!pattern.endsWith('!') && !pattern.startsWith('!'))
159
146
  return negate(pattern);
@@ -161,32 +148,16 @@ export class WorkspaceWorker {
161
148
  });
162
149
  const negatedEntryFiles = this.config.entry.filter(hasNoProductionSuffix).map(negate);
163
150
  const negatedPluginConfigPatterns = this.getPluginConfigPatterns().map(negate);
164
- const negatedPluginEntryFilePatterns = this.getPluginEntryFilePatterns(false).map(negate);
165
151
  const negatedPluginProjectFilePatterns = this.getPluginProjectFilePatterns().map(negate);
166
152
  return [
167
153
  _project,
168
154
  negatedEntryFiles,
169
155
  negatedPluginConfigPatterns,
170
- negatedPluginEntryFilePatterns,
171
156
  negatedPluginProjectFilePatterns,
172
157
  negatedTestFilePatterns,
173
158
  this.negatedWorkspacePatterns,
174
159
  ].flat();
175
160
  }
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
161
  getConfigurationFilePatterns(pluginName) {
191
162
  const plugin = plugins[pluginName];
192
163
  const pluginConfig = this.getConfigForPlugin(pluginName);
@@ -200,21 +171,23 @@ export class WorkspaceWorker {
200
171
  return [...this.rootIgnore, ...this.config.ignore.map(pattern => prependDirToPattern(this.name, pattern))];
201
172
  }
202
173
  async findDependenciesByPlugins() {
174
+ const name = this.name;
203
175
  const cwd = this.dir;
204
176
  const ignore = this.getIgnorePatterns();
205
177
  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) {
178
+ if (this.enabled[pluginName]) {
208
179
  const hasDependencyFinder = 'findDependencies' in plugin && typeof plugin.findDependencies === 'function';
209
180
  if (hasDependencyFinder) {
210
181
  const pluginConfig = this.getConfigForPlugin(pluginName);
211
182
  if (!pluginConfig)
212
183
  continue;
213
184
  const patterns = this.getConfigurationFilePatterns(pluginName);
214
- const configFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
215
- debugLogArray(`Found ${plugin.NAME} config file paths`, configFilePaths);
185
+ const allConfigFilePaths = await _pureGlob({ patterns, cwd, ignore, gitignore: false });
186
+ const configFilePaths = allConfigFilePaths.filter(filePath => !filePath.endsWith('package.json') ||
187
+ get(this.manifest, 'PACKAGE_JSON_PATH' in plugin ? plugin.PACKAGE_JSON_PATH : pluginName));
188
+ debugLogArray([name, plugin.NAME], 'config file paths', configFilePaths);
216
189
  if (configFilePaths.length === 0)
217
- continue;
190
+ configFilePaths.push(FAKE_PATH);
218
191
  const pluginDependencies = new Set();
219
192
  for (const configFilePath of configFilePaths) {
220
193
  const dependencies = await plugin.findDependencies(configFilePath, {
@@ -223,13 +196,20 @@ export class WorkspaceWorker {
223
196
  config: pluginConfig,
224
197
  isProduction: this.isProduction,
225
198
  });
226
- dependencies.map(toPosix).forEach(specifier => {
199
+ dependencies.forEach(specifier => {
227
200
  pluginDependencies.add(specifier);
228
- this.referencedDependencies.add([configFilePath, specifier]);
201
+ if (isEntryPattern(specifier)) {
202
+ this.entryFilePatterns.add(fromEntryPattern(specifier));
203
+ }
204
+ else if (isProductionEntryPattern(specifier)) {
205
+ this.productionEntryFilePatterns.add(fromProductionEntryPattern(specifier));
206
+ }
207
+ else {
208
+ this.referencedDependencies.add([configFilePath, toPosix(specifier)]);
209
+ }
229
210
  });
230
- dependencies.forEach(dependency => pluginDependencies.add(dependency));
231
211
  }
232
- debugLogArray(`Dependencies referenced in ${plugin.NAME}`, pluginDependencies);
212
+ debugLogArray([name, plugin.NAME], 'dependencies', pluginDependencies);
233
213
  }
234
214
  }
235
215
  }
@@ -242,6 +222,8 @@ export class WorkspaceWorker {
242
222
  referencedDependencies: this.referencedDependencies,
243
223
  hasTypesIncluded: this.hasTypesIncluded,
244
224
  enabledPlugins: this.enabledPlugins,
225
+ entryFilePatterns: Array.from(this.entryFilePatterns),
226
+ productionEntryFilePatterns: Array.from(this.productionEntryFilePatterns),
245
227
  };
246
228
  }
247
229
  }
@@ -52,7 +52,7 @@ export const getBinariesFromScript = (script, { cwd, manifest, knownGlobalsOnly
52
52
  return parsed?.commands ? getBinariesFromNodes(parsed.commands) : [];
53
53
  }
54
54
  catch (error) {
55
- debugLogObject('Bash parser error', error);
55
+ debugLogObject('*', 'Bash parser error', error);
56
56
  return [];
57
57
  }
58
58
  };
@@ -1,17 +1,26 @@
1
+ import { IGNORED_FILE_EXTENSIONS } from '../constants.js';
1
2
  import { compact } from '../util/array.js';
2
3
  import { getPackageNameFromModuleSpecifier } from '../util/modules.js';
3
- import { isInternal } from '../util/path.js';
4
+ import { extname, isInternal } from '../util/path.js';
4
5
  import { timerify } from '../util/Performance.js';
6
+ import { isBinary } from '../util/protocols.js';
5
7
  import { getBinariesFromScript } from './bash-parser.js';
6
- import { isBinary } from './util.js';
7
8
  const defaultCwd = process.cwd();
8
9
  const getDependenciesFromScripts = (npmScripts, options = {}) => {
9
10
  const { cwd = defaultCwd, manifest = {}, knownGlobalsOnly = false } = options;
10
11
  const scripts = typeof npmScripts === 'string' ? [npmScripts] : [...npmScripts];
11
12
  const results = scripts.flatMap(script => getBinariesFromScript(script, { cwd, manifest, knownGlobalsOnly }));
12
13
  return compact(results.map(identifier => {
13
- if (isBinary(identifier) || isInternal(identifier))
14
+ if (identifier.startsWith('http'))
15
+ return;
16
+ if (isBinary(identifier))
14
17
  return identifier;
18
+ if (isInternal(identifier)) {
19
+ const ext = extname(identifier);
20
+ if (ext && IGNORED_FILE_EXTENSIONS.includes(ext))
21
+ return;
22
+ return identifier;
23
+ }
15
24
  return getPackageNameFromModuleSpecifier(identifier);
16
25
  }));
17
26
  };
@@ -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,15 +1,17 @@
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();
7
+ const withoutRequire = () => [];
6
8
  const argFilters = {
9
+ adb: withoutRequire,
7
10
  'babel-node': withPositional,
8
11
  esbuild: withPositional,
9
12
  execa: withPositional,
10
13
  'ts-node': withPositional,
11
14
  zx: withPositional,
12
- tsx: parsed => parsed._.filter(p => p !== 'watch'),
13
15
  default: withoutPositional,
14
16
  };
15
17
  const spawningBinaries = ['cross-env', 'retry-cli'];
@@ -6,4 +6,5 @@ export * as npx from './npx.js';
6
6
  export * as nx from './nx.js';
7
7
  export * as pnpm from './pnpm.js';
8
8
  export * as rollup from './rollup.js';
9
+ export * as tsx from './tsx.js';
9
10
  export * as yarn from './yarn.js';
@@ -6,4 +6,5 @@ export * as npx from './npx.js';
6
6
  export * as nx from './nx.js';
7
7
  export * as pnpm from './pnpm.js';
8
8
  export * as rollup from './rollup.js';
9
+ export * as tsx from './tsx.js';
9
10
  export * as yarn from './yarn.js';
@@ -4,7 +4,7 @@ import { tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
4
4
  export const resolve = (binary, args, { cwd }) => {
5
5
  const parsed = parseArgs(args, {
6
6
  string: ['r'],
7
- alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter'] },
7
+ alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter', 'watch', 'import'] },
8
8
  });
9
9
  return compact([tryResolveFilePath(cwd, parsed._[0]), ...tryResolveSpecifiers(cwd, [parsed.require].flat())]);
10
10
  };
@@ -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' } });
@@ -0,0 +1,2 @@
1
+ import type { Resolver } from '../types.js';
2
+ export declare const resolve: Resolver;
@@ -0,0 +1,6 @@
1
+ import { toBinary } from '../../util/protocols.js';
2
+ import { resolve as resolveNode } from './node.js';
3
+ export const resolve = (binary, args, options) => {
4
+ args = args.map(a => (a === 'watch' ? '--watch' : a));
5
+ return [toBinary(binary), ...resolveNode(binary, args, options)];
6
+ };
@@ -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)
package/dist/cli.d.ts CHANGED
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  import './util/register.js';
package/dist/cli.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import './util/register.js';
3
2
  import prettyMilliseconds from 'pretty-ms';
4
3
  import parsedArgValues, { helpText } from './util/cli-arguments.js';
@@ -8,7 +7,7 @@ import { Performance } from './util/Performance.js';
8
7
  import { runPreprocessors, runReporters } from './util/reporter.js';
9
8
  import { version } from './version.js';
10
9
  import { main } from './index.js';
11
- const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'ignore-internal': isIgnoreInternal = false, 'include-entry-exports': isIncludeEntryExports = false, performance: isObservePerf = false, production: isProduction = false, 'reporter-options': reporterOptions = '', 'preprocessor-options': preprocessorOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
10
+ const { debug: isDebug = false, help: isHelp, 'max-issues': maxIssues = '0', 'no-config-hints': noConfigHints = false, 'no-exit-code': noExitCode = false, 'no-gitignore': isNoGitIgnore = false, 'no-progress': isNoProgress = false, 'include-entry-exports': isIncludeEntryExports = false, 'isolate-workspaces': isIsolateWorkspaces = false, performance: isObservePerf = false, production: isProduction = false, 'reporter-options': reporterOptions = '', 'preprocessor-options': preprocessorOptions = '', strict: isStrict = false, tsConfig, version: isVersion, } = parsedArgValues;
12
11
  if (isHelp) {
13
12
  console.log(helpText);
14
13
  process.exit(0);
@@ -27,13 +26,14 @@ const run = async () => {
27
26
  gitignore: !isNoGitIgnore,
28
27
  isProduction,
29
28
  isStrict,
30
- isIgnoreInternal,
31
29
  isShowProgress,
32
30
  isIncludeEntryExports,
31
+ isIsolateWorkspaces,
33
32
  });
34
33
  const initialData = {
35
34
  report,
36
35
  issues,
36
+ counters,
37
37
  configurationHints,
38
38
  noConfigHints,
39
39
  cwd,
@@ -44,9 +44,9 @@ const run = async () => {
44
44
  };
45
45
  const finalData = await runPreprocessors(initialData);
46
46
  await runReporters(finalData);
47
- const totalErrorCount = Object.keys(report)
48
- .filter(reportGroup => report[reportGroup] && rules[reportGroup] === 'error')
49
- .reduce((errorCount, reportGroup) => errorCount + counters[reportGroup], 0);
47
+ const totalErrorCount = Object.keys(finalData.report)
48
+ .filter(reportGroup => finalData.report[reportGroup] && rules[reportGroup] === 'error')
49
+ .reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
50
50
  if (isObservePerf) {
51
51
  await perfObserver.finalize();
52
52
  console.log('\n' + perfObserver.getTable());
@@ -54,18 +54,19 @@ const run = async () => {
54
54
  perfObserver.reset();
55
55
  }
56
56
  if (!noExitCode && totalErrorCount > Number(maxIssues)) {
57
- process.exit(totalErrorCount);
57
+ process.exit(1);
58
58
  }
59
59
  }
60
60
  catch (error) {
61
- if (error instanceof Error && isKnownError(error)) {
61
+ process.exitCode = 2;
62
+ if (!isDebug && error instanceof Error && isKnownError(error)) {
62
63
  const knownError = getKnownError(error);
63
64
  console.error(knownError.message);
64
65
  if (hasCause(knownError))
65
66
  console.error('Reason:', knownError.cause.message);
66
67
  if (isConfigurationError(knownError))
67
68
  console.log('\n' + helpText);
68
- process.exit(1);
69
+ process.exit(2);
69
70
  }
70
71
  throw error;
71
72
  }
@@ -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,21 +1,20 @@
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',
11
7
  'bun',
8
+ 'bunx',
12
9
  'cat',
13
10
  'cd',
14
11
  'chmod',
12
+ 'corepack',
15
13
  'cp',
16
14
  'curl',
17
15
  'deno',
18
16
  'dirname',
17
+ 'docker',
19
18
  'echo',
20
19
  'exec',
21
20
  'exit',
@@ -41,6 +40,7 @@ export const IGNORED_FILE_EXTENSIONS = [
41
40
  '.css',
42
41
  '.eot',
43
42
  '.gif',
43
+ '.html',
44
44
  '.ico',
45
45
  '.jpeg',
46
46
  '.jpg',
@@ -48,6 +48,7 @@ export const IGNORED_FILE_EXTENSIONS = [
48
48
  '.png',
49
49
  '.sass',
50
50
  '.scss',
51
+ '.sh',
51
52
  '.svg',
52
53
  '.ttf',
53
54
  '.webp',