knip 6.33.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 (90) 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 +12 -10
  6. package/dist/ProjectPrincipal.js +56 -41
  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 +9 -27
  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 +74 -56
  27. package/dist/graph/build.d.ts +3 -3
  28. package/dist/graph/build.js +64 -32
  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/node/index.js +5 -0
  39. package/dist/plugins/node/visitors/fsPromisesGlob.d.ts +2 -0
  40. package/dist/plugins/node/visitors/fsPromisesGlob.js +89 -0
  41. package/dist/plugins/nuxt/index.js +13 -10
  42. package/dist/plugins/rstest/index.js +3 -2
  43. package/dist/plugins/rstest/types.d.ts +3 -1
  44. package/dist/plugins/vite/helpers.d.ts +2 -2
  45. package/dist/plugins/vite/helpers.js +18 -11
  46. package/dist/plugins/vite/visitors/importMetaGlob.js +12 -0
  47. package/dist/plugins/vitest/index.js +5 -2
  48. package/dist/plugins/vitest/types.d.ts +1 -0
  49. package/dist/run.js +1 -1
  50. package/dist/schema/configuration.d.ts +20 -4
  51. package/dist/schema/configuration.js +5 -6
  52. package/dist/schema/plugins.d.ts +5 -0
  53. package/dist/schema/plugins.js +1 -0
  54. package/dist/session/index.d.ts +1 -1
  55. package/dist/session/index.js +1 -1
  56. package/dist/session/session.js +22 -4
  57. package/dist/types/PluginNames.d.ts +2 -2
  58. package/dist/types/PluginNames.js +1 -0
  59. package/dist/types/config.d.ts +5 -4
  60. package/dist/types/module-graph.d.ts +4 -0
  61. package/dist/types.d.ts +1 -0
  62. package/dist/typescript/SourceFileManager.d.ts +13 -9
  63. package/dist/typescript/SourceFileManager.js +58 -22
  64. package/dist/typescript/get-imports-and-exports.js +5 -1
  65. package/dist/typescript/glob-imports.js +8 -3
  66. package/dist/typescript/visitors/calls.js +1 -1
  67. package/dist/typescript/visitors/exports.js +8 -4
  68. package/dist/typescript/visitors/walk.d.ts +3 -1
  69. package/dist/typescript/visitors/walk.js +78 -13
  70. package/dist/util/catalog.d.ts +5 -0
  71. package/dist/util/catalog.js +37 -17
  72. package/dist/util/cli-arguments.d.ts +1 -0
  73. package/dist/util/cli-arguments.js +9 -0
  74. package/dist/util/create-options.d.ts +19 -4
  75. package/dist/util/create-options.js +17 -4
  76. package/dist/util/errors.d.ts +3 -1
  77. package/dist/util/errors.js +6 -1
  78. package/dist/util/file-entry-cache.js +2 -2
  79. package/dist/util/module-graph.js +1 -0
  80. package/dist/util/package-json.d.ts +1 -0
  81. package/dist/util/preprocessor.d.ts +6 -0
  82. package/dist/util/preprocessor.js +24 -0
  83. package/dist/util/reporter.d.ts +0 -1
  84. package/dist/util/reporter.js +0 -7
  85. package/dist/util/watch.d.ts +1 -1
  86. package/dist/util/watch.js +33 -15
  87. package/dist/version.d.ts +1 -1
  88. package/dist/version.js +1 -1
  89. package/package.json +8 -8
  90. package/schema.json +12 -0
@@ -6,12 +6,14 @@ export type CatalogContainer = {
6
6
  filePath: string;
7
7
  catalog?: Catalog;
8
8
  catalogs?: Catalogs;
9
+ overrides?: Catalog;
9
10
  };
