Dont fail on "create" event when watching package json files (#57971)

This commit is contained in:
Sheetal Nandi 2024-03-27 14:58:43 -07:00 committed by GitHub
parent 54504fc9b3
commit f3f70df94e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 9 deletions

View File

@ -4682,7 +4682,6 @@ export class ProjectService {
(fileName, eventKind) => {
switch (eventKind) {
case FileWatcherEventKind.Created:
return Debug.fail();
case FileWatcherEventKind.Changed:
this.packageJsonCache.addOrUpdate(fileName, path);
this.onPackageJsonChange(result);

View File

@ -290,6 +290,8 @@ export interface WatchInvokeOptions {
invokeFileDeleteCreateAsPartInsteadOfChange: boolean;
/** Dont invoke delete watches */
ignoreDelete: boolean;
/** ignore all watches */
ignoreWatches?: boolean;
/** Skip inode check on file or folder create*/
skipInodeCheckOnCreate: boolean;
/** When invoking rename event on fs watch, send event with file name suffixed with tilde */
@ -501,6 +503,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
else {
currentEntry.content = content;
currentEntry.modifiedTime = this.now();
if (options?.ignoreWatches) return;
if (options && options.invokeDirectoryWatcherInsteadOfFileChanged) {
const directoryFullPath = getDirectoryPath(currentEntry.fullPath);
this.fs.get(getDirectoryPath(currentEntry.path))!.modifiedTime = this.now();
@ -628,7 +631,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
this.fs.set(fileOrDirectory.path, fileOrDirectory);
this.setInode(fileOrDirectory.path);
if (ignoreWatch) {
if (ignoreWatch || options?.ignoreWatches) {
return;
}
const inodeWatching = this.inodeWatching;
@ -651,9 +654,9 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
if (isFsFolder(fileOrDirectory)) {
Debug.assert(fileOrDirectory.entries.length === 0 || isRenaming);
}
if (!options?.ignoreDelete) this.invokeFileAndFsWatches(fileOrDirectory.fullPath, FileWatcherEventKind.Deleted, /*modifiedTime*/ undefined, options?.useTildeAsSuffixInRenameEventFileName);
if (!options?.ignoreDelete && !options?.ignoreWatches) this.invokeFileAndFsWatches(fileOrDirectory.fullPath, FileWatcherEventKind.Deleted, /*modifiedTime*/ undefined, options?.useTildeAsSuffixInRenameEventFileName);
this.inodes?.delete(fileOrDirectory.path);
if (!options?.ignoreDelete) this.invokeFileAndFsWatches(baseFolder.fullPath, FileWatcherEventKind.Changed, baseFolder.modifiedTime, options?.useTildeAsSuffixInRenameEventFileName);
if (!options?.ignoreDelete && !options?.ignoreWatches) this.invokeFileAndFsWatches(baseFolder.fullPath, FileWatcherEventKind.Changed, baseFolder.modifiedTime, options?.useTildeAsSuffixInRenameEventFileName);
}
deleteFile(filePath: string) {

View File

@ -76,14 +76,16 @@ describe("unittests:: tsserver:: moduleResolution", () => {
const { host, session, packageFile, verifyErr } = setup(jsonToReadableText({ name: "app", version: "1.0.0" }));
session.logger.info("Modify package json file to add type module");
host.writeFile(
host.modifyFile(
packageFile.path,
jsonToReadableText({
name: "app",
version: "1.0.0",
type: "module",
}),
{ ignoreWatches: true },
);
host.invokeFsWatches(packageFile.path, "rename", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined); // Create event instead of change
host.runQueuedTimeoutCallbacks(); // Failed lookup updates
host.runQueuedTimeoutCallbacks(); // Actual update
verifyErr();

View File

@ -244,11 +244,11 @@ ScriptInfos::
/user/username/projects/myproject/src/tsconfig.json
Info seq [hh:mm:ss:mss] Modify package json file to add type module
Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/package.json 1:: WatchInfo: /user/username/projects/myproject/package.json 2000 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: File location affecting resolution
Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/package.json 0:: WatchInfo: /user/username/projects/myproject/package.json 2000 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: File location affecting resolution
Info seq [hh:mm:ss:mss] Scheduled: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
Info seq [hh:mm:ss:mss] Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/package.json 1:: WatchInfo: /user/username/projects/myproject/package.json 2000 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: File location affecting resolution
Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/package.json 1:: WatchInfo: /user/username/projects/myproject/package.json 250 undefined WatchType: package.json file
Info seq [hh:mm:ss:mss] Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/package.json 1:: WatchInfo: /user/username/projects/myproject/package.json 250 undefined WatchType: package.json file
Info seq [hh:mm:ss:mss] Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/package.json 0:: WatchInfo: /user/username/projects/myproject/package.json 2000 undefined Project: /user/username/projects/myproject/src/tsconfig.json WatchType: File location affecting resolution
Info seq [hh:mm:ss:mss] FileWatcher:: Triggered with /user/username/projects/myproject/package.json 0:: WatchInfo: /user/username/projects/myproject/package.json 250 undefined WatchType: package.json file
Info seq [hh:mm:ss:mss] Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/myproject/package.json 0:: WatchInfo: /user/username/projects/myproject/package.json 250 undefined WatchType: package.json file
Before running Timeout callback:: count: 1
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
//// [/user/username/projects/myproject/package.json]