knip 6.43.0 → 6.44.1

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 (168) hide show
  1. package/README.md +2 -4
  2. package/dist/CacheConsultant.d.ts +1 -0
  3. package/dist/CacheConsultant.js +2 -0
  4. package/dist/CatalogCounselor.d.ts +1 -3
  5. package/dist/CatalogCounselor.js +18 -15
  6. package/dist/ConfigurationChief.d.ts +24 -0
  7. package/dist/DependencyDeputy.d.ts +2 -1
  8. package/dist/DependencyDeputy.js +11 -6
  9. package/dist/IssueCollector.js +1 -0
  10. package/dist/ProjectPrincipal.d.ts +4 -2
  11. package/dist/ProjectPrincipal.js +32 -10
  12. package/dist/WorkspaceWorker.d.ts +5 -2
  13. package/dist/WorkspaceWorker.js +20 -7
  14. package/dist/binaries/resolvers/bun.js +7 -2
  15. package/dist/binaries/util.js +2 -1
  16. package/dist/cli.js +6 -1
  17. package/dist/compilers/index.d.ts +5 -0
  18. package/dist/compilers/index.js +1 -1
  19. package/dist/constants.d.ts +2 -0
  20. package/dist/constants.js +2 -0
  21. package/dist/graph/analyze.js +3 -2
  22. package/dist/graph/build.d.ts +2 -0
  23. package/dist/graph/build.js +37 -22
  24. package/dist/graph-explorer/cache.d.ts +2 -1
  25. package/dist/graph-explorer/cache.js +5 -1
  26. package/dist/graph-explorer/explorer.d.ts +3 -5
  27. package/dist/graph-explorer/explorer.js +24 -3
  28. package/dist/plugins/babel/index.js +6 -1
  29. package/dist/plugins/biome/index.js +1 -1
  30. package/dist/plugins/cspell/index.js +10 -2
  31. package/dist/plugins/dependency-cruiser/index.js +2 -2
  32. package/dist/plugins/docusaurus/helpers.js +4 -4
  33. package/dist/plugins/electron-vite/index.js +2 -2
  34. package/dist/plugins/eleventy/index.js +2 -2
  35. package/dist/plugins/expressive-code/index.d.ts +1 -1
  36. package/dist/plugins/expressive-code/index.js +2 -2
  37. package/dist/plugins/gatsby/index.js +6 -6
  38. package/dist/plugins/gatsby/types.d.ts +1 -1
  39. package/dist/plugins/github-actions/index.js +1 -1
  40. package/dist/plugins/i18next-parser/index.js +2 -2
  41. package/dist/plugins/index.d.ts +5 -1
  42. package/dist/plugins/index.js +8 -0
  43. package/dist/plugins/jasmine/index.js +2 -2
  44. package/dist/plugins/karma/index.js +4 -4
  45. package/dist/plugins/kysely-codegen/index.d.ts +3 -0
  46. package/dist/plugins/kysely-codegen/index.js +20 -0
  47. package/dist/plugins/lefthook/index.js +2 -2
  48. package/dist/plugins/lingui/index.d.ts +3 -0
  49. package/dist/plugins/lingui/index.js +16 -0
  50. package/dist/plugins/lockfile-lint/index.js +2 -2
  51. package/dist/plugins/lost-pixel/index.js +2 -2
  52. package/dist/plugins/lunaria/index.js +2 -2
  53. package/dist/plugins/marko/index.js +5 -6
  54. package/dist/plugins/mastra/index.d.ts +3 -0
  55. package/dist/plugins/mastra/index.js +57 -0
  56. package/dist/plugins/mcp/index.js +1 -1
  57. package/dist/plugins/mise/index.js +0 -3
  58. package/dist/plugins/mocha/index.js +43 -4
  59. package/dist/plugins/mocha/types.d.ts +1 -0
  60. package/dist/plugins/npm-package-json-lint/index.js +1 -1
  61. package/dist/plugins/npm-package-json-lint/types.d.ts +1 -1
  62. package/dist/plugins/nx/index.js +3 -8
  63. package/dist/plugins/nyc/index.js +1 -1
  64. package/dist/plugins/openapi-ts/index.js +2 -2
  65. package/dist/plugins/oxfmt/index.js +2 -2
  66. package/dist/plugins/playwright/index.js +6 -11
  67. package/dist/plugins/pnpm/index.js +2 -4
  68. package/dist/plugins/purgecss/index.d.ts +3 -0
  69. package/dist/plugins/purgecss/index.js +16 -0
  70. package/dist/plugins/railway/index.js +1 -4
  71. package/dist/plugins/relay/index.js +1 -1
  72. package/dist/plugins/release-it/index.js +1 -1
  73. package/dist/plugins/remix/index.js +1 -1
  74. package/dist/plugins/rsbuild/index.js +29 -1
  75. package/dist/plugins/rsbuild/types.d.ts +8 -0
  76. package/dist/plugins/rstest/index.js +2 -2
  77. package/dist/plugins/serverless-framework/index.js +1 -1
  78. package/dist/plugins/storybook/index.js +5 -5
  79. package/dist/plugins/sveltekit/resolveFromAST.js +1 -1
  80. package/dist/plugins/svgr/index.js +2 -1
  81. package/dist/plugins/swc/index.js +8 -3
  82. package/dist/plugins/syncpack/index.js +2 -2
  83. package/dist/plugins/tanstack-router/index.js +3 -2
  84. package/dist/plugins/taskfile/index.js +4 -7
  85. package/dist/plugins/textlint/helpers.js +2 -2
  86. package/dist/plugins/typescript/index.js +7 -3
  87. package/dist/plugins/unocss/index.js +2 -2
  88. package/dist/plugins/vite-plugin-pwa/index.js +1 -4
  89. package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +0 -2
  90. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  91. package/dist/plugins/vite-pwa-assets-generator/index.js +2 -2
  92. package/dist/plugins/vitest/helpers.js +4 -7
  93. package/dist/plugins/vitest/index.js +1 -1
  94. package/dist/plugins/webpack/index.d.ts +2 -0
  95. package/dist/plugins/webpack/index.js +11 -6
  96. package/dist/plugins/yarn/index.js +2 -4
  97. package/dist/reporters/codeclimate.d.ts +2 -2
  98. package/dist/reporters/codeclimate.js +2 -4
  99. package/dist/reporters/codeowners.d.ts +2 -2
  100. package/dist/reporters/codeowners.js +9 -9
  101. package/dist/reporters/compact.d.ts +2 -2
  102. package/dist/reporters/compact.js +8 -7
  103. package/dist/reporters/cycles.d.ts +2 -2
  104. package/dist/reporters/cycles.js +7 -6
  105. package/dist/reporters/disclosure.d.ts +2 -2
  106. package/dist/reporters/disclosure.js +6 -4
  107. package/dist/reporters/github-actions.d.ts +2 -2
  108. package/dist/reporters/github-actions.js +7 -5
  109. package/dist/reporters/index.d.ts +10 -10
  110. package/dist/reporters/json.d.ts +2 -2
  111. package/dist/reporters/json.js +2 -4
  112. package/dist/reporters/markdown.d.ts +2 -2
  113. package/dist/reporters/markdown.js +11 -9
  114. package/dist/reporters/sarif.d.ts +2 -2
  115. package/dist/reporters/sarif.js +2 -3
  116. package/dist/reporters/symbols.d.ts +2 -2
  117. package/dist/reporters/symbols.js +6 -4
  118. package/dist/run.d.ts +1 -1
  119. package/dist/run.js +3 -10
  120. package/dist/schema/configuration.d.ts +60 -0
  121. package/dist/schema/plugins.d.ts +20 -0
  122. package/dist/schema/plugins.js +4 -0
  123. package/dist/session/configuration.d.ts +15 -0
  124. package/dist/session/configuration.js +62 -0
  125. package/dist/session/incremental.d.ts +54 -0
  126. package/dist/session/incremental.js +49 -0
  127. package/dist/session/session.d.ts +1 -1
  128. package/dist/session/session.js +63 -27
  129. package/dist/session/watch.d.ts +2 -0
  130. package/dist/session/watch.js +41 -0
  131. package/dist/types/PluginNames.d.ts +2 -2
  132. package/dist/types/PluginNames.js +4 -0
  133. package/dist/types/config.d.ts +1 -0
  134. package/dist/types/issues.d.ts +4 -0
  135. package/dist/types/package-json.d.ts +0 -3
  136. package/dist/typescript/get-imports-and-exports.js +2 -0
  137. package/dist/typescript/visitors/calls.js +15 -11
  138. package/dist/typescript/visitors/imports.d.ts +3 -1
  139. package/dist/typescript/visitors/imports.js +77 -53
  140. package/dist/typescript/visitors/members.js +23 -26
  141. package/dist/typescript/visitors/walk.d.ts +3 -0
  142. package/dist/typescript/visitors/walk.js +43 -2
  143. package/dist/util/cli-arguments.d.ts +2 -1
  144. package/dist/util/cli-arguments.js +3 -0
  145. package/dist/util/create-input-handler.js +1 -1
  146. package/dist/util/create-options.d.ts +43 -2
  147. package/dist/util/create-options.js +17 -4
  148. package/dist/util/file-entry-cache.d.ts +2 -0
  149. package/dist/util/file-entry-cache.js +19 -1
  150. package/dist/util/gitignore-cache.d.ts +1 -0
  151. package/dist/util/gitignore-cache.js +1 -0
  152. package/dist/util/glob-core.js +4 -2
  153. package/dist/util/glob.d.ts +1 -0
  154. package/dist/util/glob.js +6 -0
  155. package/dist/util/input.d.ts +2 -0
  156. package/dist/util/loader.d.ts +1 -0
  157. package/dist/util/loader.js +29 -1
  158. package/dist/util/modules.js +5 -2
  159. package/dist/util/path.d.ts +1 -0
  160. package/dist/util/path.js +1 -0
  161. package/dist/util/reporter.d.ts +1 -1
  162. package/dist/util/reporter.js +53 -9
  163. package/dist/util/watch.d.ts +5 -11
  164. package/dist/util/watch.js +84 -68
  165. package/dist/version.d.ts +1 -1
  166. package/dist/version.js +1 -1
  167. package/package.json +1 -1
  168. package/schema.json +16 -0
