knip 6.34.0 → 6.35.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 (79) hide show
  1. package/dist/CatalogCounselor.d.ts +2 -0
  2. package/dist/CatalogCounselor.js +30 -7
  3. package/dist/ConfigurationChief.d.ts +6 -0
  4. package/dist/ConfigurationChief.js +3 -5
  5. package/dist/ProjectPrincipal.d.ts +9 -10
  6. package/dist/ProjectPrincipal.js +45 -52
  7. package/dist/WorkspaceWorker.d.ts +3 -3
  8. package/dist/WorkspaceWorker.js +6 -6
  9. package/dist/YamlCatalogPeeker.d.ts +4 -0
  10. package/dist/YamlCatalogPeeker.js +17 -0
  11. package/dist/binaries/bash-parser.d.ts +1 -1
  12. package/dist/binaries/bash-parser.js +12 -58
  13. package/dist/binaries/command.d.ts +5 -0
  14. package/dist/binaries/command.js +47 -0
  15. package/dist/binaries/fallback.d.ts +2 -0
  16. package/dist/binaries/fallback.js +2 -0
  17. package/dist/binaries/plugins.d.ts +1 -0
  18. package/dist/binaries/plugins.js +2 -1
  19. package/dist/binaries/resolvers/pnpm.js +1 -0
  20. package/dist/binaries/util.d.ts +1 -0
  21. package/dist/binaries/util.js +12 -0
  22. package/dist/cli.js +8 -26
  23. package/dist/compilers/index.d.ts +3 -1866
  24. package/dist/compilers/index.js +17 -27
  25. package/dist/compilers/types.d.ts +4 -5
  26. package/dist/graph/analyze.js +71 -53
  27. package/dist/graph/build.d.ts +3 -3
  28. package/dist/graph/build.js +63 -31
  29. package/dist/plugins/_vue/auto-import.js +28 -4
  30. package/dist/plugins/index.d.ts +1 -0
  31. package/dist/plugins/index.js +2 -0
  32. package/dist/plugins/mise/index.d.ts +3 -0
  33. package/dist/plugins/mise/index.js +82 -0
  34. package/dist/plugins/mise/scripts.d.ts +7 -0
  35. package/dist/plugins/mise/scripts.js +108 -0
  36. package/dist/plugins/mise/types.d.ts +26 -0
  37. package/dist/plugins/mise/types.js +1 -0
  38. package/dist/plugins/rstest/index.js +3 -2
  39. package/dist/plugins/rstest/types.d.ts +3 -1
  40. package/dist/plugins/vite/helpers.d.ts +2 -2
  41. package/dist/plugins/vite/helpers.js +18 -11
  42. package/dist/plugins/vite/visitors/importMetaGlob.js +12 -0
  43. package/dist/plugins/vitest/index.js +5 -2
  44. package/dist/plugins/vitest/types.d.ts +1 -0
  45. package/dist/schema/configuration.d.ts +20 -4
  46. package/dist/schema/configuration.js +5 -6
  47. package/dist/schema/plugins.d.ts +5 -0
  48. package/dist/schema/plugins.js +1 -0
  49. package/dist/session/index.d.ts +1 -1
  50. package/dist/session/index.js +1 -1
  51. package/dist/session/session.js +22 -4
  52. package/dist/types/PluginNames.d.ts +2 -2
  53. package/dist/types/PluginNames.js +1 -0
  54. package/dist/types/config.d.ts +4 -4
  55. package/dist/types/module-graph.d.ts +2 -0
  56. package/dist/types.d.ts +1 -0
  57. package/dist/typescript/SourceFileManager.d.ts +13 -9
  58. package/dist/typescript/SourceFileManager.js +58 -22
  59. package/dist/typescript/get-imports-and-exports.js +2 -1
  60. package/dist/typescript/visitors/exports.js +8 -4
  61. package/dist/util/catalog.d.ts +5 -0
  62. package/dist/util/catalog.js +37 -17
  63. package/dist/util/create-options.d.ts +17 -3
  64. package/dist/util/create-options.js +14 -3
  65. package/dist/util/errors.d.ts +3 -1
  66. package/dist/util/errors.js +6 -1
  67. package/dist/util/file-entry-cache.js +2 -2
  68. package/dist/util/module-graph.js +1 -0
  69. package/dist/util/package-json.d.ts +1 -0
  70. package/dist/util/preprocessor.d.ts +6 -0
  71. package/dist/util/preprocessor.js +24 -0
  72. package/dist/util/reporter.d.ts +0 -1
  73. package/dist/util/reporter.js +0 -7
  74. package/dist/util/watch.d.ts +1 -1
  75. package/dist/util/watch.js +33 -15
  76. package/dist/version.d.ts +1 -1
  77. package/dist/version.js +1 -1
  78. package/package.json +7 -7
  79. package/schema.json +12 -0
