Skip to content

Commit ac34584

Browse files
authored
Set impliedNodeFormat on sourceFiles maufactured in watch mode (microsoft#46349)
1 parent cd0434a commit ac34584

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed

src/compiler/watchPublic.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ namespace ts {
560560
sourceFilesCache.set(path, false);
561561
}
562562
}
563+
if (sourceFile) {
564+
sourceFile.impliedNodeFormat = getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
565+
}
563566
return sourceFile;
564567
}
565568
return hostSourceFile.sourceFile;

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
"unittests/tsc/runWithoutArgs.ts",
159159
"unittests/tscWatch/consoleClearing.ts",
160160
"unittests/tscWatch/emit.ts",
161+
"unittests/tscWatch/nodeNextWatch.ts",
161162
"unittests/tscWatch/emitAndErrorUpdates.ts",
162163
"unittests/tscWatch/forceConsistentCasingInFileNames.ts",
163164
"unittests/tscWatch/incremental.ts",
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsc-watch:: nodeNextWatch:: emit when module emit is specified as nodenext", () => {
3+
verifyTscWatch({
4+
scenario: "nodenext watch emit",
5+
subScenario: "esm-mode file is edited",
6+
commandLineArgs: ["--w", "--p", "/project/tsconfig.json"],
7+
sys: () => {
8+
const configFile: File = {
9+
path: "/project/tsconfig.json",
10+
content: JSON.stringify({
11+
compilerOptions: {
12+
strict: true,
13+
target: "es2020",
14+
module: "nodenext",
15+
moduleResolution: "nodenext",
16+
outDir: "../dist"
17+
}
18+
})
19+
};
20+
const packageFile: File = {
21+
path: "/project/package.json",
22+
content: JSON.stringify({
23+
name: "some-proj",
24+
version: "1.0.0",
25+
description: "",
26+
type: "module",
27+
main: "index.js",
28+
})
29+
};
30+
const file1: File = {
31+
path: "/project/src/index.ts",
32+
content: Utils.dedent`
33+
import * as Thing from "thing";
34+
35+
Thing.fn();`
36+
};
37+
const declFile: File = {
38+
path: "/project/src/deps.d.ts",
39+
content: `declare module "thing";`
40+
};
41+
return createWatchedSystem([configFile, file1, declFile, packageFile, { ...libFile, path: "/a/lib/lib.es2020.full.d.ts" }]);
42+
},
43+
changes: [
44+
{
45+
caption: "Modify typescript file",
46+
change: sys => sys.modifyFile(
47+
"/project/src/index.ts",
48+
Utils.dedent`
49+
import * as Thing from "thing";
50+
Thing.fn();`,
51+
{},
52+
),
53+
timeouts: runQueuedTimeoutCallbacks,
54+
}
55+
],
56+
});
57+
});
58+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
Input::
2+
//// [/project/tsconfig.json]
3+
{"compilerOptions":{"strict":true,"target":"es2020","module":"nodenext","moduleResolution":"nodenext","outDir":"../dist"}}
4+
5+
//// [/project/src/index.ts]
6+
import * as Thing from "thing";
7+
8+
Thing.fn();
9+
10+
//// [/project/src/deps.d.ts]
11+
declare module "thing";
12+
13+
//// [/project/package.json]
14+
{"name":"some-proj","version":"1.0.0","description":"","type":"module","main":"index.js"}
15+
16+
//// [/a/lib/lib.es2020.full.d.ts]
17+
/// <reference no-default-lib="true"/>
18+
interface Boolean {}
19+
interface Function {}
20+
interface CallableFunction {}
21+
interface NewableFunction {}
22+
interface IArguments {}
23+
interface Number { toExponential: any; }
24+
interface Object {}
25+
interface RegExp {}
26+
interface String { charAt: any; }
27+
interface Array<T> { length: number; [n: number]: T; }
28+
29+
30+
/a/lib/tsc.js --w --p /project/tsconfig.json
31+
Output::
32+
>> Screen clear
33+
[12:00:21 AM] Starting compilation in watch mode...
34+
35+
[12:00:27 AM] Found 0 errors. Watching for file changes.
36+
37+
38+
39+
Program root files: ["/project/src/deps.d.ts","/project/src/index.ts"]
40+
Program options: {"strict":true,"target":7,"module":199,"moduleResolution":99,"outDir":"/dist","watch":true,"project":"/project/tsconfig.json","configFilePath":"/project/tsconfig.json"}
41+
Program structureReused: Not
42+
Program files::
43+
/a/lib/lib.es2020.full.d.ts
44+
/project/src/deps.d.ts
45+
/project/src/index.ts
46+
47+
Semantic diagnostics in builder refreshed for::
48+
/a/lib/lib.es2020.full.d.ts
49+
/project/src/deps.d.ts
50+
/project/src/index.ts
51+
52+
Shape signatures in builder refreshed for::
53+
/a/lib/lib.es2020.full.d.ts (used version)
54+
/project/src/deps.d.ts (used version)
55+
/project/src/index.ts (used version)
56+
57+
WatchedFiles::
58+
/project/tsconfig.json:
59+
{"fileName":"/project/tsconfig.json","pollingInterval":250}
60+
/project/src/deps.d.ts:
61+
{"fileName":"/project/src/deps.d.ts","pollingInterval":250}
62+
/project/src/index.ts:
63+
{"fileName":"/project/src/index.ts","pollingInterval":250}
64+
/a/lib/lib.es2020.full.d.ts:
65+
{"fileName":"/a/lib/lib.es2020.full.d.ts","pollingInterval":250}
66+
/project/src/package.json:
67+
{"fileName":"/project/src/package.json","pollingInterval":250}
68+
/project/package.json:
69+
{"fileName":"/project/package.json","pollingInterval":250}
70+
/a/lib/package.json:
71+
{"fileName":"/a/lib/package.json","pollingInterval":250}
72+
/a/package.json:
73+
{"fileName":"/a/package.json","pollingInterval":250}
74+
/package.json:
75+
{"fileName":"/package.json","pollingInterval":250}
76+
77+
FsWatches::
78+
79+
FsWatchesRecursive::
80+
/project/node_modules/@types:
81+
{"directoryName":"/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
82+
/project:
83+
{"directoryName":"/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
84+
85+
exitCode:: ExitStatus.undefined
86+
87+
//// [/dist/index.js]
88+
import * as Thing from "thing";
89+
Thing.fn();
90+
91+
92+
93+
Change:: Modify typescript file
94+
95+
Input::
96+
//// [/project/src/index.ts]
97+
import * as Thing from "thing";
98+
Thing.fn();
99+
100+
101+
Output::
102+
>> Screen clear
103+
[12:00:30 AM] File change detected. Starting incremental compilation...
104+
105+
[12:00:34 AM] Found 0 errors. Watching for file changes.
106+
107+
108+
109+
Program root files: ["/project/src/deps.d.ts","/project/src/index.ts"]
110+
Program options: {"strict":true,"target":7,"module":199,"moduleResolution":99,"outDir":"/dist","watch":true,"project":"/project/tsconfig.json","configFilePath":"/project/tsconfig.json"}
111+
Program structureReused: Completely
112+
Program files::
113+
/a/lib/lib.es2020.full.d.ts
114+
/project/src/deps.d.ts
115+
/project/src/index.ts
116+
117+
Semantic diagnostics in builder refreshed for::
118+
/project/src/index.ts
119+
120+
Shape signatures in builder refreshed for::
121+
/project/src/index.ts (computed .d.ts)
122+
123+
WatchedFiles::
124+
/project/tsconfig.json:
125+
{"fileName":"/project/tsconfig.json","pollingInterval":250}
126+
/project/src/deps.d.ts:
127+
{"fileName":"/project/src/deps.d.ts","pollingInterval":250}
128+
/project/src/index.ts:
129+
{"fileName":"/project/src/index.ts","pollingInterval":250}
130+
/a/lib/lib.es2020.full.d.ts:
131+
{"fileName":"/a/lib/lib.es2020.full.d.ts","pollingInterval":250}
132+
/project/src/package.json:
133+
{"fileName":"/project/src/package.json","pollingInterval":250}
134+
/project/package.json:
135+
{"fileName":"/project/package.json","pollingInterval":250}
136+
137+
FsWatches::
138+
139+
FsWatchesRecursive::
140+
/project/node_modules/@types:
141+
{"directoryName":"/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
142+
/project:
143+
{"directoryName":"/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
144+
145+
exitCode:: ExitStatus.undefined
146+
147+
//// [/dist/index.js] file written with same contents

0 commit comments

Comments
 (0)