knip 5.9.0 → 5.9.2

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 (154) hide show
  1. package/dist/ConfigurationChief.d.ts +6 -6
  2. package/dist/ConfigurationChief.js +10 -8
  3. package/dist/ConsoleStreamer.js +1 -1
  4. package/dist/DependencyDeputy.d.ts +1 -1
  5. package/dist/DependencyDeputy.js +22 -18
  6. package/dist/IssueCollector.js +10 -9
  7. package/dist/IssueFixer.js +9 -7
  8. package/dist/PrincipalFactory.d.ts +2 -2
  9. package/dist/PrincipalFactory.js +3 -5
  10. package/dist/ProjectPrincipal.d.ts +6 -6
  11. package/dist/ProjectPrincipal.js +12 -10
  12. package/dist/WorkspaceWorker.d.ts +2 -2
  13. package/dist/WorkspaceWorker.js +13 -9
  14. package/dist/binaries/index.js +1 -1
  15. package/dist/binaries/resolvers/bun.js +1 -1
  16. package/dist/binaries/resolvers/index.d.ts +12 -12
  17. package/dist/binaries/util.js +1 -1
  18. package/dist/cli.js +10 -9
  19. package/dist/compilers/index.d.ts +1 -1
  20. package/dist/index.js +65 -57
  21. package/dist/issues/initializers.d.ts +1 -1
  22. package/dist/manifest/helpers.js +1 -1
  23. package/dist/manifest/index.d.ts +1 -1
  24. package/dist/manifest/index.js +4 -4
  25. package/dist/plugins/ava/index.js +8 -8
  26. package/dist/plugins/babel/index.js +2 -2
  27. package/dist/plugins/babel/types.d.ts +1 -1
  28. package/dist/plugins/babel/types.js +1 -1
  29. package/dist/plugins/commitlint/index.d.ts +1 -1
  30. package/dist/plugins/cspell/index.d.ts +1 -1
  31. package/dist/plugins/drizzle/index.d.ts +1 -1
  32. package/dist/plugins/eleventy/helpers.d.ts +0 -1
  33. package/dist/plugins/eleventy/helpers.js +1 -2
  34. package/dist/plugins/eleventy/index.d.ts +1 -1
  35. package/dist/plugins/eslint/helpers.d.ts +1 -1
  36. package/dist/plugins/eslint/helpers.js +5 -2
  37. package/dist/plugins/eslint/index.d.ts +0 -1
  38. package/dist/plugins/eslint/index.js +1 -1
  39. package/dist/plugins/github-actions/index.js +1 -1
  40. package/dist/plugins/graphql-codegen/index.d.ts +1 -1
  41. package/dist/plugins/jest/index.js +5 -4
  42. package/dist/plugins/lint-staged/index.d.ts +1 -1
  43. package/dist/plugins/lint-staged/index.js +2 -1
  44. package/dist/plugins/linthtml/index.d.ts +1 -1
  45. package/dist/plugins/markdownlint/index.d.ts +1 -1
  46. package/dist/plugins/npm-package-json-lint/index.d.ts +1 -1
  47. package/dist/plugins/nyc/index.d.ts +1 -1
  48. package/dist/plugins/playwright/index.d.ts +1 -1
  49. package/dist/plugins/playwright-ct/index.js +1 -1
  50. package/dist/plugins/postcss/index.d.ts +1 -1
  51. package/dist/plugins/prettier/index.d.ts +1 -1
  52. package/dist/plugins/release-it/index.d.ts +1 -1
  53. package/dist/plugins/remark/index.d.ts +1 -1
  54. package/dist/plugins/semantic-release/index.d.ts +1 -1
  55. package/dist/plugins/stryker/index.d.ts +1 -1
  56. package/dist/plugins/stylelint/index.d.ts +1 -1
  57. package/dist/plugins/tsup/index.d.ts +1 -1
  58. package/dist/plugins/typescript/index.d.ts +0 -1
  59. package/dist/plugins/typescript/index.js +4 -3
  60. package/dist/plugins/unbuild/index.d.ts +1 -1
  61. package/dist/plugins/vite/index.d.ts +2 -2
  62. package/dist/plugins/vite/index.js +1 -1
  63. package/dist/plugins/vitest/index.d.ts +1 -1
  64. package/dist/plugins/vitest/index.js +8 -4
  65. package/dist/plugins/vue/index.d.ts +1 -1
  66. package/dist/plugins/vue/index.js +2 -1
  67. package/dist/plugins/vue/types.d.ts +1 -1
  68. package/dist/plugins/webpack/index.js +4 -4
  69. package/dist/plugins/wireit/index.d.ts +1 -1
  70. package/dist/plugins/yorkie/index.d.ts +1 -1
  71. package/dist/plugins/yorkie/index.js +2 -1
  72. package/dist/plugins.d.ts +1 -1
  73. package/dist/plugins.js +6 -3
  74. package/dist/reporters/codeowners.js +9 -7
  75. package/dist/reporters/compact.js +1 -1
  76. package/dist/reporters/index.d.ts +5 -5
  77. package/dist/reporters/json.js +3 -3
  78. package/dist/reporters/markdown.js +7 -7
  79. package/dist/reporters/symbols.js +8 -8
  80. package/dist/reporters/util.js +3 -2
  81. package/dist/types/config.d.ts +5 -5
  82. package/dist/types/config.js +1 -3
  83. package/dist/types/exports.d.ts +1 -1
  84. package/dist/types/exports.js +1 -1
  85. package/dist/types/imports.d.ts +1 -1
  86. package/dist/types/imports.js +1 -1
  87. package/dist/typescript/SourceFile.d.ts +1 -1
  88. package/dist/typescript/SourceFile.js +1 -1
  89. package/dist/typescript/SourceFileManager.d.ts +1 -1
  90. package/dist/typescript/ast-helpers.js +2 -2
  91. package/dist/typescript/createHosts.d.ts +1 -1
  92. package/dist/typescript/createHosts.js +1 -1
  93. package/dist/typescript/getImportsAndExports.d.ts +1 -1
  94. package/dist/typescript/getImportsAndExports.js +15 -12
  95. package/dist/typescript/resolveModuleNames.js +2 -2
  96. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
  97. package/dist/typescript/visitors/dynamic-imports/importCall.js +24 -30
  98. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
  99. package/dist/typescript/visitors/dynamic-imports/index.d.ts +2 -2
  100. package/dist/typescript/visitors/dynamic-imports/index.js +0 -1
  101. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
  102. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
  103. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
  104. package/dist/typescript/visitors/dynamic-imports/requireCall.js +14 -22
  105. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  106. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  107. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  108. package/dist/typescript/visitors/exports/exportKeyword.js +10 -12
  109. package/dist/typescript/visitors/exports/exportsAccessExpression.d.ts +1 -1
  110. package/dist/typescript/visitors/exports/index.d.ts +2 -2
  111. package/dist/typescript/visitors/exports/index.js +0 -1
  112. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  113. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.js +2 -4
  114. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  115. package/dist/typescript/visitors/imports/importDeclaration.js +18 -20
  116. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  117. package/dist/typescript/visitors/imports/index.d.ts +2 -2
  118. package/dist/typescript/visitors/imports/index.js +0 -1
  119. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  120. package/dist/typescript/visitors/imports/reExportDeclaration.js +14 -16
  121. package/dist/typescript/visitors/index.d.ts +1 -1
  122. package/dist/typescript/visitors/index.js +0 -1
  123. package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
  124. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  125. package/dist/typescript/visitors/scripts/index.d.ts +2 -2
  126. package/dist/typescript/visitors/scripts/index.js +0 -1
  127. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  128. package/dist/util/Performance.d.ts +1 -1
  129. package/dist/util/Performance.js +5 -5
  130. package/dist/util/cli-arguments.js +1 -1
  131. package/dist/util/debug.js +1 -1
  132. package/dist/util/fs.d.ts +2 -2
  133. package/dist/util/fs.js +3 -3
  134. package/dist/util/get-included-issue-types.js +8 -5
  135. package/dist/util/get-reexporting-entry-file.js +12 -16
  136. package/dist/util/git.js +5 -5
  137. package/dist/util/glob.js +2 -2
  138. package/dist/util/globby.d.ts +1 -1
  139. package/dist/util/globby.js +11 -12
  140. package/dist/util/handle-dependency.d.ts +1 -1
  141. package/dist/util/handle-dependency.js +1 -2
  142. package/dist/util/is-identifier-referenced.js +4 -4
  143. package/dist/util/loader.js +3 -5
  144. package/dist/util/modules.js +7 -5
  145. package/dist/util/object.js +1 -1
  146. package/dist/util/plugin.d.ts +1 -1
  147. package/dist/util/plugin.js +12 -14
  148. package/dist/util/regex.js +1 -1
  149. package/dist/util/require.js +2 -2
  150. package/dist/util/tag.js +4 -2
  151. package/dist/util/type.js +2 -2
  152. package/dist/version.d.ts +1 -1
  153. package/dist/version.js +1 -1
  154. package/package.json +15 -23
