knip 3.5.0 → 3.6.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 (53) hide show
  1. package/dist/ConfigurationChief.js +3 -2
  2. package/dist/ConfigurationValidator.d.ts +16 -16
  3. package/dist/ConfigurationValidator.js +5 -4
  4. package/dist/DependencyDeputy.d.ts +10 -8
  5. package/dist/DependencyDeputy.js +67 -25
  6. package/dist/IssueCollector.js +2 -5
  7. package/dist/ProjectPrincipal.js +5 -3
  8. package/dist/WorkspaceWorker.js +2 -2
  9. package/dist/constants.js +1 -0
  10. package/dist/index.js +24 -32
  11. package/dist/plugins/_template/index.js +2 -4
  12. package/dist/plugins/astro/index.js +1 -1
  13. package/dist/plugins/ava/index.js +4 -6
  14. package/dist/plugins/babel/index.js +2 -3
  15. package/dist/plugins/commitizen/index.js +2 -3
  16. package/dist/plugins/commitlint/index.js +2 -3
  17. package/dist/plugins/eslint/helpers.js +2 -2
  18. package/dist/plugins/eslint/index.js +2 -1
  19. package/dist/plugins/github-actions/index.js +2 -3
  20. package/dist/plugins/graphql-codegen/index.js +2 -4
  21. package/dist/plugins/husky/index.js +2 -3
  22. package/dist/plugins/jest/index.js +4 -4
  23. package/dist/plugins/lefthook/index.js +5 -5
  24. package/dist/plugins/lint-staged/index.js +4 -6
  25. package/dist/plugins/mocha/index.js +2 -3
  26. package/dist/plugins/node-test-runner/index.js +1 -5
  27. package/dist/plugins/npm-package-json-lint/index.js +2 -3
  28. package/dist/plugins/nx/index.js +2 -3
  29. package/dist/plugins/postcss/index.js +2 -3
  30. package/dist/plugins/prettier/index.js +2 -3
  31. package/dist/plugins/release-it/index.js +4 -6
  32. package/dist/plugins/remark/index.js +2 -3
  33. package/dist/plugins/semantic-release/index.js +2 -3
  34. package/dist/plugins/stylelint/index.js +2 -4
  35. package/dist/plugins/typedoc/index.js +3 -2
  36. package/dist/types/config.d.ts +2 -2
  37. package/dist/types/imports.d.ts +1 -1
  38. package/dist/types/issues.d.ts +1 -1
  39. package/dist/types/workspace.d.ts +2 -2
  40. package/dist/typescript/getImportsAndExports.js +5 -4
  41. package/dist/util/compilers.d.ts +4 -4
  42. package/dist/util/modules.d.ts +1 -1
  43. package/dist/util/modules.js +2 -2
  44. package/dist/util/path.d.ts +1 -0
  45. package/dist/util/path.js +1 -0
  46. package/dist/util/plugin.d.ts +1 -0
  47. package/dist/util/plugin.js +1 -0
  48. package/dist/util/regex.d.ts +4 -0
  49. package/dist/util/regex.js +4 -0
  50. package/dist/version.d.ts +1 -1
  51. package/dist/version.js +1 -1
  52. package/package.json +7 -7
  53. package/schema.json +4 -4
@@ -1,6 +1,6 @@
1
1
  import { compact } from '../../util/array.js';
2
2
  import { getPackageNameFromModuleSpecifier } from '../../util/modules.js';
3
- import { isInternal, dirname, toAbsolute } from '../../util/path.js';
3
+ import { basename, isInternal, dirname, toAbsolute } from '../../util/path.js';
4
4
  import { load } from '../../util/plugin.js';
5
5
  import { _resolve } from '../../util/require.js';
6
6
  import { getDependenciesFromConfig } from '../babel/index.js';
@@ -21,7 +21,7 @@ const getDependencies = (config) => {
21
21
  };
22
22
  export const getDependenciesDeep = async (configFilePath, options, dependencies = new Set()) => {
23
23
  const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
24
- const localConfig = configFilePath.endsWith('package.json')
24
+ const localConfig = basename(configFilePath) === 'package.json'
25
25
  ? options.manifest[PACKAGE_JSON_PATH]
26
26
  : /(\.(jsonc?|ya?ml)|rc)$/.test(configFilePath)
27
27
  ? await load(configFilePath)
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency } from '../../util/plugin.js';
3
4
  import { getDependenciesDeep } from './helpers.js';