@@ -2,7 +2,7 @@ import { arrayify } from '../../util/array.js';
2
2
  import { findFileWithExtensions } from '../../util/fs.js';
3
3
  import { _dirGlob, _glob, negate } from '../../util/glob.js';
4
4
  import { toAlias, toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
5
- import { dirname, join, relative, toAbsolute } from '../../util/path.js';
5
+ import { dirname, join, toAbsolute } from '../../util/path.js';
6
6
  import { hasDependency, load } from '../../util/plugin.js';
7
7
  import { createRstestMockVisitor } from './visitors/mock.js';
8
8
  const title = 'Rstest';
@@ -25,7 +25,7 @@ const resolveConfig = async (localConfig, options) => {
25
25
  const seen = new Set([configFilePath]);
26
26
  const inputs = [];
27
27
  const addProject = async (project, projectRoot) => {
28
- const toPattern = (pattern) => relative(cwd, toAbsolute(replaceRootDir(pattern, projectRoot), projectRoot));
28
+ const toPattern = (pattern) => toAbsolute(replaceRootDir(pattern, projectRoot), projectRoot);
29
29
  if (!options.config.entry) {
30
30
  const include = [];
31
31
  const exclude = [...(Array.isArray(project.exclude) ? project.exclude : (project.exclude?.patterns ?? []))];
@@ -27,7 +27,7 @@ const handlerToEntry = (handler) => {
27
27
  const file = handler.slice(0, dot);
28
28
  return toProductionEntry(/\.(?:[cm]?[jt]s|[jt]sx)$/.test(file) ? file : `${file}.{js,ts}`);
29
29
  };
30
- const pluginToInput = (plugin, dir) => isInternal(plugin) ? toProductionEntry(join(dir, plugin)) : toDependency(plugin);
30
+ const pluginToInput = (plugin, dir) => isInternal(plugin) ? toProductionEntry(toAbsolute(plugin, dir)) : toDependency(plugin);
31
31
  const getFunctionEntries = async (functions, dir) => {
32
32
  const entries = [];
33
33
  const resolved = await resolveFileVariable(functions, dir);
@@ -1,6 +1,6 @@
1
1
  import MDX from '../../compilers/mdx.js';
2
2
  import { toConfig, toDeferResolve, toDependency, toEntry } from '../../util/input.js';
3
- import { join, relative } from '../../util/path.js';
3
+ import { join, toAbsolute } from '../../util/path.js';
4
4
  import { hasDependency } from '../../util/plugin.js';
5
5
  import { getBabelInputs } from '../vite/helpers.js';
6
6
  const title = 'Storybook';
@@ -14,14 +14,14 @@ const project = ['.{storybook,rnstorybook}/**/*.{js,jsx,ts,tsx,mts}'];
14
14
  const resolveConfig = async (localConfig, options) => {
15
15
  const { cwd, configFileDir } = options;
16
16
  const strs = typeof localConfig?.stories === 'function' ? await localConfig.stories(stories) : localConfig?.stories;
17
- const relativePatterns = strs?.map(pattern => {
17
+ const storyPatterns = strs?.map(pattern => {
18
18
  if (typeof pattern === 'string')
19
- return relative(cwd, join(configFileDir, pattern));
20
- return relative(cwd, join(configFileDir, pattern.directory, pattern.files ?? stories[0]));
19
+ return toAbsolute(pattern, configFileDir);
20
+ return join(toAbsolute(pattern.directory, configFileDir), pattern.files ?? stories[0]);
21
21
  });
22
22
  const patterns = [
23
23
  ...(options.config.entry ?? restEntry),
24
- ...(relativePatterns && relativePatterns.length > 0 ? relativePatterns : stories),
24
+ ...(storyPatterns && storyPatterns.length > 0 ? storyPatterns : stories),
25
25
  ];
26
26
  const addons = localConfig.addons?.map(addon => (typeof addon === 'string' ? addon : addon.name)) ?? [];
27
27
  const builder = localConfig?.core?.builder &&
@@ -5,7 +5,7 @@ import { toAlias, toIgnore, toProductionEntry } from '../../util/input.js';
5
5
  import { config as viteConfig } from '../vite/index.js';
6
6
  const production = [
7
7
  'src/routes/**/+{page,server,page.server,error,layout,layout.server}{,@*}.{js,ts,svelte}',
8
- 'src/hooks.{server,client}.{js,ts}',
8
+ 'src/hooks{,.server,.client}.{js,ts}',
9
9
  'src/params/*.{js,ts}',
10
10
  'src/service-worker.{js,ts}',
11
11
  'src/service-worker/index.{js,ts}',
@@ -1,9 +1,10 @@
1
1
  import { toDependency } from '../../util/input.js';
2
2
  import { hasDependency } from '../../util/plugin.js';
3
+ import { toCosmiconfig } from '../../util/plugin-config.js';
3
4
  const title = 'SVGR';
4
5
  const enablers = ['@svgr/cli', '@svgr/core'];
5
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = ['.svgrrc', '.svgrrc.{yaml,yml,json,js}', 'svgr.config.{js,cjs}', 'package.json'];
7
+ const config = ['package.json', ...toCosmiconfig('svgr')];
7
8
  const resolveConfig = async (config) => {
8
9
  const inputs = [];
9
10
  if (config.plugins) {
@@ -6,9 +6,14 @@ const enablers = ['@swc/core'];
6
6
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
7
  const config = ['.swcrc'];
8
8
  const resolveConfig = async (config) => {
9
- const inputs = config?.jsc?.experimental?.plugins ?? [];
10
- const externalHelpers = config.jsc?.externalHelpers ? ['@swc/helpers'] : [];
11
- return compact([...inputs.map(([id]) => id), ...externalHelpers]).map(id => toDependency(id));
9
+ const dependencies = [];
10
+ for (const item of [config].flat()) {
11
+ for (const [id] of item?.jsc?.experimental?.plugins ?? [])
12
+ dependencies.push(id);
13
+ if (item?.jsc?.externalHelpers)
14
+ dependencies.push('@swc/helpers');
15
+ }
16
+ return compact(dependencies).map(id => toDependency(id));
12
17
  };
13
18
  const plugin = {
14
19
  title,
@@ -3,11 +3,11 @@ import { toCosmiconfig } from '../../util/plugin-config.js';
3
3
  const title = 'Syncpack';
4
4
  const enablers = ['syncpack'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = ['package.json', ...toCosmiconfig('syncpack')];
6
+ const entry = ['package.json', ...toCosmiconfig('syncpack')];
7
7
  const plugin = {
8
8
  title,
9
9
  enablers,
10
10
  isEnabled,
11
- config,
11
+ entry,
12
12
  };
13
13
  export default plugin;
@@ -14,12 +14,13 @@ const enablers = [
14
14
  ];
15
15
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
16
16
  const config = ['tsr.config.json'];
17
- const production = ['src/routeTree.gen.{ts,js}', 'src/{router,start,client,server}.{js,jsx,ts,tsx}'];
17
+ const routerEntries = ['src/{router,start,client,server}.{js,jsx,ts,tsx}'];
18
+ const production = ['src/routeTree.gen.{ts,js}', ...routerEntries];
18
19
  const resolveConfig = async (localConfig, options) => {
19
20
  const { configFileDir } = options;
20
21
  const generatedRouteTree = localConfig.generatedRouteTree ?? './src/routeTree.gen.ts';
21
22
  const routeTreePath = toAbsolute(generatedRouteTree, configFileDir);
22
- return [toProductionEntry(routeTreePath)];
23
+ return [toProductionEntry(routeTreePath), ...routerEntries.map(id => toProductionEntry(id))];
23
24
  };
24
25
  const plugin = {
25
26
  title,
@@ -1,6 +1,5 @@
1
1
  import { isFile } from '../../util/fs.js';
2
2
  import { toConfig } from '../../util/input.js';
3
- import { join, relative } from '../../util/path.js';
4
3
  const title = 'Taskfile';
5
4
  const enablers = 'This plugin is enabled when a Taskfile is found (Taskfile.yml, taskfile.yml, Taskfile.yaml, taskfile.yaml, etc.).';
6
5
  const isRootOnly = true;
@@ -78,7 +77,7 @@ const extractScriptsFromTask = (task) => {
78
77
  const resolveConfig = async (localConfig, options) => {
79
78
  if (!localConfig || !options.configFilePath)
80
79
  return [];
81
- const { getInputsFromScripts, isProduction, configFileDir } = options;
80
+ const { getInputsFromScripts, isProduction, configFileDir, cwd } = options;
82
81
  const inputs = [];
83
82
  if (localConfig.includes && typeof localConfig.includes === 'object') {
84
83
  for (const includeValue of Object.values(localConfig.includes)) {
@@ -87,10 +86,8 @@ const resolveConfig = async (localConfig, options) => {
87
86
  : includeValue && typeof includeValue === 'object' && 'taskfile' in includeValue
88
87
  ? includeValue.taskfile
89
88
  : undefined;
90
- if (includePath) {
91
- const resolvedPath = join(configFileDir, includePath);
92
- inputs.push(toConfig('taskfile', relative(configFileDir, resolvedPath)));
93
- }
89
+ if (includePath)
90
+ inputs.push(toConfig('taskfile', includePath));
94
91
  }
95
92
  }
96
93
  if (localConfig.tasks && typeof localConfig.tasks === 'object') {
@@ -99,7 +96,7 @@ const resolveConfig = async (localConfig, options) => {
99
96
  for (const input of getInputsFromScripts([script], { optionalBinaries: true })) {
100
97
  if (isProduction)
101
98
  Object.assign(input, { optional: true });
102
- inputs.push({ ...input, dir: configFileDir });
99
+ inputs.push({ ...input, dir: input.type === 'entry' ? cwd : configFileDir });
103
100
  }
104
101
  }
105
102
  }
@@ -1,5 +1,5 @@
1
1
  import { toDependency, toDeferResolveEntry } from '../../util/input.js';
2
- import { isInternal, toAbsolute } from '../../util/path.js';
2
+ import { isInternal } from '../../util/path.js';
3
3
  const RULE_PREFIX = 'textlint-rule-';
4
4
  const PRESET_PREFIX = 'textlint-rule-preset-';
5
5
  const FILTER_RULE_PREFIX = 'textlint-filter-rule-';
@@ -29,7 +29,7 @@ const toPresetDependency = (key, manifest) => {
29
29
  return toPackageDependency(PRESET_PREFIX, name, candidates, manifest);
30
30
  };
31
31
  const toModuleDependency = (prefix, key, manifest) => toPackageDependency(prefix, key, [createFullPackageName(prefix, key), key], manifest);
32
- const toLocalEntry = (key, cwd) => toDeferResolveEntry(toAbsolute(key, cwd));
32
+ const toLocalEntry = (key, cwd) => toDeferResolveEntry(key, { dir: cwd });
33
33
  export const toRuleDependency = (key, manifest, cwd) => {
34
34
  if (isInternal(key))
35
35
  return toLocalEntry(key, cwd);
@@ -26,7 +26,11 @@ export const resolveConfig = (localConfig, options) => {
26
26
  const contentMappers = resolveContentMappers(localConfig);
27
27
  if (!(compilerOptions && localConfig))
28
28
  return compact([...contentMappers, ...extend, ...references]);
29
- const jsx = (compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []).map(toProductionDependency);
29
+ const jsx = (compilerOptions?.jsxImportSource ? [compilerOptions.jsxImportSource] : []).map(id => ({
30
+ ...toProductionDependency(id),
31
+ dir: options.cwd,
32
+ alsoReferenceOwner: true,
33
+ }));
30
34
  const types = compilerOptions.types ?? [];
31
35
  const plugins = Array.isArray(compilerOptions?.plugins)
32
36
  ? compilerOptions.plugins.map(plugin => (typeof plugin === 'object' && 'name' in plugin ? plugin.name : ''))
@@ -36,8 +40,8 @@ export const resolveConfig = (localConfig, options) => {
36
40
  ...contentMappers,
37
41
  ...extend,
38
42
  ...references,
39
- ...types.map(id => toDeferResolve(id, { isTypeOnly: true, dir: options.cwd })),
40
- ...[...plugins, ...importHelpers].map(id => toDeferResolve(id)),
43
+ ...types.map(id => toDeferResolve(id, { isTypeOnly: true, dir: options.cwd, alsoReferenceOwner: true })),
44
+ ...[...plugins, ...importHelpers].map(id => toDeferResolve(id, { dir: options.cwd, alsoReferenceOwner: true })),
41
45
  ...jsx,
42
46
  ]);
43
47
  };
@@ -3,11 +3,11 @@ import { toUnconfig } from '../../util/plugin-config.js';
3
3
  const title = 'UnoCSS';
4
4
  const enablers = ['unocss'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
- const config = [...toUnconfig('uno.config'), ...toUnconfig('unocss.config')];
6
+ const entry = [...toUnconfig('uno.config'), ...toUnconfig('unocss.config')];
7
7
  const plugin = {
8
8
  title,
9
9
  enablers,
10
10
  isEnabled,
11
- config,
11
+ entry,
12
12
  };
13
13
  export default plugin;
@@ -1,17 +1,14 @@
1
- import { join } from '../../util/path.js';
2
1
  import { hasDependency } from '../../util/plugin.js';
3
- import { defaultFilename, defaultSrcDir, resolveFromAST } from './resolveFromAST.js';
2
+ import { resolveFromAST } from './resolveFromAST.js';
4
3
  const title = 'vite-plugin-pwa';
5
4
  const enablers = ['vite-plugin-pwa', '@vite-pwa/nuxt'];
6
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
7
6
  const config = ['vite.config.{js,mjs,ts,cjs,mts,cts}', 'nuxt.config.{js,cjs,mjs,ts,cts,mts}'];
8
- const production = [join(defaultSrcDir, defaultFilename)];
9
7
  const plugin = {
10
8
  title,
11
9
  enablers,
12
10
  isEnabled,
13
11
  config,
14
- production,
15
12
  resolveFromAST,
16
13
  };
17
14
  export default plugin;
@@ -1,4 +1,2 @@
1
1
  import type { ResolveFromAST } from '../../types/config.ts';
2
- export declare const defaultSrcDir = "public";
3
- export declare const defaultFilename = "sw.js";
4
2
  export declare const resolveFromAST: ResolveFromAST;
@@ -2,8 +2,8 @@ import { Visitor } from 'oxc-parser';
2
2
  import { findImportedCalls, findProperty, getFirstPropertyValue, getPropertyValues, } from '../../typescript/ast-helpers.js';
3
3
  import { toProductionEntry } from '../../util/input.js';
4
4
  import { join } from '../../util/path.js';
5
- export const defaultSrcDir = 'public';
6
- export const defaultFilename = 'sw.js';
5
+ const defaultSrcDir = 'public';
6
+ const defaultFilename = 'sw.js';
7
7
  const isNuxtConfig = (configFileName) => configFileName.startsWith('nuxt.config.');
8
8
  const getInjectManifestEntry = (options, configFileDir) => {
9
9
  if (!getPropertyValues(options, 'strategies').has('injectManifest'))
@@ -2,11 +2,11 @@ import { hasDependency } from '../../util/plugin.js';
2
2
  const title = '@vite-pwa/assets-generator';
3
3
  const enablers = ['@vite-pwa/assets-generator'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['pwa-assets.config.{js,cjs,mjs,ts,cts,mts}'];
5
+ const entry = ['pwa-assets.config.{js,cjs,mjs,ts,cts,mts}'];
6
6
  const plugin = {
7
7
  title,
8
8
  enablers,
9
9
  isEnabled,
10
- config,
10
+ entry,
11
11
  };
12
12
  export default plugin;
@@ -1,5 +1,5 @@
1
1
  import { toAlias, toDependency } from '../../util/input.js';
2
- import { join, toPosix } from '../../util/path.js';
2
+ import { join } from '../../util/path.js';
3
3
  const environments = {
4
4
  node: null,
5
5
  jsdom: null,
@@ -49,13 +49,10 @@ export const getAliasInputs = (aliasOptions, cwd) => {
49
49
  for (const [alias, value] of getAliasEntries(aliasOptions)) {
50
50
  if (!value)
51
51
  continue;
52
- const prefixes = [value]
53
- .flat()
54
- .filter((value) => typeof value === 'string')
55
- .map(prefix => (toPosix(prefix).startsWith(cwd) ? prefix : join(cwd, prefix)));
52
+ const prefixes = [value].flat().filter((value) => typeof value === 'string');
56
53
  if (alias.length > 1)
57
- inputs.push(toAlias(alias, prefixes));
58
- inputs.push(toAlias(addStar(alias), prefixes.map(addStar)));
54
+ inputs.push(toAlias(alias, prefixes, { dir: cwd }));
55
+ inputs.push(toAlias(addStar(alias), prefixes.map(addStar), { dir: cwd }));
59
56
  }
60
57
  return inputs;
61
58
  };
@@ -218,7 +218,7 @@ export const resolveConfig = async (localConfig, options) => {
218
218
  }
219
219
  const _entry = cfg.build?.lib?.entry ?? [];
220
220
  const entries = typeof _entry === 'string' ? [_entry] : Array.isArray(_entry) ? _entry : Object.values(_entry).flat();
221
- const deps = entries.map(specifier => join(viteRoot, specifier)).map(id => toEntry(id));
221
+ const deps = entries.map(specifier => toAbsolute(specifier, viteRoot)).map(id => toEntry(id));
222
222
  for (const dependency of deps)
223
223
  inputs.add(dependency);
224
224
  }
@@ -1,5 +1,7 @@
1
1
  import type { Plugin, ResolveConfig } from '../../types/config.ts';
2
+ import type { SWCConfig } from '../swc/types.ts';
2
3
  import type { WebpackConfig } from './types.ts';
4
+ export declare const getSwcPluginSpecifiers: (options: SWCConfig) => string[];
3
5
  export declare const findWebpackDependenciesFromConfig: ResolveConfig<WebpackConfig>;
4
6
  declare const plugin: Plugin;
5
7
  export default plugin;
@@ -1,5 +1,5 @@
1
1
  import { toAlias, toDeferResolve, toDeferResolveEntry, toDeferResolveProductionEntry, toDependency, } from '../../util/input.js';
2
- import { extname, isInternal, join, toAbsolute } from '../../util/path.js';
2
+ import { extname, isInternal, join } from '../../util/path.js';
3
3
  import { hasDependency } from '../../util/plugin.js';
4
4
  import { getDependenciesFromConfig } from '../babel/index.js';
5
5
  import { createRequireContextVisitor } from './visitors/requireContext.js';
@@ -44,6 +44,8 @@ const resolveRuleSetDependencies = (rule) => {
44
44
  const d = getDependenciesFromConfig(rule.options).map(d => d.specifier);
45
45
  return [useItem, ...d];
46
46
  }
47
+ if (typeof useItem === 'string' && useItem && rule.options && rule.use == null)
48
+ useItem = { loader: useItem, options: rule.options };
47
49
  return [useItem].flat().flatMap((item) => {
48
50
  if (!item)
49
51
  return [];
@@ -57,10 +59,8 @@ const resolveRuleSetDependencies = (rule) => {
57
59
  });
58
60
  };
59
61
  const isSwcLoader = (loader) => loader === 'builtin:swc-loader' || loader.endsWith('/swc-loader') || loader === 'swc-loader';
60
- const resolveSwcPluginDependencies = (use) => {
61
- if (!hasLoaderOptions(use) || !isSwcLoader(use.loader))
62
- return [];
63
- const plugins = use.options.jsc?.experimental?.plugins;
62
+ export const getSwcPluginSpecifiers = (options) => {
63
+ const plugins = options.jsc?.experimental?.plugins;
64
64
  if (!Array.isArray(plugins))
65
65
  return [];
66
66
  return plugins.flatMap(plugin => {
@@ -71,6 +71,11 @@ const resolveSwcPluginDependencies = (use) => {
71
71
  return [];
72
72
  });
73
73
  };
74
+ const resolveSwcPluginDependencies = (use) => {
75
+ if (!hasLoaderOptions(use) || !isSwcLoader(use.loader))
76
+ return [];
77
+ return getSwcPluginSpecifiers(use.options);
78
+ };
74
79
  const resolveUseItem = (use) => {
75
80
  if (!use)
76
81
  return [];
@@ -149,7 +154,7 @@ export const findWebpackDependenciesFromConfig = async (config, options) => {
149
154
  if (alias.length > 1)
150
155
  inputs.add(toAlias(alias, prefixes));
151
156
  for (const prefix of prefixes) {
152
- inputs.add(toAlias(addStar(alias), [addStar(toAbsolute(prefix, options.configFileDir))]));
157
+ inputs.add(toAlias(addStar(alias), [addStar(prefix)], { dir: options.configFileDir }));
153
158
  }
154
159
  }
155
160
  }
@@ -22,10 +22,8 @@ const resolveConfig = config => {
22
22
  if (config.packageExtensions) {
23
23
  for (const extension of Object.values(config.packageExtensions)) {
24
24
  if (extension.peerDependencies) {
25
- for (const dep of Object.keys(extension.peerDependencies)) {
26
- const optional = extension.peerDependenciesMeta?.[dep]?.optional === true;
27
- inputs.push(optional ? toDependency(dep, { optional: true }) : toDependency(dep));
28
- }
25
+ for (const dep of Object.keys(extension.peerDependencies))
26
+ inputs.push(toDependency(dep, { optional: true }));
29
27
  }
30
28
  }
31
29
  }
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, cwd }: ReporterOptions): Promise<void>;
3
+ declare function _default({ report, issues, cwd, write }: InternalReporterOptions): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { toRelative } from '../util/path.js';
3
3
  import { flattenIssues, getIssueDescription, getIssuePrefix, getIssueTypeTitle } from './util/util.js';
4
- export default async ({ report, issues, cwd }) => {
4
+ export default async ({ report, issues, cwd, write }) => {
5
5
  const entries = [];
6
6
  for (const [type, isReportType] of Object.entries(report)) {
7
7
  if (!isReportType) {
@@ -33,9 +33,7 @@ export default async ({ report, issues, cwd }) => {
33
33
  }
34
34
  }
35
35
  }
36
- const output = JSON.stringify(entries);
37
- process.stdout._handle?.setBlocking?.(true);
38
- process.stdout.write(`${output}\n`);
36
+ write(JSON.stringify(entries));
39
37
  };
40
38
  function convertSeverity(severity) {
41
39
  switch (severity) {
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, isShowProgress, options, cwd }: ReporterOptions): void;
3
+ declare function _default({ report, issues, isShowProgress, options, cwd, write }: InternalReporterOptions): void;
@@ -1,13 +1,12 @@
1
1
  import { createOwnershipEngine } from '../util/codeowners.js';
2
2
  import { relative, resolve } from '../util/path.js';
3
3
  import { getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
4
- const logIssueRecord = (issues, cwd) => {
4
+ const getIssueRecordLines = (issues, cwd) => {
5
5
  const sortedByFilePath = issues.sort((a, b) => (a.owner < b.owner ? -1 : 1));
6
- for (const { filePath, symbols, owner, parentSymbol } of sortedByFilePath) {
7
- console.log(getIssueLine({ owner, filePath, symbols, parentSymbol }, cwd));
8
- }
6
+ return sortedByFilePath.map(({ filePath, symbols, owner, parentSymbol }) => getIssueLine({ owner, filePath, symbols, parentSymbol }, cwd));
9
7
  };
10
- export default ({ report, issues, isShowProgress, options, cwd }) => {
8
+ export default ({ report, issues, isShowProgress, options, cwd, write }) => {
9
+ const lines = [];
11
10
  let opts = {};
12
11
  try {
13
12
  opts = options ? JSON.parse(options) : opts;
@@ -36,14 +35,15 @@ export default ({ report, issues, isShowProgress, options, cwd }) => {
36
35
  });
37
36
  if (issuesForType.length > 0) {
38
37
  if (totalIssues)
39
- console.log();
40
- title && console.log(getColoredTitle(title, issuesForType.length));
41
- logIssueRecord(issuesForType, cwd);
38
+ lines.push('');
39
+ title && lines.push(getColoredTitle(title, issuesForType.length));
40
+ lines.push(...getIssueRecordLines(issuesForType, cwd));
42
41
  }
43
42
  totalIssues = totalIssues + issuesForType.length;
44
43
  }
45
44
  }
46
45
  if (totalIssues === 0 && isShowProgress) {
47
- console.log('✂️ Excellent, Knip found no issues.');
46
+ lines.push('✂️ Excellent, Knip found no issues.');
48
47
  }
48
+ write(lines.join('\n'));
49
49
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, isShowProgress, cwd }: ReporterOptions): void;
3
+ declare function _default({ report, issues, isShowProgress, cwd, write }: InternalReporterOptions): void;
@@ -1,10 +1,10 @@
1
1
  import { flattenIssues, getColoredTitle, getIssueLine, getIssueTypeTitle } from './util/util.js';
2
- const logIssueRecord = (issues, cwd) => {
2
+ const getIssueRecordLines = (issues, cwd) => {
3
3
  const sortedByFilePath = issues.sort((a, b) => (a.filePath > b.filePath ? 1 : -1));
4
- for (const issue of sortedByFilePath)
5
- console.log(getIssueLine(issue, cwd));
4
+ return sortedByFilePath.map(issue => getIssueLine(issue, cwd));
6
5
  };
7
- export default ({ report, issues, isShowProgress, cwd }) => {
6
+ export default ({ report, issues, isShowProgress, cwd, write }) => {
7
+ const lines = [];
8
8
  let totalIssues = 0;
9
9
  for (const [reportType, isReportType] of Object.entries(report)) {
10
10
  if (isReportType) {
@@ -18,13 +18,14 @@ export default ({ report, issues, isShowProgress, cwd }) => {
18
18
  return { ...items[0], symbols: items };
19
19
  });
20
20
  if (issuesForType.length > 0) {
21
- title && console.log(getColoredTitle(title, issuesForType.length));
22
- logIssueRecord(issuesForType, cwd);
21
+ title && lines.push(getColoredTitle(title, issuesForType.length));
22
+ lines.push(...getIssueRecordLines(issuesForType, cwd));
23
23
  }
24
24
  totalIssues = totalIssues + issuesForType.length;
25
25
  }
26
26
  }
27
27
  if (totalIssues === 0 && isShowProgress) {
28
- console.log('✂️ Excellent, Knip found no issues.');
28
+ lines.push('✂️ Excellent, Knip found no issues.');
29
29
  }
30
+ write(lines.join('\n'));
30
31
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ cwd, issues, isShowProgress }: ReporterOptions): void;
3
+ declare function _default({ cwd, issues, isShowProgress, write }: InternalReporterOptions): void;
@@ -35,14 +35,14 @@ const sortByFilePath = (cwd) => (a, b) => {
35
35
  const rootLocation = getIssueRootLocation(a, cwd).localeCompare(getIssueRootLocation(b, cwd));
36
36
  return rootLocation === 0 ? a.symbol.localeCompare(b.symbol) : rootLocation;
37
37
  };
38
- export default ({ cwd, issues, isShowProgress }) => {
38
+ export default ({ cwd, issues, isShowProgress, write }) => {
39
39
  const cycles = flattenIssues(issues.cycles).sort(sortByFilePath(cwd));
40
40
  if (cycles.length === 0) {
41
41
  if (isShowProgress)
42
- console.log('✂️ No circular dependencies found.');
42
+ write('✂️ No circular dependencies found.');
43
43
  return;
44
44
  }
45
- console.log(getColoredTitle(getIssueTypeTitle('cycles'), cycles.length));
45
+ const lines = [getColoredTitle(getIssueTypeTitle('cycles'), cycles.length)];
46
46
  const rootCounts = new Map();
47
47
  for (const issue of cycles) {
48
48
  const files = issue.symbols ?? issue.symbol.split(' → ').map(symbol => ({ symbol }));
@@ -62,18 +62,19 @@ export default ({ cwd, issues, isShowProgress }) => {
62
62
  if (rootLocation !== previousRoot) {
63
63
  const count = rootCounts.get(rootLocation) ?? 0;
64
64
  const countLabel = count > 1 ? st.dim(` (${count} cycles)`) : '';
65
- console.log(`\n${formatFile(root)}${countLabel}`);
65
+ lines.push(`\n${formatFile(root)}${countLabel}`);
66
66
  previousRoot = rootLocation;
67
67
  }
68
68
  else {
69
- console.log('');
69
+ lines.push('');
70
70
  }
71
71
  for (let depth = 1; depth <= files.length; depth++) {
72
72
  const isClose = depth === files.length;
73
73
  const edge = files[depth - 1];
74
74
  const file = isClose ? root : files[depth];
75
75
  const connector = st.dim(`${' '.repeat(depth - 1)}└── `);
76
- console.log(`${connector}${formatEdge(edge)}${formatFile(file)}${isClose ? st.dim(' ↩') : ''}`);
76
+ lines.push(`${connector}${formatEdge(edge)}${formatFile(file)}${isClose ? st.dim(' ↩') : ''}`);
77
77
  }
78
78
  }
79
+ write(lines.join('\n'));
79
80
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, cwd }: ReporterOptions): void;
3
+ declare function _default({ report, issues, cwd, write }: InternalReporterOptions): void;
@@ -1,15 +1,17 @@
1
1
  import { flattenIssues, getIssueTypeTitle, getTableForType } from './util/util.js';
2
- export default ({ report, issues, cwd }) => {
2
+ export default ({ report, issues, cwd, write }) => {
3
3
  const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
4
+ const lines = [];
4
5
  for (const [reportType, isReportType] of Object.entries(report)) {
5
6
  if (isReportType) {
6
7
  const title = reportMultipleGroups ? getIssueTypeTitle(reportType) : undefined;
7
8
  const issuesForType = flattenIssues(issues[reportType]);
8
9
  if (issuesForType.length > 0) {
9
- console.log(`<details>\n${title ? `<summary>${title} (${issuesForType.length})</summary>\n` : ''}\n\`\`\``);
10
- console.log(getTableForType(issuesForType, cwd, { isUseColors: false }).toString());
11
- console.log('```\n\n</details>\n');
10
+ lines.push(`<details>\n${title ? `<summary>${title} (${issuesForType.length})</summary>\n` : ''}\n\`\`\``);
11
+ lines.push(getTableForType(issuesForType, cwd, { isUseColors: false }).toString());
12
+ lines.push('```\n\n</details>\n');
12
13
  }
13
14
  }
14
15
  }
16
+ write(lines.join('\n'));
15
17
  };
@@ -1,3 +1,3 @@
1
- import type { ReporterOptions } from '../types/issues.ts';
1
+ import type { InternalReporterOptions } from '../types/issues.ts';
2
2
  export default _default;
3
- declare function _default({ report, issues, cwd, configurationHints, tagHints, isDisableConfigHints, isDisableTagHints, isTreatConfigHintsAsErrors, isTreatTagHintsAsErrors, configFilePath, }: ReporterOptions): void;
3
+ declare function _default({ report, issues, cwd, configurationHints, tagHints, isDisableConfigHints, isDisableTagHints, isTreatConfigHintsAsErrors, isTreatTagHintsAsErrors, configFilePath, write, }: InternalReporterOptions): void;
@@ -3,7 +3,7 @@ import { relative } from '../util/path.js';
3
3
  import { compareStrings } from '../util/string.js';
4
4
  import { hintPrinters } from './util/configuration-hints.js';
5
5
  import { flattenIssues, getIssueTypeTitle } from './util/util.js';
6
- const createGitHubActionsLogger = () => {
6
+ const createGitHubActionsLogger = (lines) => {
7
7
  const formatAnnotation = (level, message, options) => {
8
8
  const params = [`file=${options.file}`];
9
9
  if (options.startLine != null)
@@ -16,17 +16,18 @@ const createGitHubActionsLogger = () => {
16
16
  params.push(`endColumn=${options.endColumn}`);
17
17
  params.push(`title=✂️ Knip${options.title ? ` / ${options.title}` : ''}`);
18
18
  const paramString = params.join(',');
19
- console.log(`::${level} ${paramString}::${message}`);
19
+ lines.push(`::${level} ${paramString}::${message}`);
20
20
  };
21
21
  return {
22
- info: (message) => console.log(message),
22
+ info: (message) => lines.push(message),
23
23
  error: (message, options) => formatAnnotation('error', message, options),
24
24
  warning: (message, options) => formatAnnotation('warning', message, options),
25
25
  notice: (message, options) => formatAnnotation('notice', message, options),
26
26
  };
27
27
  };
28
- export default ({ report, issues, cwd, configurationHints, tagHints, isDisableConfigHints, isDisableTagHints, isTreatConfigHintsAsErrors, isTreatTagHintsAsErrors, configFilePath, }) => {
29
- const core = createGitHubActionsLogger();
28
+ export default ({ report, issues, cwd, configurationHints, tagHints, isDisableConfigHints, isDisableTagHints, isTreatConfigHintsAsErrors, isTreatTagHintsAsErrors, configFilePath, write, }) => {
29
+ const lines = [];
30
+ const core = createGitHubActionsLogger(lines);
30
31
  const reportMultipleGroups = Object.values(report).filter(Boolean).length > 1;
31
32
  for (const [reportType, isReportType] of Object.entries(report)) {
32
33
  if (isReportType) {
@@ -111,4 +112,5 @@ export default ({ report, issues, cwd, configurationHints, tagHints, isDisableCo
111
112
  });
112
113
  }
113
114
  }
115
+ write(lines.join('\n'));
114
116
  };