Skip to content

Commit e8d7a1e

Browse files
authored
Fix losing options from command line in watch mode (#2024)
1 parent a5ad4f1 commit e8d7a1e

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

internal/execute/tsc.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,14 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
193193
return tsc.CommandLineResult{Status: tsc.ExitStatusSuccess}
194194
}
195195
if configForCompilation.CompilerOptions().Watch.IsTrue() {
196-
watcher := createWatcher(sys, configForCompilation, reportDiagnostic, reportErrorSummary, testing)
196+
watcher := createWatcher(
197+
sys,
198+
configForCompilation,
199+
compilerOptionsFromCommandLine,
200+
reportDiagnostic,
201+
reportErrorSummary,
202+
testing,
203+
)
197204
watcher.start()
198205
return tsc.CommandLineResult{Status: tsc.ExitStatusSuccess, Watcher: watcher}
199206
} else if configForCompilation.CompilerOptions().IsIncremental() {

internal/execute/watcher.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
)
1515

1616
type Watcher struct {
17-
sys tsc.System
18-
configFileName string
19-
config *tsoptions.ParsedCommandLine
20-
reportDiagnostic tsc.DiagnosticReporter
21-
reportErrorSummary tsc.DiagnosticsReporter
22-
testing tsc.CommandLineTesting
17+
sys tsc.System
18+
configFileName string
19+
config *tsoptions.ParsedCommandLine
20+
compilerOptionsFromCommandLine *core.CompilerOptions
21+
reportDiagnostic tsc.DiagnosticReporter
22+
reportErrorSummary tsc.DiagnosticsReporter
23+
testing tsc.CommandLineTesting
2324

2425
host compiler.CompilerHost
2526
program *incremental.Program
@@ -29,13 +30,21 @@ type Watcher struct {
2930

3031
var _ tsc.Watcher = (*Watcher)(nil)
3132

32-
func createWatcher(sys tsc.System, configParseResult *tsoptions.ParsedCommandLine, reportDiagnostic tsc.DiagnosticReporter, reportErrorSummary tsc.DiagnosticsReporter, testing tsc.CommandLineTesting) *Watcher {
33+
func createWatcher(
34+
sys tsc.System,
35+
configParseResult *tsoptions.ParsedCommandLine,
36+
compilerOptionsFromCommandLine *core.CompilerOptions,
37+
reportDiagnostic tsc.DiagnosticReporter,
38+
reportErrorSummary tsc.DiagnosticsReporter,
39+
testing tsc.CommandLineTesting,
40+
) *Watcher {
3341
w := &Watcher{
34-
sys: sys,
35-
config: configParseResult,
36-
reportDiagnostic: reportDiagnostic,
37-
reportErrorSummary: reportErrorSummary,
38-
testing: testing,
42+
sys: sys,
43+
config: configParseResult,
44+
compilerOptionsFromCommandLine: compilerOptionsFromCommandLine,
45+
reportDiagnostic: reportDiagnostic,
46+
reportErrorSummary: reportErrorSummary,
47+
testing: testing,
3948
// reportWatchStatus: createWatchStatusReporter(sys, configParseResult.CompilerOptions().Pretty),
4049
}
4150
if configParseResult.ConfigFile != nil {
@@ -108,7 +117,7 @@ func (w *Watcher) hasErrorsInTsConfig() bool {
108117
extendedConfigCache := &tsc.ExtendedConfigCache{}
109118
if w.configFileName != "" {
110119
// !!! need to check that this merges compileroptions correctly. This differs from non-watch, since we allow overriding of previous options
111-
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, &core.CompilerOptions{}, w.sys, extendedConfigCache)
120+
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, w.sys, extendedConfigCache)
112121
if len(errors) > 0 {
113122
for _, e := range errors {
114123
w.reportDiagnostic(e)

testdata/baselines/reference/tscWatch/commandLineWatch/watch-with-tsconfig-and-incremental.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,45 @@ interface Symbol {
3636
declare const console: { log(msg: any): void; };
3737
//// [/home/src/workspaces/project/index.js] *new*
3838

39+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new*
40+
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"99aa06d3014798d86001c324468d497f-"]}
41+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
42+
{
43+
"version": "FakeTSVersion",
44+
"root": [
45+
{
46+
"files": [
47+
"./index.ts"
48+
],
49+
"original": 2
50+
}
51+
],
52+
"fileNames": [
53+
"lib.d.ts",
54+
"./index.ts"
55+
],
56+
"fileInfos": [
57+
{
58+
"fileName": "lib.d.ts",
59+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
60+
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
61+
"affectsGlobalScope": true,
62+
"impliedNodeFormat": "CommonJS",
63+
"original": {
64+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
65+
"affectsGlobalScope": true,
66+
"impliedNodeFormat": 1
67+
}
68+
},
69+
{
70+
"fileName": "./index.ts",
71+
"version": "99aa06d3014798d86001c324468d497f-",
72+
"signature": "99aa06d3014798d86001c324468d497f-",
73+
"impliedNodeFormat": "CommonJS"
74+
}
75+
],
76+
"size": 896
77+
}
3978

4079
tsconfig.json::
4180
SemanticDiagnostics::

0 commit comments

Comments
 (0)