@@ -17,7 +18,7 @@ export const CONFIG_FILE_PATTERNS = [
17
18
  const findESLintDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
18
19
  if (isProduction)
19
20
  return [];
20
- if (configFilePath.endsWith('eslint.config.js'))
21
+ if (basename(configFilePath) === 'eslint.config.js')
21
22
  return [];
22
23
  const dependencies = await getDependenciesDeep(configFilePath, { cwd, manifest });
23
24
  return Array.from(dependencies);
@@ -1,8 +1,7 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
2
1
  import { _firstGlob } from '../../util/glob.js';
3
2
  import { getValuesByKeyDeep } from '../../util/object.js';
4
3
  import { timerify } from '../../util/Performance.js';
5
- import { load } from '../../util/plugin.js';
4
+ import { getDependenciesFromScripts, load } from '../../util/plugin.js';
6
5
  export const NAME = 'GitHub Actions';
7
6
  export const ENABLERS = 'This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.';
8
7
  export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.{yml,yaml}'] }));
@@ -15,7 +14,7 @@ const findGithubActionsDependencies = async (configFilePath, options) => {
15
14
  if (!config)
16
15
  return [];
17
16
  const scripts = getValuesByKeyDeep(config, 'run').filter((value) => typeof value === 'string');
18
- return _getDependenciesFromScripts(scripts, {
17
+ return getDependenciesFromScripts(scripts, {
19
18
  cwd,
20
19
  manifest,
21
20
  knownGlobalsOnly: true,
@@ -1,4 +1,4 @@
1
- import { isInternal } from '../../util/path.js';
1
+ import { basename, isInternal } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  import { toEntryPattern } from '../../util/protocols.js';
@@ -17,9 +17,7 @@ const findPluginDependencies = async (configFilePath, options) => {
17
17
  const { manifest, isProduction } = options;
18
18
  if (isProduction)
19
19
  return [];
20
- const localConfig = configFilePath.endsWith('package.json')
21
- ? manifest[PACKAGE_JSON_PATH]
22
- : await load(configFilePath);
20
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
23
21
  if (!localConfig)
24
22
  return [];
25
23
  const generateSet = Object.values(localConfig.generates);
@@ -1,8 +1,7 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
2
1
  import { getGitHookPaths } from '../../util/git.js';
3
2
  import { FAKE_PATH } from '../../util/loader.js';
4
3
  import { timerify } from '../../util/Performance.js';
5
- import { hasDependency, loadFile } from '../../util/plugin.js';
4
+ import { getDependenciesFromScripts, hasDependency, loadFile } from '../../util/plugin.js';
6
5
  export const NAME = 'husky';
7
6
  export const ENABLERS = ['husky'];
8
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -15,7 +14,7 @@ const findHuskyDependencies = async (configFilePath, options) => {
15
14
  const script = await loadFile(configFilePath);
16
15
  if (!script)
17
16
  return [];
18
- return _getDependenciesFromScripts(String(script), {
17
+ return getDependenciesFromScripts(String(script), {
19
18
  cwd,
20
19
  manifest,
21
20
  knownGlobalsOnly: true,
@@ -1,4 +1,4 @@
1
- import { join, isInternal, toAbsolute, dirname } from '../../util/path.js';
1
+ import { basename, join, isInternal, toAbsolute, dirname } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  import { toEntryPattern } from '../../util/protocols.js';
@@ -46,6 +46,7 @@ const resolveDependencies = (config, options) => {
46
46
  ? Object.values(config.moduleNameMapper).map(mapper => (typeof mapper === 'string' ? mapper : mapper[0]))
47
47
  : []).filter(value => !/\$[0-9]/.test(value));
48
48
  const testResultsProcessor = config.testResultsProcessor ? [config.testResultsProcessor] : [];
49
+ const snapshotResolver = config.snapshotResolver ? [config.snapshotResolver] : [];
49
50
  return [
50
51
  ...entryPatterns,
51
52
  ...presets,
@@ -60,13 +61,12 @@ const resolveDependencies = (config, options) => {
60
61
  ...transform,
61
62
  ...moduleNameMapper,
62
63
  ...testResultsProcessor,
64
+ ...snapshotResolver,
63
65
  ];
64
66
  };
65
67
  const findJestDependencies = async (configFilePath, options) => {
66
68
  const { manifest, cwd } = options;
67
- let localConfig = configFilePath.endsWith('package.json')
68
- ? manifest.jest
69
- : await resolveExtensibleConfig(configFilePath);
69
+ let localConfig = basename(configFilePath) === 'package.json' ? manifest.jest : await resolveExtensibleConfig(configFilePath);
70
70
  if (typeof localConfig === 'function')
71
71
  localConfig = await localConfig();
72
72
  if (!localConfig)
@@ -1,8 +1,8 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
2
1
  import { getGitHookPaths } from '../../util/git.js';
3
2
  import { getValuesByKeyDeep } from '../../util/object.js';
3
+ import { extname } from '../../util/path.js';
4
4
  import { timerify } from '../../util/Performance.js';
5
- import { hasDependency, load, loadFile } from '../../util/plugin.js';
5
+ import { getDependenciesFromScripts, hasDependency, load, loadFile } from '../../util/plugin.js';
6
6
  import { fromBinary } from '../../util/protocols.js';
7
7
  export const NAME = 'Lefthook';
8
8
  export const ENABLERS = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthook'];
@@ -14,18 +14,18 @@ const findLefthookDependencies = async (configFilePath, options) => {
14
14
  if (isProduction)
15
15
  return [];
16
16
  const dependencies = manifest.devDependencies ? Object.keys(manifest.devDependencies) : [];
17
- if (configFilePath.endsWith('.yml')) {
17
+ if (extname(configFilePath) === '.yml') {
18
18
  const localConfig = await load(configFilePath);
19
19
  if (!localConfig)
20
20
  return [];
21
21
  const scripts = getValuesByKeyDeep(localConfig, 'run').filter((run) => typeof run === 'string');
22
22
  const lefthook = process.env.CI ? ENABLERS.filter(dependency => dependencies.includes(dependency)) : [];
23
- return [...lefthook, ..._getDependenciesFromScripts(scripts, { cwd, manifest, knownGlobalsOnly: true })];
23
+ return [...lefthook, ...getDependenciesFromScripts(scripts, { cwd, manifest, knownGlobalsOnly: true })];
24
24
  }
25
25
  const script = await loadFile(configFilePath);
26
26
  if (!script)
27
27
  return [];
28
- const scriptDependencies = _getDependenciesFromScripts([script], { cwd, manifest, knownGlobalsOnly: false });
28
+ const scriptDependencies = getDependenciesFromScripts([script], { cwd, manifest, knownGlobalsOnly: false });
29
29
  const matches = scriptDependencies.find(dep => dependencies.includes(fromBinary(dep)));
30
30
  return matches ? [matches] : [];
31
31
  };
@@ -1,6 +1,6 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
1
+ import { basename } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
- import { hasDependency, load } from '../../util/plugin.js';
3
+ import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
4
4
  export const NAME = 'lint-staged';
5
5
  export const ENABLERS = ['lint-staged'];
6
6
  export const PACKAGE_JSON_PATH = 'lint-staged';
@@ -17,9 +17,7 @@ const findLintStagedDependencies = async (configFilePath, options) => {
17
17
  const { cwd, manifest, isProduction } = options;
18
18
  if (isProduction)
19
19
  return [];
20
- let localConfig = configFilePath.endsWith('package.json')
21
- ? manifest['lint-staged']
22
- : await load(configFilePath);
20
+ let localConfig = basename(configFilePath) === 'package.json' ? manifest['lint-staged'] : await load(configFilePath);
23
21
  if (typeof localConfig === 'function')
24
22
  localConfig = localConfig();
25
23
  if (!localConfig)
@@ -28,7 +26,7 @@ const findLintStagedDependencies = async (configFilePath, options) => {
28
26
  for (const entry of Object.values(localConfig).flat()) {
29
27
  const scripts = [typeof entry === 'function' ? await entry([]) : entry].flat();
30
28
  const options = { cwd, manifest };
31
- _getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
29
+ getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
32
30
  }
33
31
  return Array.from(dependencies);
34
32
  };
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  import { toEntryPattern } from '../../util/protocols.js';
@@ -8,9 +9,7 @@ export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'p
8
9
  export const ENTRY_FILE_PATTERNS = ['**/test/*.{js,cjs,mjs}'];
9
10
  const findMochaDependencies = async (configFilePath, options) => {
10
11
  const { config, manifest, isProduction } = options;
11
- const localConfig = configFilePath.endsWith('package.json')
12
- ? manifest.mocha
13
- : await load(configFilePath);
12
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest.mocha : await load(configFilePath);
14
13
  const entryPatterns = (config.entry ?? (localConfig?.spec ? [localConfig.spec].flat() : ENTRY_FILE_PATTERNS)).map(toEntryPattern);
15
14
  if (isProduction || !localConfig)
16
15
  return entryPatterns;
@@ -2,11 +2,7 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { toEntryPattern } from '../../util/protocols.js';
3
3
  export const NAME = 'Node.js Test Runner';
4
4
  export const ENABLERS = 'This plugin is enabled when any script in `package.json` includes `node --test`';
5
- export const isEnabled = ({ manifest }) => {
6
- return Object.keys(manifest.scripts ?? {})
7
- .filter(s => /test/.test(s))
8
- .some(s => manifest.scripts && /node (.*)--test/.test(manifest.scripts[s]));
9
- };
5
+ export const isEnabled = ({ manifest }) => Object.keys(manifest.scripts ?? {}).some(script => manifest.scripts && /(?<=^|\s)node (.*)--test/.test(manifest.scripts[script]));
10
6
  export const ENTRY_FILE_PATTERNS = [
11
7
  '**/*{.,-,_}test.?(c|m)js',
12
8
  '**/test-*.?(c|m)js',
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'npm-package-json-lint';
@@ -9,9 +10,7 @@ const findNpmPkgJsonLintConfigDependencies = async (configFilePath, options) =>
9
10
  const { manifest, isProduction } = options;
10
11
  if (isProduction)
11
12
  return [];
12
- const localConfig = configFilePath.endsWith('package.json')
13
- ? manifest[PACKAGE_JSON_PATH]
14
- : await load(configFilePath);
13
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
15
14
  return localConfig?.extends ? [localConfig.extends] : [];
16
15
  };
17
16
  export const findDependencies = timerify(findNpmPkgJsonLintConfigDependencies);
@@ -1,7 +1,6 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
2
1
  import { compact } from '../../util/array.js';
3
2
  import { timerify } from '../../util/Performance.js';
4
- import { hasDependency, load } from '../../util/plugin.js';
3
+ import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
5
4
  export const NAME = 'Nx';
6
5
  export const ENABLERS = ['nx', /^@nrwl\//, /^@nx\//];
7
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -21,7 +20,7 @@ const findNxDependencies = async (configFilePath, options) => {
21
20
  const scripts = targets
22
21
  .filter(target => target.executor === 'nx:run-commands')
23
22
  .flatMap(target => target.options?.commands ?? (target.options?.command ? [target.options.command] : []));
24
- const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest });
23
+ const dependencies = getDependenciesFromScripts(scripts, { cwd, manifest });
25
24
  return compact([...executors, ...dependencies]);
26
25
  };
27
26
  export const findDependencies = timerify(findNxDependencies);
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'PostCSS';
@@ -8,9 +9,7 @@ const findPostCSSDependencies = async (configFilePath, options) => {
8
9
  const { manifest, isProduction } = options;
9
10
  if (isProduction)
10
11
  return [];
11
- const localConfig = configFilePath.endsWith('package.json')
12
- ? manifest?.postcss
13
- : await load(configFilePath);
12
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest?.postcss : await load(configFilePath);
14
13
  if (!localConfig)
15
14
  return [];
16
15
  return localConfig.plugins
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'Prettier';
@@ -12,9 +13,7 @@ export const CONFIG_FILE_PATTERNS = [
12
13
  const findPrettierDependencies = async (configFilePath, { manifest, isProduction }) => {
13
14
  if (isProduction)
14
15
  return [];
15
- const localConfig = configFilePath.endsWith('package.json')
16
- ? manifest.prettier
17
- : await load(configFilePath);
16
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest.prettier : await load(configFilePath);
18
17
  if (typeof localConfig === 'string') {
19
18
  return [localConfig];
20
19
  }
@@ -1,6 +1,6 @@
1
- import { _getDependenciesFromScripts } from '../../binaries/index.js';
1
+ import { basename } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
- import { hasDependency, load } from '../../util/plugin.js';
3
+ import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
4
4
  export const NAME = 'Release It';
5
5
  export const ENABLERS = ['release-it'];
6
6
  export const PACKAGE_JSON_PATH = 'release-it';
@@ -15,9 +15,7 @@ const findReleaseItDependencies = async (configFilePath, options) => {
15
15
  const { cwd, manifest, isProduction } = options;
16
16
  if (isProduction)
17
17
  return [];
18
- const localConfig = configFilePath.endsWith('package.json')
19
- ? manifest[PACKAGE_JSON_PATH]
20
- : await load(configFilePath);
18
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
21
19
  if (!localConfig)
22
20
  return [];
23
21
  const plugins = localConfig.plugins ? Object.keys(localConfig.plugins) : [];
@@ -28,7 +26,7 @@ const findReleaseItDependencies = async (configFilePath, options) => {
28
26
  if (typeof localConfig.gitlab?.releaseNotes === 'string') {
29
27
  scripts.push(localConfig.gitlab.releaseNotes);
30
28
  }
31
- const dependencies = _getDependenciesFromScripts(scripts, { cwd, manifest });
29
+ const dependencies = getDependenciesFromScripts(scripts, { cwd, manifest });
32
30
  return [...plugins, ...dependencies];
33
31
  };
34
32
  export const findDependencies = timerify(findReleaseItDependencies);
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'Remark';
@@ -15,9 +16,7 @@ const findRemarkDependencies = async (configFilePath, options) => {
15
16
  const { manifest, isProduction } = options;
16
17
  if (isProduction)
17
18
  return [];
18
- const localConfig = configFilePath.endsWith('package.json')
19
- ? manifest[PACKAGE_JSON_PATH]
20
- : await load(configFilePath);
19
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
21
20
  if (!localConfig)
22
21
  return [];
23
22
  const plugins = localConfig.plugins
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'Semantic Release';
@@ -14,9 +15,7 @@ const findSemanticReleaseDependencies = async (configFilePath, options) => {
14
15
  const { manifest, isProduction } = options;
15
16
  if (isProduction)
16
17
  return [];
17
- const localConfig = configFilePath.endsWith('package.json')
18
- ? manifest[PACKAGE_JSON_PATH]
19
- : await load(configFilePath);
18
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest[PACKAGE_JSON_PATH] : await load(configFilePath);
20
19
  const plugins = (localConfig?.plugins ?? []).map(plugin => (Array.isArray(plugin) ? plugin[0] : plugin));
21
20
  return plugins;
22
21
  };
@@ -1,4 +1,4 @@
1
- import { isInternal } from '../../util/path.js';
1
+ import { basename, isInternal } from '../../util/path.js';
2
2
  import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  export const NAME = 'Stylelint';
@@ -13,9 +13,7 @@ const findPluginDependencies = async (configFilePath, options) => {
13
13
  const { manifest, isProduction } = options;
14
14
  if (isProduction)
15
15
  return [];
16
- const localConfig = configFilePath.endsWith('package.json')
17
- ? manifest.stylelint
18
- : await load(configFilePath);
16
+ const localConfig = basename(configFilePath) === 'package.json' ? manifest.stylelint : await load(configFilePath);
19
17
  if (!localConfig)
20
18
  return [];
21
19
  const extend = localConfig.extends ? [localConfig.extends].flat().filter(extend => !isInternal(extend)) : [];
@@ -1,3 +1,4 @@
1
+ import { basename } from '../../util/path.js';
1
2
  import { timerify } from '../../util/Performance.js';
2
3
  import { hasDependency, load } from '../../util/plugin.js';
3
4
  export const NAME = 'TypeDoc';
@@ -16,9 +17,9 @@ const findTypeDocDependencies = async (configFilePath, options) => {
16
17
  const { manifest, isProduction } = options;
17
18
  if (isProduction)
18
19
  return [];
19
- const localConfig = configFilePath.endsWith('package.json')
20
+ const localConfig = basename(configFilePath) === 'package.json'
20
21
  ? manifest[PACKAGE_JSON_PATH]
21
- : configFilePath.endsWith('tsconfig.json')
22
+ : basename(configFilePath) === 'tsconfig.json'
22
23
  ? (await load(configFilePath)).typedocOptions
23
24
  : await load(configFilePath);
24
25
  return localConfig?.plugin ?? [];
@@ -32,8 +32,8 @@ export interface Configuration {
32
32
  include: string[];
33
33
  exclude: string[];
34
34
  ignore: NormalizedGlob;
35
- ignoreBinaries: string[];
36
- ignoreDependencies: string[];
35
+ ignoreBinaries: (string | RegExp)[];
36
+ ignoreDependencies: (string | RegExp)[];
37
37
  ignoreExportsUsedInFile: boolean | Partial<Record<IgnorableExport, boolean>>;
38
38
  ignoreWorkspaces: string[];
39
39
  isIncludeEntryExports: boolean;
@@ -5,7 +5,7 @@ type ImportItems = Set<Identifier>;
5
5
  export type ImportedModule = {
6
6
  specifier: Specifier;
7
7
  symbols: ImportItems;
8
- isStar: boolean;
8
+ hasStar: boolean;
9
9
  isReExport: boolean;
10
10
  isReExportedBy: Set<string>;
11
11
  };
@@ -68,6 +68,6 @@ export type Rules = Record<IssueType, IssueSeverity>;
68
68
  export type ConfigurationHints = Set<ConfigurationHint>;
69
69
  export type ConfigurationHint = {
70
70
  type: 'ignoreBinaries' | 'ignoreDependencies' | 'ignoreWorkspaces';
71
- identifier: string;
71
+ identifier: string | RegExp;
72
72
  workspaceName?: string;
73
73
  };
@@ -8,8 +8,8 @@ type WorkspaceManifest = {
8
8
  optionalDependencies: string[];
9
9
  devDependencies: string[];
10
10
  allDependencies: string[];
11
- ignoreDependencies: string[];
12
- ignoreBinaries: string[];
11
+ ignoreDependencies: (string | RegExp)[];
12
+ ignoreBinaries: (string | RegExp)[];
13
13
  };
14
14
  export type WorkspaceManifests = Map<string, WorkspaceManifest>;
15
15
  export type HostDependencies = Map<string, Set<{
@@ -1,7 +1,7 @@
1
1
  import { isBuiltin } from 'node:module';
2
2
  import ts from 'typescript';
3
3
  import { getOrSet } from '../util/map.js';
4
- import { isMaybePackageName, sanitizeSpecifier } from '../util/modules.js';
4
+ import { isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
5
5
  import { isInNodeModules } from '../util/path.js';
6
6
  import { isDeclarationFileExtension, isAccessExpression, getAccessExpressionName, getJSDocTags, getLineAndCharacterOfPosition, } from './ast-helpers.js';
7
7
  import getExportVisitors from './visitors/exports/index.js';
@@ -30,7 +30,7 @@ export const getImportsAndExports = (sourceFile, getResolvedModule, options) =>
30
30
  const isStar = identifier === '*';
31
31
  const internalImport = getOrSet(internalImports, filePath, {
32
32
  specifier,
33
- isStar,
33
+ hasStar: isStar,
34
34
  isReExport,
35
35
  isReExportedBy: new Set(),
36
36
  symbols: new Set(),
@@ -40,7 +40,7 @@ export const getImportsAndExports = (sourceFile, getResolvedModule, options) =>
40
40
  internalImport.isReExportedBy.add(sourceFile.fileName);
41
41
  }
42
42
  if (isStar)
43
- internalImport.isStar = isStar;
43
+ internalImport.hasStar = true;
44
44
  if (!isStar)
45
45
  internalImport.symbols.add(identifier);
46
46
  if (isStar && symbol)
@@ -59,8 +59,9 @@ export const getImportsAndExports = (sourceFile, getResolvedModule, options) =>
59
59
  addInternalImport({ identifier, specifier, symbol, filePath, isReExport });
60
60
  }
61
61
  const sanitizedSpecifier = sanitizeSpecifier(specifier);
62
- if (!isMaybePackageName(sanitizedSpecifier))
62
+ if (!isStartsLikePackageName(sanitizedSpecifier)) {
63
63
  return;
64
+ }
64
65
  if (isDeclarationFileExtension(module.resolvedModule.extension)) {
65
66
  externalImports.add(sanitizedSpecifier);
66
67
  }
@@ -9,9 +9,9 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
9
9
  project?: string | string[] | undefined;
10
10
  paths?: Record<string, string[]> | undefined;
11
11
  ignore?: string | string[] | undefined;
12
- ignoreBinaries?: string[] | undefined;
12
+ ignoreBinaries?: (string | RegExp)[] | undefined;
13
+ ignoreDependencies?: (string | RegExp)[] | undefined;
13
14
  ignoreExportsUsedInFile?: boolean | Partial<Record<"function" | "type" | "enum" | "class" | "interface" | "member", boolean>> | undefined;
14
- ignoreDependencies?: string[] | undefined;
15
15
  ignoreWorkspaces?: string[] | undefined;
16
16
  includeEntryExports?: boolean | undefined;
17
17
  compilers?: Record<string, ((args_0: string, ...args_1: unknown[]) => string) | ((args_0: string, ...args_1: unknown[]) => Promise<string>)> | undefined;
@@ -21,8 +21,8 @@ export declare const partitionCompilers: (rawLocalConfig: RawConfiguration) => {
21
21
  project?: string | string[] | undefined;
22
22
  paths?: Record<string, string[]> | undefined;
23
23
  ignore?: string | string[] | undefined;
24
- ignoreBinaries?: string[] | undefined;
25
- ignoreDependencies?: string[] | undefined;
24
+ ignoreBinaries?: (string | RegExp)[] | undefined;
25
+ ignoreDependencies?: (string | RegExp)[] | undefined;
26
26
  includeEntryExports?: boolean | undefined;
27
27
  astro?: string | boolean | string[] | {
28
28
  config?: string | string[] | undefined;
@@ -2,7 +2,7 @@ import type { PackageJson } from '@npmcli/package-json';
2
2
  export declare const getPackageNameFromModuleSpecifier: (moduleSpecifier: string) => string | undefined;
3
3
  export declare const getPackageNameFromFilePath: (value: string) => string;
4
4
  export declare const normalizeSpecifierFromFilePath: (value: string) => string;
5
- export declare const isMaybePackageName: (specifier: string) => boolean;
5
+ export declare const isStartsLikePackageName: (specifier: string) => boolean;
6
6
  export declare const isDefinitelyTyped: (packageName: string) => boolean;
7
7
  export declare const getDefinitelyTypedFor: (packageName: string) => string;
8
8
  export declare const getPackageFromDefinitelyTyped: (typedDependency: string) => string;
@@ -3,7 +3,7 @@ import { _glob } from './glob.js';
3
3
  import { getStringValues } from './object.js';
4
4
  import { isAbsolute, toPosix } from './path.js';
5
5
  export const getPackageNameFromModuleSpecifier = (moduleSpecifier) => {
6
- if (!isMaybePackageName(moduleSpecifier))
6
+ if (!isStartsLikePackageName(moduleSpecifier))
7
7
  return;
8
8
  const parts = moduleSpecifier.split('/').slice(0, 2);
9
9
  return moduleSpecifier.startsWith('@') ? parts.join('/') : parts[0];
@@ -20,7 +20,7 @@ export const normalizeSpecifierFromFilePath = (value) => {
20
20
  return match[match.length - 1];
21
21
  return value;
22
22
  };
23
- export const isMaybePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
23
+ export const isStartsLikePackageName = (specifier) => /^@?[a-z0-9]/.test(specifier);
24
24
  export const isDefinitelyTyped = (packageName) => packageName.startsWith('@types/');
25
25
  export const getDefinitelyTypedFor = (packageName) => {
26
26
  if (isDefinitelyTyped(packageName))
@@ -1,6 +1,7 @@
1
1
  export declare const isAbsolute: (path: string) => boolean;
2
2
  export declare const dirname: (path: string) => string;
3
3
  export declare const extname: (path: string) => string;
4
+ export declare const basename: (path: string, suffix?: string | undefined) => string;
4
5
  export declare const join: (...paths: string[]) => string;
5
6
  export declare const toPosix: (value: string) => string;
6
7
  export declare const cwd: string;
package/dist/util/path.js CHANGED
@@ -4,6 +4,7 @@ const { directory } = parsedArgValues;
4
4
  export const isAbsolute = path.isAbsolute;
5
5
  export const dirname = path.posix.dirname;
6
6
  export const extname = path.posix.extname;
7
+ export const basename = path.posix.basename;
7
8
  export const join = path.posix.join;
8
9
  export const toPosix = (value) => value.split(path.sep).join(path.posix.sep);
9
10
  export const cwd = directory ? path.posix.resolve(directory) : toPosix(process.cwd());
@@ -1,5 +1,6 @@
1
1
  export { _load as load, _loadFile as loadFile } from './loader.js';
2
2
  export { _tryResolve as tryResolve } from './require.js';
3
+ export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
3
4
  import type { RawPluginConfiguration } from '../types/config.js';
4
5
  export declare const toCamelCase: (name: string) => string;
5
6
  export declare const hasDependency: (dependencies: Set<string>, values: (string | RegExp)[]) => boolean;
@@ -1,5 +1,6 @@
1
1
  export { _load as load, _loadFile as loadFile } from './loader.js';
2
2
  export { _tryResolve as tryResolve } from './require.js';
3
+ export { _getDependenciesFromScripts as getDependenciesFromScripts } from '../binaries/index.js';
3
4
  import { arrayify } from './array.js';
4
5
  export const toCamelCase = (name) => name.toLowerCase().replace(/(-[a-z])/g, group => group.toUpperCase().replace('-', ''));
5
6
  export const hasDependency = (dependencies, values) => values.some(value => {
@@ -0,0 +1,4 @@
1
+ export declare const toRegexOrString: (value: string | RegExp) => string | RegExp;
2
+ export declare const hasMatch: (haystack: undefined | (string | RegExp)[], needle: string) => boolean | undefined;
3
+ export declare const hasMatchInSet: (haystack: undefined | Set<string>, needle: string | RegExp) => boolean | undefined;
4
+ export declare const hasMatchInArray: (haystack: string[], needle: string | RegExp) => boolean;
@@ -0,0 +1,4 @@
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)));
3
+ export const hasMatchInSet = (haystack, needle) => haystack && (typeof needle === 'string' ? haystack.has(needle) : [...haystack].some(n => needle.test(n)));
4
+ export const hasMatchInArray = (haystack, needle) => typeof needle === 'string' ? haystack.includes(needle) : haystack.some(n => needle.test(n));
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "3.5.0";
1
+ export declare const version = "3.6.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '3.5.0';
1
+ export const version = '3.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knip",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Find unused files, dependencies and exports in your TypeScript and JavaScript projects",
5
5
  "homepage": "https://knip.dev",
6
6
  "repository": {
@@ -47,9 +47,9 @@
47
47
  "@npmcli/map-workspaces": "3.0.4",
48
48
  "@pkgjs/parseargs": "0.11.0",
49
49
  "@pnpm/logger": "5.0.0",
50
- "@pnpm/workspace.pkgs-graph": "^2.0.10",
50
+ "@pnpm/workspace.pkgs-graph": "^2.0.11",
51
51
  "@snyk/github-codeowners": "1.1.0",
52
- "chalk": "^5.2.0",
52
+ "chalk": "^5.3.0",
53
53
  "easy-table": "1.2.0",
54
54
  "fast-glob": "3.3.2",
55
55
  "globby": "^14.0.0",
@@ -82,13 +82,13 @@
82
82
  "@types/pkgjs__parseargs": "^0.10.3",
83
83
  "@types/webpack": "^5.28.5",
84
84
  "c8": "8.0.1",
85
- "eslint": "^8.54.0",
85
+ "eslint": "^8.55.0",
86
86
  "playwright": "^1.40.1",
87
87
  "prettier": "^3.1.0",
88
88
  "release-it": "^17.0.0",
89
- "tsx": "^4.6.1",
90
- "type-fest": "^4.8.2",
91
- "typescript": "5.3.2"
89
+ "tsx": "^4.6.2",
90
+ "type-fest": "^4.8.3",
91
+ "typescript": "5.3.3"
92
92
  },
93
93
  "engines": {
94
94
  "node": ">=18.6.0"