knip 5.1.2 → 5.1.3

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 (179) hide show
  1. package/dist/ConfigurationChief.d.ts +3 -3
  2. package/dist/ConfigurationValidator.d.ts +21 -21
  3. package/dist/ProjectPrincipal.d.ts +1 -1
  4. package/dist/ProjectPrincipal.js +3 -5
  5. package/dist/WorkspaceWorker.d.ts +2 -2
  6. package/dist/WorkspaceWorker.js +61 -44
  7. package/dist/binaries/index.js +2 -2
  8. package/dist/binaries/resolvers/index.d.ts +12 -12
  9. package/dist/compilers/index.d.ts +6 -7
  10. package/dist/compilers/index.js +0 -3
  11. package/dist/constants.d.ts +1 -2
  12. package/dist/constants.js +8 -4
  13. package/dist/plugins/_template/index.d.ts +10 -9
  14. package/dist/plugins/_template/index.js +16 -30
  15. package/dist/plugins/angular/index.d.ts +8 -6
  16. package/dist/plugins/angular/index.js +17 -22
  17. package/dist/plugins/astro/index.d.ts +7 -7
  18. package/dist/plugins/astro/index.js +14 -17
  19. package/dist/plugins/ava/index.d.ts +9 -7
  20. package/dist/plugins/ava/index.js +19 -21
  21. package/dist/plugins/babel/helpers.js +1 -1
  22. package/dist/plugins/babel/index.d.ts +7 -7
  23. package/dist/plugins/babel/index.js +15 -26
  24. package/dist/plugins/capacitor/index.d.ts +7 -6
  25. package/dist/plugins/capacitor/index.js +11 -18
  26. package/dist/plugins/changesets/index.d.ts +7 -6
  27. package/dist/plugins/changesets/index.js +14 -21
  28. package/dist/plugins/changesets/types.d.ts +3 -0
  29. package/dist/plugins/changesets/types.js +1 -0
  30. package/dist/plugins/commitizen/index.d.ts +8 -7
  31. package/dist/plugins/commitizen/index.js +13 -21
  32. package/dist/plugins/commitlint/index.d.ts +9 -6
  33. package/dist/plugins/commitlint/index.js +11 -19
  34. package/dist/plugins/cspell/index.d.ts +7 -6
  35. package/dist/plugins/cspell/index.js +12 -20
  36. package/dist/plugins/cypress/index.d.ts +7 -7
  37. package/dist/plugins/cypress/index.js +13 -21
  38. package/dist/plugins/drizzle/index.d.ts +7 -6
  39. package/dist/plugins/drizzle/index.js +13 -16
  40. package/dist/plugins/eleventy/index.d.ts +11 -9
  41. package/dist/plugins/eleventy/index.js +35 -41
  42. package/dist/plugins/eslint/helpers.d.ts +3 -5
  43. package/dist/plugins/eslint/helpers.js +10 -15
  44. package/dist/plugins/eslint/index.d.ts +10 -8
  45. package/dist/plugins/eslint/index.js +15 -29
  46. package/dist/plugins/gatsby/index.d.ts +8 -7
  47. package/dist/plugins/gatsby/index.js +15 -22
  48. package/dist/plugins/github-actions/index.d.ts +6 -6
  49. package/dist/plugins/github-actions/index.js +15 -25
  50. package/dist/plugins/graphql-codegen/index.d.ts +8 -7
  51. package/dist/plugins/graphql-codegen/index.js +15 -23
  52. package/dist/plugins/husky/index.d.ts +6 -6
  53. package/dist/plugins/husky/index.js +10 -16
  54. package/dist/plugins/jest/index.d.ts +9 -7
  55. package/dist/plugins/jest/index.js +50 -31
  56. package/dist/plugins/lefthook/index.d.ts +6 -6
  57. package/dist/plugins/lefthook/index.js +19 -24
  58. package/dist/plugins/lint-staged/index.d.ts +8 -7
  59. package/dist/plugins/lint-staged/index.js +16 -23
  60. package/dist/plugins/linthtml/index.d.ts +8 -7
  61. package/dist/plugins/linthtml/index.js +16 -24
  62. package/dist/plugins/markdownlint/index.d.ts +7 -6
  63. package/dist/plugins/markdownlint/index.js +12 -17
  64. package/dist/plugins/mocha/index.d.ts +9 -7
  65. package/dist/plugins/mocha/index.js +19 -22
  66. package/dist/plugins/msw/index.d.ts +8 -7
  67. package/dist/plugins/msw/index.js +12 -15
  68. package/dist/plugins/netlify/index.d.ts +9 -7
  69. package/dist/plugins/netlify/index.js +23 -27
  70. package/dist/plugins/next/index.d.ts +6 -7
  71. package/dist/plugins/next/index.js +10 -18
  72. package/dist/plugins/node-test-runner/index.d.ts +5 -6
  73. package/dist/plugins/node-test-runner/index.js +6 -18
  74. package/dist/plugins/npm-package-json-lint/index.d.ts +8 -7
  75. package/dist/plugins/npm-package-json-lint/index.js +12 -19
  76. package/dist/plugins/nx/index.d.ts +7 -6
  77. package/dist/plugins/nx/index.js +18 -27
  78. package/dist/plugins/nyc/index.d.ts +7 -6
  79. package/dist/plugins/nyc/index.js +11 -17
  80. package/dist/plugins/playwright/index.d.ts +11 -13
  81. package/dist/plugins/playwright/index.js +23 -30
  82. package/dist/plugins/playwright-ct/index.d.ts +8 -7
  83. package/dist/plugins/playwright-ct/index.js +12 -24
  84. package/dist/plugins/postcss/index.d.ts +7 -6
  85. package/dist/plugins/postcss/index.js +12 -21
  86. package/dist/plugins/prettier/index.d.ts +7 -6
  87. package/dist/plugins/prettier/index.js +14 -20
  88. package/dist/plugins/release-it/index.d.ts +8 -7
  89. package/dist/plugins/release-it/index.js +18 -27
  90. package/dist/plugins/remark/index.d.ts +8 -7
  91. package/dist/plugins/remark/index.js +13 -28
  92. package/dist/plugins/remix/index.d.ts +6 -7
  93. package/dist/plugins/remix/index.js +10 -20
  94. package/dist/plugins/rollup/index.d.ts +5 -6
  95. package/dist/plugins/rollup/index.js +8 -16
  96. package/dist/plugins/semantic-release/index.d.ts +8 -7
  97. package/dist/plugins/semantic-release/index.js +13 -25
  98. package/dist/plugins/sentry/index.d.ts +5 -6
  99. package/dist/plugins/sentry/index.js +8 -16
  100. package/dist/plugins/storybook/index.d.ts +10 -8
  101. package/dist/plugins/storybook/index.js +28 -35
  102. package/dist/plugins/stryker/index.d.ts +7 -6
  103. package/dist/plugins/stryker/index.js +10 -18
  104. package/dist/plugins/stylelint/index.d.ts +7 -6
  105. package/dist/plugins/stylelint/index.js +13 -23
  106. package/dist/plugins/svelte/index.d.ts +7 -8
  107. package/dist/plugins/svelte/index.js +13 -23
  108. package/dist/plugins/tailwind/index.d.ts +5 -6
  109. package/dist/plugins/tailwind/index.js +8 -14
  110. package/dist/plugins/tsup/index.d.ts +7 -6
  111. package/dist/plugins/tsup/index.js +14 -21
  112. package/dist/plugins/typedoc/index.d.ts +10 -7
  113. package/dist/plugins/typedoc/index.js +14 -24
  114. package/dist/plugins/typescript/index.d.ts +8 -7
  115. package/dist/plugins/typescript/index.js +31 -25
  116. package/dist/plugins/unbuild/index.d.ts +7 -6
  117. package/dist/plugins/unbuild/index.js +12 -17
  118. package/dist/plugins/vercel-og/index.d.ts +5 -6
  119. package/dist/plugins/vercel-og/index.js +8 -16
  120. package/dist/plugins/vite/index.d.ts +9 -7
  121. package/dist/plugins/vite/index.js +13 -18
  122. package/dist/plugins/vitest/index.d.ts +11 -9
  123. package/dist/plugins/vitest/index.js +62 -49
  124. package/dist/plugins/vue/index.d.ts +7 -6
  125. package/dist/plugins/vue/index.js +14 -26
  126. package/dist/plugins/webpack/index.d.ts +7 -6
  127. package/dist/plugins/webpack/index.js +17 -20
  128. package/dist/plugins/wireit/index.d.ts +8 -7
  129. package/dist/plugins/wireit/index.js +12 -20
  130. package/dist/plugins/yorkie/index.d.ts +8 -7
  131. package/dist/plugins/yorkie/index.js +13 -21
  132. package/dist/plugins.d.ts +3 -0
  133. package/dist/plugins.js +14 -0
  134. package/dist/reporters/index.d.ts +5 -5
  135. package/dist/types/config.d.ts +1 -1
  136. package/dist/types/package-json.d.ts +12 -13
  137. package/dist/types/plugins.d.ts +20 -14
  138. package/dist/types/util.d.ts +0 -13
  139. package/dist/typescript/SourceFileManager.js +3 -0
  140. package/dist/typescript/createHosts.js +4 -3
  141. package/dist/typescript/resolveModuleNames.js +26 -41
  142. package/dist/typescript/visitors/dynamic-imports/importCall.d.ts +1 -1
  143. package/dist/typescript/visitors/dynamic-imports/importType.d.ts +1 -1
  144. package/dist/typescript/visitors/dynamic-imports/index.d.ts +1 -1
  145. package/dist/typescript/visitors/dynamic-imports/jsDocType.d.ts +1 -1
  146. package/dist/typescript/visitors/dynamic-imports/propertyAccessCall.d.ts +1 -1
  147. package/dist/typescript/visitors/dynamic-imports/requireCall.d.ts +1 -1
  148. package/dist/typescript/visitors/exports/exportAssignment.d.ts +1 -1
  149. package/dist/typescript/visitors/exports/exportDeclaration.d.ts +1 -1
  150. package/dist/typescript/visitors/exports/exportKeyword.d.ts +1 -1
  151. package/dist/typescript/visitors/exports/index.d.ts +1 -1
  152. package/dist/typescript/visitors/exports/moduleExportsAccessExpression.d.ts +1 -1
  153. package/dist/typescript/visitors/imports/importDeclaration.d.ts +1 -1
  154. package/dist/typescript/visitors/imports/importEqualsDeclaration.d.ts +1 -1
  155. package/dist/typescript/visitors/imports/index.d.ts +1 -1
  156. package/dist/typescript/visitors/imports/reExportDeclaration.d.ts +1 -1
  157. package/dist/typescript/visitors/scripts/bun.d.ts +1 -1
  158. package/dist/typescript/visitors/scripts/execa.d.ts +1 -1
  159. package/dist/typescript/visitors/scripts/index.d.ts +1 -1
  160. package/dist/typescript/visitors/scripts/zx.d.ts +1 -1
  161. package/dist/util/Performance.d.ts +1 -4
  162. package/dist/util/Performance.js +5 -1
  163. package/dist/util/fs.js +0 -3
  164. package/dist/util/loader.d.ts +0 -2
  165. package/dist/util/loader.js +8 -16
  166. package/dist/util/object.d.ts +1 -1
  167. package/dist/util/path.d.ts +0 -3
  168. package/dist/util/path.js +0 -1
  169. package/dist/util/plugin.d.ts +4 -1
  170. package/dist/util/plugin.js +28 -1
  171. package/dist/util/require.d.ts +1 -0
  172. package/dist/util/require.js +13 -0
  173. package/dist/util/tsconfig-loader.js +1 -2
  174. package/dist/util/type.d.ts +1 -1
  175. package/dist/version.d.ts +1 -1
  176. package/dist/version.js +1 -1
  177. package/package.json +5 -1
  178. package/dist/plugins/eslint/fallback.d.ts +0 -1
  179. package/dist/plugins/eslint/fallback.js +0 -18
