Skip to content

Commit c216b2d

Browse files
authored
Trace document registry operations (microsoft#47785)
...to help detect misconfigurations like microsoft#47687.
1 parent 1b6fb99 commit c216b2d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/services/documentRegistry.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,27 @@ namespace ts {
202202
scriptKind?: ScriptKind): SourceFile {
203203
scriptKind = ensureScriptKind(fileName, scriptKind);
204204
const scriptTarget = scriptKind === ScriptKind.JSON ? ScriptTarget.JSON : getEmitScriptTarget(compilationSettings);
205+
206+
const oldBucketCount = buckets.size;
205207
const bucket = getOrUpdate(buckets, key, () => new Map());
208+
if (tracing) {
209+
if (buckets.size > oldBucketCount) {
210+
// It is interesting, but not definitively problematic if a build requires multiple document registry buckets -
211+
// perhaps they are for two projects that don't have any overlap.
212+
// Bonus: these events can help us interpret the more interesting event below.
213+
tracing.instant(tracing.Phase.Session, "createdDocumentRegistryBucket", { configFilePath: compilationSettings.configFilePath, key });
214+
}
215+
216+
// It is fairly suspicious to have one path in two buckets - you'd expect dependencies to have similar configurations.
217+
// If this occurs unexpectedly, the fix is likely to synchronize the project settings.
218+
// Skip .d.ts files to reduce noise (should also cover most of node_modules).
219+
const otherBucketKey = !fileExtensionIs(path, Extension.Dts) &&
220+
forEachEntry(buckets, (bucket, bucketKey) => bucketKey !== key && bucket.has(path) && bucketKey);
221+
if (otherBucketKey) {
222+
tracing.instant(tracing.Phase.Session, "documentRegistryBucketOverlap", { path, key1: otherBucketKey, key2: key });
223+
}
224+
}
225+
206226
const bucketEntry = bucket.get(path);
207227
let entry = bucketEntry && getDocumentRegistryEntry(bucketEntry, scriptKind);
208228
if (!entry && externalCache) {

0 commit comments

Comments
 (0)