10
11
  export declare class CatalogCounselor {
11
12
  private filePath;
12
13
  private entries;
13
14
  private referencedEntries;
14
15
  private referenceIssues;
16
+ private overrideReferences;
15
17
  private fileContent?;
16
18
  constructor(options: MainOptions);
17
19
  private addReferencedCatalogEntry;
@@ -2,7 +2,7 @@ import { readFile } from 'node:fs/promises';
2
2
  import { ROOT_WORKSPACE_NAME } from './constants.js';
3
3
  import { JsonCatalogPeeker } from './JsonCatalogPeeker.js';
4
4
  import { PackagePeeker } from './PackagePeeker.js';
5
- import { extractCatalogReferences, parseCatalog } from './util/catalog.js';
5
+ import { extractCatalogReferences, getOverrideCatalogReferences, parseCatalog, } from './util/catalog.js';
6
6
  import { extname } from './util/path.js';
7
7
  import { YamlCatalogPeeker } from './YamlCatalogPeeker.js';
8
8
  export class CatalogCounselor {
@@ -10,10 +10,14 @@ export class CatalogCounselor {
10
10
  entries = new Set();
11
11
  referencedEntries = new Set();
12
12
  referenceIssues = [];
13
+ overrideReferences = [];
13
14
  fileContent;
14
15
  constructor(options) {
15
16
  this.filePath = options.catalog.filePath;
16
17
  this.entries = parseCatalog(options.catalog);
18
+ this.overrideReferences = getOverrideCatalogReferences(options.catalog.overrides);
19
+ for (const reference of this.overrideReferences)
20
+ this.addReference(reference);
17
21
  }
18
22
  addReferencedCatalogEntry(entryName) {
19
23
  this.referencedEntries.add(entryName);
@@ -23,14 +27,18 @@ export class CatalogCounselor {
23
27
  }
24
28
  addWorkspace({ name: workspace, manifest, manifestPath: filePath, manifestStr, }) {
25
29
  const catalogReferences = extractCatalogReferences(manifest);
30
+ if (workspace === ROOT_WORKSPACE_NAME) {
31
+ for (const reference of getOverrideCatalogReferences(manifest.pnpm?.overrides))
32
+ catalogReferences.push(reference);
33
+ }
26
34
  if (catalogReferences.length === 0)
27
35
  return;
28
36
  const peeker = new PackagePeeker(manifestStr);
29
- for (const { catalogName, packageName } of catalogReferences) {
37
+ for (const { catalogName, packageName, selector } of catalogReferences) {
30
38
  const catalogEntryName = `${catalogName}:${packageName}`;
31
39
  this.addReferencedCatalogEntry(catalogEntryName);
32
40
  if (!this.entries.has(catalogEntryName)) {
33
- const pos = peeker.getCatalogReferenceLocation(packageName, catalogName);
41
+ const pos = peeker.getCatalogReferenceLocation(selector ?? packageName, catalogName);
34
42
  this.referenceIssues.push({
35
43
  type: 'catalogReferences',
36
44
  filePath,
@@ -47,11 +55,12 @@ export class CatalogCounselor {
47
55
  const filePath = this.filePath;
48
56
  const workspace = ROOT_WORKSPACE_NAME;
49
57
  const catalogIssues = [];
50
- if (this.entries.size > 0) {
58
+ const overrideReferenceIssues = [];
59
+ if (this.entries.size > 0 || this.overrideReferences.length > 0) {
51
60
  this.fileContent = await readFile(filePath, 'utf-8');
52
61
  const isYaml = ['.yml', '.yaml'].includes(extname(filePath));
53
- const Peeker = isYaml ? YamlCatalogPeeker : JsonCatalogPeeker;
54
- const peeker = new Peeker(this.fileContent);
62
+ const yamlPeeker = isYaml ? new YamlCatalogPeeker(this.fileContent) : undefined;
63
+ const peeker = yamlPeeker ?? new JsonCatalogPeeker(this.fileContent);
55
64
  for (const entry of this.entries.keys()) {
56
65
  if (!this.referencedEntries.has(entry)) {
57
66
  const [parentSymbol, symbol] = entry.split(':');
@@ -62,7 +71,21 @@ export class CatalogCounselor {
62
71
  catalogIssues.push({ type: 'catalog', filePath, workspace, symbol, parentSymbol, fixes, ...pos });
63
72
  }
64
73
  }
74
+ for (const { catalogName, packageName, selector } of this.overrideReferences) {
75
+ if (this.entries.has(`${catalogName}:${packageName}`))
76
+ continue;
77
+ const pos = yamlPeeker?.getOverrideCatalogReferenceLocation(selector);
78
+ overrideReferenceIssues.push({
79
+ type: 'catalogReferences',
80
+ filePath,
81
+ workspace,
82
+ symbol: packageName,
83
+ parentSymbol: catalogName,
84
+ fixes: [],
85
+ ...pos,
86
+ });
87
+ }
65
88
  }
66
- return [...catalogIssues, ...this.referenceIssues];
89
+ return [...catalogIssues, ...this.referenceIssues, ...overrideReferenceIssues];
67
90
  }
68
91
  }
@@ -377,6 +377,11 @@ export declare class ConfigurationChief {
377
377
  entry?: string | string[] | undefined;
378
378
  project?: string | string[] | undefined;
379
379
  } | undefined;
380
+ mise?: string | boolean | string[] | {
381
+ config?: string | string[] | undefined;
382
+ entry?: string | string[] | undefined;
383
+ project?: string | string[] | undefined;
384
+ } | undefined;
380
385
  mocha?: string | boolean | string[] | {
381
386
  config?: string | string[] | undefined;
382
387
  entry?: string | string[] | undefined;
@@ -1058,6 +1063,7 @@ export declare class ConfigurationChief {
1058
1063
  mdx?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1059
1064
  mdxlint?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1060
1065
  metro?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1066
+ mise?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1061
1067
  mocha?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1062
1068
  moonrepo?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
1063
1069
  msw?: (boolean | import("./types/config.ts").EnsuredPluginConfiguration) | undefined;
@@ -1,4 +1,5 @@
1
1
  import picomatch from 'picomatch';
2
+ import { normalizeCompilers } from './compilers/index.js';
2
3
  import { DEFAULT_EXTENSIONS, ROOT_WORKSPACE_NAME } from './constants.js';
3
4
  import { pluginNames } from './types/PluginNames.js';
4
5
  import { arrayify, compact, partition } from './util/array.js';
@@ -41,8 +42,7 @@ const defaultConfig = {
41
42
  ignoreWorkspaces: [],
42
43
  ignoreExportsUsedInFile: false,
43
44
  isIncludeEntryExports: false,
44
- syncCompilers: new Map(),
45
- asyncCompilers: new Map(),
45
+ compilers: new Map(),
46
46
  rootPluginConfigs: {},
47
47
  };
48
48
  export class ConfigurationChief {
@@ -108,7 +108,6 @@ export class ConfigurationChief {
108
108
  const ignoreIssues = rawConfig.ignoreIssues ?? {};
109
109
  const ignoreWorkspaces = rawConfig.ignoreWorkspaces ?? defaultConfig.ignoreWorkspaces;
110
110
  const isIncludeEntryExports = rawConfig.includeEntryExports ?? this.isIncludeEntryExports;
111
- const { syncCompilers, asyncCompilers } = rawConfig;
112
111
  const rootPluginConfigs = {};
113
112
  for (const [pluginName, pluginConfig] of Object.entries(rawConfig)) {
114
113
  if (isPluginName(pluginName)) {
@@ -127,8 +126,7 @@ export class ConfigurationChief {
127
126
  ignoreIssues,
128
127
  ignoreWorkspaces,
129
128
  isIncludeEntryExports,
130
- syncCompilers: new Map(Object.entries(syncCompilers ?? {})),
131
- asyncCompilers: new Map(Object.entries(asyncCompilers ?? {})),
129
+ compilers: normalizeCompilers(rawConfig),
132
130
  rootPluginConfigs,
133
131
  };
134
132
  }
@@ -1,6 +1,6 @@
1
1
  import type { ParseResult } from 'oxc-parser';
2
2
  import { CacheConsultant } from './CacheConsultant.ts';
3
- import type { AsyncCompilers, SyncCompilers } from './compilers/types.ts';
3
+ import type { Compilers } from './compilers/types.ts';
4
4
  import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile, PluginVisitorContext, PluginVisitorObject } from './types/config.ts';
5
5
  import type { FileNode, ModuleGraph } from './types/module-graph.ts';
6
6
  import type { Paths } from './types/project.ts';
@@ -13,12 +13,13 @@ export declare class ProjectPrincipal {
13
13
  projectPaths: Set<string>;
14
14
  programPaths: Set<string>;
15
15
  skipExportsAnalysis: Set<string>;
16
+ private includeExportsAnalysis;
16
17
  pluginCtx: PluginVisitorContext;
17
18
  pluginVisitorObjects: PluginVisitorObject[];
18
19
  private _visitor;
19
20
  private _localRefsVisitor;
20
- syncCompilers: SyncCompilers;
21
- asyncCompilers: AsyncCompilers;
21
+ compilers: Compilers;
22
+ private scopedCompilers;
22
23
  private paths;
23
24
  private rootDirs;
24
25
  private tsConfigFile;
@@ -26,18 +27,19 @@ export declare class ProjectPrincipal {
26
27
  cache: CacheConsultant<FileNode>;
27
28
  toSourceFilePath: ToSourceFilePath;
28
29
  private findWorkspacePackageTarget;
30
+ private findWorkspaceNameByFilePath;
31
+ private isReportExports;
29
32
  fileManager: SourceFileManager;
30
33
  private resolveModule;
31
34
  resolveGlobPattern: ResolveGlobPattern;
32
35
  resolvedFiles: Set<string>;
33
36
  deletedFiles: Set<string>;
34
37
  private onPathAdded;
35
- constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspacePackageTarget?: WorkspacePackageTargetHandler);
36
- addCompilers(compilers: [SyncCompilers, AsyncCompilers]): void;
38
+ constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspacePackageTarget: WorkspacePackageTargetHandler | undefined, findWorkspaceNameByFilePath: (filePath: string) => string | undefined);
39
+ addCompilers(workspaceName: string, compilers: Compilers): void;
37
40
  addPaths(paths: Paths, basePath: string, scope: string): void;
38
41
  addRootDirs(rootDirs: string[] | undefined, scope: string): void;
39
42
  init(): void;
40
- readFile(filePath: string): string;
41
43
  private hasAcceptedExtension;
42
44
  addEntryPath(filePath: string, options?: {
43
45
  skipExportsAnalysis: boolean;
@@ -48,12 +50,12 @@ export declare class ProjectPrincipal {
48
50
  addProgramPath(filePath: string): void;
49
51
  addProjectPath(filePath: string): void;
50
52
  removeProjectPath(filePath: string): void;
51
- runAsyncCompilers(): Promise<void>;
52
- walkAndAnalyze(analyzeFile: (filePath: string, parseResult: ParseResult | undefined, sourceText: string, cachedFile?: FileNode) => Iterable<string> | undefined): void;
53
- getUsedResolvedFiles(): string[];
53
+ walkAndAnalyze(analyzeFile: (filePath: string, parseResult: ParseResult | undefined, sourceText: string, cachedFile?: FileNode) => Iterable<string> | undefined): Promise<void>;
54
+ getUsedResolvedFiles(): Promise<Set<string>>;
54
55
  private resolveSpecifier;
55
56
  getUnreferencedFiles(): string[];
56
- analyzeSourceFile(filePath: string, options: GetImportsAndExportsOptions, ignoreExportsUsedInFile: IgnoreExportsUsedInFile, parseResult?: ParseResult, sourceText?: string, cachedFile?: FileNode): FileNode;
57
+ private getCachedFile;
58
+ analyzeSourceFile(filePath: string, sourceText: string, options: GetImportsAndExportsOptions, ignoreExportsUsedInFile: IgnoreExportsUsedInFile, parseResult?: ParseResult, cachedFile?: FileNode): FileNode;
57
59
  invalidateFile(filePath: string): void;
58
60
  reconcileCache(graph: ModuleGraph): void;
59
61
  }
@@ -1,7 +1,6 @@
1
1
  import { extractSpecifiers } from './typescript/follow-imports.js';
2
2
  import { _parseFile } from './typescript/ast-nodes.js';
3
3
  import { CacheConsultant } from './CacheConsultant.js';
4
- import { getCompilerExtensions } from './compilers/index.js';
5
4
  import { DEFAULT_EXTENSIONS } from './constants.js';
6
5
  import { _getImportsAndExports } from './typescript/get-imports-and-exports.js';
7
6
  import { createBunShellVisitor } from './typescript/visitors/script-visitors.js';
@@ -16,6 +15,7 @@ export class ProjectPrincipal {
16
15
  projectPaths = new Set();
17
16
  programPaths = new Set();
18
17
  skipExportsAnalysis = new Set();
18
+ includeExportsAnalysis = new Set();
19
19
  pluginCtx = {
20
20
  filePath: '',
21
21
  sourceText: '',
@@ -28,8 +28,8 @@ export class ProjectPrincipal {
28
28
  pluginVisitorObjects = [];
29
29
  _visitor;
30
30
  _localRefsVisitor;
31
- syncCompilers = new Map();
32
- asyncCompilers = new Map();
31
+ compilers = new Map();
32
+ scopedCompilers = new Map();
33
33
  paths = new Map();
34
34
  rootDirs = new Map();
35
35
  tsConfigFile;
@@ -37,33 +37,41 @@ export class ProjectPrincipal {
37
37
  cache;
38
38
  toSourceFilePath;
39
39
  findWorkspacePackageTarget;
40
+ findWorkspaceNameByFilePath;
41
+ isReportExports;
40
42
  fileManager;
41
43
  resolveModule = () => undefined;
42
44
  resolveGlobPattern = pattern => [pattern];
43
45
  resolvedFiles = new Set();
44
46
  deletedFiles = new Set();
45
47
  onPathAdded;
46
- constructor(options, toSourceFilePath, findWorkspacePackageTarget) {
48
+ constructor(options, toSourceFilePath, findWorkspacePackageTarget, findWorkspaceNameByFilePath) {
47
49
  this.cache = new CacheConsultant('root', options);
48
50
  this.toSourceFilePath = toSourceFilePath;
49
51
  this.findWorkspacePackageTarget = findWorkspacePackageTarget;
52
+ this.findWorkspaceNameByFilePath = findWorkspaceNameByFilePath;
53
+ this.isReportExports = options.isReportExports;
50
54
  this.tsConfigFile = options.tsConfigFile ? toAbsolute(options.tsConfigFile, options.cwd) : undefined;
51
55
  this.pluginVisitorObjects.push(createBunShellVisitor(this.pluginCtx));
52
56
  this.fileManager = new SourceFileManager({
53
- compilers: [this.syncCompilers, this.asyncCompilers],
57
+ compilers: this.compilers,
58
+ isSession: options.isSession || options.isWatch,
54
59
  });
55
60
  this.walkAndAnalyze = timerify(this.walkAndAnalyze.bind(this), 'walkAndAnalyze');
56
61
  }
57
- addCompilers(compilers) {
58
- for (const [ext, compiler] of compilers[0]) {
59
- if (!this.syncCompilers.has(ext)) {
60
- this.syncCompilers.set(ext, compiler);
61
- this.extensions.add(ext);
62
+ addCompilers(workspaceName, compilers) {
63
+ for (const [ext, compiler] of compilers) {
64
+ const workspaceCompilers = this.scopedCompilers.get(ext);
65
+ if (workspaceCompilers) {
66
+ workspaceCompilers.set(workspaceName, compiler);
62
67
  }
63
- }
64
- for (const [ext, compiler] of compilers[1]) {
65
- if (!this.asyncCompilers.has(ext)) {
66
- this.asyncCompilers.set(ext, compiler);
68
+ else {
69
+ const workspaceCompilers = new Map([[workspaceName, compiler]]);
70
+ this.scopedCompilers.set(ext, workspaceCompilers);
71
+ this.compilers.set(ext, (source, filePath) => {
72
+ const owner = this.findWorkspaceNameByFilePath(filePath);
73
+ return ((owner ? workspaceCompilers.get(owner) : undefined) ?? compiler)(source, filePath);
74
+ });
67
75
  this.extensions.add(ext);
68
76
  }
69
77
  }
@@ -85,19 +93,11 @@ export class ProjectPrincipal {
85
93
  this.rootDirs.set(scope, compact([...scoped, ...rootDirs]));
86
94
  }
87
95
  init() {
88
- this.extensions = new Set([
89
- ...DEFAULT_EXTENSIONS,
90
- ...getCompilerExtensions([this.syncCompilers, this.asyncCompilers]),
91
- ]);
92
- const customCompilerExtensions = getCompilerExtensions([this.syncCompilers, this.asyncCompilers]);
93
96
  const scopedPaths = this.paths.size > 0 ? Array.from(this.paths, ([scope, paths]) => ({ scope, paths })) : undefined;
94
97
  const scopedRootDirs = this.rootDirs.size > 0 ? Array.from(this.rootDirs, ([scope, rootDirs]) => ({ scope, rootDirs })) : undefined;
95
- this.resolveModule = createCustomModuleResolver({ scopedPaths, scopedRootDirs }, customCompilerExtensions, this.toSourceFilePath, this.findWorkspacePackageTarget, this.tsConfigFile);
98
+ this.resolveModule = createCustomModuleResolver({ scopedPaths, scopedRootDirs }, [...this.compilers.keys()], this.toSourceFilePath, this.findWorkspacePackageTarget, this.tsConfigFile);
96
99
  this.resolveGlobPattern = createGlobAliasResolver(scopedPaths);
97
100
  }
98
- readFile(filePath) {
99
- return this.fileManager.readFile(filePath);
100
- }
101
101
  hasAcceptedExtension(filePath) {
102
102
  return this.extensions.has(extname(filePath));
103
103
  }
@@ -105,8 +105,16 @@ export class ProjectPrincipal {
105
105
  if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
106
106
  this.entryPaths.add(filePath);
107
107
  this.projectPaths.add(filePath);
108
- if (options?.skipExportsAnalysis)
109
- this.skipExportsAnalysis.add(filePath);
108
+ if (options) {
109
+ if (options.skipExportsAnalysis) {
110
+ if (!this.includeExportsAnalysis.has(filePath))
111
+ this.skipExportsAnalysis.add(filePath);
112
+ }
113
+ else {
114
+ this.includeExportsAnalysis.add(filePath);
115
+ this.skipExportsAnalysis.delete(filePath);
116
+ }
117
+ }
110
118
  this.onPathAdded?.(filePath);
111
119
  }
112
120
  }
@@ -129,23 +137,19 @@ export class ProjectPrincipal {
129
137
  removeProjectPath(filePath) {
130
138
  this.entryPaths.delete(filePath);
131
139
  this.projectPaths.delete(filePath);
140
+ this.skipExportsAnalysis.delete(filePath);
141
+ this.includeExportsAnalysis.delete(filePath);
132
142
  this.invalidateFile(filePath);
133
143
  this.deletedFiles.add(filePath);
134
144
  }
135
- async runAsyncCompilers() {
136
- const add = timerify(this.fileManager.compileAndAddSourceFile.bind(this.fileManager));
137
- for (const filePath of this.projectPaths)
138
- if (this.asyncCompilers.has(extname(filePath)))
139
- await add(filePath);
140
- }
141
- walkAndAnalyze(analyzeFile) {
145
+ async walkAndAnalyze(analyzeFile) {
142
146
  this.resolvedFiles.clear();
143
147
  const visited = new Set([...this.entryPaths, ...this.programPaths]);
144
148
  this.onPathAdded = p => visited.add(p);
145
149
  try {
146
150
  for (const filePath of visited) {
147
151
  const isProjectPath = this.projectPaths.has(filePath);
148
- const cachedFile = isProjectPath ? this.cache.getCachedFile(filePath) : undefined;
152
+ const cachedFile = isProjectPath ? this.getCachedFile(filePath) : undefined;
149
153
  if (cachedFile) {
150
154
  const internalPaths = analyzeFile(filePath, undefined, '', cachedFile);
151
155
  if (internalPaths)
@@ -153,7 +157,8 @@ export class ProjectPrincipal {
153
157
  visited.add(p);
154
158
  continue;
155
159
  }
156
- const sourceText = this.fileManager.readFile(filePath);
160
+ const loaded = this.fileManager.loadSourceText(filePath);
161
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
157
162
  if (!sourceText) {
158
163
  if (isProjectPath)
159
164
  analyzeFile(filePath, undefined, '');
@@ -185,11 +190,12 @@ export class ProjectPrincipal {
185
190
  }
186
191
  this.resolvedFiles = visited;
187
192
  }
188
- getUsedResolvedFiles() {
193
+ async getUsedResolvedFiles() {
189
194
  this.resolvedFiles.clear();
190
195
  const visited = new Set([...this.entryPaths, ...this.programPaths]);
191
196
  for (const filePath of visited) {
192
- const sourceText = this.fileManager.readFile(filePath);
197
+ const loaded = this.fileManager.loadSourceText(filePath);
198
+ const sourceText = typeof loaded === 'string' ? loaded : await loaded;
193
199
  if (!sourceText)
194
200
  continue;
195
201
  try {
@@ -204,7 +210,11 @@ export class ProjectPrincipal {
204
210
  }
205
211
  }
206
212
  this.resolvedFiles = visited;
207
- return Array.from(this.projectPaths).filter(filePath => visited.has(filePath));
213
+ const usedFiles = new Set();
214
+ for (const filePath of this.projectPaths)
215
+ if (visited.has(filePath))
216
+ usedFiles.add(filePath);
217
+ return usedFiles;
208
218
  }
209
219
  resolveSpecifier(specifier, containingFile) {
210
220
  return this.resolveModule(specifier, containingFile)?.resolvedFileName;
@@ -212,17 +222,21 @@ export class ProjectPrincipal {
212
222
  getUnreferencedFiles() {
213
223
  return Array.from(this.projectPaths).filter(filePath => !this.resolvedFiles.has(filePath));
214
224
  }
215
- analyzeSourceFile(filePath, options, ignoreExportsUsedInFile, parseResult, sourceText, cachedFile) {
225
+ getCachedFile(filePath) {
226
+ const cachedFile = this.cache.getCachedFile(filePath);
227
+ const skipExports = this.skipExportsAnalysis.has(filePath) || !this.isReportExports;
228
+ return cachedFile?.skipExports === skipExports ? cachedFile : undefined;
229
+ }
230
+ analyzeSourceFile(filePath, sourceText, options, ignoreExportsUsedInFile, parseResult, cachedFile) {
216
231
  if (cachedFile)
217
232
  return cachedFile;
218
- const cached = this.cache.getCachedFile(filePath);
233
+ const cached = this.getCachedFile(filePath);
219
234
  if (cached)
220
235
  return cached;
221
- sourceText ??= this.fileManager.readFile(filePath);
222
236
  const skipExports = this.skipExportsAnalysis.has(filePath);
223
237
  if (options.isFixExports || options.isFixTypes) {
224
238
  const ext = extname(filePath);
225
- if (!DEFAULT_EXTENSIONS.has(ext) && (this.syncCompilers.has(ext) || this.asyncCompilers.has(ext))) {
239
+ if (!DEFAULT_EXTENSIONS.has(ext) && this.compilers.has(ext)) {
226
240
  options = { ...options, isFixExports: false, isFixTypes: false };
227
241
  }
228
242
  }
@@ -233,6 +247,7 @@ export class ProjectPrincipal {
233
247
  }
234
248
  invalidateFile(filePath) {
235
249
  this.fileManager.invalidate(filePath);
250
+ this.cache.removeEntry(filePath);
236
251
  }
237
252
  reconcileCache(graph) {
238
253
  for (const [filePath, file] of graph) {
@@ -18,7 +18,7 @@ type WorkspaceManagerOptions = {
18
18
  handleInput: HandleInput;
19
19
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
20
20
  getManifest: (dir: string) => Manifest | undefined;
21
- readFile: (filePath: string) => string;
21
+ readRawFile: (filePath: string) => string;
22
22
  negatedWorkspacePatterns: string[];
23
23
  ignoredWorkspacePatterns: string[];
24
24
  enabledPluginsInAncestors: string[];
@@ -40,7 +40,7 @@ export declare class WorkspaceWorker {
40
40
  handleInput: HandleInput;
41
41
  findWorkspaceByFilePath: (filePath: string) => Workspace | undefined;
42
42
  getManifest: (dir: string) => Manifest | undefined;
43
- readFile: (filePath: string) => string;
43
+ readRawFile: (filePath: string) => string;
44
44
  negatedWorkspacePatterns: string[];
45
45
  ignoredWorkspacePatterns: string[];
46
46
  options: MainOptions;
@@ -49,7 +49,7 @@ export declare class WorkspaceWorker {
49
49
  enabledPluginsInAncestors: string[];
50
50
  cache: CacheConsultant<CacheItem>;
51
51
  configFilesMap: Map<string, Map<PluginName, Set<string>>>;
52
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readFile, configFilesMap, options, }: WorkspaceManagerOptions);
52
+ constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, options, }: WorkspaceManagerOptions);
53
53
  init(): Promise<void>;
54
54
  private determineEnabledPlugins;
55
55
  private getConfigForPlugin;
@@ -31,7 +31,7 @@ export class WorkspaceWorker {
31
31
  handleInput;
32
32
  findWorkspaceByFilePath;
33
33
  getManifest;
34
- readFile;
34
+ readRawFile;
35
35
  negatedWorkspacePatterns = [];
36
36
  ignoredWorkspacePatterns = [];
37
37
  options;
@@ -40,7 +40,7 @@ export class WorkspaceWorker {
40
40
  enabledPluginsInAncestors;
41
41
  cache;
42
42
  configFilesMap;
43
- constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readFile, configFilesMap, options, }) {
43
+ constructor({ name, dir, config, manifest, dependencies, rootManifest, negatedWorkspacePatterns, ignoredWorkspacePatterns, enabledPluginsInAncestors, handleInput, findWorkspaceByFilePath, getManifest, readRawFile, configFilesMap, options, }) {
44
44
  this.name = name;
45
45
  this.dir = dir;
46
46
  this.config = config;
@@ -54,7 +54,7 @@ export class WorkspaceWorker {
54
54
  this.handleInput = handleInput;
55
55
  this.findWorkspaceByFilePath = findWorkspaceByFilePath;
56
56
  this.getManifest = getManifest;
57
- this.readFile = readFile;
57
+ this.readRawFile = readRawFile;
58
58
  this.options = options;
59
59
  this.cache = new CacheConsultant(`plugins-${name}`, options);
60
60
  this.getConfigurationHints = timerify(this.getConfigurationHints.bind(this), 'getConfigurationHints');
@@ -341,7 +341,7 @@ export class WorkspaceWorker {
341
341
  parsed = parsedConfigCache.get(configFilePath);
342
342
  }
343
343
  else {
344
- const sourceText = this.readFile(configFilePath);
344
+ const sourceText = this.readRawFile(configFilePath);
345
345
  parsed = sourceText ? _parseFile(configFilePath, sourceText) : undefined;
346
346
  parsedConfigCache.set(configFilePath, parsed);
347
347
  }
@@ -387,7 +387,7 @@ export class WorkspaceWorker {
387
387
  }
388
388
  }
389
389
  if (plugin.resolveFromAST && parsed) {
390
- const resolveASTOpts = { ...resolveOpts, readFile: this.readFile };
390
+ const resolveASTOpts = { ...resolveOpts, readFile: this.readRawFile };
391
391
  const inputs = plugin.resolveFromAST(parsed.program, resolveASTOpts);
392
392
  for (const input of inputs)
393
393
  addInput(input, configFilePath);
@@ -461,7 +461,7 @@ export class WorkspaceWorker {
461
461
  if (visited.has(filePath))
462
462
  return;
463
463
  visited.add(filePath);
464
- const sourceText = this.readFile(filePath);
464
+ const sourceText = this.readRawFile(filePath);
465
465
  if (!sourceText)
466
466
  return;
467
467
  for (const literal of collectStringLiterals(sourceText, filePath)) {
@@ -9,4 +9,8 @@ export declare class YamlCatalogPeeker {
9
9
  line: number;
10
10
  col: number;
11
11
  } | undefined;
12
+ getOverrideCatalogReferenceLocation(selector: string): {
13
+ line: number;
14
+ col: number;
15
+ } | undefined;
12
16
  }
@@ -22,6 +22,9 @@ export class YamlCatalogPeeker {
22
22
  else if (line.startsWith('catalogs:')) {
23
23
  this.sections.catalogs = i;
24
24
  }
25
+ else if (line.startsWith('overrides:')) {
26
+ this.sections.overrides = i;
27
+ }
25
28
  }
26
29
  this.ready = true;
27
30
  }
@@ -63,4 +66,18 @@ export class YamlCatalogPeeker {
63
66
  }
64
67
  }
65
68
  }
69
+ getOverrideCatalogReferenceLocation(selector) {
70
+ if (!this.ready)
71
+ this.init();
72
+ const startLine = this.sections.overrides;
73
+ if (typeof startLine === 'undefined')
74
+ return;
75
+ for (let i = startLine + 1; i < this.lines.length; i++) {
76
+ const line = this.lines[i];
77
+ if (!line.startsWith(' '))
78
+ break;
79
+ if (matchesKey(line, ' ', selector))
80
+ return { line: i + 1, col: line.indexOf(selector) + 1 };
81
+ }
82
+ }
66
83
  }
@@ -1,3 +1,3 @@
1
1
  import type { GetInputsFromScriptsOptions } from '../types/config.ts';
2
- import { type Input } from '../util/input.ts';
2
+ import type { Input } from '../util/input.ts';
3
3
  export declare const getDependenciesFromScript: (script: string, options: GetInputsFromScriptsOptions) => Input[];