Skip to content

Commit

Permalink
fix(cli): reflect tsconfig tsBuildInfoFile in ts_project(ts_build_inf…
Browse files Browse the repository at this point in the history
…o_file) (#7671)

Now that `incremental` and `composite` are supported we must also set
`ts_build_info_file` if a tsconfig file is overriding the default.

---

### Changes are visible to end-users: yes

- Searched for relevant documentation and updated as needed: yes
- Breaking change (forces users to change their own code or config): no
- Suggested release notes appear below: yes

Support BUILD generation of `ts_project(ts_build_info_file)`.

### Test plan

- New test cases added

GitOrigin-RevId: f9606bfafdbd60739f51f57c15242c9a4c9a87a5
  • Loading branch information
jbedard committed Jan 2, 2025
1 parent 2719a87 commit 6012026
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gazelle/js/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,13 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin
existing.DelAttr(("incremental"))
}

// Reflect the tsconfig tsBuildInfoFile in the ts_project rule
if tsconfig.TsBuildInfoFile != "" {
sourceRule.SetAttr("ts_build_info_file", tsconfig.TsBuildInfoFile)
} else if existing != nil {
existing.DelAttr(("ts_build_info_file"))
}

// Reflect the tsconfig resolve_json_module in the ts_project rule
if tsconfig.ResolveJsonModule != nil {
sourceRule.SetAttr("resolve_json_module", *tsconfig.ResolveJsonModule)
Expand Down Expand Up @@ -615,6 +622,7 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin
existing.DelAttr("declaration")
existing.DelAttr("declaration_map")
existing.DelAttr("incremental")
existing.DelAttr("ts_build_info_file")
existing.DelAttr("out_dir")
existing.DelAttr("preserve_jsx")
existing.DelAttr("resolve_json_module")
Expand Down
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_tsbuildinfo/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:js_tsconfig enabled
16 changes: 16 additions & 0 deletions gazelle/js/tests/tsconfig_tsbuildinfo/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")

# gazelle:js_tsconfig enabled

ts_project(
name = "tsconfig_tsbuildinfo",
srcs = ["main.ts"],
incremental = True,
ts_build_info_file = "dist/tsconfig.tsbuildinfo",
tsconfig = ":tsconfig",
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
)
2 changes: 2 additions & 0 deletions gazelle/js/tests/tsconfig_tsbuildinfo/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a Bazel workspace for the Gazelle test data.
workspace(name = "tsconfig_tsbuildinfo")
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_tsbuildinfo/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('No Imports!');
6 changes: 6 additions & 0 deletions gazelle/js/tests/tsconfig_tsbuildinfo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
}
}
10 changes: 10 additions & 0 deletions gazelle/js/typescript/tsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type tsCompilerOptionsJSON struct {
Declaration *bool `json:"declaration"`
DeclarationMap *bool `json:"declarationMap"`
Incremental *bool `json:"incremental"`
TsBuildInfoFile *string `json:"tsBuildInfoFile"`
SourceMap *bool `json:"sourceMap"`
ResolveJsonModule *bool `json:"resolveJsonModule"`
OutDir *string `json:"outDir"`
Expand Down Expand Up @@ -87,6 +88,7 @@ type TsConfig struct {
Declaration *bool
DeclarationMap *bool
Incremental *bool
TsBuildInfoFile string
SourceMap *bool
OutDir string
RootDir string
Expand Down Expand Up @@ -249,6 +251,13 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r
incremental = baseConfig.Incremental
}

var tsBuildInfoFile string
if c.CompilerOptions.TsBuildInfoFile != nil {
tsBuildInfoFile = *c.CompilerOptions.TsBuildInfoFile
} else if baseConfig != nil {
tsBuildInfoFile = baseConfig.TsBuildInfoFile
}

var sourceMap *bool
if c.CompilerOptions.SourceMap != nil {
sourceMap = c.CompilerOptions.SourceMap
Expand Down Expand Up @@ -332,6 +341,7 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r
Declaration: declaration,
DeclarationMap: declarationMap,
Incremental: incremental,
TsBuildInfoFile: tsBuildInfoFile,
SourceMap: sourceMap,
ResolveJsonModule: resolveJsonModule,
OutDir: OutDir,
Expand Down

0 comments on commit 6012026

Please sign in to comment.