@@ -1,10 +1,12 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { JestConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- ENTRY_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ title: string;
5
+ enablers: string[];
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ entry: string[];
9
+ resolveEntryPaths: ResolveEntryPaths<JestConfig>;
10
+ resolveConfig: ResolveConfig<JestConfig>;
9
11
  };
10
12
  export default _default;
@@ -1,12 +1,11 @@
1
- import { basename, join, isInternal, toAbsolute, dirname } 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';
5
- const NAME = 'Jest';
6
- const ENABLERS = ['jest'];
7
- const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, ENABLERS) || Boolean(manifest.name?.startsWith('jest-presets'));
8
- const CONFIG_FILE_PATTERNS = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
9
- const ENTRY_FILE_PATTERNS = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
1
+ import { join, isInternal, toAbsolute, dirname } from '#p/util/path.js';
2
+ import { hasDependency, load } from '#p/util/plugin.js';
3
+ import { toEntryPattern } from '#p/util/protocols.js';
4
+ const title = 'Jest';
5
+ const enablers = ['jest'];
6
+ const isEnabled = ({ dependencies, manifest }) => hasDependency(dependencies, enablers) || Boolean(manifest.name?.startsWith('jest-presets'));
7
+ const config = ['jest.config.{js,ts,mjs,cjs,json}', 'package.json'];
8
+ const entry = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'];
10
9
  const resolveExtensibleConfig = async (configFilePath) => {
11
10
  const config = await load(configFilePath);
12
11
  if (config?.preset) {
@@ -19,15 +18,27 @@ const resolveExtensibleConfig = async (configFilePath) => {
19
18
  }
20
19
  return config;
21
20
  };
22
- const resolveDependencies = (config, options) => {
23
- const { isProduction } = options;
24
- const entryPatterns = (options.config?.entry ?? config.testMatch ?? ENTRY_FILE_PATTERNS).map(toEntryPattern);
25
- if (isProduction)
26
- return entryPatterns;
21
+ const resolveDependencies = async (config, options) => {
22
+ const { configFileDir } = options;
23
+ if (config?.preset) {
24
+ const { preset } = config;
25
+ if (isInternal(preset)) {
26
+ const presetConfigPath = toAbsolute(preset, configFileDir);
27
+ const presetConfig = await resolveExtensibleConfig(presetConfigPath);
28
+ Object.assign(config, presetConfig);
29
+ }
30
+ }
27
31
  const presets = (config.preset ? [config.preset] : []).map(preset => isInternal(preset) ? preset : join(preset, 'jest-preset'));
28
- const projects = Array.isArray(config.projects)
29
- ? config.projects.map(config => (typeof config === 'string' ? config : resolveDependencies(config, options))).flat()
30
- : [];
32
+ const projects = [];
33
+ for (const project of config.projects ?? []) {
34
+ if (typeof project === 'string') {
35
+ projects.push(project);
36
+ }
37
+ else {
38
+ const dependencies = await resolveDependencies(project, options);
39
+ dependencies.forEach(dependency => projects.push(dependency));
40
+ }
41
+ }
31
42
  const runner = config.runner ? [config.runner] : [];
32
43
  const environments = config.testEnvironment === 'jsdom' ? ['jest-environment-jsdom'] : [];
33
44
  const resolvers = config.resolver ? [config.resolver] : [];
@@ -48,7 +59,6 @@ const resolveDependencies = (config, options) => {
48
59
  const testResultsProcessor = config.testResultsProcessor ? [config.testResultsProcessor] : [];
49
60
  const snapshotResolver = config.snapshotResolver ? [config.snapshotResolver] : [];
50
61
  return [
51
- ...entryPatterns,
52
62
  ...presets,
53
63
  ...projects,
54
64
  ...runner,
@@ -64,25 +74,34 @@ const resolveDependencies = (config, options) => {
64
74
  ...snapshotResolver,
65
75
  ];
66
76
  };
67
- const findJestDependencies = async (configFilePath, options) => {
68
- const { manifest, cwd } = options;
69
- let localConfig = basename(configFilePath) === 'package.json' ? manifest.jest : await resolveExtensibleConfig(configFilePath);
77
+ const resolveEntryPaths = async (localConfig, options) => {
78
+ const { cwd, configFileDir } = options;
79
+ if (typeof localConfig === 'function')
80
+ localConfig = await localConfig();
81
+ const rootDir = localConfig.rootDir ? join(configFileDir, localConfig.rootDir) : configFileDir;
82
+ const replaceRootDir = (name) => (name.includes('<rootDir>') ? name.replace(/<rootDir>/, rootDir) : name);
83
+ const matchCwd = new RegExp('^' + toEntryPattern(cwd) + '/');
84
+ return (localConfig.testMatch ?? [])
85
+ .map(replaceRootDir)
86
+ .map(dependency => dependency.replace(matchCwd, toEntryPattern('')))
87
+ .map(toEntryPattern);
88
+ };
89
+ const resolveConfig = async (localConfig, options) => {
90
+ const { cwd, configFileDir } = options;
70
91
  if (typeof localConfig === 'function')
71
92
  localConfig = await localConfig();
72
- if (!localConfig)
73
- localConfig = {};
74
- const rootDir = localConfig.rootDir ? join(dirname(configFilePath), localConfig.rootDir) : dirname(configFilePath);
93
+ const rootDir = localConfig.rootDir ? join(configFileDir, localConfig.rootDir) : configFileDir;
75
94
  const replaceRootDir = (name) => (name.includes('<rootDir>') ? name.replace(/<rootDir>/, rootDir) : name);
76
- const dependencies = resolveDependencies(localConfig, options);
95
+ const dependencies = await resolveDependencies(localConfig, options);
77
96
  const matchCwd = new RegExp('^' + toEntryPattern(cwd) + '/');
78
97
  return dependencies.map(replaceRootDir).map(dependency => dependency.replace(matchCwd, toEntryPattern('')));
79
98
  };
80
- const findDependencies = timerify(findJestDependencies);
81
99
  export default {
82
- NAME,
83
- ENABLERS,
100
+ title,
101
+ enablers,
84
102
  isEnabled,
85
- CONFIG_FILE_PATTERNS,
86
- ENTRY_FILE_PATTERNS,
87
- findDependencies,
103
+ config,
104
+ entry,
105
+ resolveEntryPaths,
106
+ resolveConfig,
88
107
  };
@@ -1,9 +1,9 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { IsPluginEnabled, ResolveConfig } from '#p/types/plugins.js';
2
2
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- findDependencies: GenericPluginCallback;
3
+ title: string;
4
+ enablers: string[];
5
+ isEnabled: IsPluginEnabled;
6
+ config: string[];
7
+ resolveConfig: ResolveConfig;
8
8
  };
9
9
  export default _default;
@@ -1,39 +1,34 @@
1
- import { getGitHookPaths } from '../../util/git.js';
2
- import { getValuesByKeyDeep } from '../../util/object.js';
3
- import { extname } from '../../util/path.js';
4
- import { timerify } from '../../util/Performance.js';
5
- import { getDependenciesFromScripts, hasDependency, load, loadFile } from '../../util/plugin.js';
6
- import { fromBinary } from '../../util/protocols.js';
7
- const NAME = 'Lefthook';
8
- const ENABLERS = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthook'];
9
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
1
+ import { getGitHookPaths } from '#p/util/git.js';
2
+ import { getValuesByKeyDeep } from '#p/util/object.js';
3
+ import { extname } from '#p/util/path.js';
4
+ import { getDependenciesFromScripts, hasDependency } from '#p/util/plugin.js';
5
+ import { fromBinary } from '#p/util/protocols.js';
6
+ const title = 'Lefthook';
7
+ const enablers = ['lefthook', '@arkweid/lefthook', '@evilmartians/lefthook'];
8
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
10
9
  const gitHookPaths = getGitHookPaths();
11
- const CONFIG_FILE_PATTERNS = ['lefthook.yml', ...gitHookPaths];
12
- const findLefthookDependencies = async (configFilePath, options) => {
13
- const { manifest, isProduction } = options;
10
+ const config = ['lefthook.yml', ...gitHookPaths];
11
+ const resolveConfig = async (localConfig, options) => {
12
+ const { manifest, isProduction, configFileName } = options;
14
13
  if (isProduction)
15
14
  return [];
16
15
  const dependencies = manifest.devDependencies ? Object.keys(manifest.devDependencies) : [];
17
- if (extname(configFilePath) === '.yml') {
18
- const localConfig = await load(configFilePath);
19
- if (!localConfig)
20
- return [];
16
+ if (extname(configFileName) === '.yml') {
21
17
  const scripts = getValuesByKeyDeep(localConfig, 'run').filter((run) => typeof run === 'string');
22
- const lefthook = process.env.CI ? ENABLERS.filter(dependency => dependencies.includes(dependency)) : [];
18
+ const lefthook = process.env.CI ? enablers.filter(dependency => dependencies.includes(dependency)) : [];
23
19
  return [...lefthook, ...getDependenciesFromScripts(scripts, { ...options, knownGlobalsOnly: true })];
24
20
  }
25
- const script = await loadFile(configFilePath);
21
+ const script = localConfig;
26
22
  if (!script)
27
23
  return [];
28
- const scriptDependencies = getDependenciesFromScripts([script], options);
24
+ const scriptDependencies = getDependenciesFromScripts(script, options);
29
25
  const matches = scriptDependencies.find(dep => dependencies.includes(fromBinary(dep)));
30
26
  return matches ? [matches] : [];
31
27
  };
32
- const findDependencies = timerify(findLefthookDependencies);
33
28
  export default {
34
- NAME,
35
- ENABLERS,
29
+ title,
30
+ enablers,
36
31
  isEnabled,
37
- CONFIG_FILE_PATTERNS,
38
- findDependencies,
32
+ config,
33
+ resolveConfig,
39
34
  };
@@ -1,10 +1,11 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { ResolveConfig, IsPluginEnabled } from '#p/types/plugins.js';
2
+ import type { LintStagedConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- PACKAGE_JSON_PATH: string;
7
- CONFIG_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ readonly title: "lint-staged";
5
+ readonly enablers: string[];
6
+ readonly isEnabled: IsPluginEnabled;
7
+ readonly packageJsonPath: "lint-staged";
8
+ readonly config: string[];
9
+ readonly resolveConfig: ResolveConfig<LintStagedConfig>;
9
10
  };
10
11
  export default _default;
@@ -1,11 +1,9 @@
1
- import { basename } from '../../util/path.js';
2
- import { timerify } from '../../util/Performance.js';
3
- import { getDependenciesFromScripts, hasDependency, load } from '../../util/plugin.js';
4
- const NAME = 'lint-staged';
5
- const ENABLERS = ['lint-staged'];
6
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- const PACKAGE_JSON_PATH = 'lint-staged';
8
- const CONFIG_FILE_PATTERNS = [
1
+ import { getDependenciesFromScripts, hasDependency } from '#p/util/plugin.js';
2
+ const title = 'lint-staged';
3
+ const enablers = ['lint-staged'];
4
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
+ const packageJsonPath = 'lint-staged';
6
+ const config = [
9
7
  '.lintstagedrc',
10
8
  '.lintstagedrc.json',
11
9
  '.lintstagedrc.{yml,yaml}',
@@ -13,28 +11,23 @@ const CONFIG_FILE_PATTERNS = [
13
11
  'lint-staged.config.{js,mjs,cjs}',
14
12
  'package.json',
15
13
  ];
16
- const findLintStagedDependencies = async (configFilePath, options) => {
17
- const { manifest, isProduction } = options;
18
- if (isProduction)
19
- return [];
20
- let localConfig = basename(configFilePath) === 'package.json' ? manifest['lint-staged'] : await load(configFilePath);
21
- if (typeof localConfig === 'function')
22
- localConfig = localConfig();
23
- if (!localConfig)
14
+ const resolveConfig = async (config, options) => {
15
+ if (typeof config === 'function')
16
+ config = config();
17
+ if (!config)
24
18
  return [];
25
19
  const dependencies = new Set();
26
- for (const entry of Object.values(localConfig).flat()) {
20
+ for (const entry of Object.values(config).flat()) {
27
21
  const scripts = [typeof entry === 'function' ? await entry([]) : entry].flat();
28
22
  getDependenciesFromScripts(scripts, options).forEach(identifier => dependencies.add(identifier));
29
23
  }
30
24
  return Array.from(dependencies);
31
25
  };
32
- const findDependencies = timerify(findLintStagedDependencies);
33
26
  export default {
34
- NAME,
35
- ENABLERS,
27
+ title,
28
+ enablers,
36
29
  isEnabled,
37
- PACKAGE_JSON_PATH,
38
- CONFIG_FILE_PATTERNS,
39
- findDependencies,
30
+ packageJsonPath,
31
+ config,
32
+ resolveConfig,
40
33
  };
@@ -1,10 +1,11 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { ResolveConfig, IsPluginEnabled } from '#p/types/plugins.js';
2
+ import type { PluginConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- PACKAGE_JSON_PATH: string;
7
- CONFIG_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ readonly title: "LintHTML";
5
+ readonly enablers: string[];
6
+ readonly isEnabled: IsPluginEnabled;
7
+ readonly packageJsonPath: "linthtmlConfig";
8
+ readonly config: string[];
9
+ readonly resolveConfig: ResolveConfig<PluginConfig>;
9
10
  };
10
11
  export default _default;
@@ -1,12 +1,11 @@
1
- import { basename, isInternal } 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';
5
- const NAME = 'LintHTML';
6
- const PACKAGE_JSON_PATH = 'linthtmlConfig';
7
- const ENABLERS = ['@linthtml/linthtml'];
8
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
- const CONFIG_FILE_PATTERNS = [
1
+ import { isInternal } from '#p/util/path.js';
2
+ import { hasDependency } from '#p/util/plugin.js';
3
+ import { toEntryPattern } from '#p/util/protocols.js';
4
+ const title = 'LintHTML';
5
+ const packageJsonPath = 'linthtmlConfig';
6
+ const enablers = ['@linthtml/linthtml'];
7
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
+ const config = [
10
9
  '.linthtmlrc',
11
10
  '.linthtmlrc.json',
12
11
  '.linthtmlrc.yml',
@@ -14,25 +13,18 @@ const CONFIG_FILE_PATTERNS = [
14
13
  'linthtml.config.js',
15
14
  'package.json',
16
15
  ];
17
- const findPluginDependencies = async (configFilePath, options) => {
18
- const { manifest } = options;
19
- const localConfig = basename(configFilePath) === 'package.json' ? manifest.linthtmlConfig : await load(configFilePath);
20
- if (!localConfig)
21
- return [];
22
- const extensions = [localConfig.extends ?? []]
16
+ const resolveConfig = config => {
17
+ const extensions = [config.extends ?? []]
23
18
  .flat()
24
19
  .map(extension => (isInternal(extension) ? toEntryPattern(extension) : extension));
25
- const plugins = [localConfig.plugins ?? []]
26
- .flat()
27
- .map(plugin => (isInternal(plugin) ? toEntryPattern(plugin) : plugin));
20
+ const plugins = [config.plugins ?? []].flat().map(plugin => (isInternal(plugin) ? toEntryPattern(plugin) : plugin));
28
21
  return [...extensions, ...plugins];
29
22
  };
30
- const findDependencies = timerify(findPluginDependencies);
31
23
  export default {
32
- NAME,
33
- ENABLERS,
24
+ title,
25
+ enablers,
34
26
  isEnabled,
35
- PACKAGE_JSON_PATH,
36
- CONFIG_FILE_PATTERNS,
37
- findDependencies,
27
+ packageJsonPath,
28
+ config,
29
+ resolveConfig,
38
30
  };
@@ -1,9 +1,10 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { ResolveConfig, IsPluginEnabled } from '#p/types/plugins.js';
2
+ import type { MarkdownlintConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- findDependencies: GenericPluginCallback;
4
+ readonly title: "markdownlint";
5
+ readonly enablers: string[];
6
+ readonly isEnabled: IsPluginEnabled;
7
+ readonly config: string[];
8
+ readonly resolveConfig: ResolveConfig<MarkdownlintConfig>;
8
9
  };
9
10
  export default _default;
@@ -1,16 +1,12 @@
1
- import { timerify } from '../../util/Performance.js';
2
- import { hasDependency, load } from '../../util/plugin.js';
1
+ import { hasDependency } from '#p/util/plugin.js';
3
2
  import { getArgumentValues } from './helpers.js';
4
- const NAME = 'markdownlint';
5
- const ENABLERS = ['markdownlint-cli'];
6
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
7
- const CONFIG_FILE_PATTERNS = ['.markdownlint.{json,jsonc}', '.markdownlint.{yml,yaml}'];
8
- const findMarkdownlintConfigDependencies = async (configFilePath, options) => {
9
- const { manifest, isProduction } = options;
10
- if (isProduction)
11
- return [];
12
- const localConfig = await load(configFilePath);
13
- const extend = localConfig?.extends ? [localConfig.extends] : [];
3
+ const title = 'markdownlint';
4
+ const enablers = ['markdownlint-cli'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['.markdownlint.{json,jsonc}', '.markdownlint.{yml,yaml}'];
7
+ const resolveConfig = (config, options) => {
8
+ const { manifest } = options;
9
+ const extend = config?.extends ? [config.extends] : [];
14
10
  const scripts = manifest?.scripts
15
11
  ? Object.values(manifest.scripts).filter((script) => typeof script === 'string')
16
12
  : [];
@@ -19,11 +15,10 @@ const findMarkdownlintConfigDependencies = async (configFilePath, options) => {
19
15
  .flatMap(script => getArgumentValues(script, / (--rules|-r)[ =]([^ ]+)/g));
20
16
  return [...extend, ...uses];
21
17
  };
22
- const findDependencies = timerify(findMarkdownlintConfigDependencies);
23
18
  export default {
24
- NAME,
25
- ENABLERS,
19
+ title,
20
+ enablers,
26
21
  isEnabled,
27
- CONFIG_FILE_PATTERNS,
28
- findDependencies,
22
+ config,
23
+ resolveConfig,
29
24
  };
@@ -1,10 +1,12 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { MochaConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- ENTRY_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ readonly title: "Mocha";
5
+ readonly enablers: string[];
6
+ readonly isEnabled: IsPluginEnabled;
7
+ readonly config: string[];
8
+ readonly entry: string[];
9
+ readonly resolveConfig: ResolveConfig<MochaConfig>;
10
+ readonly resolveEntryPaths: ResolveEntryPaths<MochaConfig>;
9
11
  };
10
12
  export default _default;
@@ -1,27 +1,24 @@
1
- import { basename } 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';
5
- const NAME = 'Mocha';
6
- const ENABLERS = ['mocha'];
7
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
- const CONFIG_FILE_PATTERNS = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
9
- const ENTRY_FILE_PATTERNS = ['**/test/*.{js,cjs,mjs}'];
10
- const findMochaDependencies = async (configFilePath, options) => {
11
- const { config, manifest, isProduction } = options;
12
- const localConfig = basename(configFilePath) === 'package.json' ? manifest.mocha : await load(configFilePath);
13
- const entryPatterns = (config.entry ?? (localConfig?.spec ? [localConfig.spec].flat() : ENTRY_FILE_PATTERNS)).map(toEntryPattern);
14
- if (isProduction || !localConfig)
15
- return entryPatterns;
1
+ import { hasDependency } from '#p/util/plugin.js';
2
+ import { toEntryPattern } from '#p/util/protocols.js';
3
+ const title = 'Mocha';
4
+ const enablers = ['mocha'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['.mocharc.{js,cjs,json,jsonc,yml,yaml}', 'package.json'];
7
+ const entry = ['**/test/*.{js,cjs,mjs}'];
8
+ const resolveEntryPaths = localConfig => {
9
+ const entryPatterns = localConfig.spec ? [localConfig.spec].flat() : [];
10
+ return [...entryPatterns].map(toEntryPattern);
11
+ };
12
+ const resolveConfig = localConfig => {
16
13
  const require = localConfig.require ? [localConfig.require].flat() : [];
17
- return [...require, ...entryPatterns];
14
+ return [...require].map(toEntryPattern);
18
15
  };
19
- const findDependencies = timerify(findMochaDependencies);
20
16
  export default {
21
- NAME,
22
- ENABLERS,
17
+ title,
18
+ enablers,
23
19
  isEnabled,
24
- CONFIG_FILE_PATTERNS,
25
- ENTRY_FILE_PATTERNS,
26
- findDependencies,
20
+ config,
21
+ entry,
22
+ resolveConfig,
23
+ resolveEntryPaths,
27
24
  };
@@ -1,10 +1,11 @@
1
- import type { GenericPluginCallback, IsPluginEnabledCallback } from '../../types/plugins.js';
1
+ import type { MSWConfig } from './types.js';
2
+ import type { IsPluginEnabled, ResolveEntryPaths } from '../../types/plugins.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: string[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- ENTRY_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ title: string;
5
+ enablers: string[];
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ entry: string[];
9
+ resolveEntryPaths: ResolveEntryPaths<MSWConfig>;
9
10
  };
10
11
  export default _default;
@@ -1,23 +1,20 @@
1
1
  import { join } from '../../util/path.js';
2
- import { basename } from '../../util/path.js';
3
2
  import { hasDependency } from '../../util/plugin.js';
4
3
  import { toEntryPattern } from '../../util/protocols.js';
5
- const NAME = 'Mock Service Worker';
6
- const ENABLERS = ['msw'];
7
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
8
- const CONFIG_FILE_PATTERNS = ['package.json'];
9
- const ENTRY_FILE_PATTERNS = ['mockServiceWorker.js'];
10
- const findDependencies = async (configFilePath, options) => {
11
- const { manifest } = options;
12
- const localConfig = basename(configFilePath) === 'package.json' ? manifest.msw : undefined;
4
+ const title = 'Mock Service Worker';
5
+ const enablers = ['msw'];
6
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
+ const config = ['package.json'];
8
+ const entry = ['mockServiceWorker.js'];
9
+ const resolveEntryPaths = async (localConfig) => {
13
10
  const workerDirectory = localConfig?.workerDirectory ?? '.';
14
- return ENTRY_FILE_PATTERNS.map(pattern => toEntryPattern(join(workerDirectory, pattern)));
11
+ return entry.map(pattern => toEntryPattern(join(workerDirectory, pattern)));
15
12
  };
16
13
  export default {
17
- NAME,
18
- ENABLERS,
14
+ title,
15
+ enablers,
19
16
  isEnabled,
20
- CONFIG_FILE_PATTERNS,
21
- ENTRY_FILE_PATTERNS,
22
- findDependencies,
17
+ config,
18
+ entry,
19
+ resolveEntryPaths,
23
20
  };
@@ -1,10 +1,12 @@
1
- import type { IsPluginEnabledCallback, GenericPluginCallback } from '../../types/plugins.js';
1
+ import type { IsPluginEnabled, ResolveConfig, ResolveEntryPaths } from '#p/types/plugins.js';
2
+ import type { NetlifyConfig } from './types.js';
2
3
  declare const _default: {
3
- NAME: string;
4
- ENABLERS: (string | RegExp)[];
5
- isEnabled: IsPluginEnabledCallback;
6
- CONFIG_FILE_PATTERNS: string[];
7
- PRODUCTION_ENTRY_FILE_PATTERNS: string[];
8
- findDependencies: GenericPluginCallback;
4
+ title: string;
5
+ enablers: (string | RegExp)[];
6
+ isEnabled: IsPluginEnabled;
7
+ config: string[];
8
+ production: string[];
9
+ resolveEntryPaths: ResolveEntryPaths<NetlifyConfig>;
10
+ resolveConfig: ResolveConfig<NetlifyConfig>;
9
11
  };
10
12
  export default _default;
@@ -1,38 +1,34 @@
1
- import { join } from '../../util/path.js';
2
- import { timerify } from '../../util/Performance.js';
3
- import { hasDependency, load } from '../../util/plugin.js';
1
+ import { join } from '#p/util/path.js';
2
+ import { hasDependency } from '#p/util/plugin.js';
4
3
  import { toProductionEntryPattern } from '../../util/protocols.js';
5
4
  import { extractFunctionsConfigProperty } from './helpers.js';
6
- const NAME = 'Netlify';
7
- const ENABLERS = [/^@netlify\/plugin-/, 'netlify-cli', '@netlify/functions'];
8
- const isEnabled = ({ dependencies }) => hasDependency(dependencies, ENABLERS);
9
- const CONFIG_FILE_PATTERNS = ['netlify.toml'];
5
+ const title = 'Netlify';
6
+ const enablers = [/^@netlify\/plugin-/, 'netlify-cli', '@netlify/functions'];
7
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
+ const config = ['netlify.toml'];
10
9
  const NETLIFY_FUNCTIONS_DIR = 'netlify/functions';
11
10
  const NETLIFY_FUNCTIONS_EXTS = 'js,mjs,cjs,ts,mts,cts';
12
- const PRODUCTION_ENTRY_FILE_PATTERNS = [`${NETLIFY_FUNCTIONS_DIR}/**/*.{${NETLIFY_FUNCTIONS_EXTS}}`];
13
- const findPluginDependencies = async (configFilePath, options) => {
14
- const { config } = options;
15
- const localConfig = await load(configFilePath);
16
- if (!localConfig)
17
- return config.entry
18
- ? config.entry.map(toProductionEntryPattern)
19
- : PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
20
- const dependencies = [
11
+ const production = [`${NETLIFY_FUNCTIONS_DIR}/**/*.{${NETLIFY_FUNCTIONS_EXTS}}`];
12
+ const resolveEntryPaths = localConfig => {
13
+ return [
14
+ ...extractFunctionsConfigProperty(localConfig.functions || {}, 'included_files'),
15
+ join(localConfig.functions?.directory ?? NETLIFY_FUNCTIONS_DIR, `**/*.{${NETLIFY_FUNCTIONS_EXTS}}`),
16
+ ]
17
+ .filter(file => !file.startsWith('!'))
18
+ .map(toProductionEntryPattern);
19
+ };
20
+ const resolveConfig = async (localConfig) => {
21
+ return [
21
22
  ...(localConfig?.plugins?.map(plugin => plugin.package) ?? []),
22
23
  ...extractFunctionsConfigProperty(localConfig.functions || {}, 'external_node_modules'),
23
24
  ];
24
- const entryFiles = [
25
- ...extractFunctionsConfigProperty(localConfig.functions || {}, 'included_files'),
26
- join(localConfig.functions?.directory ?? NETLIFY_FUNCTIONS_DIR, `**/*.{${NETLIFY_FUNCTIONS_EXTS}}`),
27
- ].filter(file => !file.startsWith('!'));
28
- return [...dependencies, ...entryFiles.map(toProductionEntryPattern)];
29
25
  };
30
- const findDependencies = timerify(findPluginDependencies);
31
26
  export default {
32
- NAME,
33
- ENABLERS,
27
+ title,
28
+ enablers,
34
29
  isEnabled,
35
- CONFIG_FILE_PATTERNS,
36
- PRODUCTION_ENTRY_FILE_PATTERNS,
37
- findDependencies,
30
+ config,
31
+ production,
32
+ resolveEntryPaths,
33
+ resolveConfig,
38
34
  };