knip 6.42.1 → 6.44.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 (187) hide show
  1. package/dist/CacheConsultant.d.ts +1 -0
  2. package/dist/CacheConsultant.js +2 -0
  3. package/dist/CatalogCounselor.d.ts +1 -3
  4. package/dist/CatalogCounselor.js +18 -15
  5. package/dist/ConfigurationChief.d.ts +42 -0
  6. package/dist/DependencyDeputy.d.ts +2 -1
  7. package/dist/DependencyDeputy.js +9 -4
  8. package/dist/IssueCollector.js +1 -0
  9. package/dist/IssueFixer.js +10 -5
  10. package/dist/ProjectPrincipal.d.ts +3 -2
  11. package/dist/ProjectPrincipal.js +32 -10
  12. package/dist/WorkspaceWorker.d.ts +5 -2
  13. package/dist/WorkspaceWorker.js +35 -17
  14. package/dist/binaries/resolvers/bun.js +1 -0
  15. package/dist/binaries/resolvers/npm.js +12 -2
  16. package/dist/binaries/resolvers/pnpm.js +5 -3
  17. package/dist/binaries/util.js +2 -1
  18. package/dist/cli.js +6 -1
  19. package/dist/compilers/compilers.js +2 -2
  20. package/dist/compilers/index.d.ts +5 -0
  21. package/dist/compilers/index.js +1 -1
  22. package/dist/constants.d.ts +1 -0
  23. package/dist/constants.js +2 -0
  24. package/dist/graph/analyze.js +3 -2
  25. package/dist/graph/build.d.ts +2 -0
  26. package/dist/graph/build.js +37 -22
  27. package/dist/graph-explorer/cache.d.ts +2 -1
  28. package/dist/graph-explorer/cache.js +5 -1
  29. package/dist/graph-explorer/explorer.d.ts +3 -5
  30. package/dist/graph-explorer/explorer.js +24 -3
  31. package/dist/plugins/_vue/auto-import.js +31 -1
  32. package/dist/plugins/biome/index.js +1 -1
  33. package/dist/plugins/buf/index.d.ts +3 -0
  34. package/dist/plugins/buf/index.js +33 -0
  35. package/dist/plugins/buf/types.d.ts +8 -0
  36. package/dist/plugins/buf/types.js +1 -0
  37. package/dist/plugins/cspell/index.js +1 -0
  38. package/dist/plugins/dependency-cruiser/index.js +2 -2
  39. package/dist/plugins/docusaurus/helpers.js +4 -4
  40. package/dist/plugins/electron-forge/index.d.ts +3 -0
  41. package/dist/plugins/electron-forge/index.js +94 -0
  42. package/dist/plugins/electron-vite/index.js +2 -2
  43. package/dist/plugins/eslint/helpers.d.ts +1 -0
  44. package/dist/plugins/eslint/helpers.js +1 -1
  45. package/dist/plugins/eslint/resolveFromAST.js +35 -10
  46. package/dist/plugins/expo/helpers.d.ts +1 -1
  47. package/dist/plugins/expo/helpers.js +15 -8
  48. package/dist/plugins/expo/types.d.ts +2 -1
  49. package/dist/plugins/expressive-code/index.d.ts +1 -1
  50. package/dist/plugins/expressive-code/index.js +2 -2
  51. package/dist/plugins/gatsby/index.js +6 -6
  52. package/dist/plugins/gatsby/types.d.ts +1 -1
  53. package/dist/plugins/github-actions/index.js +1 -1
  54. package/dist/plugins/i18next-parser/index.js +2 -2
  55. package/dist/plugins/index.d.ts +8 -1
  56. package/dist/plugins/index.js +14 -0
  57. package/dist/plugins/jasmine/index.js +2 -2
  58. package/dist/plugins/karma/index.js +4 -4
  59. package/dist/plugins/kysely-codegen/index.d.ts +3 -0
  60. package/dist/plugins/kysely-codegen/index.js +20 -0
  61. package/dist/plugins/lefthook/index.js +2 -2
  62. package/dist/plugins/lingui/index.d.ts +3 -0
  63. package/dist/plugins/lingui/index.js +16 -0
  64. package/dist/plugins/lockfile-lint/index.js +2 -2
  65. package/dist/plugins/lost-pixel/index.js +2 -2
  66. package/dist/plugins/lunaria/index.js +2 -2
  67. package/dist/plugins/marko/index.js +5 -6
  68. package/dist/plugins/mastra/index.d.ts +3 -0
  69. package/dist/plugins/mastra/index.js +57 -0
  70. package/dist/plugins/mcp/index.d.ts +3 -0
  71. package/dist/plugins/mcp/index.js +33 -0
  72. package/dist/plugins/mcp/types.d.ts +11 -0
  73. package/dist/plugins/mcp/types.js +1 -0
  74. package/dist/plugins/mise/index.js +0 -3
  75. package/dist/plugins/mocha/index.js +42 -3
  76. package/dist/plugins/mocha/types.d.ts +1 -0
  77. package/dist/plugins/next/index.d.ts +3 -0
  78. package/dist/plugins/next/index.js +57 -9
  79. package/dist/plugins/next/types.d.ts +11 -0
  80. package/dist/plugins/next/types.js +1 -0
  81. package/dist/plugins/nx/index.js +3 -8
  82. package/dist/plugins/nyc/index.js +1 -1
  83. package/dist/plugins/openapi-ts/index.js +2 -2
  84. package/dist/plugins/oxfmt/index.js +2 -2
  85. package/dist/plugins/playwright/index.js +6 -11
  86. package/dist/plugins/pnpm/index.js +2 -4
  87. package/dist/plugins/purgecss/index.d.ts +3 -0
  88. package/dist/plugins/purgecss/index.js +16 -0
  89. package/dist/plugins/railway/index.js +1 -4
  90. package/dist/plugins/remix/index.js +1 -1
  91. package/dist/plugins/rstest/index.js +2 -2
  92. package/dist/plugins/serverless-framework/index.js +1 -1
  93. package/dist/plugins/storybook/index.js +5 -5
  94. package/dist/plugins/sveltekit/resolveFromAST.js +1 -1
  95. package/dist/plugins/syncpack/index.js +2 -2
  96. package/dist/plugins/tailwind/compiler.js +6 -2
  97. package/dist/plugins/tanstack-router/index.js +3 -2
  98. package/dist/plugins/taskfile/index.js +4 -7
  99. package/dist/plugins/textlint/helpers.js +2 -2
  100. package/dist/plugins/travis/index.js +2 -2
  101. package/dist/plugins/typescript/index.js +9 -7
  102. package/dist/plugins/unocss/index.js +2 -2
  103. package/dist/plugins/vite-plugin-pwa/index.js +1 -4
  104. package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +0 -2
  105. package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +2 -2
  106. package/dist/plugins/vite-pwa-assets-generator/index.js +2 -2
  107. package/dist/plugins/vitest/helpers.d.ts +1 -1
  108. package/dist/plugins/vitest/helpers.js +17 -10
  109. package/dist/plugins/vitest/index.js +53 -45
  110. package/dist/plugins/vitest/types.d.ts +11 -7
  111. package/dist/plugins/webpack/index.js +4 -2
  112. package/dist/plugins/yarn/index.js +2 -4
  113. package/dist/reporters/codeclimate.d.ts +2 -2
  114. package/dist/reporters/codeclimate.js +2 -4
  115. package/dist/reporters/codeowners.d.ts +2 -2
  116. package/dist/reporters/codeowners.js +9 -9
  117. package/dist/reporters/compact.d.ts +2 -2
  118. package/dist/reporters/compact.js +8 -7
  119. package/dist/reporters/cycles.d.ts +2 -2
  120. package/dist/reporters/cycles.js +7 -6
  121. package/dist/reporters/disclosure.d.ts +2 -2
  122. package/dist/reporters/disclosure.js +6 -4
  123. package/dist/reporters/github-actions.d.ts +2 -2
  124. package/dist/reporters/github-actions.js +7 -5
  125. package/dist/reporters/index.d.ts +10 -10
  126. package/dist/reporters/json.d.ts +2 -2
  127. package/dist/reporters/json.js +2 -4
  128. package/dist/reporters/markdown.d.ts +2 -2
  129. package/dist/reporters/markdown.js +11 -9
  130. package/dist/reporters/sarif.d.ts +2 -2
  131. package/dist/reporters/sarif.js +2 -3
  132. package/dist/reporters/symbols.d.ts +2 -2
  133. package/dist/reporters/symbols.js +6 -4
  134. package/dist/run.d.ts +1 -1
  135. package/dist/run.js +3 -10
  136. package/dist/schema/configuration.d.ts +105 -0
  137. package/dist/schema/plugins.d.ts +35 -0
  138. package/dist/schema/plugins.js +7 -0
  139. package/dist/session/configuration.d.ts +12 -0
  140. package/dist/session/configuration.js +43 -0
  141. package/dist/session/incremental.d.ts +54 -0
  142. package/dist/session/incremental.js +49 -0
  143. package/dist/session/session.d.ts +1 -1
  144. package/dist/session/session.js +62 -27
  145. package/dist/session/watch.d.ts +2 -0
  146. package/dist/session/watch.js +41 -0
  147. package/dist/types/PluginNames.d.ts +2 -2
  148. package/dist/types/PluginNames.js +7 -0
  149. package/dist/types/config.d.ts +2 -0
  150. package/dist/types/issues.d.ts +4 -0
  151. package/dist/types/package-json.d.ts +0 -3
  152. package/dist/typescript/ast-nodes.js +3 -3
  153. package/dist/typescript/get-imports-and-exports.js +2 -0
  154. package/dist/typescript/visitors/calls.js +15 -11
  155. package/dist/typescript/visitors/exports.js +5 -4
  156. package/dist/typescript/visitors/imports.d.ts +2 -1
  157. package/dist/typescript/visitors/imports.js +25 -19
  158. package/dist/typescript/visitors/members.js +23 -26
  159. package/dist/typescript/visitors/walk.d.ts +3 -0
  160. package/dist/typescript/visitors/walk.js +55 -3
  161. package/dist/util/cli-arguments.d.ts +2 -1
  162. package/dist/util/cli-arguments.js +3 -0
  163. package/dist/util/create-input-handler.js +1 -1
  164. package/dist/util/create-options.d.ts +72 -1
  165. package/dist/util/create-options.js +13 -2
  166. package/dist/util/file-entry-cache.d.ts +2 -0
  167. package/dist/util/file-entry-cache.js +19 -1
  168. package/dist/util/gitignore-cache.d.ts +1 -0
  169. package/dist/util/gitignore-cache.js +1 -0
  170. package/dist/util/glob-core.js +4 -2
  171. package/dist/util/glob.d.ts +1 -0
  172. package/dist/util/glob.js +6 -0
  173. package/dist/util/input.d.ts +2 -0
  174. package/dist/util/loader.d.ts +1 -0
  175. package/dist/util/loader.js +38 -2
  176. package/dist/util/modules.js +5 -2
  177. package/dist/util/path.d.ts +1 -0
  178. package/dist/util/path.js +1 -0
  179. package/dist/util/remove-export.js +3 -1
  180. package/dist/util/reporter.d.ts +1 -1
  181. package/dist/util/reporter.js +53 -9
  182. package/dist/util/watch.d.ts +5 -11
  183. package/dist/util/watch.js +84 -68
  184. package/dist/version.d.ts +1 -1
  185. package/dist/version.js +1 -1
  186. package/package.json +4 -4
  187. package/schema.json +28 -0
