Set impliedNodeFormat on sourceFiles maufactured in watch mode (#46349)

This commit is contained in:
Wesley Wigham 2021-10-13 17:04:13 -07:00 committed by GitHub
parent cd0434aa76
commit ac345849e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 209 additions and 0 deletions

View file

@ -560,6 +560,9 @@ namespace ts {
sourceFilesCache.set(path, false);
}
}
if (sourceFile) {
sourceFile.impliedNodeFormat = getImpliedNodeFormatForFile(path, resolutionCache.getModuleResolutionCache().getPackageJsonInfoCache(), compilerHost, compilerHost.getCompilationSettings());
}
return sourceFile;
}
return hostSourceFile.sourceFile;

View file

@ -158,6 +158,7 @@
"unittests/tsc/runWithoutArgs.ts",
"unittests/tscWatch/consoleClearing.ts",
"unittests/tscWatch/emit.ts",
"unittests/tscWatch/nodeNextWatch.ts",
"unittests/tscWatch/emitAndErrorUpdates.ts",
"unittests/tscWatch/forceConsistentCasingInFileNames.ts",
"unittests/tscWatch/incremental.ts",

View file

@ -0,0 +1,58 @@
namespace ts.tscWatch {
describe("unittests:: tsc-watch:: nodeNextWatch:: emit when module emit is specified as nodenext", () => {
verifyTscWatch({
scenario: "nodenext watch emit",
subScenario: "esm-mode file is edited",
commandLineArgs: ["--w", "--p", "/project/tsconfig.json"],
sys: () => {
const configFile: File = {
path: "/project/tsconfig.json",
content: JSON.stringify({
compilerOptions: {
strict: true,
target: "es2020",
module: "nodenext",
moduleResolution: "nodenext",
outDir: "../dist"
}
})
};
const packageFile: File = {
path: "/project/package.json",
content: JSON.stringify({
name: "some-proj",
version: "1.0.0",
description: "",
type: "module",
main: "index.js",
})
};
const file1: File = {
path: "/project/src/index.ts",
content: Utils.dedent`
import * as Thing from "thing";
Thing.fn();`
};
const declFile: File = {
path: "/project/src/deps.d.ts",
content: `declare module "thing";`
};
return createWatchedSystem([configFile, file1, declFile, packageFile, { ...libFile, path: "/a/lib/lib.es2020.full.d.ts" }]);
},
changes: [
{
caption: "Modify typescript file",
change: sys => sys.modifyFile(
"/project/src/index.ts",
Utils.dedent`
import * as Thing from "thing";
Thing.fn();`,
{},
),
timeouts: runQueuedTimeoutCallbacks,
}
],
});
});
}

View file

@ -0,0 +1,147 @@
Input::
//// [/project/tsconfig.json]
{"compilerOptions":{"strict":true,"target":"es2020","module":"nodenext","moduleResolution":"nodenext","outDir":"../dist"}}
//// [/project/src/index.ts]
import * as Thing from "thing";
Thing.fn();
//// [/project/src/deps.d.ts]
declare module "thing";
//// [/project/package.json]
{"name":"some-proj","version":"1.0.0","description":"","type":"module","main":"index.js"}
//// [/a/lib/lib.es2020.full.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
/a/lib/tsc.js --w --p /project/tsconfig.json
Output::
>> Screen clear
[12:00:21 AM] Starting compilation in watch mode...
[12:00:27 AM] Found 0 errors. Watching for file changes.
Program root files: ["/project/src/deps.d.ts","/project/src/index.ts"]
Program options: {"strict":true,"target":7,"module":199,"moduleResolution":99,"outDir":"/dist","watch":true,"project":"/project/tsconfig.json","configFilePath":"/project/tsconfig.json"}
Program structureReused: Not
Program files::
/a/lib/lib.es2020.full.d.ts
/project/src/deps.d.ts
/project/src/index.ts
Semantic diagnostics in builder refreshed for::
/a/lib/lib.es2020.full.d.ts
/project/src/deps.d.ts
/project/src/index.ts
Shape signatures in builder refreshed for::
/a/lib/lib.es2020.full.d.ts (used version)
/project/src/deps.d.ts (used version)
/project/src/index.ts (used version)
WatchedFiles::
/project/tsconfig.json:
{"fileName":"/project/tsconfig.json","pollingInterval":250}
/project/src/deps.d.ts:
{"fileName":"/project/src/deps.d.ts","pollingInterval":250}
/project/src/index.ts:
{"fileName":"/project/src/index.ts","pollingInterval":250}
/a/lib/lib.es2020.full.d.ts:
{"fileName":"/a/lib/lib.es2020.full.d.ts","pollingInterval":250}
/project/src/package.json:
{"fileName":"/project/src/package.json","pollingInterval":250}
/project/package.json:
{"fileName":"/project/package.json","pollingInterval":250}
/a/lib/package.json:
{"fileName":"/a/lib/package.json","pollingInterval":250}
/a/package.json:
{"fileName":"/a/package.json","pollingInterval":250}
/package.json:
{"fileName":"/package.json","pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/project/node_modules/@types:
{"directoryName":"/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/project:
{"directoryName":"/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined
//// [/dist/index.js]
import * as Thing from "thing";
Thing.fn();
Change:: Modify typescript file
Input::
//// [/project/src/index.ts]
import * as Thing from "thing";
Thing.fn();
Output::
>> Screen clear
[12:00:30 AM] File change detected. Starting incremental compilation...
[12:00:34 AM] Found 0 errors. Watching for file changes.
Program root files: ["/project/src/deps.d.ts","/project/src/index.ts"]
Program options: {"strict":true,"target":7,"module":199,"moduleResolution":99,"outDir":"/dist","watch":true,"project":"/project/tsconfig.json","configFilePath":"/project/tsconfig.json"}
Program structureReused: Completely
Program files::
/a/lib/lib.es2020.full.d.ts
/project/src/deps.d.ts
/project/src/index.ts
Semantic diagnostics in builder refreshed for::
/project/src/index.ts
Shape signatures in builder refreshed for::
/project/src/index.ts (computed .d.ts)
WatchedFiles::
/project/tsconfig.json:
{"fileName":"/project/tsconfig.json","pollingInterval":250}
/project/src/deps.d.ts:
{"fileName":"/project/src/deps.d.ts","pollingInterval":250}
/project/src/index.ts:
{"fileName":"/project/src/index.ts","pollingInterval":250}
/a/lib/lib.es2020.full.d.ts:
{"fileName":"/a/lib/lib.es2020.full.d.ts","pollingInterval":250}
/project/src/package.json:
{"fileName":"/project/src/package.json","pollingInterval":250}
/project/package.json:
{"fileName":"/project/package.json","pollingInterval":250}
FsWatches::
FsWatchesRecursive::
/project/node_modules/@types:
{"directoryName":"/project/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
/project:
{"directoryName":"/project","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
exitCode:: ExitStatus.undefined
//// [/dist/index.js] file written with same contents