Skip to content

Commit 1fbe20f

Browse files
ajafffsheetalkamat
authored andcommitted
resolveJsonModule affectsModuleResolution (microsoft#36290)
* resolveJsonModule affectsModuleResolutionFixes: microsoft#36251 * fix lint
1 parent bc1e772 commit 1fbe20f

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ namespace ts {
766766
{
767767
name: "resolveJsonModule",
768768
type: "boolean",
769+
affectsModuleResolution: true,
769770
category: Diagnostics.Advanced_Options,
770771
description: Diagnostics.Include_modules_imported_with_json_extension
771772
},

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,34 @@ export function f(p: C) { return p; }`
12281228
]
12291229
});
12301230

1231+
verifyTscWatch({
1232+
scenario,
1233+
subScenario: "updates moduleResolution when resolveJsonModule changes",
1234+
commandLineArgs: ["-w"],
1235+
sys: () => {
1236+
const aFile: File = {
1237+
path: `${projectRoot}/a.ts`,
1238+
content: `import * as data from './data.json'`
1239+
};
1240+
const jsonFile: File = {
1241+
path: `${projectRoot}/data.json`,
1242+
content: `{ "foo": 1 }`
1243+
};
1244+
const config: File = {
1245+
path: `${projectRoot}/tsconfig.json`,
1246+
content: JSON.stringify({ compilerOptions: { moduleResolution: "node" } })
1247+
};
1248+
return createWatchedSystem([aFile, jsonFile, config, libFile], { currentDirectory: projectRoot });
1249+
},
1250+
changes: [
1251+
sys => {
1252+
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { moduleResolution: "node", resolveJsonModule: true } }));
1253+
sys.runQueuedTimeoutCallbacks();
1254+
return "Enable resolveJsonModule";
1255+
},
1256+
]
1257+
});
1258+
12311259
verifyTscWatch({
12321260
scenario,
12331261
subScenario: "updates errors when ambient modules of program changes",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/a/lib/tsc.js -w
2+
//// [/user/username/projects/myproject/a.ts]
3+
import * as data from './data.json'
4+
5+
//// [/user/username/projects/myproject/data.json]
6+
{ "foo": 1 }
7+
8+
//// [/user/username/projects/myproject/tsconfig.json]
9+
{"compilerOptions":{"moduleResolution":"node"}}
10+
11+
//// [/a/lib/lib.d.ts]
12+
/// <reference no-default-lib="true"/>
13+
interface Boolean {}
14+
interface Function {}
15+
interface CallableFunction {}
16+
interface NewableFunction {}
17+
interface IArguments {}
18+
interface Number { toExponential: any; }
19+
interface Object {}
20+
interface RegExp {}
21+
interface String { charAt: any; }
22+
interface Array<T> { length: number; [n: number]: T; }
23+
24+
//// [/user/username/projects/myproject/a.js]
25+
"use strict";
26+
exports.__esModule = true;
27+
28+
29+
30+
Output::
31+
>> Screen clear
32+
12:00:23 AM - Starting compilation in watch mode...
33+
34+
35+
a.ts(1,23): error TS2732: Cannot find module './data.json'. Consider using '--resolveJsonModule' to import module with '.json' extension
36+
37+
38+
12:00:26 AM - Found 1 error. Watching for file changes.
39+
40+
41+
Program root files: ["/user/username/projects/myproject/a.ts"]
42+
Program options: {"moduleResolution":2,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
43+
Program files::
44+
/a/lib/lib.d.ts
45+
/user/username/projects/myproject/a.ts
46+
47+
Semantic diagnostics in builder refreshed for::
48+
/a/lib/lib.d.ts
49+
/user/username/projects/myproject/a.ts
50+
51+
WatchedFiles::
52+
/user/username/projects/myproject/tsconfig.json:
53+
{"pollingInterval":250}
54+
/user/username/projects/myproject/a.ts:
55+
{"pollingInterval":250}
56+
/a/lib/lib.d.ts:
57+
{"pollingInterval":250}
58+
59+
FsWatches::
60+
/user/username/projects/myproject:
61+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
62+
63+
FsWatchesRecursive::
64+
/user/username/projects/myproject/data.json:
65+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
66+
/user/username/projects/myproject/node_modules/@types:
67+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
68+
/user/username/projects/myproject:
69+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
70+
71+
exitCode:: ExitStatus.undefined
72+
73+
Change:: Enable resolveJsonModule
74+
75+
//// [/user/username/projects/myproject/tsconfig.json]
76+
{"compilerOptions":{"moduleResolution":"node","resolveJsonModule":true}}
77+
78+
//// [/user/username/projects/myproject/a.js] file written with same contents
79+
80+
Output::
81+
>> Screen clear
82+
12:00:30 AM - File change detected. Starting incremental compilation...
83+
84+
85+
86+
12:00:34 AM - Found 0 errors. Watching for file changes.
87+
88+
89+
Program root files: ["/user/username/projects/myproject/a.ts"]
90+
Program options: {"moduleResolution":2,"resolveJsonModule":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
91+
Program files::
92+
/a/lib/lib.d.ts
93+
/user/username/projects/myproject/data.json
94+
/user/username/projects/myproject/a.ts
95+
96+
Semantic diagnostics in builder refreshed for::
97+
/a/lib/lib.d.ts
98+
/user/username/projects/myproject/data.json
99+
/user/username/projects/myproject/a.ts
100+
101+
WatchedFiles::
102+
/user/username/projects/myproject/tsconfig.json:
103+
{"pollingInterval":250}
104+
/user/username/projects/myproject/a.ts:
105+
{"pollingInterval":250}
106+
/a/lib/lib.d.ts:
107+
{"pollingInterval":250}
108+
/user/username/projects/myproject/data.json:
109+
{"pollingInterval":250}
110+
111+
FsWatches::
112+
/user/username/projects/myproject:
113+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
114+
115+
FsWatchesRecursive::
116+
/user/username/projects/myproject:
117+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
118+
/user/username/projects/myproject/data.json:
119+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
120+
/user/username/projects/myproject/node_modules/@types:
121+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
122+
123+
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)