@@ -89,6 +89,7 @@ const commands = [
89
89
  'with',
90
90
  ];
91
91
  const recursiveCommands = ['recursive', 'multi', 'm'];
92
+ const testAliases = new Set(['t', 'tst']);
92
93
  export const resolve = (_binary, words, options) => {
93
94
  const parseOptions = {
94
95
  isStorePositions: true,
@@ -120,16 +121,17 @@ export const resolve = (_binary, words, options) => {
120
121
  if (parsed.filter && !parsed.recursive)
121
122
  return [];
122
123
  const childInputs = parsed['--'] && parsed['--'].length > 0 ? fromArgs(argsAfter(words, '--'), { isForwardedArgs: true }) : [];
123
- if (command === 'run') {
124
+ if (command === 'run' || command === 'run-script') {
124
125
  const script = parsed._[1];
125
126
  if (script && manifest.scriptNames.has(script)) {
126
127
  return expandScript(script, argsAfter(words, script), manifest.scripts, options) ?? childInputs;
127
128
  }
128
129
  return childInputs;
129
130
  }
130
- const isScript = manifest.scriptNames.has(command);
131
+ const name = testAliases.has(command) ? 'test' : command;
132
+ const isScript = manifest.scriptNames.has(name);
131
133
  if (isScript)
132
- return expandScript(command, argsAfter(words, command), manifest.scripts, options) ?? childInputs;
134
+ return expandScript(name, argsAfter(words, command), manifest.scripts, options) ?? childInputs;
133
135
  if (commands.includes(command))
134
136
  return childInputs;
135
137
  return command && isValidBinary(command) ? [toBinary(command)] : [];
@@ -48,7 +48,8 @@ export const expandScript = (name, forwardedArgs, scripts, options, opts = {}) =
48
48
  if (expandedScripts.has(name))
49
49
  return;
50
50
  expandedScripts.add(name);
51
- return options.fromArgs([source, ...forwardedArgs], { ...opts, expandedScripts });
51
+ const cwd = options.manifestDir ?? options.cwd;
52
+ return options.fromArgs([source, ...forwardedArgs], { cwd, manifestDir: undefined, ...opts, expandedScripts });
52
53
  };
53
54
  export const parseNodeArgs = (args) => parseArgs(args, {
54
55
  string: ['r'],
package/dist/cli.js CHANGED
@@ -9,6 +9,7 @@ import { createPreprocessor, toReporterOptions } from './util/preprocessor.js';
9
9
  import { runReporters } from './util/reporter.js';
10
10
  import { prettyMilliseconds } from './util/string.js';
11
11
  import { version } from './version.js';
12
+ import { watchSession } from './session/watch.js';
12
13
  let args = {};
13
14
  try {
14
15
  args = parseArgs();
@@ -32,6 +33,10 @@ const main = async () => {
32
33
  process.exit(0);
33
34
  }
34
35
  const options = await createOptions({ args });
36
+ if (options.isWatch) {
37
+ await watchSession(options);
38
+ return;
39
+ }
35
40
  const { results } = await run(options);
36
41
  if (options.isWatch || options.isTrace)
37
42
  return;
@@ -39,7 +44,7 @@ const main = async () => {
39
44
  const finalData = await preprocess(toReporterOptions(options, results, args));
40
45
  if (options.isFix)
41
46
  await fix(finalData.issues, finalData.counters, options);
42
- await runReporters(args.reporter ?? ['symbols'], finalData);
47
+ await runReporters(args.reporter ?? ['symbols'], args['output-file'] ?? [], finalData);
43
48
  const totalErrorCount = Object.keys(finalData.report)
44
49
  .filter(reportGroup => finalData.report[reportGroup] && options.rules[reportGroup] === 'error')
45
50
  .reduce((errorCount, reportGroup) => errorCount + finalData.counters[reportGroup], 0);
@@ -1,7 +1,7 @@
1
1
  export const fencedCodeBlockMatcher = /```[\s\S]*?```/g;
2
2
  export const inlineCodeMatcher = /`[^`]+`/g;
3
- export const scriptExtractor = /<script\b((?:[^>"']|"[^"]*"|'[^']*')*)(?<!\/)>([\s\S]*?)<\/script>/gi;
4
- export const styleExtractor = /<style\b((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/style>/gi;
3
+ export const scriptExtractor = /<script(?=[\s/>])((?:[^>"']|"[^"]*"|'[^']*')*)(?<!\/)>([\s\S]*?)<\/script>/gi;
4
+ export const styleExtractor = /<style(?![\w-])((?:[^>"']|"[^"]*"|'[^']*')*)>([\s\S]*?)<\/style>/gi;
5
5
  const langAttrMatcher = /\blang\s*=\s*["']([^"']+)["']/i;
6
6
  export const blockCommentMatcher = /\/\*[\s\S]*?\*\//g;
7
7
  export const lineCommentMatcher = /^[ \t]*\/\/.*$/gm;
@@ -3,4 +3,9 @@ import type { DependencySet } from '../types/workspace.ts';
3
3
  import type { Compilers, RawCompilers } from './types.ts';
4
4
  export declare const normalizeCompilerExtension: (ext: string) => string;
5
5
  export declare const normalizeCompilers: (rawLocalConfig: RawConfiguration) => RawCompilers;
6
+ export declare const builtInCompilers: {
7
+ dependencies: string[];
8
+ compiler: import("./types.ts").CompilerSync;
9
+ extensions: string[];
10
+ }[];
6
11
  export declare const getIncludedCompilers: (rawCompilers: RawCompilers, dependencies: DependencySet, onReferencedDependency?: (packageName: string) => void) => Compilers;
@@ -18,7 +18,7 @@ export const normalizeCompilers = (rawLocalConfig) => {
18
18
  }
19
19
  return compilers;
20
20
  };
21
- const builtInCompilers = [
21
+ export const builtInCompilers = [
22
22
  { extensions: ['.mdx'], ...MDX },
23
23
  { extensions: ['.sass', '.scss'], ...SCSS },
24
24
  { extensions: ['.less'], ...LESS },
@@ -69,4 +69,5 @@ export declare const IMPORT_FLAGS: {
69
69
  readonly AUGMENT: number;
70
70
  readonly DYNAMIC: number;
71
71
  readonly LOADER: number;
72
+ readonly CAUGHT: number;
72
73
  };
package/dist/constants.js CHANGED
@@ -101,6 +101,7 @@ export const IGNORED_GLOBAL_BINARIES = new Set([
101
101
  'nub',
102
102
  'nubx',
103
103
  'open',
104
+ 'osascript',
104
105
  'paste',
105
106
  'pnpm',
106
107
  'pnpx',
@@ -277,4 +278,5 @@ export const IMPORT_FLAGS = {
277
278
  AUGMENT: 1 << 7,
278
279
  DYNAMIC: 1 << 8,
279
280
  LOADER: 1 << 9,
281
+ CAUGHT: 1 << 10,
280
282
  };
@@ -7,7 +7,7 @@ import { relative } from '../util/path.js';
7
7
  import { perfObserver, timerify } from '../util/Performance.js';
8
8
  import { findMatch } from '../util/regex.js';
9
9
  import { getShouldIgnoreHandler, getShouldIgnoreTagHandler, hasTag, isAlwaysIgnored } from '../util/tag.js';
10
- import { INTERNAL_TAG } from '../constants.js';
10
+ import { IMPORT_FLAGS, INTERNAL_TAG } from '../constants.js';
11
11
  const toCyclePathKey = (path) => {
12
12
  const length = path.length > 1 && path[0] === path[path.length - 1] ? path.length - 1 : path.length;
13
13
  return path.slice(0, length).join('\0');
@@ -25,7 +25,7 @@ const isAllowedCycle = (symbols, paths) => paths?.has(toCyclePathKey(symbols.map
25
25
  export const analyze = async ({ analyzedFiles, counselor, chief, collector, deputy, entryPaths, graph, streamer, unreferencedFiles, options, }) => {
26
26
  const shouldIgnore = getShouldIgnoreHandler(options.isProduction);
27
27
  const shouldIgnoreTags = getShouldIgnoreTagHandler(options.tags);
28
- const explorer = createGraphExplorer(graph, entryPaths);
28
+ const explorer = createGraphExplorer(graph, entryPaths, options.isSession);
29
29
  const isReferencedInUsedExport = (exportedItem, filePath, includeEntryExports, ignoreExportsUsedInFile, visited) => {
30
30
  if (!exportedItem.referencedIn)
31
31
  return false;
@@ -230,6 +230,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
230
230
  specifier: extImport.specifier,
231
231
  isTypeOnly: extImport.isTypeOnly,
232
232
  isResolved: extImport.filePath !== undefined,
233
+ isCaught: !!(extImport.modifiers & IMPORT_FLAGS.CAUGHT),
233
234
  });
234
235
  if (!isHandled && !(extImport.jsDocTags?.size && shouldIgnoreTags(extImport.jsDocTags)))
235
236
  collector.addIssue({
@@ -7,6 +7,7 @@ import type { IssueCollector } from '../IssueCollector.ts';
7
7
  import type { ProjectPrincipal } from '../ProjectPrincipal.ts';
8
8
  import type { ModuleGraph } from '../types/module-graph.ts';
9
9
  import type { MainOptions } from '../util/create-options.ts';
10
+ import { ConfigurationFiles } from '../session/configuration.ts';
10
11
  interface BuildOptions {
11
12
  chief: ConfigurationChief;
12
13
  collector: IssueCollector;
@@ -21,6 +22,7 @@ interface BuildOptions {
21
22
  }
22
23
  export declare function build({ chief, collector, counselor, deputy, principal, isGitIgnored, scriptParserContext, streamer, workspaces, options, }: BuildOptions): Promise<{
23
24
  graph: ModuleGraph;
25
+ configurationFiles: ConfigurationFiles | undefined;
24
26
  entryPaths: Set<string>;
25
27
  analyzedFiles: Set<string>;
26
28
  unreferencedFiles: Set<string>;
@@ -4,12 +4,13 @@ import { getIncludedCompilers, normalizeCompilerExtension } from '../compilers/i
4
4
  import { DEFAULT_EXTENSIONS, FOREIGN_FILE_EXTENSIONS, IS_DTS, ROOT_WORKSPACE_NAME } from '../constants.js';
5
5
  import { partition } from '../util/array.js';
6
6
  import { createInputHandler } from '../util/create-input-handler.js';
7
+ import { ConfigurationFiles } from '../session/configuration.js';
7
8
  import { debugLog, debugLogArray } from '../util/debug.js';
8
9
  import { existsSync } from 'node:fs';
9
10
  import picomatch from 'picomatch';
10
11
  import { tryRealpath } from '../util/fs.js';
11
12
  import { createManifest } from '../util/package-json.js';
12
- import { _glob, _syncGlob, prependDirToPattern as prependDir, removeProductionSuffix } from '../util/glob.js';
13
+ import { _glob, _syncGlob, prependDirToPattern as prependDir, rebasePattern, removeProductionSuffix, } from '../util/glob.js';
13
14
  import { isAlias, isCatalog, isConfig, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isIgnore, isProductionEntry, isProject, toDeferResolveEntry, toDependency, toProductionEntry, } from '../util/input.js';
14
15
  import { isAmbientDeclarationFile } from '../typescript/ast-nodes.js';
15
16
  import { resolveImportGlobs } from '../typescript/glob-imports.js';
@@ -26,10 +27,11 @@ import { augmentWorkspace, getToSourcePathsHandler, toSourceMappedSpecifiers } f
26
27
  import { WorkspaceWorker } from '../WorkspaceWorker.js';
27
28
  export async function build({ chief, collector, counselor, deputy, principal, isGitIgnored, scriptParserContext, streamer, workspaces, options, }) {
28
29
  const configFilesMap = new Map();
30
+ const configurationFiles = options.isSession ? new ConfigurationFiles(options) : undefined;
29
31
  const enabledPluginsStore = new Map();
30
32
  const registeredVisitorPlugins = new Set();
31
33
  const toSourceFilePaths = getToSourcePathsHandler(chief);
32
- const addIssue = (issue) => collector.addIssue(issue) && options.isWatch && collector.retainIssue(issue);
34
+ const addIssue = (issue) => collector.addIssue(issue) && options.isSession && collector.retainIssue(issue);
33
35
  const externalRefsFromInputs = options.isSession ? new Map() : undefined;
34
36
  const handleInput = createInputHandler(deputy, chief, isGitIgnored, addIssue, externalRefsFromInputs, options);
35
37
  const getPublishedTypeDependencies = options.isReportDependencies
@@ -79,6 +81,8 @@ export async function build({ chief, collector, counselor, deputy, principal, is
79
81
  continue;
80
82
  const dependencies = deputy.getDependencies(name);
81
83
  const tsConfigFilePath = join(dir, options.tsConfigFile ?? 'tsconfig.json');
84
+ configurationFiles?.paths.add(filePath);
85
+ configurationFiles?.paths.add(tsConfigFilePath);
82
86
  const { isFile, compilerOptions, fileNames, include, exclude, sourceMapPairs, paths: tsConfigPaths, } = await loadTSConfig(tsConfigFilePath, options.isUseTscFiles);
83
87
  const [definitionPaths, tscSourcePaths] = partition(fileNames, filePath => IS_DTS.test(filePath));
84
88
  const worker = new WorkspaceWorker({
@@ -97,6 +101,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
97
101
  enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
98
102
  readRawFile: (filePath) => principal.fileManager.readRawFile(filePath) ?? '',
99
103
  configFilesMap,
104
+ configurationFiles,
100
105
  options,
101
106
  });
102
107
  await worker.init();
@@ -189,32 +194,42 @@ export async function build({ chief, collector, counselor, deputy, principal, is
189
194
  });
190
195
  const DEFAULT_GROUP = 'default';
191
196
  const createPatternMap = () => new Map([[DEFAULT_GROUP, new Set()]]);
192
- const groups = new Set([DEFAULT_GROUP]);
197
+ const groups = new Map([[DEFAULT_GROUP, undefined]]);
193
198
  const entryPatterns = createPatternMap();
194
199
  const entryPatternsSkipExports = createPatternMap();
195
200
  const productionPatterns = createPatternMap();
196
201
  const productionPatternsSkipExports = createPatternMap();
197
202
  const projectFilePatterns = new Set();
198
- const addPattern = (map, input, pattern) => {
199
- if (input.group && !map.has(input.group))
200
- map.set(input.group, new Set());
201
- map.get(input.group ?? DEFAULT_GROUP).add(pattern);
203
+ const addPattern = (map, group, pattern) => {
204
+ let patterns = map.get(group);
205
+ if (!patterns)
206
+ map.set(group, (patterns = new Set()));
207
+ patterns.add(pattern);
202
208
  };
203
209
  const toWorkspaceRelative = (path) => (isAbsolute(path) ? relative(dir, path) : path);
210
+ const addEntryPattern = (map, input) => {
211
+ const base = input.dir;
212
+ if (base && base !== dir) {
213
+ const group = `${input.group ?? DEFAULT_GROUP}:${base}`;
214
+ groups.set(group, base);
215
+ addPattern(map, group, rebasePattern(input.specifier, base, dir));
216
+ }
217
+ else {
218
+ addPattern(map, input.group ?? DEFAULT_GROUP, toWorkspaceRelative(input.specifier));
219
+ }
220
+ };
204
221
  for (const input of inputs) {
205
222
  if (input.group)
206
- groups.add(input.group);
223
+ groups.set(input.group, undefined);
207
224
  const specifier = input.specifier;
208
225
  if (isCatalog(input)) {
209
226
  counselor.addReference({ catalogName: input.catalogName, packageName: specifier });
210
227
  }
211
228
  else if (isEntry(input)) {
212
- const targetMap = input.skipExportsAnalysis ? entryPatternsSkipExports : entryPatterns;
213
- addPattern(targetMap, input, toWorkspaceRelative(specifier));
229
+ addEntryPattern(input.skipExportsAnalysis ? entryPatternsSkipExports : entryPatterns, input);
214
230
  }
215
231
  else if (isProductionEntry(input)) {
216
- const targetMap = input.skipExportsAnalysis ? productionPatternsSkipExports : productionPatterns;
217
- addPattern(targetMap, input, toWorkspaceRelative(specifier));
232
+ addEntryPattern(input.skipExportsAnalysis ? productionPatternsSkipExports : productionPatterns, input);
218
233
  }
219
234
  else if (isProject(input)) {
220
235
  projectFilePatterns.add(toWorkspaceRelative(specifier));
@@ -239,7 +254,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
239
254
  if (resolvedFilePath) {
240
255
  if (isDeferResolveEntry(input) && options.isProduction && !isDeferResolveProductionEntry(input)) {
241
256
  if (!input.optional)
242
- addPattern(entryPatternsSkipExports, input, resolvedFilePath);
257
+ addPattern(entryPatternsSkipExports, input.group ?? DEFAULT_GROUP, resolvedFilePath);
243
258
  }
244
259
  else {
245
260
  principal.addEntryPath(resolvedFilePath, { skipExportsAnalysis: true });
@@ -278,13 +293,9 @@ export async function build({ chief, collector, counselor, deputy, principal, is
278
293
  gitignore: false,
279
294
  label: 'entry paths',
280
295
  });
281
- for (const group of groups) {
296
+ for (const [group, base] of groups) {
282
297
  {
283
- const patterns = worker.getPluginEntryFilePatterns([
284
- ...((!options.isProduction && entryPatterns.get(group)) || []),
285
- ...((!options.isProduction && group === DEFAULT_GROUP && worker.getPluginConfigPatterns()) || []),
286
- ...(productionPatterns.get(group) ?? []),
287
- ]);
298
+ const patterns = worker.getPluginEntryFilePatterns([...((!options.isProduction && entryPatterns.get(group)) || []), ...(productionPatterns.get(group) ?? [])], base);
288
299
  const label = `entry paths from plugins${group !== DEFAULT_GROUP ? ` - ${group}` : ''}`;
289
300
  const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, label });
290
301
  principal.addEntryPaths(productionPaths(pluginWorkspaceEntryPaths));
@@ -293,7 +304,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
293
304
  const patterns = worker.getPluginEntryFilePatterns([
294
305
  ...((!options.isProduction && entryPatternsSkipExports.get(group)) || []),
295
306
  ...(productionPatternsSkipExports.get(group) ?? []),
296
- ]);
307
+ ], base);
297
308
  const label = `entry paths from plugins (ignore exports)${group !== DEFAULT_GROUP ? ` - ${group}` : ''}`;
298
309
  const pluginWorkspaceEntryPaths = await _glob({ ...sharedGlobOptions, patterns, label });
299
310
  principal.addEntryPaths(pluginWorkspaceEntryPaths, { skipExportsAnalysis: true });
@@ -368,7 +379,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
368
379
  tags: options.tags,
369
380
  };
370
381
  const analyzeSourceFile = (filePath, sourceText, parseResult, cachedFile) => {
371
- if (!options.isWatch && !options.isSession && analyzedFiles.has(filePath))
382
+ if (!options.isSession && analyzedFiles.has(filePath))
372
383
  return;
373
384
  analyzedFiles.add(filePath);
374
385
  const workspace = chief.findWorkspaceByFilePath(filePath);
@@ -433,6 +444,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
433
444
  const dir = dirname(filePath);
434
445
  const opts = {
435
446
  cwd: dir,
447
+ manifestDir: workspace.dir,
436
448
  rootCwd: options.cwd,
437
449
  containingFilePath: filePath,
438
450
  dependencies,
@@ -448,6 +460,8 @@ export async function build({ chief, collector, counselor, deputy, principal, is
448
460
  }
449
461
  input.containingFilePath ??= filePath;
450
462
  input.dir ??= dir;
463
+ if (options.isProduction)
464
+ input.production = true;
451
465
  const specifierFilePath = handleInput(input, workspace);
452
466
  if (specifierFilePath)
453
467
  principal.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
@@ -515,7 +529,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
515
529
  }
516
530
  for (const filePath of principal.entryPaths)
517
531
  entryPaths.add(filePath);
518
- principal.reconcileCache(graph);
532
+ principal.reconcileCache();
519
533
  perfObserver.addMemoryMark('build');
520
534
  if (externalRefsFromInputs) {
521
535
  for (const [filePath, refs] of externalRefsFromInputs) {
@@ -527,6 +541,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
527
541
  }
528
542
  return {
529
543
  graph,
544
+ configurationFiles,
530
545
  entryPaths,
531
546
  analyzedFiles,
532
547
  unreferencedFiles,
@@ -2,7 +2,8 @@ import type { ModuleGraph } from '../types/module-graph.ts';
2
2
  import type { UsageResult } from './operations/get-usage.ts';
3
3
  import type { DefinitionResult } from './operations/resolve-definition.ts';
4
4
  import type { ExportTableCache } from './operations/resolve-export-origins.ts';
5
- export declare const invalidateCache: (graph: ModuleGraph) => void;
5
+ export declare const getTopologyGeneration: (graph: ModuleGraph) => number;
6
+ export declare const invalidateCache: (graph: ModuleGraph, topologyUnchanged?: boolean) => void;
6
7
  export declare const getCachedDefinition: (graph: ModuleGraph, filePath: string, identifier: string) => DefinitionResult | null | undefined;
7
8
  export declare const setCachedDefinition: (graph: ModuleGraph, filePath: string, identifier: string, result: DefinitionResult | null) => void;
8
9
  export declare const getCachedUsage: (graph: ModuleGraph, filePath: string, identifier: string) => UsageResult | undefined;
@@ -6,6 +6,7 @@ const createEmptyCache = () => ({
6
6
  exportedIdentifiers: new Map(),
7
7
  exportTables: new Map(),
8
8
  generation: 0,
9
+ topologyGeneration: 0,
9
10
  });
10
11
  const getCache = (graph) => {
11
12
  let cache = caches.get(graph);
@@ -15,7 +16,8 @@ const getCache = (graph) => {
15
16
  }
16
17
  return cache;
17
18
  };
18
- export const invalidateCache = (graph) => {
19
+ export const getTopologyGeneration = (graph) => getCache(graph).topologyGeneration;
20
+ export const invalidateCache = (graph, topologyUnchanged = false) => {
19
21
  const cache = caches.get(graph);
20
22
  if (cache) {
21
23
  cache.definitions.clear();
@@ -24,6 +26,8 @@ export const invalidateCache = (graph) => {
24
26
  cache.exportedIdentifiers.clear();
25
27
  cache.exportTables.clear();
26
28
  cache.generation++;
29
+ if (!topologyUnchanged)
30
+ cache.topologyGeneration++;
27
31
  }
28
32
  };
29
33
  export const getCachedDefinition = (graph, filePath, identifier) => {
@@ -1,9 +1,7 @@
1
1
  import type { ModuleGraph } from '../types/module-graph.ts';
2
- export declare const createGraphExplorer: (graph: ModuleGraph, entryPaths: Set<string>) => {
3
- isReferenced: (filePath: string, identifier: string, options: {
4
- traverseEntries: boolean;
5
- treatStarAtEntryAsReferenced?: boolean;
6
- }) => readonly [false, string | undefined, Set<string> | undefined];
2
+ import { isReferenced } from './operations/is-referenced.ts';
3
+ export declare const createGraphExplorer: (graph: ModuleGraph, entryPaths: Set<string>, cacheUsage?: boolean) => {
4
+ isReferenced: (filePath: string, identifier: string, options: Parameters<typeof isReferenced>[4]) => readonly [false, string | undefined, Set<string> | undefined];
7
5
  hasStrictlyNsReferences: (filePath: string, identifier: string) => [boolean, (string | undefined)?];
8
6
  isEnumerated: (filePath: string, identifier: string) => boolean;
9
7
  buildExportsTree: (options: {
@@ -1,4 +1,4 @@
1
- import { invalidateCache as invalidateCacheInternal } from './cache.js';
1
+ import { getTopologyGeneration, invalidateCache as invalidateCacheInternal } from './cache.js';
2
2
  import { buildExportsTree } from './operations/build-exports-tree.js';
3
3
  import { findAllCycles } from './operations/find-all-cycles.js';
4
4
  import { findCycles } from './operations/find-cycles.js';
@@ -10,9 +10,30 @@ import { isEnumerated } from './operations/is-enumerated.js';
10
10
  import { isReferenced } from './operations/is-referenced.js';
11
11
  import { resolveDefinition } from './operations/resolve-definition.js';
12
12
  import { resolveExportOrigins } from './operations/resolve-export-origins.js';
13
- export const createGraphExplorer = (graph, entryPaths) => {
13
+ export const createGraphExplorer = (graph, entryPaths, cacheUsage = false) => {
14
+ const references = new Map();
15
+ let generation = getTopologyGeneration(graph);
16
+ const reference = (filePath, identifier, options) => {
17
+ if (!cacheUsage)
18
+ return isReferenced(graph, entryPaths, filePath, identifier, options);
19
+ const current = getTopologyGeneration(graph);
20
+ if (current !== generation) {
21
+ references.clear();
22
+ generation = current;
23
+ }
24
+ let file = references.get(filePath);
25
+ if (!file)
26
+ references.set(filePath, (file = new Map()));
27
+ const key = `${options.traverseEntries ? 1 : 0}${options.treatStarAtEntryAsReferenced ? 1 : 0}:${identifier}`;
28
+ const cached = file.get(key);
29
+ if (cached)
30
+ return cached;
31
+ const result = isReferenced(graph, entryPaths, filePath, identifier, options);
32
+ file.set(key, result);
33
+ return result;
34
+ };
14
35
  return {
15
- isReferenced: (filePath, identifier, options) => isReferenced(graph, entryPaths, filePath, identifier, options),
36
+ isReferenced: reference,
16
37
  hasStrictlyNsReferences: (filePath, identifier) => hasStrictlyNsReferences(graph, filePath, graph.get(filePath)?.importedBy, identifier),
17
38
  isEnumerated: (filePath, identifier) => isEnumerated(graph, filePath, graph.get(filePath)?.importedBy, identifier),
18
39
  buildExportsTree: (options) => buildExportsTree(graph, entryPaths, options),
@@ -250,9 +250,36 @@ const getImportedComponentImports = (maps, names) => {
250
250
  }
251
251
  return imports;
252
252
  };
253
+ const srcBlockMatcher = /<!--[\s\S]*?-->|<(script|style)(?=[\s/>])((?:[^>"']|"[^"]*"|'[^']*')*?)(?:\/>|>[\s\S]*?<\/\1\s*>)/g;
254
+ const attributeMatcher = /([^\s=/>]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
255
+ const getSrc = (attrs) => {
256
+ for (const [, name, double, single, unquoted] of attrs.matchAll(attributeMatcher)) {
257
+ if (name === 'src')
258
+ return double ?? single ?? unquoted;
259
+ }
260
+ };
261
+ const getSrcImports = (source) => {
262
+ if (!source.includes('src'))
263
+ return '';
264
+ const imports = [];
265
+ for (const [, tag, attrs] of source.matchAll(srcBlockMatcher)) {
266
+ const src = tag && getSrc(attrs);
267
+ if (!src)
268
+ continue;
269
+ const specifier = JSON.stringify(src);
270
+ if (tag === 'script') {
271
+ imports.push(`import _sfc_main from ${specifier};\nexport * from ${specifier};\nexport default _sfc_main;`);
272
+ }
273
+ else
274
+ imports.push(`import ${specifier};`);
275
+ }
276
+ return imports.join('\n');
277
+ };
253
278
  const compileVueSfc = (source, path, maps, root) => {
254
279
  if (maps.importMap.size === 0 && maps.componentMap.size === 0) {
255
- return [scriptBodies(source, path), stylePreprocessorImports(source, path)].filter(Boolean).join(';\n');
280
+ return [scriptBodies(source, path), getSrcImports(source), stylePreprocessorImports(source, path)]
281
+ .filter(Boolean)
282
+ .join(';\n');
256
283
  }
257
284
  const sfc = sfcForRoot(root);
258
285
  const { descriptor } = sfc.parse(source, path);
@@ -284,6 +311,9 @@ const compileVueSfc = (source, path, maps, root) => {
284
311
  }
285
312
  scripts.push(...getSyntheticImports(maps, identifiers, path, templateTags));
286
313
  scripts.push(...getImportedComponentImports(maps, importedComponents));
314
+ const srcImports = getSrcImports(source);
315
+ if (srcImports)
316
+ scripts.push(srcImports);
287
317
  const styles = stylePreprocessorImports(source, path);
288
318
  if (styles)
289
319
  scripts.push(styles);
@@ -5,7 +5,7 @@ import { hasDependency } from '../../util/plugin.js';
5
5
  const title = 'Biome';
6
6
  const enablers = ['@biomejs/biome'];
7
7
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
8
- const config = ['biome.json', 'biome.jsonc'];
8
+ const config = ['biome.json', 'biome.jsonc', '.biome.json', '.biome.jsonc'];
9
9
  const isRootConfigReference = (specifier) => specifier === '//';
10
10
  const resolveExtends = (extendsArray, options) => {
11
11
  return extendsArray.map(specifier => {
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,33 @@
1
+ import { hasDependency } from '../../util/plugin.js';
2
+ import { toShellCommand } from '../../util/scripts.js';
3
+ const title = 'Buf';
4
+ const enablers = ['@bufbuild/buf', '@bufbuild/protoc-gen-es'];
5
+ const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
+ const config = ['buf.gen.yaml'];
7
+ const args = {
8
+ config: ['template'],
9
+ };
10
+ const resolveConfig = (config, options) => {
11
+ const inputs = [];
12
+ for (const plugin of config.plugins ?? []) {
13
+ const name = plugin.plugin ?? plugin.name;
14
+ const command = plugin.local ?? plugin.path ?? (name && !name.includes('/') ? `protoc-gen-${name}` : undefined);
15
+ if (!command)
16
+ continue;
17
+ const script = toShellCommand(typeof command === 'string' ? [command] : command);
18
+ for (const input of options.getInputsFromScripts(script, { optionalBinaries: true })) {
19
+ input.dir ??= options.cwd;
20
+ inputs.push(input);
21
+ }
22
+ }
23
+ return inputs;
24
+ };
25
+ const plugin = {
26
+ title,
27
+ enablers,
28
+ isEnabled,
29
+ config,
30
+ args,
31
+ resolveConfig,
32
+ };
33
+ export default plugin;
@@ -0,0 +1,8 @@
1
+ export interface BufGenConfig {
2
+ plugins?: Array<{
3
+ local?: string | string[];
4
+ path?: string | string[];
5
+ plugin?: string;
6
+ name?: string;
7
+ }>;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,7 @@ const title = 'CSpell';
4
4
  const enablers = ['cspell'];
5
5
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
6
6
  const config = [
7
+ 'package.json',
7
8
  'cspell.config.{js,cjs,mjs,ts,mts,json,yaml,yml}',
8
9
  'cspell.{json,yaml,yml}',
9
10
  '.c{s,S}pell.json',
@@ -2,7 +2,7 @@ import { hasDependency } from '../../util/plugin.js';
2
2
  const title = 'dependency-cruiser';
3
3
  const enablers = ['dependency-cruiser'];
4
4
  const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
5
- const config = ['.dependency-cruiser.{js,cjs,mjs,json}'];
5
+ const entry = ['.dependency-cruiser.{js,cjs,mjs,json}'];
6
6
  const args = {
7
7
  binaries: ['depcruise', 'dependency-cruise', 'dependency-cruiser', 'depcruise-baseline'],
8
8
  config: true,
@@ -11,7 +11,7 @@ const plugin = {
11
11
  title,
12
12
  enablers,
13
13
  isEnabled,
14
- config,
14
+ entry,
15
15
  args,
16
16
  };
17
17
  export default plugin;
@@ -1,7 +1,7 @@
1
1
  import { toDeferResolve, toProductionEntry } from '../../util/input.js';
2
- import { join } from '../../util/path.js';
2
+ import { isAbsolute, toAbsolute } from '../../util/path.js';
3
3
  import { findWebpackDependenciesFromConfig } from '../webpack/index.js';
4
- const isLocalPath = (name) => name.startsWith('.') || name.startsWith('/');
4
+ const isLocalPath = (name) => name.startsWith('.') || isAbsolute(name);
5
5
  const FIRST_PARTY_MODULES = new Set([
6
6
  'content-docs',
7
7
  'content-blog',
@@ -63,7 +63,7 @@ const resolveArrayConfig = ([name, config], type, cwd) => {
63
63
  const sidebarPath = type !== 'theme' ? resolveSidebarPath(config) : undefined;
64
64
  const sidebar = sidebarPath ? [toProductionEntry(sidebarPath)] : [];
65
65
  if (isLocalPath(name))
66
- return [toProductionEntry(join(cwd, name)), ...sidebar];
66
+ return [toProductionEntry(toAbsolute(name, cwd)), ...sidebar];
67
67
  return [toDeferResolve(resolveModuleName(name, type)), ...sidebar];
68
68
  };
69
69
  export const resolveConfigItems = async (items, type, options) => {
@@ -75,7 +75,7 @@ export const resolveConfigItems = async (items, type, options) => {
75
75
  continue;
76
76
  if (typeof item === 'string') {
77
77
  if (isLocalPath(item))
78
- inputs.add(toProductionEntry(join(options.cwd, item)));
78
+ inputs.add(toProductionEntry(toAbsolute(item, options.cwd)));
79
79
  else
80
80
  inputs.add(toDeferResolve(resolveModuleName(item, type)));
81
81
  }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;