From e50e06c3d61425a6f3fb793e4be812c3707fa2ee Mon Sep 17 00:00:00 2001 From: Walker Burgin Date: Fri, 29 Nov 2024 15:24:23 -0800 Subject: [PATCH 1/2] Reflect the tsconfig "composite" setting into ts_project() rules --- gazelle/js/generate.go | 8 ++++++++ gazelle/js/tests/tsconfig_composite/BUILD.in | 1 + gazelle/js/tests/tsconfig_composite/BUILD.out | 15 +++++++++++++++ gazelle/js/tests/tsconfig_composite/WORKSPACE | 2 ++ gazelle/js/tests/tsconfig_composite/main.ts | 1 + gazelle/js/tests/tsconfig_composite/tsconfig.json | 5 +++++ gazelle/js/typescript/tsconfig.go | 10 ++++++++++ 7 files changed, 42 insertions(+) create mode 100644 gazelle/js/tests/tsconfig_composite/BUILD.in create mode 100644 gazelle/js/tests/tsconfig_composite/BUILD.out create mode 100644 gazelle/js/tests/tsconfig_composite/WORKSPACE create mode 100644 gazelle/js/tests/tsconfig_composite/main.ts create mode 100644 gazelle/js/tests/tsconfig_composite/tsconfig.json diff --git a/gazelle/js/generate.go b/gazelle/js/generate.go index d76807931..ca412f366 100644 --- a/gazelle/js/generate.go +++ b/gazelle/js/generate.go @@ -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) @@ -565,6 +572,7 @@ 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("out_dir") diff --git a/gazelle/js/tests/tsconfig_composite/BUILD.in b/gazelle/js/tests/tsconfig_composite/BUILD.in new file mode 100644 index 000000000..5b0ea19fe --- /dev/null +++ b/gazelle/js/tests/tsconfig_composite/BUILD.in @@ -0,0 +1 @@ +# gazelle:js_tsconfig enabled \ No newline at end of file diff --git a/gazelle/js/tests/tsconfig_composite/BUILD.out b/gazelle/js/tests/tsconfig_composite/BUILD.out new file mode 100644 index 000000000..13d9b344f --- /dev/null +++ b/gazelle/js/tests/tsconfig_composite/BUILD.out @@ -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", +) diff --git a/gazelle/js/tests/tsconfig_composite/WORKSPACE b/gazelle/js/tests/tsconfig_composite/WORKSPACE new file mode 100644 index 000000000..66f28f7cd --- /dev/null +++ b/gazelle/js/tests/tsconfig_composite/WORKSPACE @@ -0,0 +1,2 @@ +# This is a Bazel workspace for the Gazelle test data. +workspace(name = "tsconfig_composite") diff --git a/gazelle/js/tests/tsconfig_composite/main.ts b/gazelle/js/tests/tsconfig_composite/main.ts new file mode 100644 index 000000000..7b68cbff7 --- /dev/null +++ b/gazelle/js/tests/tsconfig_composite/main.ts @@ -0,0 +1 @@ +console.log('No Imports!'); diff --git a/gazelle/js/tests/tsconfig_composite/tsconfig.json b/gazelle/js/tests/tsconfig_composite/tsconfig.json new file mode 100644 index 000000000..664df5f60 --- /dev/null +++ b/gazelle/js/tests/tsconfig_composite/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "composite": true + } +} diff --git a/gazelle/js/typescript/tsconfig.go b/gazelle/js/typescript/tsconfig.go index e07bf68af..ee3504fff 100644 --- a/gazelle/js/typescript/tsconfig.go +++ b/gazelle/js/typescript/tsconfig.go @@ -29,6 +29,7 @@ import ( type tsCompilerOptionsJSON struct { AllowJs *bool `json:"allowJs"` + Composite *bool `json:"composite"` Declaration *bool `json:"declaration"` DeclarationMap *bool `json:"declarationMap"` SourceMap *bool `json:"sourceMap"` @@ -81,6 +82,7 @@ type TsConfig struct { AllowJs *bool ResolveJsonModule *bool + Composite *bool Declaration *bool DeclarationMap *bool SourceMap *bool @@ -217,6 +219,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 @@ -310,6 +319,7 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r ConfigDir: configDir, ConfigName: configName, AllowJs: allowJs, + Composite: composite, Declaration: declaration, DeclarationMap: declarationMap, SourceMap: sourceMap, From 9e84c24e9faaec98034e3d48c30034919e8af104 Mon Sep 17 00:00:00 2001 From: Walker Burgin Date: Fri, 29 Nov 2024 15:32:43 -0800 Subject: [PATCH 2/2] Reflect the tsconfig "incremental" setting into ts_project() rules --- gazelle/js/generate.go | 8 ++++++++ gazelle/js/tests/tsconfig_incremental/BUILD.in | 1 + gazelle/js/tests/tsconfig_incremental/BUILD.out | 15 +++++++++++++++ gazelle/js/tests/tsconfig_incremental/WORKSPACE | 2 ++ gazelle/js/tests/tsconfig_incremental/main.ts | 1 + .../js/tests/tsconfig_incremental/tsconfig.json | 5 +++++ gazelle/js/typescript/tsconfig.go | 10 ++++++++++ 7 files changed, 42 insertions(+) create mode 100644 gazelle/js/tests/tsconfig_incremental/BUILD.in create mode 100644 gazelle/js/tests/tsconfig_incremental/BUILD.out create mode 100644 gazelle/js/tests/tsconfig_incremental/WORKSPACE create mode 100644 gazelle/js/tests/tsconfig_incremental/main.ts create mode 100644 gazelle/js/tests/tsconfig_incremental/tsconfig.json diff --git a/gazelle/js/generate.go b/gazelle/js/generate.go index ca412f366..6ba40ef38 100644 --- a/gazelle/js/generate.go +++ b/gazelle/js/generate.go @@ -541,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) @@ -575,6 +582,7 @@ func (ts *typeScriptLang) addProjectRule(cfg *JsGazelleConfig, tsconfigRel strin 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") diff --git a/gazelle/js/tests/tsconfig_incremental/BUILD.in b/gazelle/js/tests/tsconfig_incremental/BUILD.in new file mode 100644 index 000000000..5b0ea19fe --- /dev/null +++ b/gazelle/js/tests/tsconfig_incremental/BUILD.in @@ -0,0 +1 @@ +# gazelle:js_tsconfig enabled \ No newline at end of file diff --git a/gazelle/js/tests/tsconfig_incremental/BUILD.out b/gazelle/js/tests/tsconfig_incremental/BUILD.out new file mode 100644 index 000000000..fbce55e09 --- /dev/null +++ b/gazelle/js/tests/tsconfig_incremental/BUILD.out @@ -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", +) diff --git a/gazelle/js/tests/tsconfig_incremental/WORKSPACE b/gazelle/js/tests/tsconfig_incremental/WORKSPACE new file mode 100644 index 000000000..d1fabaa02 --- /dev/null +++ b/gazelle/js/tests/tsconfig_incremental/WORKSPACE @@ -0,0 +1,2 @@ +# This is a Bazel workspace for the Gazelle test data. +workspace(name = "tsconfig_incremental") diff --git a/gazelle/js/tests/tsconfig_incremental/main.ts b/gazelle/js/tests/tsconfig_incremental/main.ts new file mode 100644 index 000000000..7b68cbff7 --- /dev/null +++ b/gazelle/js/tests/tsconfig_incremental/main.ts @@ -0,0 +1 @@ +console.log('No Imports!'); diff --git a/gazelle/js/tests/tsconfig_incremental/tsconfig.json b/gazelle/js/tests/tsconfig_incremental/tsconfig.json new file mode 100644 index 000000000..78f0d4589 --- /dev/null +++ b/gazelle/js/tests/tsconfig_incremental/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "incremental": true + } +} diff --git a/gazelle/js/typescript/tsconfig.go b/gazelle/js/typescript/tsconfig.go index ee3504fff..708629417 100644 --- a/gazelle/js/typescript/tsconfig.go +++ b/gazelle/js/typescript/tsconfig.go @@ -32,6 +32,7 @@ type tsCompilerOptionsJSON struct { 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"` @@ -85,6 +86,7 @@ type TsConfig struct { Composite *bool Declaration *bool DeclarationMap *bool + Incremental *bool SourceMap *bool OutDir string RootDir string @@ -240,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 @@ -322,6 +331,7 @@ func parseTsConfigJSON(parsed map[string]*TsConfig, resolver TsConfigResolver, r Composite: composite, Declaration: declaration, DeclarationMap: declarationMap, + Incremental: incremental, SourceMap: sourceMap, ResolveJsonModule: resolveJsonModule, OutDir: OutDir,