knip 2.33.3 → 2.34.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 (97) hide show
  1. package/README.md +27 -7
  2. package/dist/ConfigurationChief.d.ts +1 -0
  3. package/dist/ConfigurationChief.js +13 -1
  4. package/dist/ConfigurationValidator.d.ts +56 -0
  5. package/dist/ConfigurationValidator.js +1 -0
  6. package/dist/WorkspaceWorker.d.ts +1 -1
  7. package/dist/WorkspaceWorker.js +12 -17
  8. package/dist/binaries/bash-parser.js +1 -1
  9. package/dist/cli.js +1 -1
  10. package/dist/index.js +17 -16
  11. package/dist/plugins/_template/index.js +14 -3
  12. package/dist/plugins/_template/types.d.ts +1 -0
  13. package/dist/plugins/angular/index.js +11 -11
  14. package/dist/plugins/astro/index.d.ts +7 -0
  15. package/dist/plugins/astro/index.js +10 -0
  16. package/dist/plugins/ava/index.js +13 -12
  17. package/dist/plugins/babel/index.js +8 -5
  18. package/dist/plugins/capacitor/index.js +4 -2
  19. package/dist/plugins/changesets/index.js +7 -5
  20. package/dist/plugins/commitizen/index.js +4 -3
  21. package/dist/plugins/commitizen/types.d.ts +1 -1
  22. package/dist/plugins/commitlint/index.js +4 -2
  23. package/dist/plugins/cspell/index.js +4 -2
  24. package/dist/plugins/cspell/types.d.ts +1 -1
  25. package/dist/plugins/cypress/index.js +7 -4
  26. package/dist/plugins/drizzle/index.js +4 -4
  27. package/dist/plugins/eslint/fallback.js +6 -1
  28. package/dist/plugins/eslint/helpers.d.ts +2 -2
  29. package/dist/plugins/eslint/helpers.js +7 -7
  30. package/dist/plugins/eslint/index.d.ts +0 -1
  31. package/dist/plugins/eslint/index.js +3 -4
  32. package/dist/plugins/gatsby/index.js +5 -8
  33. package/dist/plugins/github-actions/index.d.ts +1 -1
  34. package/dist/plugins/github-actions/index.js +5 -4
  35. package/dist/plugins/husky/index.js +4 -2
  36. package/dist/plugins/index.d.ts +1 -0
  37. package/dist/plugins/index.js +1 -0
  38. package/dist/plugins/jest/index.js +8 -8
  39. package/dist/plugins/jest/types.d.ts +3 -0
  40. package/dist/plugins/jest/types.js +1 -0
  41. package/dist/plugins/lefthook/index.js +5 -4
  42. package/dist/plugins/lint-staged/index.js +7 -7
  43. package/dist/plugins/markdownlint/index.js +5 -4
  44. package/dist/plugins/mocha/index.js +8 -7
  45. package/dist/plugins/mocha/types.d.ts +4 -0
  46. package/dist/plugins/mocha/types.js +1 -0
  47. package/dist/plugins/npm-package-json-lint/index.js +4 -3
  48. package/dist/plugins/nx/index.js +6 -5
  49. package/dist/plugins/nyc/index.js +4 -3
  50. package/dist/plugins/nyc/types.d.ts +3 -0
  51. package/dist/plugins/nyc/types.js +1 -0
  52. package/dist/plugins/playwright/index.d.ts +1 -1
  53. package/dist/plugins/playwright/index.js +7 -6
  54. package/dist/plugins/playwright-ct/index.js +11 -6
  55. package/dist/plugins/postcss/index.js +6 -5
  56. package/dist/plugins/prettier/index.js +3 -3
  57. package/dist/plugins/prettier/types.d.ts +8 -0
  58. package/dist/plugins/prettier/types.js +1 -0
  59. package/dist/plugins/release-it/index.js +10 -9
  60. package/dist/plugins/remark/index.js +6 -5
  61. package/dist/plugins/remix/index.js +1 -5
  62. package/dist/plugins/rollup/index.js +1 -1
  63. package/dist/plugins/semantic-release/index.js +5 -4
  64. package/dist/plugins/semantic-release/types.d.ts +1 -1
  65. package/dist/plugins/storybook/index.js +13 -11
  66. package/dist/plugins/stryker/index.js +9 -6
  67. package/dist/plugins/stylelint/index.js +6 -5
  68. package/dist/plugins/typedoc/index.js +4 -3
  69. package/dist/plugins/typedoc/types.d.ts +1 -1
  70. package/dist/plugins/typescript/index.js +13 -10
  71. package/dist/plugins/vite/index.js +4 -2
  72. package/dist/plugins/vitest/index.d.ts +1 -1
  73. package/dist/plugins/vitest/index.js +8 -8
  74. package/dist/plugins/webpack/index.js +25 -15
  75. package/dist/plugins/webpack/types.d.ts +2 -1
  76. package/dist/types/config.d.ts +1 -1
  77. package/dist/types/plugins.d.ts +1 -1
  78. package/dist/typescript/SourceFileManager.js +3 -3
  79. package/dist/typescript/ast-helpers.d.ts +2 -1
  80. package/dist/typescript/ast-helpers.js +3 -0
  81. package/dist/typescript/visitors/exports/exportKeyword.js +5 -2
  82. package/dist/util/cli-arguments.d.ts +2 -1
  83. package/dist/util/cli-arguments.js +2 -0
  84. package/dist/util/compilers.d.ts +10 -0
  85. package/dist/util/debug.d.ts +3 -3
  86. package/dist/util/debug.js +10 -8
  87. package/dist/util/glob.js +1 -1
  88. package/dist/util/modules.js +1 -1
  89. package/dist/util/path.js +4 -2
  90. package/dist/util/plugin.js +7 -1
  91. package/dist/util/require.js +1 -1
  92. package/dist/util/unwrapFunction.d.ts +1 -0
  93. package/dist/util/unwrapFunction.js +13 -0
  94. package/dist/version.d.ts +1 -1
  95. package/dist/version.js +1 -1
  96. package/package.json +1 -1
  97. package/schema.json +4 -0
