-
Notifications
You must be signed in to change notification settings - Fork 749
Fix --customConditions null not being respected when overriding tsconfig.json #1868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When --customConditions null is passed on command line, it should override any value in tsconfig.json. This fix: - Adds a new parameter to pass raw command line options through config parsing - Updates mergeCompilerOptions to handle command line raw options correctly - Adds test to verify customConditions null override behavior Co-authored-by: jakebailey <[email protected]>
- Handle nil OrderedMap in mergeCompilerOptions - Handle nil targetOptions in mergeCompilerOptions - Accept baseline for composite null test (correct behavior) Co-authored-by: jakebailey <[email protected]>
jakebailey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot This PR may be too narrowly focused. null should work to unset all of the other options at the CLI too.
Instead of checking for nil in mergeCompilerOptions, properly initialize options to empty struct when circularity error is detected in parseConfig. This ensures targetOptions is never nil when mergeCompilerOptions is called. Co-authored-by: jakebailey <[email protected]>
The implementation already works for all options, not just customConditions. It uses reflection to iterate through all CompilerOptions fields and checks the raw map for any field set to null. I verified this works with --lib null, --types null, and --outDir null - all correctly override their tsconfig.json values. |
Instead of having separate WithRaw variants, add optionsRaw parameter to GetParsedCommandLineOfConfigFile and ParseJsonSourceFileConfigFileContent. This simplifies the API by consolidating the two variants into one. Co-authored-by: jakebailey <[email protected]>
|
@copilot you did not run the formatter as instructed |
Co-authored-by: jakebailey <[email protected]>
Fixed in commit 81d4e0d. Ran |
Instead of having two code paths in mergeCompilerOptions (one for tsconfig with nested compilerOptions, one for raw command line options), wrap the command line options in a compilerOptions key before passing them. This simplifies the logic and prevents accidentally processing top-level keys from tsconfig as compiler options. Also removes the options initialization in parseConfig error case, which is no longer needed with the wrapped approach. Co-authored-by: jakebailey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the issue where passing --customConditions null on the command line was not properly overriding the customConditions setting from tsconfig.json. The fix enables the command line parser to track explicitly null values and merge them correctly when loading config files.
Key Changes
- Added
existingOptionsRawparameter to config parsing functions to preserve raw command line options with explicit null values - Updated
mergeCompilerOptionsto detect and apply explicitly null fields from raw command line options by wrapping them in a "compilerOptions" key structure - Added test case
TestCustomConditionsNullOverrideto verify the fix works correctly
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
internal/tsoptions/tsconfigparsing.go |
Added existingOptionsRaw parameter to ParseJsonSourceFileConfigFileContent, GetParsedCommandLineOfConfigFile, GetParsedCommandLineOfConfigFilePath, and parseJsonConfigFileContentWorker to thread raw command line options through config parsing |
internal/tsoptions/parsinghelpers.go |
Updated mergeCompilerOptions to extract explicitly null fields from raw options (nested under "compilerOptions" key) and apply them to target options |
internal/execute/tsc.go |
Wraps command line raw options in a "compilerOptions" key before passing to config parsing to match tsconfig.json structure |
internal/tsoptions/commandlineparser_test.go |
Added TestCustomConditionsNullOverride test to verify command line null values override tsconfig.json settings |
internal/tsoptions/tsconfigparsing_test.go |
Updated all test call sites to include the new existingOptionsRaw parameter (passing nil) |
internal/tsoptions/tsoptionstest/parsedcommandline.go |
Updated helper function to include the new parameter |
internal/testrunner/test_case_parser.go |
Updated config parsing call to include the new parameter |
internal/project/configfileregistrybuilder.go |
Updated config parsing call to pass nil for optionsRaw |
internal/execute/watcher.go |
Updated config parsing call to pass nil for optionsRaw (watch mode doesn't support raw option overrides) |
internal/execute/build/host.go |
Updated config parsing call to pass nil for optionsRaw |
internal/execute/tsctests/tscbuild_test.go |
Updated test call to include the new parameter |
internal/compiler/program_test.go |
Updated test calls to include the new parameter |
internal/compiler/host.go |
Updated config parsing call to include the new parameter |
internal/checker/checker_test.go |
Updated test calls to include the new parameter |
internal/api/api.go |
Updated config parsing call to include the new parameter |
testdata/baselines/reference/tsc/composite/when-setting-composite-null-on-command-line.js |
Baseline update showing that --composite null correctly suppresses .d.ts and .tsbuildinfo file generation, overriding tsconfig.json |
internal/execute/build/host.go
Outdated
| return h.resolvedReferences.loadOrStoreNew(path, func(path tspath.Path) *tsoptions.ParsedCommandLine { | ||
| configStart := h.orchestrator.opts.Sys.Now() | ||
| commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, h, &h.extendedConfigCache) | ||
| commandLine, _ := tsoptions.GetParsedCommandLineOfConfigFilePath(fileName, path, h.orchestrator.opts.Command.CompilerOptions, nil /*optionsRaw*/, h, &h.extendedConfigCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont you need the "raw" thing here because this is tsc -b which will pass commandline options ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. @copilot 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit b8f9e2a. Added Raw field to ParsedBuildCommandLine and now wrapping and passing raw options in build mode.
For tsc -b (build mode), command line options also need to be passed with their raw values to properly support null overrides. This adds: - Raw field to ParsedBuildCommandLine to store raw command line options - Wrapping of raw options in "compilerOptions" key in build/host.go - Passing wrapped raw options to GetParsedCommandLineOfConfigFilePath Co-authored-by: jakebailey <[email protected]>
Original prompt
Fixes #1866
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.