Skip to content

Commit f3f70df

Browse files
authored
Dont fail on "create" event when watching package json files (#57971)
1 parent 54504fc commit f3f70df

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/server/editorServices.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4682,7 +4682,6 @@ export class ProjectService {
46824682
(fileName, eventKind) => {
46834683
switch (eventKind) {
46844684
case FileWatcherEventKind.Created:
4685-
return Debug.fail();
46864685
case FileWatcherEventKind.Changed:
46874686
this.packageJsonCache.addOrUpdate(fileName, path);
46884687
this.onPackageJsonChange(result);

src/testRunner/unittests/helpers/virtualFileSystemWithWatch.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ export interface WatchInvokeOptions {
290290
invokeFileDeleteCreateAsPartInsteadOfChange: boolean;
291291
/** Dont invoke delete watches */
292292
ignoreDelete: boolean;
293+
/** ignore all watches */
294+
ignoreWatches?: boolean;
293295
/** Skip inode check on file or folder create*/
294296
skipInodeCheckOnCreate: boolean;
295297
/** 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,
501503
else {
502504
currentEntry.content = content;
503505
currentEntry.modifiedTime = this.now();
506+
if (options?.ignoreWatches) return;
504507
if (options && options.invokeDirectoryWatcherInsteadOfFileChanged) {
505508
const directoryFullPath = getDirectoryPath(currentEntry.fullPath);
506509
this.fs.get(getDirectoryPath(currentEntry.path))!.modifiedTime = this.now();
@@ -628,7 +631,7 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
628631
this.fs.set(fileOrDirectory.path, fileOrDirectory);
629632
this.setInode(fileOrDirectory.path);
630633

631-
if (ignoreWatch) {
634+
if (ignoreWatch || options?.ignoreWatches) {
632635
return;
633636
}
634637
const inodeWatching = this.inodeWatching;
@@ -651,9 +654,9 @@ export class TestServerHost implements server.ServerHost, FormatDiagnosticsHost,
651654
if (isFsFolder(fileOrDirectory)) {
652655
Debug.assert(fileOrDirectory.entries.length === 0 || isRenaming);
653656
}
654-
if (!options?.ignoreDelete) this.invokeFileAndFsWatches(fileOrDirectory.fullPath, FileWatcherEventKind.Deleted, /*modifiedTime*/ undefined, options?.useTildeAsSuffixInRenameEventFileName);
657+
if (!options?.ignoreDelete && !options?.ignoreWatches) this.invokeFileAndFsWatches(fileOrDirectory.fullPath, FileWatcherEventKind.Deleted, /*modifiedTime*/ undefined, options?.useTildeAsSuffixInRenameEventFileName);
655658
this.inodes?.delete(fileOrDirectory.path);
656-
if (!options?.ignoreDelete) this.invokeFileAndFsWatches(baseFolder.fullPath, FileWatcherEventKind.Changed, baseFolder.modifiedTime, options?.useTildeAsSuffixInRenameEventFileName);
659+
if (!options?.ignoreDelete && !options?.ignoreWatches) this.invokeFileAndFsWatches(baseFolder.fullPath, FileWatcherEventKind.Changed, baseFolder.modifiedTime, options?.useTildeAsSuffixInRenameEventFileName);
657660
}
658661

659662
deleteFile(filePath: string) {

src/testRunner/unittests/tsserver/moduleResolution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ describe("unittests:: tsserver:: moduleResolution", () => {
7676
const { host, session, packageFile, verifyErr } = setup(jsonToReadableText({ name: "app", version: "1.0.0" }));
7777

7878
session.logger.info("Modify package json file to add type module");
79-
host.writeFile(
79+
host.modifyFile(
8080
packageFile.path,
8181
jsonToReadableText({
8282
name: "app",
8383
version: "1.0.0",
8484
type: "module",
8585
}),
86+
{ ignoreWatches: true },
8687
);
88+
host.invokeFsWatches(packageFile.path, "rename", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined); // Create event instead of change
8789
host.runQueuedTimeoutCallbacks(); // Failed lookup updates
8890
host.runQueuedTimeoutCallbacks(); // Actual update
8991
verifyErr();

tests/baselines/reference/tsserver/moduleResolution/package-json-file-is-edited.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ ScriptInfos::
244244
/user/username/projects/myproject/src/tsconfig.json
245245

246246
Info seq [hh:mm:ss:mss] Modify package json file to add type module
247-
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
247+
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
248248
Info seq [hh:mm:ss:mss] Scheduled: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
249-
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
250-
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
251-
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
249+
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
250+
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
251+
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
252252
Before running Timeout callback:: count: 1
253253
1: /user/username/projects/myproject/src/tsconfig.jsonFailedLookupInvalidation
254254
//// [/user/username/projects/myproject/package.json]

0 commit comments

Comments
 (0)