@@ -23,10 +23,13 @@ export const getDependenciesFromConfig = (config) => {
23
23
  const findBabelDependencies = async (configFilePath, { manifest, isProduction }) => {
24
24
  if (isProduction)
25
25
  return [];
26
- let config = configFilePath.endsWith('package.json') ? manifest.babel : await load(configFilePath);
27
- if (typeof config === 'function') {
28
- config = config(api);
29
- }
30
- return config ? getDependenciesFromConfig(config) : [];
26
+ let localConfig = configFilePath.endsWith('package.json')
27
+ ? manifest.babel
28
+ : await load(configFilePath);
29
+ if (typeof localConfig === 'function')
30
+ localConfig = localConfig(api);
31
+ if (!localConfig)
32
+ return [];
33
+ return getDependenciesFromConfig(localConfig);
31
34
  };
32
35
  export const findDependencies = timerify(findBabelDependencies);
@@ -7,7 +7,9 @@ export const CONFIG_FILE_PATTERNS = ['capacitor.config.ts'];
7
7
  const findCapacitorDependencies = async (configFilePath, { isProduction }) => {
8
8
  if (isProduction)
9
9
  return [];
10
- const config = await load(configFilePath);
11
- return config.includePlugins ?? [];
10
+ const localConfig = await load(configFilePath);
11
+ if (!localConfig)
12
+ return [];
13
+ return localConfig.includePlugins ?? [];
12
14
  };
13
15
  export const findDependencies = timerify(findCapacitorDependencies);
@@ -7,11 +7,13 @@ export const CONFIG_FILE_PATTERNS = ['.changeset/config.json'];
7
7
  const findChangesetsDependencies = async (configFilePath, { isProduction }) => {
8
8
  if (isProduction)
9
9
  return [];
10
- const config = await load(configFilePath);
11
- return Array.isArray(config.changelog)
12
- ? [config.changelog[0]]
13
- : typeof config.changelog === 'string'
14
- ? [config.changelog]
10
+ const localConfig = await load(configFilePath);
11
+ if (!localConfig)
12
+ return [];
13
+ return Array.isArray(localConfig.changelog)
14
+ ? [localConfig.changelog[0]]
15
+ : typeof localConfig.changelog === 'string'
16
+ ? [localConfig.changelog]
15
17
  : [];
16
18
  };
17
19
  export const findDependencies = timerify(findChangesetsDependencies);
@@ -8,10 +8,11 @@ export const CONFIG_FILE_PATTERNS = ['.czrc', '.cz.json', 'package.json'];
8
8
  const findPluginDependencies = async (configFilePath, { manifest, isProduction }) => {
9
9
  if (isProduction)
10
10
  return [];
11
- const config = configFilePath.endsWith('package.json')
11
+ const localConfig = configFilePath.endsWith('package.json')
12
12
  ? manifest.config?.commitizen
13
13
  : await load(configFilePath);
14
- const path = config?.path;
15
- return path === undefined ? [] : [path];
14
+ if (!localConfig)
15
+ return [];
16
+ return localConfig.path ? [localConfig.path] : [];
16
17
  };
17
18
  export const findDependencies = timerify(findPluginDependencies);
@@ -1,3 +1,3 @@
1
- export type PluginConfig = {
1
+ export type CommitizenConfig = {
2
2
  path?: string;
3
3
  };
@@ -12,9 +12,11 @@ export const CONFIG_FILE_PATTERNS = [
12
12
  const findCommitLintDependencies = async (configFilePath, { manifest, isProduction }) => {
13
13
  if (isProduction)
14
14
  return [];
15
- const config = configFilePath.endsWith('package.json')
15
+ const localConfig = configFilePath.endsWith('package.json')
16
16
  ? manifest.commitlint
17
17
  : await load(configFilePath);
18
- return config?.extends ? [config.extends].flat() : [];
18
+ if (!localConfig)
19
+ return [];
20
+ return localConfig.extends ? [localConfig.extends].flat() : [];
19
21
  };
20
22
  export const findDependencies = timerify(findCommitLintDependencies);
@@ -12,8 +12,10 @@ export const CONFIG_FILE_PATTERNS = [
12
12
  const findCspellDependencies = async (configFilePath, { isProduction }) => {
13
13
  if (isProduction)
14
14
  return [];
15
- const config = await load(configFilePath);
16
- const imports = config?.import ?? [];
15
+ const localConfig = await load(configFilePath);
16
+ if (!localConfig)
17
+ return [];
18
+ const imports = localConfig.import ?? [];
17
19
  return imports;
18
20
  };
19
21
  export const findDependencies = timerify(findCspellDependencies);
@@ -1,3 +1,3 @@
1
- export type PluginConfig = {
1
+ export type CSpellConfig = {
2
2
  import?: string[];
3
3
  };
@@ -10,11 +10,14 @@ const SUPPORT_FILE_PATTERNS = [
10
10
  'cypress/plugins/index.js',
11
11
  ];
12
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)
13
+ export const findDependencies = async (configFilePath, options) => {
14
+ const { config } = options;
15
+ const localConfig = await load(configFilePath);
16
+ if (!localConfig)
16
17
  return [];
17
- const patterns = [config.e2e?.specPattern ?? [], config.component?.specPattern ?? []].flat();
18
+ if (config.entry)
19
+ return config.entry.map(toEntryPattern);
20
+ const patterns = [localConfig.e2e?.specPattern ?? [], localConfig.component?.specPattern ?? []].flat();
18
21
  const entryPatterns = (patterns.length > 0 ? patterns : TEST_FILE_PATTERNS).map(toEntryPattern);
19
22
  return [...entryPatterns, ...SUPPORT_FILE_PATTERNS.map(toEntryPattern)];
20
23
  };
@@ -1,14 +1,14 @@
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
+ import { toProductionEntryPattern } 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
8
  const findDrizzleDependencies = async (configFilePath) => {
9
- const config = await load(configFilePath);
10
- if (!config || !config.schema)
9
+ const localConfig = await load(configFilePath);
10
+ if (!localConfig?.schema)
11
11
  return [];
12
- return [config.schema].flat().map(toEntryPattern);
12
+ return [localConfig.schema].flat().map(toProductionEntryPattern);
13
13
  };
14
14
  export const findDependencies = timerify(findDrizzleDependencies);
@@ -1,5 +1,6 @@
1
1
  import createJITI from 'jiti';
2
2
  import transform from 'jiti/dist/babel.js';
3
+ import { FAKE_PATH } from '../../util/loader.js';
3
4
  import { timerify } from '../../util/Performance.js';
4
5
  const rushstackMatch = /require\(("|')@rushstack\/(eslint-config\/patch|eslint-patch)\/modern-module-resolution("|')\)/;
5
6
  const jiti = createJITI(process.cwd(), {
@@ -9,5 +10,9 @@ const jiti = createJITI(process.cwd(), {
9
10
  return transform(opts);
10
11
  },
11
12
  });
12
- const load = (configFilePath) => jiti(configFilePath);
13
+ const load = (configFilePath) => {
14
+ if (configFilePath === FAKE_PATH)
15
+ return;
16
+ return jiti(configFilePath);
17
+ };
13
18
  export const fallback = timerify(load);
@@ -4,10 +4,10 @@ import type { PackageJson } from '@npmcli/package-json';
4
4
  type Manifest = PackageJson & {
5
5
  eslintConfig?: ESLintConfig;
6
6
  };
7
- type GetDependenciesDeep = (configFilePath: string, dependencies: Set<string>, options: {
7
+ type GetDependenciesDeep = (configFilePath: string, options: {
8
8
  cwd: string;
9
9
  manifest: Manifest;
10
- }) => Promise<Set<string>>;
10
+ }, dependencies?: Set<string>) => Promise<Set<string>>;
11
11
  export declare const getDependenciesDeep: GetDependenciesDeep;
12
12
  export declare const resolvePluginSpecifier: (specifier: string) => string;
13
13
  export declare const resolveExtendSpecifier: (specifier: string) => string | undefined;
@@ -24,25 +24,25 @@ const getDependencies = (config) => {
24
24
  ...overrides,
25
25
  ]);
26
26
  };
27
- export const getDependenciesDeep = async (configFilePath, dependencies = new Set(), options) => {
27
+ export const getDependenciesDeep = async (configFilePath, options, dependencies = new Set()) => {
28
28
  const addAll = (deps) => deps.forEach(dependency => dependencies.add(dependency));
29
- const config = configFilePath.endsWith('package.json')
29
+ const localConfig = configFilePath.endsWith('package.json')
30
30
  ? options.manifest[PACKAGE_JSON_PATH]
31
31
  : /(\.(jsonc?|ya?ml)|rc)$/.test(configFilePath)
32
32
  ? await load(configFilePath)
33
33
  : await fallback(configFilePath);
34
- if (config) {
35
- if (config.extends) {
36
- for (const extend of [config.extends].flat()) {
34
+ if (localConfig) {
35
+ if (localConfig.extends) {
36
+ for (const extend of [localConfig.extends].flat()) {
37
37
  if (isInternal(extend)) {
38
38
  const filePath = toAbsolute(extend, dirname(configFilePath));
39
39
  const extendConfigFilePath = _resolve(filePath);
40
40
  dependencies.add(extendConfigFilePath);
41
- addAll(await getDependenciesDeep(extendConfigFilePath, dependencies, options));
41
+ addAll(await getDependenciesDeep(extendConfigFilePath, options, dependencies));
42
42
  }
43
43
  }
44
44
  }
45
- addAll(getDependencies(config));
45
+ addAll(getDependencies(localConfig));
46
46
  }
47
47
  return dependencies;
48
48
  };
@@ -4,5 +4,4 @@ export declare const ENABLERS: string[];
4
4
  export declare const PACKAGE_JSON_PATH = "eslintConfig";
5
5
  export declare const isEnabled: IsPluginEnabledCallback;
6
6
  export declare const CONFIG_FILE_PATTERNS: string[];
7
- export declare const ENTRY_FILE_PATTERNS: never[];
8
7
  export declare const findDependencies: GenericPluginCallback;
@@ -14,13 +14,12 @@ export const CONFIG_FILE_PATTERNS = [
14
14
  '.eslintrc.{yml,yaml}',
15
15
  'package.json',
16
16
  ];
17
- export const ENTRY_FILE_PATTERNS = [];
18
17
  const findESLintDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
19
- if (configFilePath.endsWith('eslint.config.js'))
20
- return [];
21
18
  if (isProduction)
22
19
  return [];
23
- const dependencies = await getDependenciesDeep(configFilePath, new Set(), { cwd, manifest });
20
+ if (configFilePath.endsWith('eslint.config.js'))
21
+ return [];
22
+ const dependencies = await getDependenciesDeep(configFilePath, { cwd, manifest });
24
23
  return Array.from(dependencies);
25
24
  };
26
25
  export const findDependencies = timerify(findESLintDependencies);
@@ -4,10 +4,7 @@ import { toProductionEntryPattern } from '../../util/protocols.js';
4
4
  export const NAME = 'Gatsby';
5
5
  export const ENABLERS = ['gatsby', 'gatsby-cli'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- export const CONFIG_FILE_PATTERNS = [
8
- 'gatsby-{config,node}.{js,jsx,ts,tsx}',
9
- 'plugins/**/gatsby-node.{js,jsx,ts,tsx}',
10
- ];
7
+ export const CONFIG_FILE_PATTERNS = ['gatsby-{config,node}.{js,jsx,ts,tsx}', 'plugins/**/gatsby-node.{js,jsx,ts,tsx}'];
11
8
  export const PRODUCTION_ENTRY_FILE_PATTERNS = [
12
9
  'gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
13
10
  'src/api/**/*.{js,ts}',
@@ -17,17 +14,17 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
17
14
  'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
18
15
  ];
19
16
  const findGatsbyDependencies = async (configFilePath, { isProduction }) => {
20
- const config = await load(configFilePath);
17
+ const localConfig = await load(configFilePath);
21
18
  const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
22
- if (isProduction)
19
+ if (isProduction || !localConfig)
23
20
  return entryPatterns;
24
21
  if (/gatsby-config/.test(configFilePath)) {
25
- return config.plugins.map(plugin => (typeof plugin === 'string' ? plugin : plugin.resolve));
22
+ return localConfig.plugins.map(plugin => (typeof plugin === 'string' ? plugin : plugin.resolve));
26
23
  }
27
24
  if (/gatsby-node/.test(configFilePath)) {
28
25
  const plugins = new Set();
29
26
  const actions = { setBabelPlugin: plugin => plugins.add(plugin.name) };
30
- const _config = config;
27
+ const _config = localConfig;
31
28
  if (typeof _config.onCreateBabelConfig === 'function') {
32
29
  _config.onCreateBabelConfig({ actions });
33
30
  }
@@ -1,6 +1,6 @@
1
1
  import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
2
2
  export declare const NAME = "GitHub Actions";
3
- export declare const ENABLERS = "This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.";
3
+ export declare const ENABLERS = "This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.";
4
4
  export declare const isEnabled: IsPluginEnabledCallback;
5
5
  export declare const CONFIG_FILE_PATTERNS: string[];
6
6
  export declare const findDependencies: GenericPluginCallback;
@@ -4,10 +4,11 @@ import { getValuesByKeyDeep } from '../../util/object.js';
4
4
  import { timerify } from '../../util/Performance.js';
5
5
  import { load } from '../../util/plugin.js';
6
6
  export const NAME = 'GitHub Actions';
7
- export const ENABLERS = 'This plugin is enabled when a `.yml` file is found in the `.github/workflows` folder.';
8
- export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.yml'] }));
9
- export const CONFIG_FILE_PATTERNS = ['.github/workflows/*.yml', '.github/**/action.{yml,yaml}'];
10
- const findGithubActionsDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
7
+ export const ENABLERS = 'This plugin is enabled when a `.yml` or `.yaml` file is found in the `.github/workflows` folder.';
8
+ export const isEnabled = async ({ cwd }) => Boolean(await _firstGlob({ cwd, patterns: ['.github/workflows/*.{yml,yaml}'] }));
9
+ export const CONFIG_FILE_PATTERNS = ['.github/workflows/*.{yml,yaml}', '.github/**/action.{yml,yaml}'];
10
+ const findGithubActionsDependencies = async (configFilePath, options) => {
11
+ const { cwd, manifest, isProduction } = options;
11
12
  if (isProduction)
12
13
  return [];
13
14
  const config = await load(configFilePath);
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from 'fs';
2
2
  import { _getDependenciesFromScripts } from '../../binaries/index.js';
3
3
  import { getGitHookPaths } from '../../util/git.js';
4
+ import { FAKE_PATH } from '../../util/loader.js';
4
5
  import { timerify } from '../../util/Performance.js';
5
6
  import { hasDependency } from '../../util/plugin.js';
6
7
  export const NAME = 'husky';
@@ -8,8 +9,9 @@ export const ENABLERS = ['husky'];
8
9
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
10
  const gitHookPaths = getGitHookPaths('.husky');
10
11
  export const CONFIG_FILE_PATTERNS = [...gitHookPaths];
11
- const findHuskyDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
12
- if (isProduction)
12
+ const findHuskyDependencies = async (configFilePath, options) => {
13
+ const { cwd, manifest, isProduction } = options;
14
+ if (isProduction || configFilePath === FAKE_PATH)
13
15
  return [];
14
16
  const script = readFileSync(configFilePath);
15
17
  return _getDependenciesFromScripts(String(script), {
@@ -1,4 +1,5 @@
1
1
  export * as angular from './angular/index.js';
2
+ export * as astro from './astro/index.js';
2
3
  export * as ava from './ava/index.js';
3
4
  export * as babel from './babel/index.js';
4
5
  export * as capacitor from './capacitor/index.js';
@@ -1,4 +1,5 @@
1
1
  export * as angular from './angular/index.js';
2
+ export * as astro from './astro/index.js';
2
3
  export * as ava from './ava/index.js';
3
4
  export * as babel from './babel/index.js';
4
5
  export * as capacitor from './capacitor/index.js';
@@ -21,7 +21,7 @@ const resolveExtensibleConfig = async (configFilePath) => {
21
21
  };
22
22
  const resolveDependencies = (config, options) => {
23
23
  const { isProduction } = options;
24
- const entryPatterns = (config.testMatch ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
24
+ const entryPatterns = (options.config?.entry ?? config.testMatch ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
25
25
  if (isProduction)
26
26
  return entryPatterns;
27
27
  const presets = (config.preset ? [config.preset] : []).map(preset => isInternal(preset) ? preset : join(preset, 'jest-preset'));
@@ -64,16 +64,16 @@ const resolveDependencies = (config, options) => {
64
64
  };
65
65
  const findJestDependencies = async (configFilePath, options) => {
66
66
  const { manifest, cwd } = options;
67
- let config = configFilePath.endsWith('package.json')
67
+ let localConfig = configFilePath.endsWith('package.json')
68
68
  ? manifest.jest
69
69
  : await resolveExtensibleConfig(configFilePath);
70
- if (typeof config === 'function')
71
- config = await config();
72
- if (!config)
73
- return [];
74
- const rootDir = config.rootDir ? join(dirname(configFilePath), config.rootDir) : dirname(configFilePath);
70
+ if (typeof localConfig === 'function')
71
+ localConfig = await localConfig();
72
+ if (!localConfig)
73
+ localConfig = {};
74
+ const rootDir = localConfig.rootDir ? join(dirname(configFilePath), localConfig.rootDir) : dirname(configFilePath);
75
75
  const replaceRootDir = (name) => (name.includes('<rootDir>') ? name.replace(/<rootDir>/, rootDir) : name);
76
- const dependencies = resolveDependencies(config, options);
76
+ const dependencies = resolveDependencies(localConfig, options);
77
77
  const matchCwd = new RegExp('^' + toEntryPattern(cwd) + '/');
78
78
  return dependencies.map(replaceRootDir).map(dependency => dependency.replace(matchCwd, toEntryPattern('')));
79
79
  };
@@ -0,0 +1,3 @@
1
+ import type { Config } from '@jest/types';
2
+ export type JestInitialOptions = Config.InitialOptions;
3
+ export type JestConfig = JestInitialOptions | (() => JestInitialOptions) | (() => Promise<JestInitialOptions>);
@@ -0,0 +1 @@
1
+ export {};
@@ -10,15 +10,16 @@ export const ENABLERS = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthoo
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, isProduction }) => {
13
+ const findLefthookDependencies = async (configFilePath, options) => {
14
+ const { cwd, manifest, isProduction } = options;
14
15
  if (isProduction)
15
16
  return [];
16
17
  const dependencies = manifest.devDependencies ? Object.keys(manifest.devDependencies) : [];
17
18
  if (configFilePath.endsWith('.yml')) {
18
- const config = await load(configFilePath);
19
- if (!config)
19
+ const localConfig = await load(configFilePath);
20
+ if (!localConfig)
20
21
  return [];
21
- const scripts = getValuesByKeyDeep(config, 'run').filter((value) => typeof value === 'string');
22
+ const scripts = getValuesByKeyDeep(localConfig, 'run').filter((run) => typeof run === 'string');
22
23
  const lefthook = process.env.CI ? ENABLERS.filter(dependency => dependencies.includes(dependency)) : [];
23
24
  return [...lefthook, ..._getDependenciesFromScripts(scripts, { cwd, manifest, knownGlobalsOnly: true })];
24
25
  }
@@ -13,19 +13,19 @@ export const CONFIG_FILE_PATTERNS = [
13
13
  'lint-staged.config.{js,mjs,cjs}',
14
14
  'package.json',
15
15
  ];
16
- const findLintStagedDependencies = async (configFilePath, { cwd, manifest, isProduction }) => {
16
+ const findLintStagedDependencies = async (configFilePath, options) => {
17
+ const { cwd, manifest, isProduction } = options;
17
18
  if (isProduction)
18
19
  return [];
19
- let config = configFilePath.endsWith('package.json')
20
+ let localConfig = configFilePath.endsWith('package.json')
20
21
  ? manifest['lint-staged']
21
22
  : await load(configFilePath);
22
- if (!config)
23
+ if (typeof localConfig === 'function')
24
+ localConfig = localConfig();
25
+ if (!localConfig)
23
26
  return [];
24
- if (typeof config === 'function') {
25
- config = config();
26
- }
27
27
  const dependencies = new Set();
28
- for (const entry of Object.values(config).flat()) {
28
+ for (const entry of Object.values(localConfig).flat()) {
29
29
  const scripts = [typeof entry === 'function' ? await entry([]) : entry].flat();
30
30
  const options = { cwd, manifest };
31
31
  _getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
@@ -5,12 +5,13 @@ 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, isProduction }) => {
8
+ const findMarkdownlintConfigDependencies = async (configFilePath, options) => {
9
+ const { manifest, isProduction } = options;
9
10
  if (isProduction)
10
11
  return [];
11
- const config = await load(configFilePath);
12
- const extend = config?.extends ? [config.extends] : [];
13
- const scripts = manifest.scripts
12
+ const localConfig = await load(configFilePath);
13
+ const extend = localConfig?.extends ? [localConfig.extends] : [];
14
+ const scripts = manifest?.scripts
14
15
  ? Object.values(manifest.scripts).filter((script) => typeof script === 'string')
15
16
  : [];
16
17
  const uses = scripts
@@ -6,14 +6,15 @@ export const ENABLERS = ['mocha'];
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
8
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)
9
+ const findMochaDependencies = async (configFilePath, options) => {
10
+ const { config, manifest, isProduction } = options;
11
+ const localConfig = configFilePath.endsWith('package.json')
12
+ ? manifest.mocha
13
+ : await load(configFilePath);
14
+ const entryPatterns = (config.entry ?? (localConfig?.spec ? [localConfig.spec].flat() : ENTRY_FILE_PATTERNS)).map(toEntryPattern);
15
+ if (isProduction || !localConfig)
12
16
  return entryPatterns;
13
- const config = configFilePath.endsWith('package.json') ? manifest.mocha : await load(configFilePath);
14
- if (!config)
15
- return [];
16
- const require = config.require ? [config.require].flat() : [];
17
+ const require = localConfig.require ? [localConfig.require].flat() : [];
17
18
  return [...require, ...entryPatterns];
18
19
  };
19
20
  export const findDependencies = timerify(findMochaDependencies);
@@ -0,0 +1,4 @@
1
+ export interface MochaConfig {
2
+ require?: string | string[];
3
+ spec?: string | string[];
4
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -5,12 +5,13 @@ export const ENABLERS = ['npm-package-json-lint'];
5
5
  export const PACKAGE_JSON_PATH = 'npmpackagejsonlint';
6
6
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
7
  export const CONFIG_FILE_PATTERNS = ['.npmpackagejsonlintrc.json', 'npmpackagejsonlint.config.js', 'package.json'];
8
- const findNpmPkgJsonLintConfigDependencies = async (configFilePath, { manifest, isProduction }) => {
8
+ const findNpmPkgJsonLintConfigDependencies = async (configFilePath, options) => {
9
+ const { manifest, isProduction } = options;
9
10
  if (isProduction)
10
11
  return [];
11
- const config = configFilePath.endsWith('package.json')
12
+ const localConfig = configFilePath.endsWith('package.json')
12
13
  ? manifest[PACKAGE_JSON_PATH]
13
14
  : await load(configFilePath);
14
- return config?.extends ? [config.extends] : [];
15
+ return localConfig?.extends ? [localConfig.extends] : [];
15
16
  };
16
17
  export const findDependencies = timerify(findNpmPkgJsonLintConfigDependencies);
@@ -3,16 +3,17 @@ import { compact } from '../../util/array.js';
3
3
  import { timerify } from '../../util/Performance.js';
4
4
  import { hasDependency, load } from '../../util/plugin.js';
5
5
  export const NAME = 'Nx';
6
- export const ENABLERS = ['nx', /^@nrwl\//];
6
+ export const ENABLERS = ['nx', /^@nrwl\//, /^@nx\//];
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, isProduction }) => {
9
+ const findNxDependencies = async (configFilePath, options) => {
10
+ const { cwd, manifest, isProduction } = options;
10
11
  if (isProduction)
11
12
  return [];
12
- const config = await load(configFilePath);
13
- if (!config)
13
+ const localConfig = await load(configFilePath);
14
+ if (!localConfig)
14
15
  return [];
15
- const targets = config.targets ? Object.values(config.targets) : [];
16
+ const targets = localConfig.targets ? Object.values(localConfig.targets) : [];
16
17
  const executors = compact(targets
17
18
  .map(target => target?.executor)
18
19
  .filter(executor => executor && !executor.startsWith('.'))
@@ -4,10 +4,11 @@ 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, { isProduction }) => {
7
+ const findNycDependencies = async (configFilePath, options) => {
8
+ const { isProduction } = options;
8
9
  if (isProduction)
9
10
  return [];
10
- const config = await load(configFilePath);
11
- return config.extends ? [config.extends].flat() : [];
11
+ const localConfig = await load(configFilePath);
12
+ return localConfig?.extends ? [localConfig.extends].flat() : [];
12
13
  };
13
14
  export const findDependencies = timerify(findNycDependencies);
@@ -0,0 +1,3 @@
1
+ export type NycConfig = {
2
+ extends?: string;
3
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,7 +3,7 @@ import type { PlaywrightTestConfig } from 'playwright/test';
3
3
  export declare const NAME = "Playwright";
4
4
  export declare const ENABLERS: string[];
5
5
  export declare const isEnabled: IsPluginEnabledCallback;
6
- export declare const ENTRY_FILE_PATTERNS: string[];
7
6
  export declare const CONFIG_FILE_PATTERNS: string[];
7
+ export declare const ENTRY_FILE_PATTERNS: string[];
8
8
  export declare const toEntryPatterns: (testMatch: string | RegExp | Array<string | RegExp> | undefined, cwd: string, configFilePath: string, config: PlaywrightTestConfig) => string[];
9
9
  export declare const findDependencies: GenericPluginCallback;
@@ -5,8 +5,8 @@ import { toEntryPattern } from '../../util/protocols.js';
5
5
  export const NAME = 'Playwright';
6
6
  export const ENABLERS = ['@playwright/test'];
7
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
- export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
9
8
  export const CONFIG_FILE_PATTERNS = ['playwright.config.{js,ts}'];
9
+ export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
10
10
  export const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
11
11
  if (!testMatch)
12
12
  return [];
@@ -14,14 +14,15 @@ export const toEntryPatterns = (testMatch, cwd, configFilePath, config) => {
14
14
  const patterns = [testMatch].flat().filter((p) => typeof p === 'string');
15
15
  return patterns.map(pattern => toEntryPattern(join(dir, pattern)));
16
16
  };
17
- const findPlaywrightDependencies = async (configFilePath, { cwd, config }) => {
18
- const cfg = await load(configFilePath);
19
- if (cfg) {
20
- const projects = cfg.projects ? [cfg, ...cfg.projects] : [cfg];
17
+ const findPlaywrightDependencies = async (configFilePath, options) => {
18
+ const { cwd, config } = options;
19
+ const localConfig = await load(configFilePath);
20
+ if (localConfig) {
21
+ const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
21
22
  const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
22
23
  if (patterns.length > 0)
23
24
  return patterns;
24
25
  }
25
- return toEntryPatterns(config?.entry ?? ENTRY_FILE_PATTERNS, cwd, configFilePath, cfg ?? {});
26
+ return (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
26
27
  };
27
28
  export const findDependencies = timerify(findPlaywrightDependencies);
@@ -1,16 +1,21 @@
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
  import { toEntryPatterns } from '../playwright/index.js';
4
5
  export const NAME = 'Playwright for components';
5
6
  export const ENABLERS = [/^@playwright\/experimental-ct-/];
6
7
  export const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
8
  export const CONFIG_FILE_PATTERNS = ['playwright-ct.config.{js,ts}', 'playwright/index.{js,ts,jsx,tsx}'];
8
9
  export const ENTRY_FILE_PATTERNS = ['**/*.@(spec|test).?(c|m)[jt]s?(x)'];
9
- const findPlaywrightCTDependencies = async (configFilePath, { cwd }) => {
10
- const config = await load(configFilePath);
11
- const entryPatterns = toEntryPatterns(config.testMatch, cwd, configFilePath, config);
12
- if (entryPatterns.length > 0)
13
- return entryPatterns;
14
- return toEntryPatterns(ENTRY_FILE_PATTERNS, cwd, configFilePath, config);
10
+ const findPlaywrightCTDependencies = async (configFilePath, options) => {
11
+ const { cwd, config } = options;
12
+ const localConfig = await load(configFilePath);
13
+ if (localConfig) {
14
+ const projects = localConfig.projects ? [localConfig, ...localConfig.projects] : [localConfig];
15
+ const patterns = projects.flatMap(config => toEntryPatterns(config.testMatch, cwd, configFilePath, config));
16
+ if (patterns.length > 0)
17
+ return patterns;
18
+ }
19
+ return (config?.entry ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
15
20
  };
16
21
  export const findDependencies = timerify(findPlaywrightCTDependencies);