Skip to content
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

Reflect tsconfig composite and incremental to ts_project() #780

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gazelle/js/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin
existing.DelAttr("allow_js")
}

// Reflect the tsconfig composite in the ts_project rule
if tsconfig.Composite != nil {
sourceRule.SetAttr("composite", *tsconfig.Composite)
} else if existing != nil {
existing.DelAttr("composite")
}

// Reflect the tsconfig declaration in the ts_project rule
if tsconfig.Declaration != nil {
sourceRule.SetAttr("declaration", *tsconfig.Declaration)
Expand All @@ -534,6 +541,13 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin
existing.DelAttr("source_map")
}

// Reflect the tsconfig incremental in the ts_project rule
if tsconfig.Incremental != nil {
sourceRule.SetAttr("incremental", *tsconfig.Incremental)
} else if existing != nil {
existing.DelAttr(("incremental"))
}

// 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 @@ -565,8 +579,10 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin
// Clear tsconfig related attributes if no tsconfig is found
existing.DelAttr("tsconfig")
existing.DelAttr("allow_js")
existing.DelAttr("composite")
existing.DelAttr("declaration")
existing.DelAttr("declaration_map")
existing.DelAttr("incremental")
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_composite/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:js_tsconfig enabled
15 changes: 15 additions & 0 deletions gazelle/js/tests/tsconfig_composite/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")

# gazelle:js_tsconfig enabled

ts_project(
name = "tsconfig_composite",
srcs = ["main.ts"],
composite = True,
tsconfig = ":tsconfig",
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
)
2 changes: 2 additions & 0 deletions gazelle/js/tests/tsconfig_composite/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_composite")
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_composite/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('No Imports!');
5 changes: 5 additions & 0 deletions gazelle/js/tests/tsconfig_composite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"composite": true
}
}
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_incremental/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# gazelle:js_tsconfig enabled
15 changes: 15 additions & 0 deletions gazelle/js/tests/tsconfig_incremental/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")

# gazelle:js_tsconfig enabled

ts_project(
name = "tsconfig_incremental",
srcs = ["main.ts"],
incremental = True,
tsconfig = ":tsconfig",
)

ts_config(
name = "tsconfig",
src = "tsconfig.json",
)
2 changes: 2 additions & 0 deletions gazelle/js/tests/tsconfig_incremental/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_incremental")
1 change: 1 addition & 0 deletions gazelle/js/tests/tsconfig_incremental/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('No Imports!');
5 changes: 5 additions & 0 deletions gazelle/js/tests/tsconfig_incremental/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"incremental": true
}
}
20 changes: 20 additions & 0 deletions gazelle/js/typescript/tsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ import (

type tsCompilerOptionsJSON struct {
AllowJs *bool `json:"allowJs"`
Composite *bool `json:"composite"`
Declaration *bool `json:"declaration"`
DeclarationMap *bool `json:"declarationMap"`
Incremental *bool `json:"incremental"`
SourceMap *bool `json:"sourceMap"`
ResolveJsonModule *bool `json:"resolveJsonModule"`
OutDir *string `json:"outDir"`
Expand Down Expand Up @@ -81,8 +83,10 @@ type TsConfig struct {

AllowJs *bool
ResolveJsonModule *bool
Composite *bool
Declaration *bool
DeclarationMap *bool
Incremental *bool
SourceMap *bool
OutDir string
RootDir string
Expand Down Expand Up @@ -217,6 +221,13 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r
allowJs = baseConfig.AllowJs
}

var composite *bool
if c.CompilerOptions.Composite != nil {
composite = c.CompilerOptions.Composite
} else if baseConfig != nil {
composite = baseConfig.Composite
}

var declaration *bool
if c.CompilerOptions.Declaration != nil {
declaration = c.CompilerOptions.Declaration
Expand All @@ -231,6 +242,13 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r
declarationMap = baseConfig.DeclarationMap
}

var incremental *bool
if c.CompilerOptions.Incremental != nil {
incremental = c.CompilerOptions.Incremental
} else if baseConfig != nil {
incremental = baseConfig.Incremental
}

var sourceMap *bool
if c.CompilerOptions.SourceMap != nil {
sourceMap = c.CompilerOptions.SourceMap
Expand Down Expand Up @@ -310,8 +328,10 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r
ConfigDir: configDir,
ConfigName: configName,
AllowJs: allowJs,
Composite: composite,
Declaration: declaration,
DeclarationMap: declarationMap,
Incremental: incremental,
SourceMap: sourceMap,
ResolveJsonModule: resolveJsonModule,
OutDir: OutDir,
Expand Down