knip 2.30.1 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +15 -24
  2. package/dist/ConfigurationChief.d.ts +2 -0
  3. package/dist/ConfigurationChief.js +57 -61
  4. package/dist/ConfigurationValidator.d.ts +377 -321
  5. package/dist/ConfigurationValidator.js +2 -1
  6. package/dist/WorkspaceWorker.d.ts +8 -6
  7. package/dist/WorkspaceWorker.js +41 -62
  8. package/dist/binaries/index.js +1 -1
  9. package/dist/binaries/resolvers/c8.js +2 -1
  10. package/dist/binaries/resolvers/dotenv.js +2 -1
  11. package/dist/binaries/resolvers/fallback.js +2 -1
  12. package/dist/binaries/resolvers/nodemon.js +2 -1
  13. package/dist/binaries/resolvers/npx.js +2 -1
  14. package/dist/binaries/resolvers/nx.js +1 -1
  15. package/dist/binaries/resolvers/pnpm.js +1 -1
  16. package/dist/binaries/resolvers/rollup.js +2 -1
  17. package/dist/binaries/resolvers/yarn.js +1 -1
  18. package/dist/binaries/util.d.ts +0 -3
  19. package/dist/binaries/util.js +1 -3
  20. package/dist/constants.d.ts +0 -1
  21. package/dist/constants.js +0 -4
  22. package/dist/index.js +27 -20
  23. package/dist/plugins/ava/index.d.ts +1 -1
  24. package/dist/plugins/ava/index.js +23 -5
  25. package/dist/plugins/ava/types.d.ts +1 -0
  26. package/dist/plugins/babel/index.js +3 -1
  27. package/dist/plugins/capacitor/index.js +3 -1
  28. package/dist/plugins/changesets/index.js +3 -1
  29. package/dist/plugins/commitizen/index.d.ts +1 -0
  30. package/dist/plugins/commitizen/index.js +4 -1
  31. package/dist/plugins/commitlint/index.js +3 -1
  32. package/dist/plugins/cspell/index.js +3 -1
  33. package/dist/plugins/cypress/index.d.ts +3 -1
  34. package/dist/plugins/cypress/index.js +14 -4
  35. package/dist/plugins/drizzle/index.js +3 -5
  36. package/dist/plugins/eslint/helpers.js +2 -1
  37. package/dist/plugins/eslint/index.d.ts +1 -0
  38. package/dist/plugins/eslint/index.js +4 -1
  39. package/dist/plugins/gatsby/index.js +10 -2
  40. package/dist/plugins/github-actions/index.js +3 -1
  41. package/dist/plugins/husky/index.js +3 -1
  42. package/dist/plugins/index.d.ts +1 -0
  43. package/dist/plugins/index.js +1 -0
  44. package/dist/plugins/jest/index.d.ts +1 -1
  45. package/dist/plugins/jest/index.js +16 -7
  46. package/dist/plugins/lefthook/index.js +4 -2
  47. package/dist/plugins/lint-staged/index.d.ts +1 -0
  48. package/dist/plugins/lint-staged/index.js +4 -1
  49. package/dist/plugins/markdownlint/index.js +3 -1
  50. package/dist/plugins/mocha/index.d.ts +1 -0
  51. package/dist/plugins/mocha/index.js +10 -6
  52. package/dist/plugins/next/index.d.ts +2 -1
  53. package/dist/plugins/next/index.js +4 -0
  54. package/dist/plugins/node-test-runner/index.d.ts +6 -0
  55. package/dist/plugins/node-test-runner/index.js +17 -0
  56. package/dist/plugins/npm-package-json-lint/index.d.ts +1 -0
  57. package/dist/plugins/npm-package-json-lint/index.js +5 -2
  58. package/dist/plugins/nx/index.js +3 -1
  59. package/dist/plugins/nyc/index.js +3 -1
  60. package/dist/plugins/playwright/index.d.ts +3 -1
  61. package/dist/plugins/playwright/index.js +22 -2
  62. package/dist/plugins/playwright-ct/index.d.ts +3 -1
  63. package/dist/plugins/playwright-ct/index.js +13 -2
  64. package/dist/plugins/postcss/index.js +8 -6
  65. package/dist/plugins/prettier/index.js +3 -1
  66. package/dist/plugins/release-it/index.d.ts +1 -0
  67. package/dist/plugins/release-it/index.js +5 -2
  68. package/dist/plugins/remark/index.d.ts +1 -0
  69. package/dist/plugins/remark/index.js +10 -3
  70. package/dist/plugins/remix/index.d.ts +2 -1
  71. package/dist/plugins/remix/index.js +10 -0
  72. package/dist/plugins/rollup/index.d.ts +2 -1
  73. package/dist/plugins/rollup/index.js +7 -0
  74. package/dist/plugins/semantic-release/index.d.ts +1 -0
  75. package/dist/plugins/semantic-release/index.js +7 -2
  76. package/dist/plugins/sentry/index.d.ts +2 -1
  77. package/dist/plugins/sentry/index.js +7 -0
  78. package/dist/plugins/storybook/index.js +6 -2
  79. package/dist/plugins/stryker/index.js +9 -8
  80. package/dist/plugins/stylelint/index.js +3 -1
  81. package/dist/plugins/svelte/index.d.ts +2 -1
  82. package/dist/plugins/svelte/index.js +6 -0
  83. package/dist/plugins/typedoc/index.d.ts +1 -0
  84. package/dist/plugins/typedoc/index.js +5 -2
  85. package/dist/plugins/typescript/index.js +3 -1
  86. package/dist/plugins/vite/index.js +2 -2
  87. package/dist/plugins/vitest/index.d.ts +3 -3
  88. package/dist/plugins/vitest/index.js +16 -23
  89. package/dist/plugins/vitest/types.d.ts +1 -0
  90. package/dist/plugins/webpack/index.js +3 -1
  91. package/dist/types/config.d.ts +5 -3
  92. package/dist/types/plugins.d.ts +3 -3
  93. package/dist/util/compilers.d.ts +90 -80
  94. package/dist/util/object.d.ts +1 -0
  95. package/dist/util/object.js +1 -0
  96. package/dist/util/plugin.d.ts +2 -2
  97. package/dist/util/plugin.js +2 -2
  98. package/dist/util/protocols.d.ts +9 -0
  99. package/dist/util/protocols.js +9 -0
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.js +1 -1
  102. package/package.json +2 -1
  103. package/schema.json +4 -0
