Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty string when getting file version #51689

Merged
merged 2 commits into from Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/tsbuildPublic.ts
Expand Up @@ -1811,7 +1811,7 @@ function getUpToDateStatusWorker(state: SolutionBuilderState, project: ParsedCom
if (!buildInfoVersionMap) buildInfoVersionMap = getBuildInfoFileVersionMap(buildInfoProgram, buildInfoPath!, host);
version = buildInfoVersionMap.get(toPath(state, inputFile));
const text = version ? state.readFileWithCache(inputFile) : undefined;
currentVersion = text && getSourceFileVersionAsHashFromText(host, text);
currentVersion = text !== undefined ? getSourceFileVersionAsHashFromText(host, text) : undefined;
if (version && version === currentVersion) pseudoInputUpToDate = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/watchPublic.ts
Expand Up @@ -715,7 +715,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
if (hostSourceFile.version) return hostSourceFile.version;
// Read file and get new version
const text = readFileWithCache(path);
return text ? getSourceFileVersionAsHashFromText(compilerHost, text) : undefined;
return text !== undefined ? getSourceFileVersionAsHashFromText(compilerHost, text) : undefined;
}

function onReleaseOldSourceFile(oldSourceFile: SourceFile, _oldOptions: CompilerOptions, hasSourceFileByPath: boolean) {
Expand Down
10 changes: 10 additions & 0 deletions src/testRunner/unittests/tscWatch/watchEnvironment.ts
Expand Up @@ -717,6 +717,16 @@ describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different po
change: sys => sys.replaceFileText("/user/username/projects/project/main.ts", "Hello", "Hello World"),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "receive another change event without modifying the file",
change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "change main.ts to empty text",
change: sys => sys.writeFile("/user/username/projects/project/main.ts", ""),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "receive another change event without modifying the file",
change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined),
Expand Down
Expand Up @@ -136,25 +136,11 @@ Output::
>> Screen clear
[12:00:36 AM] File change detected. Starting incremental compilation...

[12:00:37 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'
[12:00:37 AM] Project 'tsconfig.json' is up to date but needs to update timestamps of output files that are older than input files

[12:00:38 AM] Building project '/user/username/projects/myproject/tsconfig.json'...
[12:00:38 AM] Found 0 errors. Watching for file changes.

[12:00:39 AM] Found 0 errors. Watching for file changes.



Program root files: ["/user/username/projects/myproject/a.js","/user/username/projects/myproject/b.ts"]
Program options: {"allowJs":true,"noEmit":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.d.ts
/user/username/projects/myproject/a.js
/user/username/projects/myproject/b.ts

Semantic diagnostics in builder refreshed for::

No shapes updated in the builder::

PolledWatches::

Expand Down Expand Up @@ -182,13 +168,13 @@ const x = 10;

Output::
>> Screen clear
[12:00:43 AM] File change detected. Starting incremental compilation...
[12:00:42 AM] File change detected. Starting incremental compilation...

[12:00:44 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'
[12:00:43 AM] Project 'tsconfig.json' is out of date because output 'tsconfig.tsbuildinfo' is older than input 'a.js'

[12:00:45 AM] Building project '/user/username/projects/myproject/tsconfig.json'...
[12:00:44 AM] Building project '/user/username/projects/myproject/tsconfig.json'...

[12:00:53 AM] Found 0 errors. Watching for file changes.
[12:00:52 AM] Found 0 errors. Watching for file changes.



Expand Down
Expand Up @@ -121,6 +121,84 @@ var a = "Hello World";



Change:: receive another change event without modifying the file

Input::

Output::
FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Scheduling update
Elapsed:: *ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Synchronizing program


PolledWatches::
/user/username/projects/project/node_modules/@types:
{"pollingInterval":500}

FsWatches::
/user/username/projects/project/main.ts:
{}
/a/lib/lib.d.ts:
{}

FsWatchesRecursive::

exitCode:: ExitStatus.undefined


Change:: change main.ts to empty text

Input::
//// [/user/username/projects/project/main.ts]



Output::
FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Scheduling update
Elapsed:: *ms FileWatcher:: Triggered with main.ts 1:: WatchInfo: main.ts 250 undefined Source file
Synchronizing program
[12:00:34 AM] File change detected. Starting incremental compilation...

CreatingProgramWith::
roots: ["main.ts"]
options: {"watch":true,"extendedDiagnostics":true}
[12:00:38 AM] Found 0 errors. Watching for file changes.



Program root files: ["main.ts"]
Program options: {"watch":true,"extendedDiagnostics":true}
Program structureReused: Completely
Program files::
/a/lib/lib.d.ts
main.ts

Semantic diagnostics in builder refreshed for::
main.ts

Shape signatures in builder refreshed for::
/user/username/projects/project/main.ts (used version)

PolledWatches::
/user/username/projects/project/node_modules/@types:
{"pollingInterval":500}

FsWatches::
/user/username/projects/project/main.ts:
{}
/a/lib/lib.d.ts:
{}

FsWatchesRecursive::

exitCode:: ExitStatus.undefined

//// [/user/username/projects/project/main.js]



Change:: receive another change event without modifying the file

Input::
Expand Down