Skip to content

Commit b9811b8

Browse files
sheetalkamatdar
authored and
dar
committed
Pick PR microsoft#53468 (Fix incorrect assert about configFi...) into release-5.0 (microsoft#53471)
1 parent 850a9bf commit b9811b8

File tree

4 files changed

+479
-3
lines changed

4 files changed

+479
-3
lines changed

src/compiler/watchPublic.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,6 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
10881088
}
10891089

10901090
function updateExtendedConfigFilesWatches(forProjectPath: Path, options: CompilerOptions | undefined, watchOptions: WatchOptions | undefined, watchType: WatchTypeRegistry["ExtendedConfigFile"] | WatchTypeRegistry["ExtendedConfigOfReferencedProject"]) {
1091-
Debug.assert(configFileName);
10921091
updateSharedExtendedConfigFileWatcher(
10931092
forProjectPath,
10941093
options,
@@ -1104,7 +1103,7 @@ export function createWatchProgram<T extends BuilderProgram>(host: WatchCompiler
11041103
// If there are no referenced projects this extended config file watcher depend on ignore
11051104
if (!projects?.size) return;
11061105
projects.forEach(projectPath => {
1107-
if (toPath(configFileName) === projectPath) {
1106+
if (configFileName && toPath(configFileName) === projectPath) {
11081107
// If this is the config file of the project, reload completely
11091108
reloadLevel = ConfigFileProgramReloadLevel.Full;
11101109
}

src/testRunner/unittests/tscWatch/watchApi.ts

+103-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as Harness from "../../_namespaces/Harness";
22
import * as ts from "../../_namespaces/ts";
3-
import { commandLineCallbacks } from "../tsc/helpers";
3+
import { dedent } from "../../_namespaces/Utils";
4+
import { commandLineCallbacks, libContent } from "../tsc/helpers";
45
import {
56
createWatchedSystem,
67
File,
@@ -11,6 +12,7 @@ import {
1112
applyEdit,
1213
createBaseline,
1314
createWatchCompilerHostOfConfigFileForBaseline,
15+
createWatchCompilerHostOfFilesAndCompilerOptionsForBaseline,
1416
runWatchBaseline,
1517
watchBaseline,
1618
} from "./helpers";
@@ -718,3 +720,103 @@ describe("unittests:: tsc-watch:: watchAPI:: when builder emit occurs with emitO
718720
verify("when emitting with emitOnlyDtsFiles");
719721
verify("when emitting with emitOnlyDtsFiles with outFile", "outFile.js");
720722
});
723+
724+
describe("unittests:: tsc-watch:: watchAPI:: when creating program with project references but not config file", () => {
725+
function setup(libExtends: boolean) {
726+
const system = createWatchedSystem({
727+
"/user/username/projects/project/tsconfig.json": JSON.stringify({
728+
compilerOptions: { types: [] },
729+
files: ["app.ts"],
730+
references: [{ path: "./lib" }]
731+
}),
732+
"/user/username/projects/project/app.ts": dedent`
733+
import { one } from './lib';
734+
console.log(one);
735+
`,
736+
"/user/username/projects/project/lib/tsconfig.json": JSON.stringify({
737+
extends: libExtends ? "./tsconfig.base.json" : undefined,
738+
compilerOptions: libExtends ? undefined : { composite: true, types: [] },
739+
files: ["index.ts"],
740+
}),
741+
"/user/username/projects/project/lib/tsconfig.base.json": JSON.stringify({
742+
compilerOptions: { composite: true, types: [] },
743+
}),
744+
"/user/username/projects/project/lib/index.ts": "export const one = 1;",
745+
"/user/username/projects/project/lib/index.d.ts": "export const one = 1;",
746+
[libFile.path]: libContent,
747+
});
748+
const baseline = createBaseline(system);
749+
const commandLine = ts.getParsedCommandLineOfConfigFile(
750+
"/user/username/projects/project/tsconfig.json",
751+
{ extendedDiagnostics: true },
752+
{
753+
useCaseSensitiveFileNames: true,
754+
fileExists: path => system.fileExists(path),
755+
readFile: path => system.readFile(path),
756+
getCurrentDirectory: () => system.getCurrentDirectory(),
757+
readDirectory: (path, extensions, excludes, includes, depth) => system.readDirectory(path, extensions, excludes, includes, depth),
758+
onUnRecoverableConfigFileDiagnostic: ts.noop,
759+
}
760+
)!;
761+
const compilerHost = createWatchCompilerHostOfFilesAndCompilerOptionsForBaseline({
762+
cb: baseline.cb,
763+
system,
764+
rootFiles: commandLine.fileNames,
765+
options: commandLine.options,
766+
projectReferences: commandLine.projectReferences,
767+
watchOptions: commandLine.watchOptions,
768+
});
769+
const watch = ts.createWatchProgram(compilerHost);
770+
return { watch, baseline };
771+
}
772+
773+
it("when watching referenced project when there is no config file name", () => {
774+
const { watch, baseline } = setup(/*libExtends*/ false);
775+
runWatchBaseline({
776+
scenario: "watchApi",
777+
subScenario: "when watching referenced project when there is no config file name",
778+
commandLineArgs: ["--w", "-p", ".", "--extendedDiagnostics"],
779+
...baseline,
780+
edits: [
781+
{
782+
caption: "Modify lib tsconfig",
783+
edit: sys => sys.writeFile(`/user/username/projects/project/lib/tsconfig.json`, JSON.stringify({
784+
compilerOptions: { composite: true },
785+
files: ["index.ts"],
786+
})),
787+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
788+
},
789+
],
790+
watchOrSolution: watch
791+
});
792+
});
793+
794+
it("when watching referenced project with extends when there is no config file name", () => {
795+
const { watch, baseline } = setup(/*libExtends*/ true);
796+
runWatchBaseline({
797+
scenario: "watchApi",
798+
subScenario: "when watching referenced project with extends when there is no config file name",
799+
commandLineArgs: ["--w", "-p", ".", "--extendedDiagnostics"],
800+
...baseline,
801+
edits: [
802+
{
803+
caption: "Modify lib tsconfig",
804+
edit: sys => sys.writeFile(`/user/username/projects/project/lib/tsconfig.json`, JSON.stringify({
805+
extends: "./tsconfig.base.json",
806+
compilerOptions: { typeRoots: [] },
807+
files: ["index.ts"],
808+
})),
809+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
810+
},
811+
{
812+
caption: "Modify lib extends",
813+
edit: sys => sys.writeFile(`/user/username/projects/project/lib/tsconfig.base.json`, JSON.stringify({
814+
compilerOptions: { composite: true },
815+
})),
816+
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
817+
},
818+
],
819+
watchOrSolution: watch
820+
});
821+
});
822+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
Input::
2+
//// [/user/username/projects/project/tsconfig.json]
3+
{"compilerOptions":{"types":[]},"files":["app.ts"],"references":[{"path":"./lib"}]}
4+
5+
//// [/user/username/projects/project/app.ts]
6+
import { one } from './lib';
7+
console.log(one);
8+
9+
10+
//// [/user/username/projects/project/lib/tsconfig.json]
11+
{"compilerOptions":{"composite":true,"types":[]},"files":["index.ts"]}
12+
13+
//// [/user/username/projects/project/lib/tsconfig.base.json]
14+
{"compilerOptions":{"composite":true,"types":[]}}
15+
16+
//// [/user/username/projects/project/lib/index.ts]
17+
export const one = 1;
18+
19+
//// [/user/username/projects/project/lib/index.d.ts]
20+
export const one = 1;
21+
22+
//// [/a/lib/lib.d.ts]
23+
/// <reference no-default-lib="true"/>
24+
interface Boolean {}
25+
interface Function {}
26+
interface CallableFunction {}
27+
interface NewableFunction {}
28+
interface IArguments {}
29+
interface Number { toExponential: any; }
30+
interface Object {}
31+
interface RegExp {}
32+
interface String { charAt: any; }
33+
interface Array<T> { length: number; [n: number]: T; }
34+
interface ReadonlyArray<T> {}
35+
declare const console: { log(msg: any): void; };
36+
37+
38+
/a/lib/tsc.js --w -p . --extendedDiagnostics
39+
Output::
40+
[12:00:31 AM] Starting compilation in watch mode...
41+
42+
Current directory: / CaseSensitiveFileNames: false
43+
Synchronizing program
44+
CreatingProgramWith::
45+
roots: ["/user/username/projects/project/app.ts"]
46+
options: {"types":[],"extendedDiagnostics":true,"configFilePath":"/user/username/projects/project/tsconfig.json"}
47+
projectReferences: [{"path":"/user/username/projects/project/lib","originalPath":"./lib"}]
48+
Loading config file: /user/username/projects/project/lib/tsconfig.json
49+
FileWatcher:: Added:: WatchInfo: /user/username/projects/project/lib/tsconfig.json 2000 undefined Config file of referened project
50+
FileWatcher:: Added:: WatchInfo: /user/username/projects/project/app.ts 250 undefined Source file
51+
DirectoryWatcher:: Added:: WatchInfo: /user 1 undefined Failed Lookup Locations
52+
Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user 1 undefined Failed Lookup Locations
53+
FileWatcher:: Added:: WatchInfo: /user/username/projects/project/lib/index.d.ts 250 undefined Source file
54+
FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 undefined Source file
55+
DirectoryWatcher:: Triggered with /user/username/projects/project/app.js :: WatchInfo: /user 1 undefined Failed Lookup Locations
56+
Elapsed:: *ms DirectoryWatcher:: Triggered with /user/username/projects/project/app.js :: WatchInfo: /user 1 undefined Failed Lookup Locations
57+
[12:00:34 AM] Found 0 errors. Watching for file changes.
58+
59+
60+
61+
Program root files: ["/user/username/projects/project/app.ts"]
62+
Program options: {"types":[],"extendedDiagnostics":true,"configFilePath":"/user/username/projects/project/tsconfig.json"}
63+
Program structureReused: Not
64+
Program files::
65+
/a/lib/lib.d.ts
66+
/user/username/projects/project/lib/index.d.ts
67+
/user/username/projects/project/app.ts
68+
69+
Semantic diagnostics in builder refreshed for::
70+
/a/lib/lib.d.ts
71+
/user/username/projects/project/lib/index.d.ts
72+
/user/username/projects/project/app.ts
73+
74+
Shape signatures in builder refreshed for::
75+
/a/lib/lib.d.ts (used version)
76+
/user/username/projects/project/lib/index.d.ts (used version)
77+
/user/username/projects/project/app.ts (used version)
78+
79+
PolledWatches::
80+
81+
FsWatches::
82+
/user/username/projects/project/lib/tsconfig.json:
83+
{}
84+
/user/username/projects/project/app.ts:
85+
{}
86+
/user/username/projects/project/lib/index.d.ts:
87+
{}
88+
/a/lib/lib.d.ts:
89+
{}
90+
91+
FsWatchesRecursive::
92+
/user:
93+
{}
94+
95+
exitCode:: ExitStatus.undefined
96+
97+
//// [/user/username/projects/project/app.js]
98+
"use strict";
99+
Object.defineProperty(exports, "__esModule", { value: true });
100+
var lib_1 = require("./lib");
101+
console.log(lib_1.one);
102+
103+
104+
105+
Change:: Modify lib tsconfig
106+
107+
Input::
108+
//// [/user/username/projects/project/lib/tsconfig.json]
109+
{"compilerOptions":{"composite":true},"files":["index.ts"]}
110+
111+
112+
Output::
113+
FileWatcher:: Triggered with /user/username/projects/project/lib/tsconfig.json 1:: WatchInfo: /user/username/projects/project/lib/tsconfig.json 2000 undefined Config file of referened project
114+
Scheduling update
115+
Elapsed:: *ms FileWatcher:: Triggered with /user/username/projects/project/lib/tsconfig.json 1:: WatchInfo: /user/username/projects/project/lib/tsconfig.json 2000 undefined Config file of referened project
116+
Synchronizing program
117+
Loading config file: /user/username/projects/project/lib/tsconfig.json
118+
[12:00:38 AM] File change detected. Starting incremental compilation...
119+
120+
CreatingProgramWith::
121+
roots: ["/user/username/projects/project/app.ts"]
122+
options: {"types":[],"extendedDiagnostics":true,"configFilePath":"/user/username/projects/project/tsconfig.json"}
123+
projectReferences: [{"path":"/user/username/projects/project/lib","originalPath":"./lib"}]
124+
[12:00:39 AM] Found 0 errors. Watching for file changes.
125+
126+
127+
128+
Program root files: ["/user/username/projects/project/app.ts"]
129+
Program options: {"types":[],"extendedDiagnostics":true,"configFilePath":"/user/username/projects/project/tsconfig.json"}
130+
Program structureReused: Not
131+
Program files::
132+
/a/lib/lib.d.ts
133+
/user/username/projects/project/lib/index.d.ts
134+
/user/username/projects/project/app.ts
135+
136+
Semantic diagnostics in builder refreshed for::
137+
138+
No shapes updated in the builder::
139+
140+
PolledWatches::
141+
142+
FsWatches::
143+
/user/username/projects/project/lib/tsconfig.json:
144+
{}
145+
/user/username/projects/project/app.ts:
146+
{}
147+
/user/username/projects/project/lib/index.d.ts:
148+
{}
149+
/a/lib/lib.d.ts:
150+
{}
151+
152+
FsWatchesRecursive::
153+
/user:
154+
{}
155+
156+
exitCode:: ExitStatus.undefined
157+

0 commit comments

Comments
 (0)