Skip to content

Commit 487416c

Browse files
Copilotjakebailey
andauthored
Fix --customConditions null not being respected when overriding tsconfig.json (#1868)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: jakebailey <[email protected]>
1 parent 7812f24 commit 487416c

File tree

18 files changed

+91
-75
lines changed

18 files changed

+91
-75
lines changed

internal/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (api *API) ParseConfigFile(configFileName string) (*ConfigFileResponse, err
127127
api.session,
128128
configDir,
129129
nil, /*existingOptions*/
130+
nil, /*existingOptionsRaw*/
130131
configFileName,
131132
nil, /*resolutionStack*/
132133
nil, /*extraFileExtensions*/

internal/checker/checker_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ foo.bar;`
3838
cd := "/"
3939
host := compiler.NewCompilerHost(cd, fs, bundled.LibPath(), nil, nil)
4040

41-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, host, nil)
41+
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile("/tsconfig.json", &core.CompilerOptions{}, nil, host, nil)
4242
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
4343

4444
p := compiler.NewProgram(compiler.ProgramOptions{
@@ -71,7 +71,7 @@ func TestCheckSrcCompiler(t *testing.T) {
7171
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
7272

7373
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
74-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
74+
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, nil, host, nil)
7575
assert.Equal(t, len(errors), 0, "Expected no errors in parsed command line")
7676
p := compiler.NewProgram(compiler.ProgramOptions{
7777
Config: parsed,
@@ -88,7 +88,7 @@ func BenchmarkNewChecker(b *testing.B) {
8888
rootPath := tspath.CombinePaths(tspath.NormalizeSlashes(repo.TypeScriptSubmodulePath), "src", "compiler")
8989

9090
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
91-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, host, nil)
91+
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), &core.CompilerOptions{}, nil, host, nil)
9292
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")
9393
p := compiler.NewProgram(compiler.ProgramOptions{
9494
Config: parsed,

internal/compiler/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ func (h *compilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast.Sourc
8484
}
8585

8686
func (h *compilerHost) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine {
87-
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, h, h.extendedConfigCache)
87+
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, nil /*optionsRaw*/, h, h.extendedConfigCache)
8888
return commandLine
8989
}

internal/compiler/program_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func BenchmarkNewProgram(b *testing.B) {
299299

300300
host := compiler.NewCompilerHost(rootPath, fs, bundled.LibPath(), nil, nil)
301301

302-
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, host, nil)
302+
parsed, errors := tsoptions.GetParsedCommandLineOfConfigFile(tspath.CombinePaths(rootPath, "tsconfig.json"), nil, nil, host, nil)
303303
assert.Equal(b, len(errors), 0, "Expected no errors in parsed command line")
304304

305305
opts := compiler.ProgramOptions{

internal/execute/build/host.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ func (h *host) GetSourceFile(opts ast.SourceFileParseOptions) *ast.SourceFile {
6060
func (h *host) GetResolvedProjectReference(fileName string, path tspath.Path) *tsoptions.ParsedCommandLine {
6161
return h.resolvedReferences.loadOrStoreNew(path, func(path tspath.Path) *tsoptions.ParsedCommandLine {
6262
configStart := h.orchestrator.opts.Sys.Now()
63-
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, h, &h.extendedConfigCache)
63+
// Wrap command line options in "compilerOptions" key to match tsconfig.json structure
64+
var commandLineRaw *collections.OrderedMap[string, any]
65+
if raw, ok := h.orchestrator.opts.Command.Raw.(*collections.OrderedMap[string, any]); ok {
66+
wrapped := &collections.OrderedMap[string, any]{}
67+
wrapped.Set("compilerOptions", raw)
68+
commandLineRaw = wrapped
69+
}
70+
commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, commandLineRaw, h, &h.extendedConfigCache)
6471
configTime := h.orchestrator.opts.Sys.Now().Sub(configStart)
6572
h.configTimes.Store(path, configTime)
6673
return commandLine

internal/execute/tsc.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,14 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
177177
var compileTimes tsc.CompileTimes
178178
if configFileName != "" {
179179
configStart := sys.Now()
180-
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(configFileName, compilerOptionsFromCommandLine, sys, extendedConfigCache)
180+
var commandLineRaw *collections.OrderedMap[string, any]
181+
if raw, ok := commandLine.Raw.(*collections.OrderedMap[string, any]); ok {
182+
// Wrap command line options in a "compilerOptions" key to match tsconfig.json structure
183+
wrapped := &collections.OrderedMap[string, any]{}
184+
wrapped.Set("compilerOptions", raw)
185+
commandLineRaw = wrapped
186+
}
187+
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(configFileName, compilerOptionsFromCommandLine, commandLineRaw, sys, extendedConfigCache)
181188
compileTimes.ConfigTime = sys.Now().Sub(configStart)
182189
if len(errors) != 0 {
183190
// these are unrecoverable errors--exit to report them as diagnostics

internal/execute/tsctests/tscbuild_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,7 @@ func TestBuildOutputPaths(t *testing.T) {
15451545
t.Run("GetOutputFileNames/"+s.subScenario, func(t *testing.T) {
15461546
t.Parallel()
15471547
sys := newTestSys(input, false)
1548-
config, _ := tsoptions.GetParsedCommandLineOfConfigFile("/home/src/workspaces/project/tsconfig.json", &core.CompilerOptions{}, sys, nil)
1548+
config, _ := tsoptions.GetParsedCommandLineOfConfigFile("/home/src/workspaces/project/tsconfig.json", &core.CompilerOptions{}, nil, sys, nil)
15491549
assert.DeepEqual(t, slices.Collect(config.GetOutputFileNames()), s.expectedDtsNames)
15501550
})
15511551
}

internal/execute/watcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (w *Watcher) hasErrorsInTsConfig() bool {
117117
extendedConfigCache := &tsc.ExtendedConfigCache{}
118118
if w.configFileName != "" {
119119
// !!! need to check that this merges compileroptions correctly. This differs from non-watch, since we allow overriding of previous options
120-
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, w.sys, extendedConfigCache)
120+
configParseResult, errors := tsoptions.GetParsedCommandLineOfConfigFile(w.configFileName, w.compilerOptionsFromCommandLine, nil, w.sys, extendedConfigCache)
121121
if len(errors) > 0 {
122122
for _, e := range errors {
123123
w.reportDiagnostic(e)

internal/project/configfileregistrybuilder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (c *configFileRegistryBuilder) reloadIfNeeded(entry *configFileEntry, fileN
106106
entry.commandLine = entry.commandLine.ReloadFileNamesOfParsedCommandLine(c.fs.fs)
107107
case PendingReloadFull:
108108
logger.Log("Loading config file: " + fileName)
109-
entry.commandLine, _ = tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, c, c)
109+
entry.commandLine, _ = tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, nil, nil /*optionsRaw*/, c, c)
110110
c.updateExtendingConfigs(path, entry.commandLine, entry.commandLine)
111111
c.updateRootFilesWatch(fileName, entry)
112112
logger.Log("Finished loading config file")

internal/testrunner/test_case_parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func makeUnitsFromTest(code string, fileName string) testCaseContent {
8787
parseConfigHost,
8888
configDir,
8989
nil, /*existingOptions*/
90+
nil, /*existingOptionsRaw*/
9091
configFileName,
9192
nil, /*resolutionStack*/
9293
nil, /*extraFileExtensions*/

0 commit comments

Comments
 (0)