@@ -3,41 +3,35 @@ import MDX from './mdx.js';
3
3
  import SCSS from './scss.js';
4
4
  import STYLUS from './stylus.js';
5
5
  import TSRX from './tsrx.js';
6
- const isAsyncCompiler = (fn) => (fn ? fn.constructor.name === 'AsyncFunction' : false);
7
6
  export const normalizeCompilerExtension = (ext) => ext.replace(/^\.*/, '.');
8
- export const partitionCompilers = (rawLocalConfig) => {
9
- const syncCompilers = {};
10
- const asyncCompilers = {};
7
+ export const normalizeCompilers = (rawLocalConfig) => {
8
+ const compilers = new Map();
11
9
  for (const extension in rawLocalConfig.compilers) {
12
10
  const ext = normalizeCompilerExtension(extension);
13
11
  const compilerFn = rawLocalConfig.compilers[extension];
14
- if (typeof compilerFn === 'function') {
15
- if (!rawLocalConfig.asyncCompilers?.[ext] && isAsyncCompiler(compilerFn)) {
16
- asyncCompilers[ext] = compilerFn;
17
- }
18
- else {
19
- syncCompilers[ext] = compilerFn;
20
- }
21
- }
22
- else if (compilerFn === true) {
23
- syncCompilers[ext] = true;
24
- }
12
+ if (typeof compilerFn === 'function' || compilerFn === true)
13
+ compilers.set(ext, compilerFn);
25
14
  }
26
15
  for (const extension in rawLocalConfig.asyncCompilers) {
27
16
  const ext = normalizeCompilerExtension(extension);
28
- asyncCompilers[ext] = rawLocalConfig.asyncCompilers[extension];
17
+ compilers.set(ext, rawLocalConfig.asyncCompilers[extension]);
29
18
  }
30
- return { ...rawLocalConfig, syncCompilers, asyncCompilers };
19
+ return compilers;
31
20
  };
32
- const compilers = [
21
+ const builtInCompilers = [
33
22
  { extensions: ['.mdx'], ...MDX },
34
23
  { extensions: ['.sass', '.scss'], ...SCSS },
35
24
  { extensions: ['.less'], ...LESS },
36
25
  { extensions: ['.styl', '.stylus'], ...STYLUS },
37
26
  { extensions: ['.tsrx'], ...TSRX },
38
27
  ];
39
- export const getIncludedCompilers = (syncCompilers, asyncCompilers, dependencies, onReferencedDependency) => {
40
- for (const { extensions, dependencies: compilerDependencies, compiler } of compilers) {
28
+ export const getIncludedCompilers = (rawCompilers, dependencies, onReferencedDependency) => {
29
+ const compilers = new Map();
30
+ for (const [extension, compiler] of rawCompilers) {
31
+ if (typeof compiler === 'function')
32
+ compilers.set(extension, compiler);
33
+ }
34
+ for (const { extensions, dependencies: compilerDependencies, compiler } of builtInCompilers) {
41
35
  let hasCompilerDependency = false;
42
36
  for (const dependency of compilerDependencies) {
43
37
  if (dependencies.has(dependency)) {
@@ -49,15 +43,11 @@ export const getIncludedCompilers = (syncCompilers, asyncCompilers, dependencies
49
43
  }
50
44
  }
51
45
  for (const extension of extensions) {
52
- const existingCompiler = syncCompilers.get(extension);
46
+ const existingCompiler = rawCompilers.get(extension);
53
47
  if (existingCompiler === true || (existingCompiler === undefined && hasCompilerDependency)) {
54
- syncCompilers.set(extension, compiler);
48
+ compilers.set(extension, compiler);
55
49
  }
56
50
  }
57
51
  }
58
- return [syncCompilers, asyncCompilers];
52
+ return compilers;
59
53
  };
60
- export const getCompilerExtensions = (compilers) => [
61
- ...compilers[0].keys(),
62
- ...compilers[1].keys(),
63
- ];
@@ -1,9 +1,8 @@
1
1
  type FileExtension = string;
2
2
  export type CompilerSync = (source: string, path: string) => string;
3
- export type CompilerAsync = (source: string, path: string) => Promise<string>;
4
- export type RawSyncCompilers = Map<FileExtension, CompilerSync | true>;
5
- export type SyncCompilers = Map<FileExtension, CompilerSync>;
6
- export type AsyncCompilers = Map<FileExtension, CompilerAsync>;
7
- export type Compilers = [SyncCompilers, AsyncCompilers];
3
+ export type CompilerResult = string | PromiseLike<string>;
4
+ export type Compiler = (source: string, path: string) => CompilerResult;
5
+ export type RawCompilers = Map<FileExtension, Compiler | true>;
6
+ export type Compilers = Map<FileExtension, Compiler>;
8
7
  export type HasDependency = (pkgName: string) => boolean;
9
8
  export {};
@@ -55,6 +55,45 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
55
55
  }
56
56
  return false;
57
57
  };
58
+ const getMemberIssues = (exportedItem, filePath, identifier, workspace, importsForExport) => {
59
+ const isEnumMembers = options.includedIssueTypes.enumMembers && exportedItem.type === 'enum';
60
+ const isNsMembers = options.includedIssueTypes.namespaceMembers && exportedItem.members.length > 0 && exportedItem.type !== 'enum';
61
+ if (!isEnumMembers && !isNsMembers)
62
+ return;
63
+ if (exportedItem.members.length === 0)
64
+ return;
65
+ if (explorer.isEnumerated(filePath, identifier))
66
+ return;
67
+ if (!options.includedIssueTypes.nsTypes && importsForExport.refs.has(identifier))
68
+ return;
69
+ if (isEnumMembers && hasStrictlyEnumReferences(importsForExport, identifier))
70
+ return;
71
+ const issueType = isEnumMembers ? 'enumMembers' : 'namespaceMembers';
72
+ const unusedMembers = [];
73
+ const ignoredMemberIds = [];
74
+ for (const member of exportedItem.members) {
75
+ if (findMatch(workspace.ignoreMembers, member.identifier))
76
+ continue;
77
+ if (shouldIgnore(member.jsDocTags))
78
+ continue;
79
+ if (member.hasRefsInFile)
80
+ continue;
81
+ const id = `${identifier}.${member.identifier}`;
82
+ const [isMemberReferenced] = explorer.isReferenced(filePath, id, {
83
+ traverseEntries: true,
84
+ treatStarAtEntryAsReferenced: true,
85
+ });
86
+ const isMemberIgnored = shouldIgnoreTags(member.jsDocTags);
87
+ if (!isMemberReferenced) {
88
+ if (!isMemberIgnored)
89
+ unusedMembers.push(member);
90
+ }
91
+ else if (isMemberIgnored) {
92
+ ignoredMemberIds.push(id);
93
+ }
94
+ }
95
+ return { issueType, unusedMembers, ignoredMemberIds };
96
+ };
58
97
  const analyzeGraph = async () => {
59
98
  if (options.isReportValues || options.isReportTypes) {
60
99
  streamer.cast('Connecting the dots');
@@ -79,17 +118,22 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
79
118
  const [isReferenced, reExportingEntryFile] = explorer.isReferenced(filePath, identifier, {
80
119
  traverseEntries: isIncludeEntryExports,
81
120
  });
82
- if (isIgnored &&
83
- (isReferenced ||
84
- isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports, ignoreExportsUsedInFile))) {
85
- for (const tagName of exportedItem.jsDocTags) {
86
- if (options.tags[1].includes(tagName) || (isInternalProd && tagName === INTERNAL_TAG)) {
87
- collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
121
+ if (isIgnored) {
122
+ if (isReferenced ||
123
+ isReferencedInUsedExport(exportedItem, filePath, isIncludeEntryExports, ignoreExportsUsedInFile)) {
124
+ const memberIssues = isReferenced
125
+ ? getMemberIssues(exportedItem, filePath, identifier, workspace, importsForExport)
126
+ : undefined;
127
+ if (!memberIssues || memberIssues.unusedMembers.length === 0) {
128
+ for (const tagName of exportedItem.jsDocTags) {
129
+ if (options.tags[1].includes(tagName) || (isInternalProd && tagName === INTERNAL_TAG)) {
130
+ collector.addTagHint({ type: 'tag', filePath, identifier, tagName });
131
+ }
132
+ }
88
133
  }
89
134
  }
90
- }
91
- if (isIgnored)
92
135
  continue;
136
+ }
93
137
  if (reExportingEntryFile) {
94
138
  if (!isIncludeEntryExports) {
95
139
  continue;
@@ -101,51 +145,25 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
101
145
  }
102
146
  }
103
147
  if (isReferenced) {
104
- const isEnumMembers = options.includedIssueTypes.enumMembers && exportedItem.type === 'enum';
105
- const isNsMembers = options.includedIssueTypes.namespaceMembers &&
106
- exportedItem.members.length > 0 &&
107
- exportedItem.type !== 'enum';
108
- if ((isEnumMembers || isNsMembers) && exportedItem.members.length > 0) {
109
- if (explorer.isEnumerated(filePath, identifier))
110
- continue;
111
- if (!options.includedIssueTypes.nsTypes && importsForExport.refs.has(identifier))
112
- continue;
113
- if (isEnumMembers && hasStrictlyEnumReferences(importsForExport, identifier))
114
- continue;
115
- const issueType = isEnumMembers ? 'enumMembers' : 'namespaceMembers';
116
- for (const member of exportedItem.members) {
117
- if (findMatch(workspace.ignoreMembers, member.identifier))
118
- continue;
119
- if (shouldIgnore(member.jsDocTags))
120
- continue;
121
- if (!member.hasRefsInFile) {
122
- const id = `${identifier}.${member.identifier}`;
123
- const [isMemberReferenced] = explorer.isReferenced(filePath, id, {
124
- traverseEntries: true,
125
- treatStarAtEntryAsReferenced: true,
126
- });
127
- const isIgnored = shouldIgnoreTags(member.jsDocTags);
128
- if (!isMemberReferenced) {
129
- if (isIgnored)
130
- continue;
131
- collector.addIssue({
132
- type: issueType,
133
- filePath,
134
- workspace: workspace.name,
135
- symbol: member.identifier,
136
- parentSymbol: identifier,
137
- pos: member.pos,
138
- line: member.line,
139
- col: member.col,
140
- fixes: member.fix ? [member.fix] : [],
141
- });
142
- }
143
- else if (isIgnored) {
144
- for (const tagName of exportedItem.jsDocTags) {
145
- if (options.tags[1].includes(tagName)) {
146
- collector.addTagHint({ type: 'tag', filePath, identifier: id, tagName });
147
- }
148
- }
148
+ const memberIssues = getMemberIssues(exportedItem, filePath, identifier, workspace, importsForExport);
149
+ if (memberIssues) {
150
+ for (const member of memberIssues.unusedMembers) {
151
+ collector.addIssue({
152
+ type: memberIssues.issueType,
153
+ filePath,
154
+ workspace: workspace.name,
155
+ symbol: member.identifier,
156
+ parentSymbol: identifier,
157
+ pos: member.pos,
158
+ line: member.line,
159
+ col: member.col,
160
+ fixes: member.fix ? [member.fix] : [],
161
+ });
162
+ }
163
+ for (const id of memberIssues.ignoredMemberIds) {
164
+ for (const tagName of exportedItem.jsDocTags) {
165
+ if (options.tags[1].includes(tagName)) {
166
+ collector.addTagHint({ type: 'tag', filePath, identifier: id, tagName });
149
167
  }
150
168
  }
151
169
  }
@@ -1,11 +1,11 @@
1
1
  import type { ScriptParserContext } from '../binaries/create-script-parser-context.ts';
2
2
  import type { CatalogCounselor } from '../CatalogCounselor.ts';
3
- import type { ConfigurationChief, Workspace } from '../ConfigurationChief.ts';
3
+ import { type ConfigurationChief, type Workspace } from '../ConfigurationChief.ts';
4
4
  import type { ConsoleStreamer } from '../ConsoleStreamer.ts';
5
5
  import type { DependencyDeputy } from '../DependencyDeputy.ts';
6
6
  import type { IssueCollector } from '../IssueCollector.ts';
7
7
  import type { ProjectPrincipal } from '../ProjectPrincipal.ts';
8
- import type { FileNode, ModuleGraph } from '../types/module-graph.ts';
8
+ import type { ModuleGraph } from '../types/module-graph.ts';
9
9
  import type { MainOptions } from '../util/create-options.ts';
10
10
  interface BuildOptions {
11
11
  chief: ConfigurationChief;
@@ -24,7 +24,7 @@ export declare function build({ chief, collector, counselor, deputy, principal,
24
24
  entryPaths: Set<string>;
25
25
  analyzedFiles: Set<string>;
26
26
  unreferencedFiles: Set<string>;
27
- analyzeSourceFile: (filePath: string, pp: ProjectPrincipal, parseResult?: import('oxc-parser').ParseResult, sourceText?: string, cachedFile?: FileNode) => void;
27
+ analyzeSourceFile: (filePath: string) => Promise<void>;
28
28
  enabledPluginsStore: Map<string, string[]>;
29
29
  }>;
30
30
  export {};
@@ -1,6 +1,7 @@
1
1
  import { _getInputsFromScripts } from '../binaries/index.js';
2
- import { getCompilerExtensions, getIncludedCompilers, normalizeCompilerExtension } from '../compilers/index.js';
3
- import { DEFAULT_EXTENSIONS, FOREIGN_FILE_EXTENSIONS, IS_DTS } from '../constants.js';
2
+ import { isDefaultPattern } from '../ConfigurationChief.js';
3
+ import { getIncludedCompilers, normalizeCompilerExtension } from '../compilers/index.js';
4
+ import { DEFAULT_EXTENSIONS, FOREIGN_FILE_EXTENSIONS, IS_DTS, ROOT_WORKSPACE_NAME } from '../constants.js';
4
5
  import { partition } from '../util/array.js';
5
6
  import { createInputHandler } from '../util/create-input-handler.js';
6
7
  import { debugLog, debugLogArray } from '../util/debug.js';
@@ -9,7 +10,7 @@ import picomatch from 'picomatch';
9
10
  import { tryRealpath } from '../util/fs.js';
10
11
  import { createManifest } from '../util/package-json.js';
11
12
  import { _glob, _syncGlob, negate, prependDirToPattern as prependDir } from '../util/glob.js';
12
- import { isAlias, isCatalog, isConfig, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isIgnore, isProductionEntry, isProject, toProductionEntry, } from '../util/input.js';
13
+ import { isAlias, isCatalog, isConfig, isDeferResolveEntry, isDeferResolveProductionEntry, isEntry, isIgnore, isProductionEntry, isProject, toDeferResolveEntry, toDependency, toProductionEntry, } from '../util/input.js';
13
14
  import { isAmbientDeclarationFile } from '../typescript/ast-nodes.js';
14
15
  import { resolveImportGlobs } from '../typescript/glob-imports.js';
15
16
  import { createPublishedTypeDependencyAnalyzer } from '../typescript/get-published-type-dependencies.js';
@@ -18,7 +19,7 @@ import { createFileNode, updateImportMap } from '../util/module-graph.js';
18
19
  import { getPackageNameFromModuleSpecifier, isStartsLikePackageName, sanitizeSpecifier } from '../util/modules.js';
19
20
  import { perfObserver } from '../util/Performance.js';
20
21
  import { getEntrySpecifiersFromManifest, getManifestImportDependencies } from '../util/package-json.js';
21
- import { dirname, extname, isAbsolute, isInNodeModules, join, relative } from '../util/path.js';
22
+ import { dirname, extname, isAbsolute, isInNodeModules, isInternal, join, relative } from '../util/path.js';
22
23
  import { extensionAlias } from '../util/resolve.js';
23
24
  import { augmentWorkspace, getToSourcePathsHandler, toSourceMappedSpecifiers } from '../util/to-source-path.js';
24
25
  import { WorkspaceWorker } from '../WorkspaceWorker.js';
@@ -54,6 +55,21 @@ export async function build({ chief, collector, counselor, deputy, principal, is
54
55
  if (options.configFilePath) {
55
56
  principal.addEntryPath(options.configFilePath, { skipExportsAnalysis: true });
56
57
  }
58
+ const preprocessorInputs = new Map();
59
+ for (const specifier of options.preprocessorInputs) {
60
+ const containingFilePath = options.configFilePath ?? join(options.cwd, 'package.json');
61
+ const isLocal = isInternal(specifier);
62
+ const input = isLocal
63
+ ? toDeferResolveEntry(specifier, { containingFilePath })
64
+ : toDependency(specifier, { containingFilePath, optional: true });
65
+ const owner = isLocal ? chief.findWorkspaceByFilePath(specifier)?.name : undefined;
66
+ const name = owner ?? ROOT_WORKSPACE_NAME;
67
+ const inputs = preprocessorInputs.get(name);
68
+ if (inputs)
69
+ inputs.push(input);
70
+ else
71
+ preprocessorInputs.set(name, [input]);
72
+ }
57
73
  for (const workspace of workspaces) {
58
74
  const { name, dir, ancestors, config: baseConfig, manifestPath: filePath } = workspace;
59
75
  streamer.cast('Analyzing workspace', name);
@@ -77,27 +93,27 @@ export async function build({ chief, collector, counselor, deputy, principal, is
77
93
  negatedWorkspacePatterns: chief.getNegatedWorkspacePatterns(name),
78
94
  ignoredWorkspacePatterns: chief.getIgnoredWorkspacesFor(name),
79
95
  enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
80
- readFile: (filePath) => principal.readFile(filePath),
96
+ readRawFile: (filePath) => principal.fileManager.readRawFile(filePath) ?? '',
81
97
  configFilesMap,
82
98
  options,
83
99
  });
84
100
  await worker.init();
85
- const compilers = getIncludedCompilers(new Map(chief.config.syncCompilers), new Map(chief.config.asyncCompilers), dependencies, dep => deputy.addReferencedDependency(name, dep));
86
- const registerCompiler = async ({ extension, compiler }) => {
101
+ const compilers = getIncludedCompilers(chief.config.compilers, dependencies, dep => deputy.addReferencedDependency(name, dep));
102
+ const registerCompiler = ({ extension, compiler }) => {
87
103
  const ext = normalizeCompilerExtension(extension);
88
- if (compilers[0].has(ext))
104
+ if (compilers.has(ext))
89
105
  return;
90
- compilers[0].set(ext, compiler);
106
+ compilers.set(ext, compiler);
91
107
  };
92
108
  await worker.registerCompilers(registerCompiler);
93
109
  principal.addCompilers(name, compilers);
94
- const extensions = getCompilerExtensions(compilers);
110
+ const extensions = [...compilers.keys()];
95
111
  const extensionGlobStr = `.{${[...DEFAULT_EXTENSIONS, ...extensions].map(ext => ext.slice(1)).join(',')}}`;
96
112
  const config = chief.getConfigForWorkspace(name, extensions);
97
113
  worker.config = config;
98
114
  const pluginSourceMaps = await worker.resolveSourceMaps();
99
115
  augmentWorkspace(workspace, dir, isFile ? compilerOptions : undefined, [...pluginSourceMaps, ...sourceMapPairs]);
100
- const inputs = new Set();
116
+ const inputs = new Set(preprocessorInputs.get(name));
101
117
  if (definitionPaths.length > 0) {
102
118
  debugLogArray(name, 'Definition paths', definitionPaths);
103
119
  for (const id of definitionPaths)
@@ -268,11 +284,15 @@ export async function build({ chief, collector, counselor, deputy, principal, is
268
284
  }
269
285
  }
270
286
  if (!options.isProduction) {
271
- const hints = worker.getConfigurationHints('entry', userEntryPatterns, userEntryPaths, principal.entryPaths);
287
+ const includedPaths = config.isIncludeEntryExports
288
+ ? new Set([...principal.entryPaths].filter(filePath => !principal.skipExportsAnalysis.has(filePath)))
289
+ : principal.entryPaths;
290
+ const hints = worker.getConfigurationHints('entry', userEntryPatterns, userEntryPaths, includedPaths);
272
291
  for (const hint of hints)
273
292
  collector.addConfigurationHint(hint);
274
293
  }
275
- principal.addEntryPaths(userEntryPaths);
294
+ const hasExplicitEntries = config.entry.some(pattern => !isDefaultPattern('entry', pattern));
295
+ principal.addEntryPaths(userEntryPaths, hasExplicitEntries ? { skipExportsAnalysis: false } : undefined);
276
296
  if (options.isUseTscFiles && isFile) {
277
297
  const isIgnoredWorkspace = chief.createIgnoredWorkspaceMatcher(name, dir);
278
298
  debugLogArray(name, 'Using tsconfig files as project files', tscSourcePaths);
@@ -330,13 +350,13 @@ export async function build({ chief, collector, counselor, deputy, principal, is
330
350
  skipTypeOnly: options.isStrict,
331
351
  tags: options.tags,
332
352
  };
333
- const analyzeSourceFile = (filePath, pp, parseResult, sourceText, cachedFile) => {
353
+ const analyzeSourceFile = (filePath, sourceText, parseResult, cachedFile) => {
334
354
  if (!options.isWatch && !options.isSession && analyzedFiles.has(filePath))
335
355
  return;
336
356
  analyzedFiles.add(filePath);
337
357
  const workspace = chief.findWorkspaceByFilePath(filePath);
338
358
  if (workspace) {
339
- const file = pp.analyzeSourceFile(filePath, analyzeOpts, workspace.config.ignoreExportsUsedInFile, parseResult, sourceText, cachedFile);
359
+ const file = principal.analyzeSourceFile(filePath, sourceText, analyzeOpts, workspace.config.ignoreExportsUsedInFile, parseResult, cachedFile);
340
360
  const unresolvedImports = new Set();
341
361
  for (const unresolvedImport of file.imports.unresolved) {
342
362
  const { specifier } = unresolvedImport;
@@ -368,12 +388,12 @@ export async function build({ chief, collector, counselor, deputy, principal, is
368
388
  for (const filePath of file.imports.programFiles) {
369
389
  const isIgnored = isGitIgnored(filePath);
370
390
  if (!isIgnored)
371
- pp.addProgramPath(filePath);
391
+ principal.addProgramPath(filePath);
372
392
  }
373
393
  for (const filePath of file.imports.entryFiles) {
374
394
  const isIgnored = isGitIgnored(filePath);
375
395
  if (!isIgnored)
376
- pp.addEntryPath(filePath, { skipExportsAnalysis: true });
396
+ principal.addEntryPath(filePath, { skipExportsAnalysis: true });
377
397
  }
378
398
  const wsDependencies = deputy.getDependencies(workspace.name);
379
399
  for (const _import of file.imports.imports) {
@@ -386,7 +406,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
386
406
  if (isWorkspace || wsDependencies.has(packageName)) {
387
407
  file.imports.external.add({ ..._import, specifier: packageName });
388
408
  if (isWorkspace && !isGitIgnored(_import.filePath)) {
389
- pp.addProgramPath(_import.filePath);
409
+ principal.addProgramPath(_import.filePath);
390
410
  }
391
411
  }
392
412
  }
@@ -413,14 +433,20 @@ export async function build({ chief, collector, counselor, deputy, principal, is
413
433
  input.dir ??= dir;
414
434
  const specifierFilePath = handleInput(input, workspace);
415
435
  if (specifierFilePath)
416
- pp.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
436
+ principal.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
417
437
  }
418
438
  }
419
439
  if (file.importGlobs.length > 0) {
420
- const globbed = resolveImportGlobs(file.importGlobs, filePath, pp.resolveGlobPattern, workspace.dir);
421
- for (const importedFilePath of globbed) {
440
+ const [analyzedImportGlobs, entryImportGlobs] = partition(file.importGlobs, glob => glob.analyzeExports);
441
+ const analyzed = resolveImportGlobs(analyzedImportGlobs, filePath, principal.resolveGlobPattern, workspace.dir);
442
+ for (const importedFilePath of analyzed) {
443
+ if (!isGitIgnored(importedFilePath))
444
+ principal.addProgramPath(importedFilePath);
445
+ }
446
+ const entries = resolveImportGlobs(entryImportGlobs, filePath, principal.resolveGlobPattern, workspace.dir);
447
+ for (const importedFilePath of entries) {
422
448
  if (!isGitIgnored(importedFilePath))
423
- pp.addEntryPath(importedFilePath, { skipExportsAnalysis: true });
449
+ principal.addEntryPath(importedFilePath, { skipExportsAnalysis: true });
424
450
  }
425
451
  }
426
452
  file.imports.unresolved = unresolvedImports;
@@ -430,6 +456,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
430
456
  file.imports.externalRefs.add(ref);
431
457
  const node = graph.get(filePath);
432
458
  if (node) {
459
+ node.skipExports = file.skipExports;
433
460
  node.imports = file.imports;
434
461
  node.exports = file.exports;
435
462
  node.duplicates = file.duplicates;
@@ -446,13 +473,9 @@ export async function build({ chief, collector, counselor, deputy, principal, is
446
473
  }
447
474
  };
448
475
  principal.init();
449
- if (principal.asyncCompilers.size > 0) {
450
- streamer.cast('Running async compilers');
451
- await principal.runAsyncCompilers();
452
- }
453
476
  streamer.cast('Analyzing source files');
454
- principal.walkAndAnalyze((filePath, parseResult, sourceText, cachedFile) => {
455
- analyzeSourceFile(filePath, principal, parseResult, sourceText, cachedFile);
477
+ await principal.walkAndAnalyze((filePath, parseResult, sourceText, cachedFile) => {
478
+ analyzeSourceFile(filePath, sourceText, parseResult, cachedFile);
456
479
  const node = graph.get(filePath);
457
480
  if (!node)
458
481
  return;
@@ -464,8 +487,13 @@ export async function build({ chief, collector, counselor, deputy, principal, is
464
487
  return paths;
465
488
  });
466
489
  for (const filePath of principal.getUnreferencedFiles()) {
467
- if (IS_DTS.test(filePath) && isAmbientDeclarationFile(filePath, principal.readFile(filePath)))
468
- continue;
490
+ if (IS_DTS.test(filePath)) {
491
+ const loaded = principal.fileManager.loadSourceText(filePath);
492
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
493
+ principal.fileManager.sourceTextCache.delete(filePath);
494
+ if (isAmbientDeclarationFile(filePath, sourceText))
495
+ continue;
496
+ }
469
497
  unreferencedFiles.add(filePath);
470
498
  }
471
499
  for (const filePath of principal.entryPaths)
@@ -485,7 +513,11 @@ export async function build({ chief, collector, counselor, deputy, principal, is
485
513
  entryPaths,
486
514
  analyzedFiles,
487
515
  unreferencedFiles,
488
- analyzeSourceFile,
516
+ analyzeSourceFile: async (filePath) => {
517
+ const loaded = principal.fileManager.loadSourceText(filePath);
518
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
519
+ analyzeSourceFile(filePath, sourceText);
520
+ },
489
521
  enabledPluginsStore,
490
522
  };
491
523
  }
@@ -46,12 +46,21 @@ const readFile = (filePath) => {
46
46
  }
47
47
  };
48
48
  export const readAndParseFile = (filePath) => _parseFile(filePath, readFile(filePath));
49
- const collectIdentifiers = (source, fileName) => {
49
+ const collectIdentifiers = (source, fileName, importedComponents) => {
50
50
  const identifiers = new Set();
51
51
  const visitor = new Visitor({
52
52
  Identifier(node) {
53
53
  identifiers.add(node.name);
54
54
  },
55
+ ImportDeclaration(node) {
56
+ if (importedComponents && node.source.value === '#components') {
57
+ for (const specifier of node.specifiers) {
58
+ if (specifier.type === 'ImportSpecifier') {
59
+ importedComponents.add(specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value);
60
+ }
61
+ }
62
+ }
63
+ },
55
64
  });
56
65
  visitor.visit(_parseFile(fileName, source).program);
57
66
  return identifiers;
@@ -225,6 +234,15 @@ const getSyntheticImports = (maps, identifiers, templateTags) => {
225
234
  }
226
235
  return syntheticImports;
227
236
  };
237
+ const getImportedComponentImports = (maps, names) => {
238
+ const imports = [];
239
+ for (const importedName of names) {
240
+ const name = importedName.startsWith('Lazy') ? importedName.slice(4) : importedName;
241
+ for (const specifier of maps.componentMap.get(name) ?? [])
242
+ imports.push(`import '${specifier}';`);
243
+ }
244
+ return imports;
245
+ };
228
246
  const compileVueSfc = (source, path, maps, root) => {
229
247
  if (maps.importMap.size === 0 && maps.componentMap.size === 0) {
230
248
  return [scriptBodies(source, path), stylePreprocessorImports(source, path)].filter(Boolean).join(';\n');
@@ -236,7 +254,8 @@ const compileVueSfc = (source, path, maps, root) => {
236
254
  scripts.push(descriptor.script.content);
237
255
  if (descriptor.scriptSetup?.content)
238
256
  scripts.push(descriptor.scriptSetup.content);
239
- const identifiers = scripts.length === 0 ? new Set() : collectIdentifiers(scripts.join('\n'), path);
257
+ const importedComponents = new Set();
258
+ const identifiers = scripts.length === 0 ? new Set() : collectIdentifiers(scripts.join('\n'), path, importedComponents);
240
259
  const template = descriptor.template;
241
260
  const compiled = template && !template.ast && sfc.compileTemplate
242
261
  ? sfc.compileTemplate(template.content, path, descriptor.script?.lang === 'ts' ||
@@ -257,15 +276,20 @@ const compileVueSfc = (source, path, maps, root) => {
257
276
  identifiers.add(id);
258
277
  }
259
278
  scripts.push(...getSyntheticImports(maps, identifiers, templateTags));
279
+ scripts.push(...getImportedComponentImports(maps, importedComponents));
260
280
  const styles = stylePreprocessorImports(source, path);
261
281
  if (styles)
262
282
  scripts.push(styles);
263
283
  return scripts.join(';\n');
264
284
  };
265
285
  const compileTs = (source, path, maps) => {
266
- if (maps.importMap.size === 0 || path.endsWith('.d.ts') || path.endsWith('.config.ts'))
286
+ if ((maps.importMap.size === 0 && maps.componentMap.size === 0) ||
287
+ path.endsWith('.d.ts') ||
288
+ path.endsWith('.config.ts'))
267
289
  return source;
268
- const syntheticImports = getSyntheticImports(maps, collectIdentifiers(source, path));
290
+ const importedComponents = new Set();
291
+ const syntheticImports = getSyntheticImports(maps, collectIdentifiers(source, path, importedComponents));
292
+ syntheticImports.push(...getImportedComponentImports(maps, importedComponents));
269
293
  return syntheticImports.length === 0 ? source : `${source}\n${syntheticImports.join('\n')}`;
270
294
  };
271
295
  const tagMatcher = /<([a-zA-Z][\w.-]*)/g;
@@ -68,6 +68,7 @@ export declare const Plugins: {
68
68
  mdx: import("../types/config.ts").Plugin;
69
69
  mdxlint: import("../types/config.ts").Plugin;
70
70
  metro: import("../types/config.ts").Plugin;
71
+ mise: import("../types/config.ts").Plugin;
71
72
  mocha: import("../types/config.ts").Plugin;
72
73
  moonrepo: import("../types/config.ts").Plugin;
73
74
  msw: import("../types/config.ts").Plugin;
@@ -62,6 +62,7 @@ import { default as marko } from './marko/index.js';
62
62
  import { default as mdx } from './mdx/index.js';
63
63
  import { default as mdxlint } from './mdxlint/index.js';
64
64
  import { default as metro } from './metro/index.js';
65
+ import { default as mise } from './mise/index.js';
65
66
  import { default as mocha } from './mocha/index.js';
66
67
  import { default as moonrepo } from './moonrepo/index.js';
67
68
  import { default as msw } from './msw/index.js';
@@ -245,6 +246,7 @@ export const Plugins = {
245
246
  mdx,
246
247
  mdxlint,
247
248
  metro,
249
+ mise,
248
250
  mocha,
249
251
  moonrepo,
250
252
  msw,
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '../../types/config.ts';
2
+ declare const plugin: Plugin;
3
+ export default plugin;