knip 5.50.2 → 5.50.4

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.
@@ -86,7 +86,7 @@ export class ConfigurationChief {
86
86
  this.manifest = manifest;
87
87
  const pnpmWorkspacesPath = findFile(this.cwd, 'pnpm-workspace.yaml');
88
88
  const pnpmWorkspaces = pnpmWorkspacesPath && (await _load(pnpmWorkspacesPath));
89
- if (this.manifest && !this.manifest.workspaces && pnpmWorkspaces) {
89
+ if (this.manifest && pnpmWorkspaces) {
90
90
  this.manifest.workspaces = pnpmWorkspaces;
91
91
  }
92
92
  for (const configPath of rawConfigArg ? [rawConfigArg] : KNIP_CONFIG_LOCATIONS) {
@@ -23,8 +23,7 @@ type WorkspaceManagerOptions = {
23
23
  isStrict: boolean;
24
24
  isCache: boolean;
25
25
  cacheLocation: string;
26
- extConfigFilesMap: Map<string, Map<PluginName, Set<string>>>;
27
- configFilesMap: Map<PluginName, Set<string>>;
26
+ configFilesMap: Map<string, Map<PluginName, Set<string>>>;
28
27
  };
29
28
  type CacheItem = {
30
29
  resolveEntryPaths?: Input[];
@@ -50,9 +49,8 @@ export declare class WorkspaceWorker {
50
49
  enabledPlugins: PluginName[];
51
50
  enabledPluginsInAncestors: string[];
52
51
  cache: CacheConsultant<CacheItem>;
53
- extConfigFilesMap: Map<string, Map<PluginName, Set<string>>>;
54
- configFilesMap: Map<PluginName, Set<string>>;
55
- constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, extConfigFilesMap, configFilesMap, }: WorkspaceManagerOptions);
52
+ configFilesMap: Map<string, Map<PluginName, Set<string>>>;
53
+ constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, configFilesMap, }: WorkspaceManagerOptions);
56
54
  init(): Promise<void>;
57
55
  private determineEnabledPlugins;
58
56
  private getConfigForPlugin;
@@ -31,9 +31,8 @@ export class WorkspaceWorker {
31
31
  enabledPlugins = [];
32
32
  enabledPluginsInAncestors;
33
33
  cache;
34
- extConfigFilesMap;
35
34
  configFilesMap;
36
- constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, extConfigFilesMap, configFilesMap, }) {
35
+ constructor({ name, dir, cwd, config, manifest, dependencies, isProduction, isStrict, rootIgnore, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, getReferencedInternalFilePath, findWorkspaceByFilePath, getSourceFile, isCache, cacheLocation, configFilesMap, }) {
37
36
  this.name = name;
38
37
  this.dir = dir;
39
38
  this.cwd = cwd;
@@ -46,7 +45,6 @@ export class WorkspaceWorker {
46
45
  this.negatedWorkspacePatterns = negatedWorkspacePatterns;
47
46
  this.ignoredWorkspacePatterns = ignoredWorkspacePatterns;
48
47
  this.enabledPluginsInAncestors = enabledPluginsInAncestors;
49
- this.extConfigFilesMap = extConfigFilesMap;
50
48
  this.configFilesMap = configFilesMap;
51
49
  this.getReferencedInternalFilePath = getReferencedInternalFilePath;
52
50
  this.findWorkspaceByFilePath = findWorkspaceByFilePath;
@@ -189,19 +187,20 @@ export class WorkspaceWorker {
189
187
  inputs.push({ ...input, containingFilePath });
190
188
  }
191
189
  };
192
- const extMap = this.extConfigFilesMap;
193
- const configFiles = this.extConfigFilesMap.get(wsName);
190
+ const configFilesMap = this.configFilesMap;
191
+ const configFiles = this.configFilesMap.get(wsName);
192
+ const seen = new Map();
194
193
  const handleConfigInput = (pluginName, input) => {
195
194
  const configFilePath = this.getReferencedInternalFilePath(input);
196
195
  if (configFilePath) {
197
196
  const workspace = this.findWorkspaceByFilePath(configFilePath);
198
197
  if (workspace) {
199
198
  const name = this.name === ROOT_WORKSPACE_NAME ? workspace.name : this.name;
200
- if (!extMap.has(name))
201
- extMap.set(name, new Map());
202
- if (!extMap.get(name)?.has(pluginName))
203
- extMap.get(name)?.set(pluginName, new Set());
204
- extMap.get(name)?.get(pluginName)?.add(configFilePath);
199
+ if (!configFilesMap.has(name))
200
+ configFilesMap.set(name, new Map());
201
+ if (!configFilesMap.get(name)?.has(pluginName))
202
+ configFilesMap.get(name)?.set(pluginName, new Set());
203
+ configFilesMap.get(name)?.get(pluginName)?.add(configFilePath);
205
204
  }
206
205
  }
207
206
  };
@@ -222,10 +221,7 @@ export class WorkspaceWorker {
222
221
  if (!config)
223
222
  return;
224
223
  const label = 'config file';
225
- const configFilePaths = await _glob({ patterns, cwd, dir: cwd, gitignore: false, label });
226
- if (!this.configFilesMap.has(pluginName))
227
- this.configFilesMap.set(pluginName, new Set());
228
- const filteredFilePaths = configFilePaths.filter(filePath => !this.configFilesMap.get(pluginName)?.has(filePath));
224
+ const configFilePaths = await _glob({ patterns, cwd: rootCwd, dir: cwd, gitignore: false, label });
229
225
  const options = {
230
226
  ...baseScriptOptions,
231
227
  config,
@@ -241,8 +237,8 @@ export class WorkspaceWorker {
241
237
  }
242
238
  else if ((!plugin.resolveEntryPaths && !plugin.resolveFromAST) ||
243
239
  (configFilePaths.length === 0 &&
244
- (!this.extConfigFilesMap.get(wsName)?.get(pluginName) ||
245
- this.extConfigFilesMap.get(wsName)?.get(pluginName)?.size === 0))) {
240
+ (!this.configFilesMap.get(wsName)?.get(pluginName) ||
241
+ this.configFilesMap.get(wsName)?.get(pluginName)?.size === 0))) {
246
242
  if (plugin.entry)
247
243
  for (const id of plugin.entry)
248
244
  addInput(toEntry(id));
@@ -250,8 +246,7 @@ export class WorkspaceWorker {
250
246
  for (const id of plugin.production)
251
247
  addInput(toProductionEntry(id));
252
248
  }
253
- for (const configFilePath of filteredFilePaths) {
254
- this.configFilesMap.get(pluginName)?.add(configFilePath);
249
+ for (const configFilePath of configFilePaths) {
255
250
  const isManifest = basename(configFilePath) === 'package.json';
256
251
  const fd = isManifest ? undefined : this.cache.getFileDescriptor(configFilePath);
257
252
  if (fd?.meta?.data && !fd.changed) {
@@ -274,10 +269,9 @@ export class WorkspaceWorker {
274
269
  configFileDir: dirname(configFilePath),
275
270
  configFileName: basename(configFilePath),
276
271
  };
277
- const seen = this.extConfigFilesMap.get(wsName)?.get(pluginName)?.has(configFilePath);
278
272
  const cache = {};
279
273
  let loadedConfig;
280
- if (plugin.resolveEntryPaths && !seen) {
274
+ if (plugin.resolveEntryPaths && !seen.get(wsName)?.has(configFilePath)) {
281
275
  if (!loadedConfig)
282
276
  loadedConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
283
277
  if (loadedConfig) {
@@ -287,7 +281,7 @@ export class WorkspaceWorker {
287
281
  cache.resolveEntryPaths = inputs;
288
282
  }
289
283
  }
290
- if (plugin.resolveConfig && !seen) {
284
+ if (plugin.resolveConfig && !seen.get(wsName)?.has(configFilePath)) {
291
285
  if (!loadedConfig)
292
286
  loadedConfig = await loadConfigForPlugin(configFilePath, plugin, resolveOpts, pluginName);
293
287
  if (loadedConfig) {
@@ -314,6 +308,9 @@ export class WorkspaceWorker {
314
308
  if (basename(configFilePath) !== 'package.json') {
315
309
  addInput(toEntry(configFilePath));
316
310
  addInput(toConfig(pluginName, configFilePath));
311
+ if (!seen.has(wsName))
312
+ seen.set(wsName, new Set());
313
+ seen.get(wsName)?.add(configFilePath);
317
314
  }
318
315
  if (!isManifest && fd?.changed && fd.meta)
319
316
  fd.meta.data = cache;
@@ -333,7 +330,7 @@ export class WorkspaceWorker {
333
330
  remainingPlugins.delete(pluginName);
334
331
  }
335
332
  {
336
- const configFiles = this.extConfigFilesMap.get(wsName);
333
+ const configFiles = this.configFilesMap.get(wsName);
337
334
  if (configFiles) {
338
335
  do {
339
336
  for (const [pluginName, dependencies] of configFiles.entries()) {
@@ -12,7 +12,6 @@ import {} from '../util/tag.js';
12
12
  import { augmentWorkspace, getToSourcePathHandler } from '../util/to-source-path.js';
13
13
  import { loadTSConfig } from '../util/tsconfig-loader.js';
14
14
  export async function build({ cacheLocation, chief, collector, cwd, deputy, factory, gitignore, isCache, isFixExports, isFixTypes, isGitIgnored, isIsolateWorkspaces, isProduction, isSkipLibs, isStrict, isWatch, report, streamer, tags, tsConfigFile, workspaces, }) {
15
- const extConfigFilesMap = new Map();
16
15
  const configFilesMap = new Map();
17
16
  const enabledPluginsStore = new Map();
18
17
  const toSourceFilePath = getToSourcePathHandler(chief);
@@ -58,7 +57,6 @@ export async function build({ cacheLocation, chief, collector, cwd, deputy, fact
58
57
  getSourceFile: (filePath) => principal.backend.fileManager.getSourceFile(filePath),
59
58
  isCache,
60
59
  cacheLocation,
61
- extConfigFilesMap,
62
60
  configFilesMap,
63
61
  });
64
62
  await worker.init();
@@ -1,3 +1,4 @@
1
+ import { toDependency } from '../../util/input.js';
1
2
  import { hasDependency } from '../../util/plugin.js';
2
3
  const title = 'simple-git-hooks';
3
4
  const enablers = ['simple-git-hooks'];
@@ -13,7 +14,7 @@ const resolveConfig = async (config, options) => {
13
14
  for (const id of options.getInputsFromScripts(hook))
14
15
  inputs.add(id);
15
16
  }
16
- return Array.from(inputs);
17
+ return [toDependency('simple-git-hooks'), ...Array.from(inputs)];
17
18
  };
18
19
  export default {
19
20
  title,
@@ -41,6 +41,14 @@ export default visit(() => true, node => {
41
41
  });
42
42
  }
43
43
  }
44
+ if (imports.length === 0) {
45
+ imports.push({
46
+ specifier,
47
+ identifier: undefined,
48
+ isTypeOnly: node.importClause?.isTypeOnly,
49
+ pos: node.importClause.namedBindings.pos,
50
+ });
51
+ }
44
52
  }
45
53
  return imports;
46
54
  }
@@ -4,8 +4,8 @@ import { debugLog } from './debug.js';
4
4
  import { isDirectory } from './fs.js';
5
5
  import { isInternal, join, toRelative } from './path.js';
6
6
  const defaultExtensions = `.{${DEFAULT_EXTENSIONS.map(ext => ext.slice(1)).join(',')}}`;
7
- const hasJSExt = /\.(m|c)js$/;
8
7
  const hasTSExt = /(?<!\.d)\.(m|c)?tsx?$/;
8
+ const hasDTSExt = /.d\.(m|c)?ts$/;
9
9
  const matchExt = /(\.d)?\.(m|c)?(j|t)s$/;
10
10
  export const augmentWorkspace = (workspace, dir, compilerOptions) => {
11
11
  const srcDir = join(dir, 'src');
@@ -15,13 +15,14 @@ export const augmentWorkspace = (workspace, dir, compilerOptions) => {
15
15
  export const getToSourcePathHandler = (chief) => {
16
16
  const toSourceMapCache = new Map();
17
17
  return (filePath) => {
18
- if (!isInternal(filePath) || hasJSExt.test(filePath) || hasTSExt.test(filePath))
18
+ if (!isInternal(filePath) || hasTSExt.test(filePath))
19
19
  return;
20
20
  if (toSourceMapCache.has(filePath))
21
21
  return toSourceMapCache.get(filePath);
22
22
  const workspace = chief.findWorkspaceByFilePath(filePath);
23
23
  if (workspace?.srcDir && workspace.outDir) {
24
- if (filePath.startsWith(workspace.outDir)) {
24
+ if ((!filePath.startsWith(workspace.srcDir) && filePath.startsWith(workspace.outDir)) ||
25
+ (workspace.srcDir === workspace.outDir && hasDTSExt.test(filePath))) {
25
26
  const pattern = filePath.replace(workspace.outDir, workspace.srcDir).replace(matchExt, defaultExtensions);
26
27
  const [srcFilePath] = fastGlob.sync(pattern);
27
28
  toSourceMapCache.set(filePath, srcFilePath);
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.50.2";
1
+ export declare const version = "5.50.4";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.50.2';
1
+ export const version = '5.50.4';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.50.2",
3
+ "version": "5.50.4",
4
4
  "description": "Find and fix unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {