knip 6.34.0 → 6.35.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 (88) 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/IssueCollector.d.ts +3 -0
  6. package/dist/IssueCollector.js +5 -0
  7. package/dist/ProjectPrincipal.d.ts +9 -10
  8. package/dist/ProjectPrincipal.js +45 -52
  9. package/dist/WorkspaceWorker.d.ts +5 -3
  10. package/dist/WorkspaceWorker.js +9 -6
  11. package/dist/YamlCatalogPeeker.d.ts +4 -0
  12. package/dist/YamlCatalogPeeker.js +17 -0
  13. package/dist/binaries/bash-parser.d.ts +1 -1
  14. package/dist/binaries/bash-parser.js +12 -58
  15. package/dist/binaries/command.d.ts +5 -0
  16. package/dist/binaries/command.js +47 -0
  17. package/dist/binaries/fallback.d.ts +2 -0
  18. package/dist/binaries/fallback.js +2 -0
  19. package/dist/binaries/plugins.d.ts +1 -0
  20. package/dist/binaries/plugins.js +2 -1
  21. package/dist/binaries/resolvers/pnpm.js +1 -0
  22. package/dist/binaries/util.d.ts +1 -0
  23. package/dist/binaries/util.js +12 -0
  24. package/dist/cli.js +12 -26
  25. package/dist/compilers/index.d.ts +3 -1866
  26. package/dist/compilers/index.js +17 -27
  27. package/dist/compilers/types.d.ts +4 -5
  28. package/dist/graph/analyze.js +71 -53
  29. package/dist/graph/build.d.ts +3 -3
  30. package/dist/graph/build.js +64 -31
  31. package/dist/index.d.ts +1 -0
  32. package/dist/plugins/_vue/auto-import.js +28 -4
  33. package/dist/plugins/index.d.ts +1 -0
  34. package/dist/plugins/index.js +2 -0
  35. package/dist/plugins/mise/index.d.ts +3 -0
  36. package/dist/plugins/mise/index.js +82 -0
  37. package/dist/plugins/mise/scripts.d.ts +7 -0
  38. package/dist/plugins/mise/scripts.js +108 -0
  39. package/dist/plugins/mise/types.d.ts +26 -0
  40. package/dist/plugins/mise/types.js +1 -0
  41. package/dist/plugins/rstest/index.js +3 -2
  42. package/dist/plugins/rstest/types.d.ts +3 -1
  43. package/dist/plugins/vite/helpers.d.ts +2 -2
  44. package/dist/plugins/vite/helpers.js +18 -11
  45. package/dist/plugins/vite/visitors/importMetaGlob.js +12 -0
  46. package/dist/plugins/vitest/index.js +5 -2
  47. package/dist/plugins/vitest/types.d.ts +1 -0
  48. package/dist/reporters/util/configuration-hints.d.ts +1 -1
  49. package/dist/reporters/util/configuration-hints.js +11 -2
  50. package/dist/run.d.ts +2 -0
  51. package/dist/run.js +2 -1
  52. package/dist/schema/configuration.d.ts +20 -4
  53. package/dist/schema/configuration.js +5 -6
  54. package/dist/schema/plugins.d.ts +5 -0
  55. package/dist/schema/plugins.js +1 -0
  56. package/dist/session/index.d.ts +1 -1
  57. package/dist/session/index.js +1 -1
  58. package/dist/session/session.js +22 -4
  59. package/dist/types/PluginNames.d.ts +2 -2
  60. package/dist/types/PluginNames.js +1 -0
  61. package/dist/types/config.d.ts +4 -4
  62. package/dist/types/issues.d.ts +1 -0
  63. package/dist/types/module-graph.d.ts +2 -0
  64. package/dist/types.d.ts +1 -0
  65. package/dist/typescript/SourceFileManager.d.ts +13 -9
  66. package/dist/typescript/SourceFileManager.js +58 -22
  67. package/dist/typescript/get-imports-and-exports.js +2 -1
  68. package/dist/typescript/resolve-module-names.js +7 -27
  69. package/dist/typescript/visitors/exports.js +8 -4
  70. package/dist/util/catalog.d.ts +5 -0
  71. package/dist/util/catalog.js +37 -17
  72. package/dist/util/create-options.d.ts +17 -3
  73. package/dist/util/create-options.js +14 -3
  74. package/dist/util/errors.d.ts +3 -1
  75. package/dist/util/errors.js +6 -1
  76. package/dist/util/file-entry-cache.js +2 -2
  77. package/dist/util/module-graph.js +1 -0
  78. package/dist/util/package-json.d.ts +1 -0
  79. package/dist/util/preprocessor.d.ts +6 -0
  80. package/dist/util/preprocessor.js +24 -0
  81. package/dist/util/reporter.d.ts +0 -1
  82. package/dist/util/reporter.js +0 -7
  83. package/dist/util/watch.d.ts +2 -1
  84. package/dist/util/watch.js +33 -15
  85. package/dist/version.d.ts +1 -1
  86. package/dist/version.js +1 -1
  87. package/package.json +7 -7
  88. 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);
