Skip to content

Commit 817e45d

Browse files
authored
Dont update timestamps of output files if noEmit was specified (#44306)
* Add failing test for #44303 * Dont update timestamps of output files if noEmit was specified. Fixes #44303
1 parent 7c31d97 commit 817e45d

File tree

6 files changed

+462
-0
lines changed

6 files changed

+462
-0
lines changed

src/compiler/tsbuildPublic.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,7 @@ namespace ts {
15421542
}
15431543

15441544
function updateOutputTimestampsWorker(state: SolutionBuilderState, proj: ParsedCommandLine, priorNewestUpdateTime: Date, verboseMessage: DiagnosticMessage, skipOutputs?: ESMap<Path, string>) {
1545+
if (proj.options.noEmit) return priorNewestUpdateTime;
15451546
const { host } = state;
15461547
const outputs = getAllProjectOutputs(proj, !host.useCaseSensitiveFileNames());
15471548
if (!skipOutputs || outputs.length !== skipOutputs.size) {

src/harness/virtualFileSystemWithWatch.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ interface Array<T> { length: number; [n: number]: T; }`
870870
const fsEntry = this.fs.get(path);
871871
if (fsEntry) {
872872
fsEntry.modifiedTime = date;
873+
this.invokeFileAndFsWatches(fsEntry.fullPath, FileWatcherEventKind.Changed);
873874
}
874875
}
875876

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
"unittests/tsbuildWatch/configFileErrors.ts",
139139
"unittests/tsbuildWatch/demo.ts",
140140
"unittests/tsbuildWatch/moduleResolution.ts",
141+
"unittests/tsbuildWatch/noEmit.ts",
141142
"unittests/tsbuildWatch/noEmitOnError.ts",
142143
"unittests/tsbuildWatch/programUpdates.ts",
143144
"unittests/tsbuildWatch/reexport.ts",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsbuildWatch:: watchMode:: with noEmit", () => {
3+
verifyTscWatch({
4+
scenario: "noEmit",
5+
subScenario: "does not go in loop when watching when no files are emitted",
6+
commandLineArgs: ["-b", "-w", "-verbose"],
7+
sys: () => createWatchedSystem(
8+
[
9+
libFile,
10+
{ path: `${projectRoot}/a.js`, content: "" },
11+
{ path: `${projectRoot}/b.ts`, content: "" },
12+
{ path: `${projectRoot}/tsconfig.json`, content: JSON.stringify({ compilerOptions: { allowJs: true, noEmit: true } }) },
13+
{ path: libFile.path, content: libContent }
14+
],
15+
{ currentDirectory: projectRoot }
16+
),
17+
changes: [
18+
{
19+
caption: "No change",
20+
change: sys => sys.writeFile(`${projectRoot}/a.js`, sys.readFile(`${projectRoot}/a.js`)!),
21+
// build project
22+
timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout,
23+
},
24+
{
25+
caption: "change",
26+
change: sys => sys.writeFile(`${projectRoot}/a.js`, "const x = 10;"),
27+
// build project
28+
timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout,
29+
},
30+
],
31+
baselineIncremental: true
32+
});
33+
});
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
Input::
2+
//// [/a/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/user/username/projects/myproject/a.js]
18+
19+
20+
//// [/user/username/projects/myproject/b.ts]
21+
22+
23+
//// [/user/username/projects/myproject/tsconfig.json]
24+
{"compilerOptions":{"allowJs":true,"noEmit":true}}
25+
26+
27+
/a/lib/tsc.js -b -w -verbose --incremental
28+
Output::
29+
>> Screen clear
30+
[12:00:25 AM] Starting compilation in watch mode...
31+
32+
[12:00:26 AM] Projects in this build:
33+
* tsconfig.json
34+
35+
[12:00:27 AM] Project 'tsconfig.json' is out of date because oldest output 'a.js' is older than newest input 'b.ts'
36+
37+
[12:00:28 AM] Building project '/user/username/projects/myproject/tsconfig.json'...
38+
39+
[12:00:33 AM] Found 0 errors. Watching for file changes.
40+
41+
42+
43+
Program root files: ["/user/username/projects/myproject/a.js","/user/username/projects/myproject/b.ts"]
44+
Program options: {"allowJs":true,"noEmit":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
45+
Program structureReused: Not
46+
Program files::
47+
/a/lib/lib.d.ts
48+
/user/username/projects/myproject/a.js
49+
/user/username/projects/myproject/b.ts
50+
51+
Semantic diagnostics in builder refreshed for::
52+
/a/lib/lib.d.ts
53+
/user/username/projects/myproject/a.js
54+
/user/username/projects/myproject/b.ts
55+
56+
WatchedFiles::
57+
/user/username/projects/myproject/tsconfig.json:
58+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
59+
/user/username/projects/myproject/a.js:
60+
{"fileName":"/user/username/projects/myproject/a.js","pollingInterval":250}
61+
/user/username/projects/myproject/b.ts:
62+
{"fileName":"/user/username/projects/myproject/b.ts","pollingInterval":250}
63+
64+
FsWatches::
65+
66+
FsWatchesRecursive::
67+
/user/username/projects/myproject:
68+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
69+
70+
exitCode:: ExitStatus.undefined
71+
72+
//// [/user/username/projects/myproject/tsconfig.tsbuildinfo]
73+
{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./a.js","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},"5381-","5381-"],"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3],"affectedFilesPendingEmit":[[2,1],[3,1]]},"version":"FakeTSVersion"}
74+
75+
//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt]
76+
{
77+
"program": {
78+
"fileNames": [
79+
"../../../../a/lib/lib.d.ts",
80+
"./a.js",
81+
"./b.ts"
82+
],
83+
"fileInfos": {
84+
"../../../../a/lib/lib.d.ts": {
85+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
86+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
87+
"affectsGlobalScope": true
88+
},
89+
"./a.js": {
90+
"version": "5381-",
91+
"signature": "5381-"
92+
},
93+
"./b.ts": {
94+
"version": "5381-",
95+
"signature": "5381-"
96+
}
97+
},
98+
"referencedMap": {},
99+
"exportedModulesMap": {},
100+
"semanticDiagnosticsPerFile": [
101+
"../../../../a/lib/lib.d.ts",
102+
"./a.js",
103+
"./b.ts"
104+
],
105+
"affectedFilesPendingEmit": [
106+
[
107+
"./a.js",
108+
"Full"
109+
],
110+
[
111+
"./b.ts",
112+
"Full"
113+
]
114+
]
115+
},
116+
"version": "FakeTSVersion",
117+
"size": 730
118+
}
119+
120+
121+
Change:: No change
122+
123+
Input::
124+
//// [/user/username/projects/myproject/a.js] file written with same contents
125+
126+
Output::
127+
>> Screen clear
128+
[12:00:37 AM] File change detected. Starting incremental compilation...
129+
130+
[12:00:38 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
131+
132+
[12:00:39 AM] Building project '/user/username/projects/myproject/tsconfig.json'...
133+
134+
[12:00:40 AM] Found 0 errors. Watching for file changes.
135+
136+
137+
138+
Program root files: ["/user/username/projects/myproject/a.js","/user/username/projects/myproject/b.ts"]
139+
Program options: {"allowJs":true,"noEmit":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
140+
Program structureReused: Not
141+
Program files::
142+
/a/lib/lib.d.ts
143+
/user/username/projects/myproject/a.js
144+
/user/username/projects/myproject/b.ts
145+
146+
Semantic diagnostics in builder refreshed for::
147+
148+
WatchedFiles::
149+
/user/username/projects/myproject/tsconfig.json:
150+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
151+
/user/username/projects/myproject/a.js:
152+
{"fileName":"/user/username/projects/myproject/a.js","pollingInterval":250}
153+
/user/username/projects/myproject/b.ts:
154+
{"fileName":"/user/username/projects/myproject/b.ts","pollingInterval":250}
155+
156+
FsWatches::
157+
158+
FsWatchesRecursive::
159+
/user/username/projects/myproject:
160+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
161+
162+
exitCode:: ExitStatus.undefined
163+
164+
165+
Change:: change
166+
167+
Input::
168+
//// [/user/username/projects/myproject/a.js]
169+
const x = 10;
170+
171+
172+
Output::
173+
>> Screen clear
174+
[12:00:44 AM] File change detected. Starting incremental compilation...
175+
176+
[12:00:45 AM] Project 'tsconfig.json' is out of date because output file 'b.js' does not exist
177+
178+
[12:00:46 AM] Building project '/user/username/projects/myproject/tsconfig.json'...
179+
180+
[12:00:53 AM] Found 0 errors. Watching for file changes.
181+
182+
183+
184+
Program root files: ["/user/username/projects/myproject/a.js","/user/username/projects/myproject/b.ts"]
185+
Program options: {"allowJs":true,"noEmit":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
186+
Program structureReused: Not
187+
Program files::
188+
/a/lib/lib.d.ts
189+
/user/username/projects/myproject/a.js
190+
/user/username/projects/myproject/b.ts
191+
192+
Semantic diagnostics in builder refreshed for::
193+
/a/lib/lib.d.ts
194+
/user/username/projects/myproject/a.js
195+
/user/username/projects/myproject/b.ts
196+
197+
WatchedFiles::
198+
/user/username/projects/myproject/tsconfig.json:
199+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
200+
/user/username/projects/myproject/a.js:
201+
{"fileName":"/user/username/projects/myproject/a.js","pollingInterval":250}
202+
/user/username/projects/myproject/b.ts:
203+
{"fileName":"/user/username/projects/myproject/b.ts","pollingInterval":250}
204+
205+
FsWatches::
206+
207+
FsWatchesRecursive::
208+
/user/username/projects/myproject:
209+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
210+
211+
exitCode:: ExitStatus.undefined
212+
213+
//// [/user/username/projects/myproject/tsconfig.tsbuildinfo]
214+
{"program":{"fileNames":["../../../../a/lib/lib.d.ts","./a.js","./b.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"5029505981-const x = 10;","signature":"-3042032780-declare const x: 10;\n","affectsGlobalScope":true},"5381-"],"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2,3],"affectedFilesPendingEmit":[[2,1],[3,1]]},"version":"FakeTSVersion"}
215+
216+
//// [/user/username/projects/myproject/tsconfig.tsbuildinfo.readable.baseline.txt]
217+
{
218+
"program": {
219+
"fileNames": [
220+
"../../../../a/lib/lib.d.ts",
221+
"./a.js",
222+
"./b.ts"
223+
],
224+
"fileInfos": {
225+
"../../../../a/lib/lib.d.ts": {
226+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
227+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
228+
"affectsGlobalScope": true
229+
},
230+
"./a.js": {
231+
"version": "5029505981-const x = 10;",
232+
"signature": "-3042032780-declare const x: 10;\n",
233+
"affectsGlobalScope": true
234+
},
235+
"./b.ts": {
236+
"version": "5381-",
237+
"signature": "5381-"
238+
}
239+
},
240+
"referencedMap": {},
241+
"exportedModulesMap": {},
242+
"semanticDiagnosticsPerFile": [
243+
"../../../../a/lib/lib.d.ts",
244+
"./a.js",
245+
"./b.ts"
246+
],
247+
"affectedFilesPendingEmit": [
248+
[
249+
"./a.js",
250+
"Full"
251+
],
252+
[
253+
"./b.ts",
254+
"Full"
255+
]
256+
]
257+
},
258+
"version": "FakeTSVersion",
259+
"size": 836
260+
}
261+

0 commit comments

Comments
 (0)