@@ -1,4 +1,4 @@
1
- import { performance, PerformanceObserver, PerformanceEntry } from 'node:perf_hooks';
1
+ import { PerformanceObserver, performance } from 'node:perf_hooks';
2
2
  import { constants } from 'node:perf_hooks';
3
3
  import { memoryUsage } from 'node:process';
4
4
  import EasyTable from 'easy-table';
@@ -27,9 +27,9 @@ export class Performance {
27
27
  this.startTime = performance.now();
28
28
  this.instanceId = Math.floor(performance.now() * 100);
29
29
  this.fnObserver = new PerformanceObserver(items => {
30
- items.getEntries().forEach(entry => {
30
+ for (const entry of items.getEntries()) {
31
31
  this.entries.push(entry);
32
- });
32
+ }
33
33
  });
34
34
  this.fnObserver.observe({ entryTypes: ['function'] });
35
35
  this.gcObserver = new PerformanceObserver(items => {
@@ -71,7 +71,7 @@ export class Performance {
71
71
  getTable() {
72
72
  const entriesByName = this.getEntriesByName();
73
73
  const table = new EasyTable();
74
- Object.entries(entriesByName).forEach(([name, values]) => {
74
+ for (const [name, values] of Object.entries(entriesByName)) {
75
75
  const stats = new Summary(values);
76
76
  table.cell('Name', name);
77
77
  table.cell('size', stats.size(), EasyTable.number(0));
@@ -80,7 +80,7 @@ export class Performance {
80
80
  table.cell('median', stats.median(), EasyTable.number(2));
81
81
  table.cell('sum', stats.sum(), EasyTable.number(2));
82
82
  table.newRow();
83
- });
83
+ }
84
84
  table.sort(['sum|des']);
85
85
  return table.toString().trim();
86
86
  }
@@ -91,7 +91,7 @@ try {
91
91
  catch (error) {
92
92
  if (error instanceof Error) {
93
93
  console.error(error.message);
94
- console.log('\n' + helpText);
94
+ console.log(`\n${helpText}`);
95
95
  process.exit(1);
96
96
  }
97
97
  throw error;
@@ -34,7 +34,7 @@ const levels = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨'];
34
34
  export const exportLookupLog = IS_TRACE_ENABLED
35
35
  ? (depth, message, filePath) => {
36
36
  if (depth === -1)
37
- console.log('\n' + message, relative(filePath));
37
+ console.log(`\n${message}`, relative(filePath));
38
38
  else
39
39
  console.log(new Array(depth + 1).join(' '), levels[depth], message, relative(filePath));
40
40
  }
package/dist/util/fs.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export declare const isDirectory: (filePath: string) => boolean;
2
- export declare const isFile: (filePath: string) => boolean;
1
+ export declare const isDirectory: (filePath: string) => boolean | undefined;
2
+ export declare const isFile: (filePath: string) => boolean | undefined;
3
3
  export declare const findFile: (workingDir: string, fileName: string) => string | undefined;
4
4
  export declare const loadFile: (filePath: string) => Promise<string>;
5
5
  export declare const loadJSON: (filePath: string) => Promise<any>;
package/dist/util/fs.js CHANGED
@@ -3,16 +3,16 @@ import { readFile } from 'node:fs/promises';
3
3
  import yaml from 'js-yaml';
4
4
  import { parse as parseTOML } from 'smol-toml';
5
5
  import stripJsonComments from 'strip-json-comments';
6
+ import { timerify } from './Performance.js';
6
7
  import { LoaderError } from './errors.js';
7
8
  import { dirname, join } from './path.js';
8
- import { timerify } from './Performance.js';
9
9
  export const isDirectory = (filePath) => {
10
10
  const stat = statSync(filePath, { throwIfNoEntry: false });
11
- return stat !== undefined && stat.isDirectory();
11
+ return stat?.isDirectory();
12
12
  };
13
13
  export const isFile = (filePath) => {
14
14
  const stat = statSync(filePath, { throwIfNoEntry: false });
15
- return stat !== undefined && stat.isFile();
15
+ return stat?.isFile();
16
16
  };
17
17
  export const findFile = (workingDir, fileName) => {
18
18
  const filePath = join(workingDir, fileName);
@@ -2,14 +2,14 @@ import { ISSUE_TYPES } from '../constants.js';
2
2
  import { ConfigurationError } from './errors.js';
3
3
  export const defaultExcludedIssueTypes = ['classMembers', 'nsExports', 'nsTypes'];
4
4
  const defaultIssueTypes = ISSUE_TYPES.filter(type => !defaultExcludedIssueTypes.includes(type));
5
- const normalize = (values) => values.map(value => value.split(',')).flat();
5
+ const normalize = (values) => values.flatMap(value => value.split(','));
6
6
  export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isProduction = false } = {}) => {
7
7
  let incl = normalize(cliArgs.include);
8
- let excl = normalize(cliArgs.exclude);
9
- [...incl, ...excl, ...include, ...exclude].forEach(type => {
8
+ const excl = normalize(cliArgs.exclude);
9
+ for (const type of [...incl, ...excl, ...include, ...exclude]) {
10
10
  if (!ISSUE_TYPES.includes(type))
11
11
  throw new ConfigurationError(`Invalid issue type: ${type}`);
12
- });
12
+ }
13
13
  const excludes = exclude.filter(exclude => !incl.includes(exclude));
14
14
  const includes = include.filter(include => !excl.includes(include));
15
15
  if (cliArgs.dependencies) {
@@ -37,5 +37,8 @@ export const getIncludedIssueTypes = (cliArgs, { include = [], exclude = [], isP
37
37
  ? _include
38
38
  : [..._include, ...defaultIssueTypes]
39
39
  : defaultIssueTypes).filter(group => !_exclude.includes(group));
40
- return ISSUE_TYPES.reduce((types, group) => ((types[group] = included.includes(group)), types), {});
40
+ return ISSUE_TYPES.reduce((types, group) => {
41
+ types[group] = included.includes(group);
42
+ return types;
43
+ }, {});
41
44
  };
@@ -9,16 +9,16 @@ export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, impo
9
9
  for (const filePath of importedModule.isReExportedBy) {
10
10
  if (entryPaths.has(filePath)) {
11
11
  if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
12
- exportLookupLog(depth, `re-exported by entry`, filePath);
12
+ exportLookupLog(depth, 're-exported by entry', filePath);
13
13
  return filePath;
14
14
  }
15
- else if (importedModule.hasStar) {
16
- exportLookupLog(depth, `re-exported (*) by entry`, filePath);
15
+ if (importedModule.hasStar) {
16
+ exportLookupLog(depth, 're-exported (*) by entry', filePath);
17
17
  return filePath;
18
18
  }
19
19
  }
20
20
  else {
21
- exportLookupLog(depth, `re-exported by`, filePath);
21
+ exportLookupLog(depth, 're-exported by', filePath);
22
22
  const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
23
23
  if (file)
24
24
  return file;
@@ -29,24 +29,20 @@ export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, impo
29
29
  exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
30
30
  return filePath;
31
31
  }
32
- else {
33
- exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
34
- const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
35
- if (file)
36
- return file;
37
- }
32
+ exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
33
+ const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
34
+ if (file)
35
+ return file;
38
36
  }
39
37
  for (const [filePath, alias] of importedModule.isReExportedAs) {
40
38
  if (entryPaths.has(filePath)) {
41
39
  exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
42
40
  return filePath;
43
41
  }
44
- else {
45
- exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
46
- const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
47
- if (file)
48
- return file;
49
- }
42
+ exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
43
+ const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
44
+ if (file)
45
+ return file;
50
46
  }
51
47
  }
52
48
  exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
package/dist/util/git.js CHANGED
@@ -1,10 +1,10 @@
1
- import { execSync } from 'child_process';
1
+ import { execSync } from 'node:child_process';
2
2
  import { join } from './path.js';
3
3
  const hookFileNames = [
4
- `prepare-commit-msg`,
5
- `commit-msg`,
6
- `pre-{applypatch,commit,merge-commit,push,rebase,receive}`,
7
- `post-{checkout,commit,merge,rewrite}`,
4
+ 'prepare-commit-msg',
5
+ 'commit-msg',
6
+ 'pre-{applypatch,commit,merge-commit,push,rebase,receive}',
7
+ 'post-{checkout,commit,merge,rewrite}',
8
8
  ];
9
9
  const getGitHooksPath = (defaultPath = '.git/hooks') => {
10
10
  try {
package/dist/util/glob.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import fg from 'fast-glob';
2
2
  import { GLOBAL_IGNORE_PATTERNS } from '../constants.js';
3
+ import { timerify } from './Performance.js';
3
4
  import { compact } from './array.js';
4
5
  import { globby } from './globby.js';
5
6
  import { join, relative } from './path.js';
6
- import { timerify } from './Performance.js';
7
7
  export const prependDirToPattern = (workingDir, pattern) => {
8
8
  if (pattern.startsWith('!'))
9
- return '!' + join(workingDir, pattern.slice(1));
9
+ return `!${join(workingDir, pattern.slice(1))}`;
10
10
  return join(workingDir, pattern);
11
11
  };
12
12
  export const negate = (pattern) => pattern.replace(/^!?/, '!');
@@ -1,4 +1,4 @@
1
- import { type Options as FastGlobOptions } from 'fast-glob';
1
+ import type { Options as FastGlobOptions } from 'fast-glob';
2
2
  type Options = {
3
3
  gitignore: boolean;
4
4
  cwd: string;
@@ -1,18 +1,17 @@
1
- import * as fs from 'fs';
1
+ import * as fs from 'node:fs';
2
2
  import { promisify } from 'node:util';
3
3
  import { walk as _walk } from '@nodelib/fs.walk';
4
- import {} from 'fast-glob';
5
4
  import fastGlob from 'fast-glob';
6
5
  import picomatch from 'picomatch';
7
6
  import { GLOBAL_IGNORE_PATTERNS, ROOT_WORKSPACE_NAME } from '../constants.js';
7
+ import { timerify } from './Performance.js';
8
8
  import { debugLogObject } from './debug.js';
9
9
  import { dirname, join, relative, toPosix } from './path.js';
10
- import { timerify } from './Performance.js';
11
10
  const walk = promisify(_walk);
12
11
  const _picomatch = timerify(picomatch);
13
12
  const cachedIgnores = new Map();
14
13
  function convertGitignoreToMicromatch(pattern) {
15
- let negated = pattern[0] === '!';
14
+ const negated = pattern[0] === '!';
16
15
  if (negated) {
17
16
  pattern = pattern.slice(1);
18
17
  }
@@ -22,20 +21,20 @@ function convertGitignoreToMicromatch(pattern) {
22
21
  if (pattern.startsWith('/'))
23
22
  pattern = pattern.slice(1);
24
23
  else if (!pattern.startsWith('**/'))
25
- pattern = '**/' + pattern;
24
+ pattern = `**/${pattern}`;
26
25
  if (pattern.endsWith('/*'))
27
26
  extPattern = pattern;
28
27
  else if (pattern.endsWith('/'))
29
- extPattern = pattern + '**';
28
+ extPattern = `${pattern}**`;
30
29
  else
31
- extPattern = pattern + '/**';
30
+ extPattern = `${pattern}/**`;
32
31
  return { negated, patterns: [pattern, extPattern] };
33
32
  }
34
33
  function parseGitignoreFile(filePath) {
35
34
  const file = fs.readFileSync(filePath, 'utf8');
36
35
  return file
37
36
  .split(/\r?\n/)
38
- .filter(line => line && !line.startsWith('#'))
37
+ .filter(line => line.trim() && !line.startsWith('#'))
39
38
  .map(pattern => convertGitignoreToMicromatch(pattern.replace(/(?<!\\)#.*/, '').trim()));
40
39
  }
41
40
  async function parseFindGitignores(options) {
@@ -67,7 +66,7 @@ async function parseFindGitignores(options) {
67
66
  dirUnignores.push(...rule.patterns);
68
67
  }
69
68
  else {
70
- if (!unignores.includes(ext.startsWith('**/') ? ext : '**/' + ext)) {
69
+ if (!unignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
71
70
  dirUnignores.push(join(base, p), join(base, ext));
72
71
  }
73
72
  }
@@ -78,7 +77,7 @@ async function parseFindGitignores(options) {
78
77
  dirIgnores.push(...rule.patterns);
79
78
  }
80
79
  else {
81
- if (!ignores.includes(ext.startsWith('**/') ? ext : '**/' + ext)) {
80
+ if (!ignores.includes(ext.startsWith('**/') ? ext : `**/${ext}`)) {
82
81
  dirIgnores.push(join(base, p), join(base, ext));
83
82
  }
84
83
  }
@@ -109,7 +108,7 @@ export async function globby(patterns, options) {
109
108
  const i = cachedIgnores.get(dir);
110
109
  if (i) {
111
110
  ignore.push(...i.ignores);
112
- ignore.push(...i.unignores.map(e => '!' + e));
111
+ ignore.push(...i.unignores.map(e => `!${e}`));
113
112
  }
114
113
  dir = dirname(dir);
115
114
  }
@@ -118,7 +117,7 @@ export async function globby(patterns, options) {
118
117
  ignore.push(...i.ignores);
119
118
  }
120
119
  const { dir, ...fastGlobOptions } = { ...options, ignore };
121
- debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, `Glob options`, { patterns, ...options });
120
+ debugLogObject(relative(options.cwd, dir) || ROOT_WORKSPACE_NAME, 'Glob options', { patterns, ...options });
122
121
  return fastGlob(patterns, fastGlobOptions);
123
122
  }
124
123
  export async function getGitIgnoredFn(options) {
@@ -1,5 +1,5 @@
1
- import { ProjectPrincipal } from '../ProjectPrincipal.js';
2
1
  import type { ConfigurationChief, Workspace } from '../ConfigurationChief.js';
3
2
  import type { DependencyDeputy } from '../DependencyDeputy.js';
4
3
  import type { IssueCollector } from '../IssueCollector.js';
4
+ import type { ProjectPrincipal } from '../ProjectPrincipal.js';
5
5
  export declare const getHandler: (collector: IssueCollector, deputy: DependencyDeputy, chief: ConfigurationChief) => (specifier: string, containingFilePath: string, workspace: Workspace, principal: ProjectPrincipal) => void;
@@ -1,7 +1,6 @@
1
1
  import micromatch from 'micromatch';
2
- import { ProjectPrincipal } from '../ProjectPrincipal.js';
3
2
  import { getPackageNameFromFilePath, getPackageNameFromModuleSpecifier, normalizeSpecifierFromFilePath, } from './modules.js';
4
- import { isInNodeModules, join, isInternal } from './path.js';
3
+ import { isInNodeModules, isInternal, join } from './path.js';
5
4
  import { fromBinary, isBinary } from './protocols.js';
6
5
  import { _resolveSpecifier } from './require.js';
7
6
  export const getHandler = (collector, deputy, chief) => (specifier, containingFilePath, workspace, principal) => {
@@ -4,11 +4,11 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
4
4
  if (depth === 0)
5
5
  exportLookupLog(-1, `Looking up export "${id}" from`, filePath);
6
6
  if (!importsForExport) {
7
- exportLookupLog(depth, `no imports found from`, filePath);
7
+ exportLookupLog(depth, 'no imports found from', filePath);
8
8
  return false;
9
9
  }
10
10
  if (importsForExport.identifiers.has(id)) {
11
- exportLookupLog(depth, `imported from`, filePath);
11
+ exportLookupLog(depth, 'imported from', filePath);
12
12
  return true;
13
13
  }
14
14
  for (const ns of importsForExport.importedNs) {
@@ -20,7 +20,7 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
20
20
  if (importsForExport.isReExport) {
21
21
  for (const filePath of importsForExport.isReExportedBy) {
22
22
  if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
23
- exportLookupLog(depth, `re-exported by`, filePath);
23
+ exportLookupLog(depth, 're-exported by', filePath);
24
24
  return true;
25
25
  }
26
26
  }
@@ -37,7 +37,7 @@ export const getIsIdentifierReferencedHandler = (importedSymbols) => {
37
37
  }
38
38
  }
39
39
  }
40
- exportLookupLog(depth, `not imported from`, filePath);
40
+ exportLookupLog(depth, 'not imported from', filePath);
41
41
  return false;
42
42
  };
43
43
  return isIdentifierReferenced;
@@ -1,9 +1,9 @@
1
1
  import { pathToFileURL } from 'node:url';
2
+ import { timerify } from './Performance.js';
2
3
  import { LoaderError } from './errors.js';
3
- import { loadJSON, loadYAML, loadTOML, loadFile, parseJSON, parseYAML } from './fs.js';
4
+ import { loadFile, loadJSON, loadTOML, loadYAML, parseJSON, parseYAML } from './fs.js';
4
5
  import { isTypeModule } from './fs.js';
5
6
  import { extname, isInternal } from './path.js';
6
- import { timerify } from './Performance.js';
7
7
  import { jitiCJS, jitiESM } from './register.js';
8
8
  const load = async (filePath) => {
9
9
  try {
@@ -44,9 +44,7 @@ const load = async (filePath) => {
44
44
  if (ext === '.mts' || ((ext === '.ts' || ext === '.tsx') && isTypeModule(filePath))) {
45
45
  return await jitiESM(filePath);
46
46
  }
47
- else {
48
- return await jitiCJS(filePath);
49
- }
47
+ return await jitiCJS(filePath);
50
48
  }
51
49
  catch (error) {
52
50
  throw new LoaderError(`Error loading ${filePath}`, { cause: error });
@@ -1,4 +1,4 @@
1
- import { isBuiltin } from 'module';
1
+ import { isBuiltin } from 'node:module';
2
2
  import { _glob } from './glob.js';
3
3
  import { getStringValues } from './object.js';
4
4
  import { isAbsolute, toPosix } from './path.js';
@@ -26,8 +26,8 @@ export const getDefinitelyTypedFor = (packageName) => {
26
26
  if (isDefinitelyTyped(packageName))
27
27
  return packageName;
28
28
  if (packageName.startsWith('@'))
29
- return '@types/' + packageName.slice(1).replace('/', '__');
30
- return '@types/' + packageName;
29
+ return `@types/${packageName.slice(1).replace('/', '__')}`;
30
+ return `@types/${packageName}`;
31
31
  };
32
32
  export const getPackageFromDefinitelyTyped = (typedDependency) => {
33
33
  if (typedDependency.includes('__')) {
@@ -45,10 +45,12 @@ export const getEntryPathFromManifest = (manifest, sharedGlobOptions) => {
45
45
  if (typeof bin === 'string')
46
46
  entryPaths.add(bin);
47
47
  if (typeof bin === 'object')
48
- Object.values(bin).forEach(bin => entryPaths.add(bin));
48
+ for (const id of Object.values(bin))
49
+ entryPaths.add(id);
49
50
  }
50
51
  if (exports) {
51
- getStringValues(exports).forEach(item => entryPaths.add(item));
52
+ for (const item of getStringValues(exports))
53
+ entryPaths.add(item);
52
54
  }
53
55
  return _glob({ ...sharedGlobOptions, patterns: Array.from(entryPaths) });
54
56
  };
@@ -37,4 +37,4 @@ export const getKeysByValue = (obj, value) => {
37
37
  }
38
38
  return keys;
39
39
  };
40
- export const get = (obj, path) => path.split('.').reduce((o, p) => o && o[p], obj);
40
+ export const get = (obj, path) => path.split('.').reduce((o, p) => o?.[p], obj);
@@ -3,7 +3,7 @@ export { _loadJSON as loadJSON } from './fs.js';
3
3
  export { _tryResolve as tryResolve } from './require.js';
4
4
  export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
5
5
  import type { RawPluginConfiguration } from '../types/config.js';
6
- import type { PluginOptions, Plugin } from '../types/plugins.js';
6
+ import type { Plugin, PluginOptions } from '../types/plugins.js';
7
7
  export declare const toCamelCase: (name: string) => string;
8
8
  export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
9
9
  export declare const normalizePluginConfig: (pluginConfig: RawPluginConfiguration) => boolean | {
@@ -13,7 +13,7 @@ export const hasDependency = (dependencies, values) => values.some(value => {
13
13
  if (typeof value === 'string') {
14
14
  return dependencies.has(value);
15
15
  }
16
- else if (value instanceof RegExp) {
16
+ if (value instanceof RegExp) {
17
17
  for (const dependency of dependencies) {
18
18
  if (value.test(dependency))
19
19
  return true;
@@ -25,19 +25,17 @@ export const normalizePluginConfig = (pluginConfig) => {
25
25
  if (typeof pluginConfig === 'boolean') {
26
26
  return pluginConfig;
27
27
  }
28
- else {
29
- const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
30
- const config = isObject
31
- ? 'config' in pluginConfig
32
- ? arrayify(pluginConfig.config)
33
- : null
34
- : pluginConfig
35
- ? arrayify(pluginConfig)
36
- : null;
37
- const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
38
- const project = isObject && 'project' in pluginConfig ? arrayify(pluginConfig.project) : entry;
39
- return { config, entry, project };
40
- }
28
+ const isObject = typeof pluginConfig !== 'string' && !Array.isArray(pluginConfig);
29
+ const config = isObject
30
+ ? 'config' in pluginConfig
31
+ ? arrayify(pluginConfig.config)
32
+ : null
33
+ : pluginConfig
34
+ ? arrayify(pluginConfig)
35
+ : null;
36
+ const entry = isObject && 'entry' in pluginConfig ? arrayify(pluginConfig.entry) : null;
37
+ const project = isObject && 'project' in pluginConfig ? arrayify(pluginConfig.project) : entry;
38
+ return { config, entry, project };
41
39
  };
42
40
  export const loadConfigForPlugin = async (configFilePath, plugin, options, pluginName) => {
43
41
  const { packageJsonPath } = plugin;
@@ -1,4 +1,4 @@
1
1
  export const toRegexOrString = (value) => typeof value === 'string' && /[*+\\(|{^$]/.test(value) ? new RegExp(value) : value;
2
- export const hasMatch = (haystack, needle) => haystack && haystack.some(n => (typeof n === 'string' ? n === needle : n.test(needle)));
2
+ export const hasMatch = (haystack, needle) => haystack?.some(n => (typeof n === 'string' ? n === needle : n.test(needle)));
3
3
  export const hasMatchInSet = (haystack, needle) => haystack && (typeof needle === 'string' ? haystack.has(needle) : [...haystack].some(n => needle.test(n)));
4
4
  export const findKey = (map, key) => [...map.keys()].find(k => k instanceof RegExp && k.source === key.source);
@@ -2,10 +2,10 @@ import { createRequire as nodeCreateRequire } from 'node:module';
2
2
  import { pathToFileURL } from 'node:url';
3
3
  import createJITI from 'jiti';
4
4
  import transform from 'jiti/dist/babel.js';
5
+ import { timerify } from './Performance.js';
5
6
  import { debugLog } from './debug.js';
6
7
  import { getPackageNameFromModuleSpecifier } from './modules.js';
7
- import { cwd, toPosix, join } from './path.js';
8
- import { timerify } from './Performance.js';
8
+ import { cwd, join, toPosix } from './path.js';
9
9
  import { jitiCJS } from './register.js';
10
10
  const createRequire = (path) => nodeCreateRequire(pathToFileURL(path ?? cwd));
11
11
  const require = createRequire();
package/dist/util/tag.js CHANGED
@@ -1,10 +1,12 @@
1
1
  export const splitTags = (tags) => tags
2
2
  .flatMap(tag => tag.split(','))
3
3
  .reduce(([incl, excl], tag) => {
4
- (tag.startsWith('-') ? excl : incl).push(tag.match(/[a-zA-Z]+/)[0]);
4
+ const match = tag.match(/[a-zA-Z]+/);
5
+ if (match)
6
+ (tag.startsWith('-') ? excl : incl).push(match[0]);
5
7
  return [incl, excl];
6
8
  }, [[], []]);
7
- const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.includes('@' + tag));
9
+ const hasTag = (tags, jsDocTags) => tags.some(tag => jsDocTags.includes(`@${tag}`));
8
10
  export const shouldIgnore = (jsDocTags, tags) => {
9
11
  const [includeJSDocTags, excludeJSDocTags] = tags;
10
12
  if (includeJSDocTags.length > 0 && !hasTag(includeJSDocTags, jsDocTags))
package/dist/util/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export const getHasStrictlyNsReferences = (importsForExport) => {
2
- if (!importsForExport || !importsForExport.hasStar || importsForExport.importedNs.size === 0)
2
+ if (!importsForExport?.hasStar || importsForExport.importedNs.size === 0)
3
3
  return [false];
4
4
  let namespace;
5
5
  for (const ns of importsForExport.importedNs) {
@@ -7,7 +7,7 @@ export const getHasStrictlyNsReferences = (importsForExport) => {
7
7
  if (!hasNs)
8
8
  return [false, ns];
9
9
  for (const id of importsForExport.identifiers)
10
- if (id.startsWith(ns + '.'))
10
+ if (id.startsWith(`${ns}.`))
11
11
  return [false, ns];
12
12
  namespace = ns;
13
13
  }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "5.9.0";
1
+ export declare const version = "5.9.2";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '5.9.0';
1
+ export const version = '5.9.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "5.9.0",
3
+ "version": "5.9.2",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -37,19 +37,17 @@
37
37
  "scripts": {
38
38
  "knip": "node ./dist/cli.js --directory ../..",
39
39
  "knip:production": "node ./dist/cli.js --directory ../.. --production --strict",
40
- "lint": "eslint scripts src test",
41
- "lint:fix": "eslint scripts src test --fix",
42
- "format": "prettier scripts src test schema.json schema-jsonc.json --with-node-modules --write",
43
- "pretest": "node rmdir.js tmp && swc src -d tmp && swc test -d tmp",
44
- "test": "node --no-warnings --test tmp",
45
- "coverage": "c8 --reporter html node --no-warnings --import tsx --test test/*.test.ts test/*/*.test.ts",
40
+ "lint": "biome lint .",
41
+ "format": "biome format --write .",
42
+ "test": "bun test test/**/*.test.ts",
43
+ "test:node": "glob -c \"tsx --test --import ./transform-test.js\" \"test/**/*.test.ts\"",
46
44
  "watch": "npm link && tsc --watch",
47
45
  "prebuild": "node rmdir.js dist",
48
46
  "build": "tsc",
49
- "qa": "npm run lint && npm run build && npm run knip && npm run knip:production && npm test",
47
+ "ci": "bun run lint && bun run build && bun run knip && bun run knip:production && npm test",
50
48
  "release": "release-it",
51
- "create-plugin": "tsx --no-warnings ./scripts/create-new-plugin.ts",
52
- "postcreate-plugin": "prettier schema.json schema-jsonc.json src/ConfigurationValidator.ts --write --config .prettierrc.json"
49
+ "create-plugin": "bun ./scripts/create-new-plugin.ts",
50
+ "postcreate-plugin": "biome format --write schema.json schema-jsonc.json src/ConfigurationValidator.ts"
53
51
  },
54
52
  "files": [
55
53
  "dist",
@@ -61,8 +59,7 @@
61
59
  "@nodelib/fs.walk": "2.0.0",
62
60
  "@npmcli/map-workspaces": "3.0.4",
63
61
  "@npmcli/package-json": "5.0.0",
64
- "@pnpm/logger": "5.0.0",
65
- "@pnpm/workspace.pkgs-graph": "^2.0.15",
62
+ "@pnpm/workspace.pkgs-graph": "2.0.14",
66
63
  "@snyk/github-codeowners": "1.1.0",
67
64
  "@types/picomatch": "2.3.3",
68
65
  "easy-table": "1.2.0",
@@ -87,11 +84,8 @@
87
84
  },
88
85
  "devDependencies": {
89
86
  "@jest/types": "^29.6.3",
90
- "@knip/eslint-config": "0.0.0",
91
87
  "@release-it/bumper": "^6.0.1",
92
- "@swc/cli": "^0.3.10",
93
- "@swc/core": "^1.4.6",
94
- "@types/bun": "^1.0.8",
88
+ "@types/bun": "^1.0.12",
95
89
  "@types/js-yaml": "^4.0.9",
96
90
  "@types/micromatch": "^4.0.6",
97
91
  "@types/minimist": "^1.2.5",
@@ -99,14 +93,12 @@
99
93
  "@types/npmcli__package-json": "^4.0.4",
100
94
  "@types/resolve": "^1.20.6",
101
95
  "@types/webpack": "^5.28.5",
102
- "c8": "9.1.0",
103
- "eslint": "^8.57.0",
104
- "playwright": "^1.42.1",
105
- "prettier": "^3.2.5",
96
+ "glob": "^10.3.12",
97
+ "playwright": "^1.43.0",
106
98
  "release-it": "^17.1.1",
107
- "tsx": "^4.7.1",
108
- "type-fest": "^4.12.0",
109
- "typescript": "5.4.2"
99
+ "tsx": "^4.7.2",
100
+ "type-fest": "^4.15.0",
101
+ "typescript": "^5.4.2"
110
102
  },
111
103
  "engines": {
112
104
  "node": ">=18.6.0"