@@ -72,32 +88,33 @@ export async function build({ chief, collector, counselor, deputy, principal, is
72
88
  dependencies,
73
89
  rootManifest,
74
90
  handleInput: (input) => handleInput(input, workspace),
91
+ handleConfigLoadError: () => collector.addConfigLoadError(),
75
92
  findWorkspaceByFilePath: chief.findWorkspaceByFilePath.bind(chief),
76
93
  getManifest,
77
94
  negatedWorkspacePatterns: chief.getNegatedWorkspacePatterns(name),
78
95
  ignoredWorkspacePatterns: chief.getIgnoredWorkspacesFor(name),
79
96
  enabledPluginsInAncestors: ancestors.flatMap(ancestor => enabledPluginsStore.get(ancestor) ?? []),
80
- readFile: (filePath) => principal.readFile(filePath),
97
+ readRawFile: (filePath) => principal.fileManager.readRawFile(filePath) ?? '',
81
98
  configFilesMap,
82
99
  options,
83
100
  });
84
101
  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 }) => {
102
+ const compilers = getIncludedCompilers(chief.config.compilers, dependencies, dep => deputy.addReferencedDependency(name, dep));
103
+ const registerCompiler = ({ extension, compiler }) => {
87
104
  const ext = normalizeCompilerExtension(extension);
88
- if (compilers[0].has(ext))
105
+ if (compilers.has(ext))
89
106
  return;
90
- compilers[0].set(ext, compiler);
107
+ compilers.set(ext, compiler);
91
108
  };
92
109
  await worker.registerCompilers(registerCompiler);
93
110
  principal.addCompilers(name, compilers);
94
- const extensions = getCompilerExtensions(compilers);
111
+ const extensions = [...compilers.keys()];
95
112
  const extensionGlobStr = `.{${[...DEFAULT_EXTENSIONS, ...extensions].map(ext => ext.slice(1)).join(',')}}`;
96
113
  const config = chief.getConfigForWorkspace(name, extensions);
97
114
  worker.config = config;
98
115
  const pluginSourceMaps = await worker.resolveSourceMaps();
99
116
  augmentWorkspace(workspace, dir, isFile ? compilerOptions : undefined, [...pluginSourceMaps, ...sourceMapPairs]);
100
- const inputs = new Set();
117
+ const inputs = new Set(preprocessorInputs.get(name));
101
118
  if (definitionPaths.length > 0) {
102
119
  debugLogArray(name, 'Definition paths', definitionPaths);
103
120
  for (const id of definitionPaths)
@@ -268,11 +285,15 @@ export async function build({ chief, collector, counselor, deputy, principal, is
268
285
  }
269
286
  }
270
287
  if (!options.isProduction) {
271
- const hints = worker.getConfigurationHints('entry', userEntryPatterns, userEntryPaths, principal.entryPaths);
288
+ const includedPaths = config.isIncludeEntryExports
289
+ ? new Set([...principal.entryPaths].filter(filePath => !principal.skipExportsAnalysis.has(filePath)))
290
+ : principal.entryPaths;
291
+ const hints = worker.getConfigurationHints('entry', userEntryPatterns, userEntryPaths, includedPaths);
272
292
  for (const hint of hints)
273
293
  collector.addConfigurationHint(hint);
274
294
  }
275
- principal.addEntryPaths(userEntryPaths);
295
+ const hasExplicitEntries = config.entry.some(pattern => !isDefaultPattern('entry', pattern));
296
+ principal.addEntryPaths(userEntryPaths, hasExplicitEntries ? { skipExportsAnalysis: false } : undefined);
276
297
  if (options.isUseTscFiles && isFile) {
277
298
  const isIgnoredWorkspace = chief.createIgnoredWorkspaceMatcher(name, dir);
278
299
  debugLogArray(name, 'Using tsconfig files as project files', tscSourcePaths);
@@ -330,13 +351,13 @@ export async function build({ chief, collector, counselor, deputy, principal, is
330
351
  skipTypeOnly: options.isStrict,
331
352
  tags: options.tags,
332
353
  };
333
- const analyzeSourceFile = (filePath, pp, parseResult, sourceText, cachedFile) => {
354
+ const analyzeSourceFile = (filePath, sourceText, parseResult, cachedFile) => {
334
355
  if (!options.isWatch && !options.isSession && analyzedFiles.has(filePath))
335
356
  return;
336
357
  analyzedFiles.add(filePath);
337
358
  const workspace = chief.findWorkspaceByFilePath(filePath);
338
359
  if (workspace) {
339
- const file = pp.analyzeSourceFile(filePath, analyzeOpts, workspace.config.ignoreExportsUsedInFile, parseResult, sourceText, cachedFile);
360
+ const file = principal.analyzeSourceFile(filePath, sourceText, analyzeOpts, workspace.config.ignoreExportsUsedInFile, parseResult, cachedFile);
340
361
  const unresolvedImports = new Set();
341
362
  for (const unresolvedImport of file.imports.unresolved) {
342
363
  const { specifier } = unresolvedImport;
@@ -368,12 +389,12 @@ export async function build({ chief, collector, counselor, deputy, principal, is
368
389
  for (const filePath of file.imports.programFiles) {
369
390
  const isIgnored = isGitIgnored(filePath);
370
391
  if (!isIgnored)
371
- pp.addProgramPath(filePath);
392
+ principal.addProgramPath(filePath);
372
393
  }
373
394
  for (const filePath of file.imports.entryFiles) {
374
395
  const isIgnored = isGitIgnored(filePath);
375
396
  if (!isIgnored)
376
- pp.addEntryPath(filePath, { skipExportsAnalysis: true });
397
+ principal.addEntryPath(filePath, { skipExportsAnalysis: true });
377
398
  }
378
399
  const wsDependencies = deputy.getDependencies(workspace.name);
379
400
  for (const _import of file.imports.imports) {
@@ -386,7 +407,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
386
407
  if (isWorkspace || wsDependencies.has(packageName)) {
387
408
  file.imports.external.add({ ..._import, specifier: packageName });
388
409
  if (isWorkspace && !isGitIgnored(_import.filePath)) {
389
- pp.addProgramPath(_import.filePath);
410
+ principal.addProgramPath(_import.filePath);
390
411
  }
391
412
  }
392
413
  }
@@ -413,14 +434,20 @@ export async function build({ chief, collector, counselor, deputy, principal, is
413
434
  input.dir ??= dir;
414
435
  const specifierFilePath = handleInput(input, workspace);
415
436
  if (specifierFilePath)
416
- pp.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
437
+ principal.addEntryPath(specifierFilePath, { skipExportsAnalysis: true });
417
438
  }
418
439
  }
419
440
  if (file.importGlobs.length > 0) {
420
- const globbed = resolveImportGlobs(file.importGlobs, filePath, pp.resolveGlobPattern, workspace.dir);
421
- for (const importedFilePath of globbed) {
441
+ const [analyzedImportGlobs, entryImportGlobs] = partition(file.importGlobs, glob => glob.analyzeExports);
442
+ const analyzed = resolveImportGlobs(analyzedImportGlobs, filePath, principal.resolveGlobPattern, workspace.dir);
443
+ for (const importedFilePath of analyzed) {
444
+ if (!isGitIgnored(importedFilePath))
445
+ principal.addProgramPath(importedFilePath);
446
+ }
447
+ const entries = resolveImportGlobs(entryImportGlobs, filePath, principal.resolveGlobPattern, workspace.dir);
448
+ for (const importedFilePath of entries) {
422
449
  if (!isGitIgnored(importedFilePath))
423
- pp.addEntryPath(importedFilePath, { skipExportsAnalysis: true });
450
+ principal.addEntryPath(importedFilePath, { skipExportsAnalysis: true });
424
451
  }
425
452
  }
426
453
  file.imports.unresolved = unresolvedImports;
@@ -430,6 +457,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
430
457
  file.imports.externalRefs.add(ref);
431
458
  const node = graph.get(filePath);
432
459
  if (node) {
460
+ node.skipExports = file.skipExports;
433
461
  node.imports = file.imports;
434
462
  node.exports = file.exports;
435
463
  node.duplicates = file.duplicates;
@@ -446,13 +474,9 @@ export async function build({ chief, collector, counselor, deputy, principal, is
446
474
  }
447
475
  };
448
476
  principal.init();
449
- if (principal.asyncCompilers.size > 0) {
450
- streamer.cast('Running async compilers');
451
- await principal.runAsyncCompilers();
452
- }
453
477
  streamer.cast('Analyzing source files');
454
- principal.walkAndAnalyze((filePath, parseResult, sourceText, cachedFile) => {
455
- analyzeSourceFile(filePath, principal, parseResult, sourceText, cachedFile);
478
+ await principal.walkAndAnalyze((filePath, parseResult, sourceText, cachedFile) => {
479
+ analyzeSourceFile(filePath, sourceText, parseResult, cachedFile);
456
480
  const node = graph.get(filePath);
457
481
  if (!node)
458
482
  return;
@@ -464,8 +488,13 @@ export async function build({ chief, collector, counselor, deputy, principal, is
464
488
  return paths;
465
489
  });
466
490
  for (const filePath of principal.getUnreferencedFiles()) {
467
- if (IS_DTS.test(filePath) && isAmbientDeclarationFile(filePath, principal.readFile(filePath)))
468
- continue;
491
+ if (IS_DTS.test(filePath)) {
492
+ const loaded = principal.fileManager.loadSourceText(filePath);
493
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
494
+ principal.fileManager.sourceTextCache.delete(filePath);
495
+ if (isAmbientDeclarationFile(filePath, sourceText))
496
+ continue;
497
+ }
469
498
  unreferencedFiles.add(filePath);
470
499
  }
471
500
  for (const filePath of principal.entryPaths)
@@ -485,7 +514,11 @@ export async function build({ chief, collector, counselor, deputy, principal, is
485
514
  entryPaths,
486
515
  analyzedFiles,
487
516
  unreferencedFiles,
488
- analyzeSourceFile,
517
+ analyzeSourceFile: async (filePath) => {
518
+ const loaded = principal.fileManager.loadSourceText(filePath);
519
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
520
+ analyzeSourceFile(filePath, sourceText);
521
+ },
489
522
  enabledPluginsStore,
490
523
  };
491
524
  }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const main: (options: MainOptions) => Promise<{
4
4
  counters: import("./types/issues.ts").Counters;
5
5
  tagHints: Set<import("./types/issues.ts").TagHint>;
6
6
  configurationHints: import("./types/issues.ts").ConfigurationHint[];
7
+ hasConfigLoadErrors: boolean;
7
8
  selectedWorkspaces: string[] | undefined;
8
9
  includedWorkspaceDirs: string[];
9
10
  enabledPlugins: {
@@ -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;