@@ -4,7 +4,9 @@ export const NAME = 'Changesets';
4
4
  export const ENABLERS = ['@changesets/cli'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const CONFIG_FILE_PATTERNS = ['.changeset/config.json'];
7
- const findChangesetsDependencies = async (configFilePath) => {
7
+ const findChangesetsDependencies = async (configFilePath, { isProduction }) => {
8
+ if (isProduction)
9
+ return [];
8
10
  const config = await load(configFilePath);
9
11
  return Array.isArray(config.changelog)
10
12
  ? [config.changelog[0]]
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Commitizen";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "config.commitizen";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -2,9 +2,12 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'Commitizen';
4
4
  export const ENABLERS = ['commitizen'];
5
+ export const PACKAGE_JSON_PATH = 'config.commitizen';
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = ['.czrc', '.cz.json', 'package.json'];
7
- const findPluginDependencies = async (configFilePath, { manifest }) => {
8
+ const findPluginDependencies = async (configFilePath, { manifest, isProduction }) => {
9
+ if (isProduction)
10
+ return [];
8
11
  const config = configFilePath.endsWith('package.json')
9
12
  ? manifest.config?.commitizen
10
13
  : await load(configFilePath);
@@ -9,7 +9,9 @@ export const CONFIG_FILE_PATTERNS = [
9
9
  'commitlint.config.{js,cjs,ts,cts}',
10
10
  'package.json',
11
11
  ];
12
- const findCommitLintDependencies = async (configFilePath, { manifest }) => {
12
+ const findCommitLintDependencies = async (configFilePath, { manifest, isProduction }) => {
13
+ if (isProduction)
14
+ return [];
13
15
  const config = configFilePath.endsWith('package.json')
14
16
  ? manifest.commitlint
15
17
  : await load(configFilePath);
@@ -9,7 +9,9 @@ export const CONFIG_FILE_PATTERNS = [
9
9
  '.c{s,S}pell.json',
10
10
  'cSpell.json',
11
11
  ];
12
- const findCspellDependencies = async (configFilePath) => {
12
+ const findCspellDependencies = async (configFilePath, { isProduction }) => {
13
+ if (isProduction)
14
+ return [];
13
15
  const config = await load(configFilePath);
14
16
  const imports = config?.import ?? [];
15
17
  return imports;
@@ -1,5 +1,7 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Cypress";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
5
6
  export declare const ENTRY_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,10 +1,20 @@
1
- import { hasDependency } from '../../util/plugin.js';
1
+ import { load, hasDependency } from '../../util/plugin.js';
2
+ import { toEntryPattern } from '../../util/protocols.js';
2
3
  export const NAME = 'Cypress';
3
4
  export const ENABLERS = ['cypress'];
4
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
- export const ENTRY_FILE_PATTERNS = [
6
- 'cypress.config.{js,ts,mjs,cjs}',
6
+ export const CONFIG_FILE_PATTERNS = ['cypress.config.{js,ts,mjs,cjs}'];
7
+ const TEST_FILE_PATTERNS = ['cypress/e2e/**/*.cy.{js,jsx,ts,tsx}'];
8
+ const SUPPORT_FILE_PATTERNS = [
7
9
  'cypress/support/e2e.{js,jsx,ts,tsx}',
8
- 'cypress/e2e/**/*.cy.{js,jsx,ts,tsx}',
9
10
  'cypress/plugins/index.js',
10
11
  ];
12
+ export const ENTRY_FILE_PATTERNS = [...TEST_FILE_PATTERNS, ...SUPPORT_FILE_PATTERNS];
13
+ export const findDependencies = async (configFilePath) => {
14
+ const config = await load(configFilePath);
15
+ if (!config)
16
+ return [];
17
+ const patterns = [config.e2e?.specPattern ?? [], config.component?.specPattern ?? []].flat();
18
+ const entryPatterns = (patterns.length > 0 ? patterns : TEST_FILE_PATTERNS).map(toEntryPattern);
19
+ return [...entryPatterns, ...SUPPORT_FILE_PATTERNS.map(toEntryPattern)];
20
+ };
@@ -1,16 +1,14 @@
1
- import { _glob } from '../../util/glob.js';
2
1
  import { timerify } from '../../util/Performance.js';
3
2
  import { hasDependency, load } from '../../util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
4
4
  export const NAME = 'Drizzle';
5
5
  export const ENABLERS = ['drizzle-kit'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['drizzle.config.{ts,js,json}'];
8
- const findDrizzleDependencies = async (configFilePath, { cwd }) => {
8
+ const findDrizzleDependencies = async (configFilePath) => {
9
9
  const config = await load(configFilePath);
10
10
  if (!config || !config.schema)
11
11
  return [];
12
- const patterns = Array.isArray(config.schema) ? config.schema : [config.schema];
13
- const paths = await _glob({ cwd, patterns });
14
- return paths;
12
+ return [config.schema].flat().map(toEntryPattern);
15
13
  };
16
14
  export const findDependencies = timerify(findDrizzleDependencies);
@@ -3,6 +3,7 @@ import { isInternal, dirname, toAbsolute } from '../../util/path.js';
3
3
  import { load } from '../../util/plugin.js';
4
4
  import { _resolve } from '../../util/require.js';
5
5
  import { fallback } from './fallback.js';
6
+ import { PACKAGE_JSON_PATH } from './index.js';
6
7
  const getDependencies = (config) => {
7
8
  const extendsSpecifiers = config.extends ? [config.extends].flat().map(resolveExtendSpecifier) : [];
8
9
  if (extendsSpecifiers.some(specifier => specifier?.startsWith('eslint-plugin-prettier')))
@@ -26,7 +27,7 @@ const getDependencies = (config) => {
26
27
  export const getDependenciesDeep = async (configFilePath, dependencies = new Set(), options) => {
27
28
  const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
28
29
  const config = configFilePath.endsWith('package.json')
29
- ? options.manifest.eslintConfig
30
+ ? options.manifest[PACKAGE_JSON_PATH]
30
31
  : /(\.(jsonc?|ya?ml)|rc)$/.test(configFilePath)
31
32
  ? await load(configFilePath)
32
33
  : await fallback(configFilePath);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "ESLint";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "eslintConfig";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const ENTRY_FILE_PATTERNS: string[];
@@ -3,12 +3,15 @@ import { hasDependency } from '../../util/plugin.js';
3
3
  import { getDependenciesDeep } from './helpers.js';
4
4
  export const NAME = 'ESLint';
5
5
  export const ENABLERS = ['eslint'];
6
+ export const PACKAGE_JSON_PATH = 'eslintConfig';
6
7
  export const isEnabled = ({ dependencies, manifest, config }) => hasDependency(dependencies, ENABLERS) ||
7
8
  'eslint' in config ||
8
9
  Boolean(manifest.name && /(^eslint-config|\/eslint-config)/.test(manifest.name));
9
10
  export const CONFIG_FILE_PATTERNS = ['.eslintrc', '.eslintrc.{js,json,cjs}', '.eslintrc.{yml,yaml}', 'package.json'];
10
11
  export const ENTRY_FILE_PATTERNS = ['eslint.config.js'];
11
- const findESLintDependencies = async (configFilePath, { cwd, manifest }) => {
12
+ const findESLintDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
13
+ if (isProduction)
14
+ return [];
12
15
  const dependencies = await getDependenciesDeep(configFilePath, new Set(), { cwd, manifest });
13
16
  return Array.from(dependencies);
14
17
  };
@@ -1,18 +1,26 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
+ import { toProductionEntryPattern } from '../../util/protocols.js';
3
4
  export const NAME = 'Gatsby';
4
5
  export const ENABLERS = ['gatsby', 'gatsby-cli'];
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
- export const CONFIG_FILE_PATTERNS = ['gatsby-{config,node}.{js,jsx,ts,tsx}'];
7
+ export const CONFIG_FILE_PATTERNS = [
8
+ 'gatsby-{config,node}.{js,jsx,ts,tsx}',
9
+ 'plugins/**/gatsby-node.{js,jsx,ts,tsx}',
10
+ ];
7
11
  export const PRODUCTION_ENTRY_FILE_PATTERNS = [
8
12
  'gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
9
13
  'src/api/**/*.{js,ts}',
10
14
  'src/pages/**/*.{js,jsx,ts,tsx}',
11
15
  'src/templates/**/*.{js,jsx,ts,tsx}',
12
16
  'src/html.{js,jsx,ts,tsx}',
17
+ 'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
13
18
  ];
14
- const findGatsbyDependencies = async (configFilePath) => {
19
+ const findGatsbyDependencies = async (configFilePath, { isProduction }) => {
15
20
  const config = await load(configFilePath);
21
+ const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
22
+ if (isProduction)
23
+ return entryPatterns;
16
24
  if (/gatsby-config/.test(configFilePath)) {
17
25
  return config.plugins.map(plugin => (typeof plugin === 'string' ? plugin : plugin.resolve));
18
26
  }
@@ -7,7 +7,9 @@ export const NAME = 'GitHub Actions';
7
7
  export const ENABLERS = 'This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.';
8
8
  export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.yml'] }));
9
9
  export const CONFIG_FILE_PATTERNS = ['.github/workflows/*.yml', '.github/**/action.{yml,yaml}'];
10
- const findGithubActionsDependencies = async (configFilePath, { cwd, manifest }) => {
10
+ const findGithubActionsDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
11
+ if (isProduction)
12
+ return [];
11
13
  const config = await load(configFilePath);
12
14
  if (!config)
13
15
  return [];
@@ -8,7 +8,9 @@ export const ENABLERS = ['husky'];
8
8
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
9
  const gitHookPaths = getGitHookPaths('.husky');
10
10
  export const CONFIG_FILE_PATTERNS = [...gitHookPaths];
11
- const findHuskyDependencies = async (configFilePath, { cwd, manifest }) => {
11
+ const findHuskyDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
12
+ if (isProduction)
13
+ return [];
12
14
  const script = readFileSync(configFilePath);
13
15
  return _getDependenciesFromScripts(String(script), {
14
16
  cwd,
@@ -18,6 +18,7 @@ export * as lintStaged from './lint-staged/index.js';
18
18
  export * as markdownlint from './markdownlint/index.js';
19
19
  export * as mocha from './mocha/index.js';
20
20
  export * as next from './next/index.js';
21
+ export * as nodeTestRunner from './node-test-runner/index.js';
21
22
  export * as npmPackageJsonLint from './npm-package-json-lint/index.js';
22
23
  export * as nx from './nx/index.js';
23
24
  export * as nyc from './nyc/index.js';
@@ -18,6 +18,7 @@ export * as lintStaged from './lint-staged/index.js';
18
18
  export * as markdownlint from './markdownlint/index.js';
19
19
  export * as mocha from './mocha/index.js';
20
20
  export * as next from './next/index.js';
21
+ export * as nodeTestRunner from './node-test-runner/index.js';
21
22
  export * as npmPackageJsonLint from './npm-package-json-lint/index.js';
22
23
  export * as nx from './nx/index.js';
23
24
  export * as nyc from './nyc/index.js';
@@ -3,5 +3,5 @@ export declare const NAME = "Jest";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
- export declare const ENTRY_FILE_PATTERNS: never[];
6
+ export declare const ENTRY_FILE_PATTERNS: string[];
7
7
  export declare const findDependencies: GenericPluginCallback;
@@ -1,11 +1,12 @@
1
1
  import { 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
+ import { toEntryPattern } from '../../util/protocols.js';
4
5
  export const NAME = 'Jest';
5
6
  export const ENABLERS = ['jest'];
6
7
  export const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) || Boolean(manifest.name?.startsWith('jest-presets'));
7
8
  export const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
8
- export const ENTRY_FILE_PATTERNS = [];
9
+ export const ENTRY_FILE_PATTERNS = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
9
10
  const resolveExtensibleConfig = async (configFilePath) => {
10
11
  const config = await load(configFilePath);
11
12
  if (config?.preset) {
@@ -18,10 +19,14 @@ const resolveExtensibleConfig = async (configFilePath) => {
18
19
  }
19
20
  return config;
20
21
  };
21
- const resolveDependencies = (config) => {
22
+ const resolveDependencies = (config, options) => {
23
+ const { isProduction } = options;
24
+ const entryPatterns = (config.testMatch ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
25
+ if (isProduction)
26
+ return entryPatterns;
22
27
  const presets = (config.preset ? [config.preset] : []).map(preset => isInternal(preset) ? preset : join(preset, 'jest-preset'));
23
28
  const projects = Array.isArray(config.projects)
24
- ? config.projects.map(config => (typeof config === 'string' ? config : resolveDependencies(config))).flat()
29
+ ? config.projects.map(config => (typeof config === 'string' ? config : resolveDependencies(config, options))).flat()
25
30
  : [];
26
31
  const runner = config.runner ? [config.runner] : [];
27
32
  const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : [];
@@ -42,6 +47,7 @@ const resolveDependencies = (config) => {
42
47
  : []).filter(value => !/\$[0-9]/.test(value));
43
48
  const testResultsProcessor = config.testResultsProcessor ? [config.testResultsProcessor] : [];
44
49
  return [
50
+ ...entryPatterns,
45
51
  ...presets,
46
52
  ...projects,
47
53
  ...runner,
@@ -56,7 +62,8 @@ const resolveDependencies = (config) => {
56
62
  ...testResultsProcessor,
57
63
  ];
58
64
  };
59
- const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
65
+ const findJestDependencies = async (configFilePath, options) => {
66
+ const { manifest, cwd } = options;
60
67
  let config = configFilePath.endsWith('package.json')
61
68
  ? manifest.jest
62
69
  : await resolveExtensibleConfig(configFilePath);
@@ -64,8 +71,10 @@ const findJestDependencies = async (configFilePath, { cwd, manifest }) => {
64
71
  config = await config();
65
72
  if (!config)
66
73
  return [];
67
- const rootDir = config.rootDir ?? '';
68
- const replaceRootDir = (name) => name.includes('<rootDir>') ? join(cwd, name.replace(/^.*<rootDir>/, rootDir)) : name;
69
- return resolveDependencies(config).map(replaceRootDir);
74
+ const rootDir = config.rootDir ? join(dirname(configFilePath), config.rootDir) : dirname(configFilePath);
75
+ const replaceRootDir = (name) => (name.includes('<rootDir>') ? name.replace(/<rootDir>/, rootDir) : name);
76
+ const dependencies = resolveDependencies(config, options);
77
+ const matchCwd = new RegExp('^' + toEntryPattern(cwd) + '/');
78
+ return dependencies.map(replaceRootDir).map(dependency => dependency.replace(matchCwd, toEntryPattern('')));
70
79
  };
71
80
  export const findDependencies = timerify(findJestDependencies);
@@ -1,16 +1,18 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { _getDependenciesFromScripts } from '../../binaries/index.js';
3
- import { fromBinary } from '../../binaries/util.js';
4
3
  import { getGitHookPaths } from '../../util/git.js';
5
4
  import { getValuesByKeyDeep } from '../../util/object.js';
6
5
  import { timerify } from '../../util/Performance.js';
7
6
  import { hasDependency, load } from '../../util/plugin.js';
7
+ import { fromBinary } from '../../util/protocols.js';
8
8
  export const NAME = 'Lefthook';
9
9
  export const ENABLERS = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthook'];
10
10
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
11
11
  const gitHookPaths = getGitHookPaths();
12
12
  export const CONFIG_FILE_PATTERNS = ['lefthook.yml', ...gitHookPaths];
13
- const findLefthookDependencies = async (configFilePath, { cwd, manifest }) => {
13
+ const findLefthookDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
14
+ if (isProduction)
15
+ return [];
14
16
  const dependencies = manifest.devDependencies ? Object.keys(manifest.devDependencies) : [];
15
17
  if (configFilePath.endsWith('.yml')) {
16
18
  const config = await load(configFilePath);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "lint-staged";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "lint-staged";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -3,6 +3,7 @@ import { timerify } from '../../util/Performance.js';
3
3
  import { hasDependency, load } from '../../util/plugin.js';
4
4
  export const NAME = 'lint-staged';
5
5
  export const ENABLERS = ['lint-staged'];
6
+ export const PACKAGE_JSON_PATH = 'lint-staged';
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
8
  export const CONFIG_FILE_PATTERNS = [
8
9
  '.lintstagedrc',
@@ -12,7 +13,9 @@ export const CONFIG_FILE_PATTERNS = [
12
13
  'lint-staged.config.{js,mjs,cjs}',
13
14
  'package.json',
14
15
  ];
15
- const findLintStagedDependencies = async (configFilePath, { cwd, manifest }) => {
16
+ const findLintStagedDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
17
+ if (isProduction)
18
+ return [];
16
19
  let config = configFilePath.endsWith('package.json')
17
20
  ? manifest['lint-staged']
18
21
  : await load(configFilePath);
@@ -5,7 +5,9 @@ export const NAME = 'markdownlint';
5
5
  export const ENABLERS = ['markdownlint-cli'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['.markdownlint.{json,jsonc}', '.markdownlint.{yml,yaml}'];
8
- const findMarkdownlintConfigDependencies = async (configFilePath, { manifest }) => {
8
+ const findMarkdownlintConfigDependencies = async (configFilePath, { manifest, isProduction }) => {
9
+ if (isProduction)
10
+ return [];
9
11
  const config = await load(configFilePath);
10
12
  const extend = config?.extends ? [config.extends] : [];
11
13
  const scripts = manifest.scripts
@@ -3,4 +3,5 @@ export declare const NAME = "Mocha";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
+ export declare const ENTRY_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -1,15 +1,19 @@
1
1
  import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
+ import { toEntryPattern } from '../../util/protocols.js';
3
4
  export const NAME = 'Mocha';
4
5
  export const ENABLERS = ['mocha'];
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
7
- const findMochaDependencies = async (configFilePath, { manifest }) => {
8
+ export const ENTRY_FILE_PATTERNS = ['**/test/*.{js,cjs,mjs}'];
9
+ const findMochaDependencies = async (configFilePath, { manifest, isProduction }) => {
10
+ const entryPatterns = ENTRY_FILE_PATTERNS.map(toEntryPattern);
11
+ if (isProduction)
12
+ return entryPatterns;
8
13
  const config = configFilePath.endsWith('package.json') ? manifest.mocha : await load(configFilePath);
9
- if (config) {
10
- const require = config.require;
11
- return require ? [require].flat() : [];
12
- }
13
- return [];
14
+ if (!config)
15
+ return [];
16
+ const require = config.require ? [config.require].flat() : [];
17
+ return [...require, ...entryPatterns];
14
18
  };
15
19
  export const findDependencies = timerify(findMochaDependencies);
@@ -1,6 +1,7 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Next.js";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
6
  export declare const PRODUCTION_ENTRY_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,4 +1,5 @@
1
1
  import { hasDependency } from '../../util/plugin.js';
2
+ import { toEntryPattern, toProductionEntryPattern } from '../../util/protocols.js';
2
3
  export const NAME = 'Next.js';
3
4
  export const ENABLERS = ['next'];
4
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
@@ -17,3 +18,6 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
17
18
  ...productionEntryFilePatternsWithoutSrc,
18
19
  ...productionEntryFilePatternsWithoutSrc.map(pattern => `src/${pattern}`),
19
20
  ];
21
+ export const findDependencies = async () => {
22
+ return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
23
+ };
@@ -0,0 +1,6 @@
1
+ import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
+ export declare const NAME = "Node.js Test Runner";
3
+ export declare const ENABLERS: string[];
4
+ export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const ENTRY_FILE_PATTERNS: string[];
6
+ export declare const findDependencies: GenericPluginCallback;
@@ -0,0 +1,17 @@
1
+ import { timerify } from '../../util/Performance.js';
2
+ import { toEntryPattern } from '../../util/protocols.js';
3
+ export const NAME = 'Node.js Test Runner';
4
+ export const ENABLERS = [''];
5
+ export const isEnabled = ({ manifest }) => {
6
+ return Boolean(manifest.scripts?.test && /node.+--test/.test(manifest.scripts?.test));
7
+ };
8
+ export const ENTRY_FILE_PATTERNS = [
9
+ '**/test.{js,cjs,mjs}',
10
+ '**/test-*.{js,cjs,mjs}',
11
+ '**/*{.,-,_}test.{js,cjs,mjs}',
12
+ '**/test/**/*.{js,cjs,mjs}',
13
+ ];
14
+ const findNodeTestRunnerDependencies = async (configFilePath, options) => {
15
+ return (options.config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
16
+ };
17
+ export const findDependencies = timerify(findNodeTestRunnerDependencies);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "npm-package-json-lint";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "npmpackagejsonlint";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;
@@ -2,11 +2,14 @@ import { timerify } from '../../util/Performance.js';
2
2
  import { hasDependency, load } from '../../util/plugin.js';
3
3
  export const NAME = 'npm-package-json-lint';
4
4
  export const ENABLERS = ['npm-package-json-lint'];
5
+ export const PACKAGE_JSON_PATH = 'npmpackagejsonlint';
5
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
7
  export const CONFIG_FILE_PATTERNS = ['.npmpackagejsonlintrc.json', 'npmpackagejsonlint.config.js', 'package.json'];
7
- const findNpmPkgJsonLintConfigDependencies = async (configFilePath, { manifest }) => {
8
+ const findNpmPkgJsonLintConfigDependencies = async (configFilePath, { manifest, isProduction }) => {
9
+ if (isProduction)
10
+ return [];
8
11
  const config = configFilePath.endsWith('package.json')
9
- ? manifest.npmpackagejsonlint
12
+ ? manifest[PACKAGE_JSON_PATH]
10
13
  : await load(configFilePath);
11
14
  return config?.extends ? [config.extends] : [];
12
15
  };
@@ -6,7 +6,9 @@ export const NAME = 'Nx';
6
6
  export const ENABLERS = ['nx', /^@nrwl\//];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
8
  export const CONFIG_FILE_PATTERNS = ['project.json', '{apps,libs}/**/project.json'];
9
- const findNxDependencies = async (configFilePath, { cwd, manifest }) => {
9
+ const findNxDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
10
+ if (isProduction)
11
+ return [];
10
12
  const config = await load(configFilePath);
11
13
  if (!config)
12
14
  return [];
@@ -4,7 +4,9 @@ export const NAME = 'nyc';
4
4
  export const ENABLERS = ['nyc'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const CONFIG_FILE_PATTERNS = ['.nycrc', '.nycrc.json', '.nycrc.{yml,yaml}', 'nyc.config.js'];
7
- const findNycDependencies = async (configFilePath) => {
7
+ const findNycDependencies = async (configFilePath, { isProduction }) => {
8
+ if (isProduction)
9
+ return [];
8
10
  const config = await load(configFilePath);
9
11
  return config.extends ? [config.extends].flat() : [];
10
12
  };
@@ -1,5 +1,7 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Playwright";
3
3
  export declare const ENABLERS: string[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const ENTRY_FILE_PATTERNS: string[];
6
+ export declare const CONFIG_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,5 +1,25 @@
1
- import { hasDependency } from '../../util/plugin.js';
1
+ import { dirname, join, relative } from '../../util/path.js';
2
+ import { timerify } from '../../util/Performance.js';
3
+ import { hasDependency, load } from '../../util/plugin.js';
4
+ import { toEntryPattern } from '../../util/protocols.js';
2
5
  export const NAME = 'Playwright';
3
6
  export const ENABLERS = ['@playwright/test'];
4
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
- export const ENTRY_FILE_PATTERNS = ['playwright.config.{js,ts}'];
8
+ export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
9
+ export const CONFIG_FILE_PATTERNS = ['playwright.config.{js,ts}'];
10
+ const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
11
+ if (!testMatch)
12
+ return [];
13
+ const dir = relative(cwd, config.testDir ? join(dirname(configFilePath), config.testDir) : dirname(configFilePath));
14
+ const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
15
+ return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
16
+ };
17
+ const findPlaywrightDependencies = async (configFilePath, { cwd }) => {
18
+ const config = await load(configFilePath);
19
+ const projects = config.projects ? [config, ...config.projects] : [config];
20
+ const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
21
+ if (patterns.length > 0)
22
+ return patterns;
23
+ return toEntryPatterns(ENTRY_FILE_PATTERNS, cwd, configFilePath, config);
24
+ };
25
+ export const findDependencies = timerify(findPlaywrightDependencies);
@@ -1,5 +1,7 @@
1
- import type { IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Playwright for components";
3
3
  export declare const ENABLERS: RegExp[];
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
+ export declare const CONFIG_FILE_PATTERNS: string[];
5
6
  export declare const ENTRY_FILE_PATTERNS: string[];
7
+ export declare const findDependencies: GenericPluginCallback;
@@ -1,5 +1,16 @@
1
- import { hasDependency } from '../../util/plugin.js';
1
+ import { dirname, join } from '../../util/path.js';
2
+ import { timerify } from '../../util/Performance.js';
3
+ import { hasDependency, load } from '../../util/plugin.js';
4
+ import { toEntryPattern } from '../../util/protocols.js';
2
5
  export const NAME = 'Playwright for components';
3
6
  export const ENABLERS = [/^@playwright\/experimental-ct-/];
4
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
5
- export const ENTRY_FILE_PATTERNS = ['playwright-ct.config.{js,ts}', 'playwright/index.{js,ts,jsx,tsx}'];
8
+ export const CONFIG_FILE_PATTERNS = ['playwright-ct.config.{js,ts}', 'playwright/index.{js,ts,jsx,tsx}'];
9
+ export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
10
+ const findPlaywrightCTDependencies = async (configFilePath) => {
11
+ const cfg = await load(configFilePath);
12
+ const dir = cfg.testDir ? join(dirname(configFilePath), cfg.testDir) : dirname(configFilePath);
13
+ const entryPatterns = (cfg.testMatch ? [cfg.testMatch] : ENTRY_FILE_PATTERNS).map(p => toEntryPattern(join(dir, p)));
14
+ return entryPatterns;
15
+ };
16
+ export const findDependencies = timerify(findPlaywrightCTDependencies);
@@ -4,18 +4,20 @@ export const NAME = 'PostCSS';
4
4
  export const ENABLERS = ['postcss', 'next'];
5
5
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
6
6
  export const CONFIG_FILE_PATTERNS = ['postcss.config.js', 'postcss.config.json', 'package.json'];
7
- const findPostCSSDependencies = async (configFilePath, { manifest }) => {
7
+ const findPostCSSDependencies = async (configFilePath, { manifest, isProduction }) => {
8
+ if (isProduction)
9
+ return [];
8
10
  const config = configFilePath.endsWith('package.json')
9
11
  ? manifest?.postcss
10
12
  : await load(configFilePath);
11
- return config?.plugins
13
+ if (!config)
14
+ return [];
15
+ return config.plugins
12
16
  ? (Array.isArray(config.plugins) ? config.plugins : Object.keys(config.plugins)).flatMap(plugin => {
13
- if (typeof plugin === 'string') {
17
+ if (typeof plugin === 'string')
14
18
  return plugin;
15
- }
16
- if (Array.isArray(plugin) && typeof plugin[0] === 'string') {
19
+ if (Array.isArray(plugin) && typeof plugin[0] === 'string')
17
20
  return plugin[0];
18
- }
19
21
  return [];
20
22
  })
21
23
  : [];
@@ -9,7 +9,9 @@ export const CONFIG_FILE_PATTERNS = [
9
9
  'prettier.config.{js,cjs}',
10
10
  'package.json',
11
11
  ];
12
- const findPrettierDependencies = async (configFilePath, { manifest }) => {
12
+ const findPrettierDependencies = async (configFilePath, { manifest, isProduction }) => {
13
+ if (isProduction)
14
+ return [];
13
15
  const config = configFilePath.endsWith('package.json')
14
16
  ? manifest.prettier
15
17
  : await load(configFilePath);
@@ -1,6 +1,7 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "Release It";
3
3
  export declare const ENABLERS: string[];
4
+ export declare const PACKAGE_JSON_PATH = "release-it";
4
5
  export declare const isEnabled: IsPluginEnabledCallback;
5
6
  export declare const CONFIG_FILE_PATTERNS: string[];
6
7
  export declare const findDependencies: GenericPluginCallback;