Skip to content

Commit ea69909

Browse files
authored
We may not always get file notifications for file creation, so always check for failed lookups starting with the path as well as exact path (#59882)
1 parent 2fb1363 commit ea69909

File tree

3 files changed

+418
-0
lines changed

3 files changed

+418
-0
lines changed

src/compiler/resolutionCache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,6 +1537,10 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
15371537
// Resolution need to be invalidated if failed lookup location is same as the file or directory getting created
15381538
(failedLookupChecks ||= new Set()).add(fileOrDirectoryPath);
15391539

1540+
// Also any path that starts with this path should be added just in case if this is directory notification
1541+
// and we dont get any notification for file
1542+
(startsWithPathChecks ||= new Set()).add(fileOrDirectoryPath);
1543+
15401544
// If the invalidated file is from a node_modules package, invalidate everything else
15411545
// in the package since we might not get notifications for other files in the package.
15421546
// This hardens our logic against unreliable file watchers.

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,4 +720,41 @@ declare namespace NodeJS {
720720
},
721721
],
722722
});
723+
724+
verifyTscWatch({
725+
scenario,
726+
subScenario: "when dir watcher is invoked without file change",
727+
commandLineArgs: ["--w", "--traceResolution", "--extendedDiagnostics"],
728+
sys: () =>
729+
TestServerHost.createWatchedSystem({
730+
"/home/src/workspaces/project/src/main.ts": dedent`
731+
import { y } from "./app/services/generated";
732+
const x = y;
733+
`,
734+
"/home/src/workspaces/project/src/app/services/generated/index.ts": "export const y = 10;",
735+
"/home/src/workspaces/project/tsconfig.json": "{}",
736+
}),
737+
edits: [
738+
{
739+
caption: "delete folder",
740+
edit: sys => sys.deleteFolder("/home/src/workspaces/project/src/app/services/generated", /*recursive*/ true),
741+
timeouts: sys => {
742+
sys.runQueuedTimeoutCallbacks();
743+
sys.runQueuedTimeoutCallbacks();
744+
},
745+
},
746+
{
747+
caption: "generate folder",
748+
edit: sys =>
749+
sys.ensureFileOrFolder({
750+
path: "/home/src/workspaces/project/src/app/services/generated/index.ts",
751+
content: "export const y = 10;",
752+
}, /*ignoreWatchInvokedWithTriggerAsFileCreate*/ true),
753+
timeouts: sys => {
754+
sys.runQueuedTimeoutCallbacks();
755+
sys.runQueuedTimeoutCallbacks();
756+
},
757+
},
758+
],
759+
});
723760
});

0 commit comments

Comments
 (0)