Skip to content

Commit 505ffab

Browse files
authored
Merge pull request microsoft#19511 from Microsoft/add-tsconfig-after-running-rwc
Generate tsconfig.json for RWC projects that lack them.
2 parents 212efd5 + c5b1990 commit 505ffab

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/harness/loggedIO.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,33 @@ namespace Playback {
249249
wrapper.endRecord = () => {
250250
if (recordLog !== undefined) {
251251
let i = 0;
252-
const fn = () => recordLogFileNameBase + i;
253-
while (underlying.fileExists(ts.combinePaths(fn(), "test.json"))) i++;
254-
underlying.writeFile(ts.combinePaths(fn(), "test.json"), JSON.stringify(oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), fn()), null, 4)); // tslint:disable-line:no-null-keyword
252+
const getBase = () => recordLogFileNameBase + i;
253+
while (underlying.fileExists(ts.combinePaths(getBase(), "test.json"))) i++;
254+
const newLog = oldStyleLogIntoNewStyleLog(recordLog, (path, string) => underlying.writeFile(path, string), getBase());
255+
underlying.writeFile(ts.combinePaths(getBase(), "test.json"), JSON.stringify(newLog, null, 4)); // tslint:disable-line:no-null-keyword
256+
const syntheticTsconfig = generateTsconfig(newLog);
257+
if (syntheticTsconfig) {
258+
underlying.writeFile(ts.combinePaths(getBase(), "tsconfig.json"), JSON.stringify(syntheticTsconfig, null, 4)); // tslint:disable-line:no-null-keyword
259+
}
255260
recordLog = undefined;
256261
}
257262
};
258263

264+
function generateTsconfig(newLog: IOLog): undefined | { compilerOptions: ts.CompilerOptions, files: string[] } {
265+
if (newLog.filesRead.some(file => /tsconfig.+json$/.test(file.path))) {
266+
return;
267+
}
268+
const files = [];
269+
for (const file of newLog.filesRead) {
270+
if (file.result.contentsPath &&
271+
Harness.isDefaultLibraryFile(file.result.contentsPath) &&
272+
/\.[tj]s$/.test(file.result.contentsPath)) {
273+
files.push(file.result.contentsPath);
274+
}
275+
}
276+
return { compilerOptions: ts.parseCommandLine(newLog.arguments).options, files };
277+
}
278+
259279
wrapper.fileExists = recordReplay(wrapper.fileExists, underlying)(
260280
path => callAndRecord(underlying.fileExists(path), recordLog.fileExists, { path }),
261281
memoize(path => {

0 commit comments

Comments
 (0)