Adjust rules_typescript to changes in tsickle.
Support the "hasImplementation" attribute to toggle whether to
`goog.provide` a namespace when annotation TypeScript code for Closure.
PiperOrigin-RevId: 208618948
diff --git a/examples/BUILD.bazel b/examples/BUILD.bazel
index db5bf95..0698c13 100644
--- a/examples/BUILD.bazel
+++ b/examples/BUILD.bazel
@@ -23,12 +23,12 @@
ts_library(
name = "foo_ts_library",
- srcs = [
- "foo.ts",
- ":types",
- ],
+ srcs = ["foo.ts"],
tsconfig = ":tsconfig.json",
- deps = ["//examples/generated_ts"],
+ deps = [
+ ":types",
+ "//examples/generated_ts",
+ ],
)
ts_library(
diff --git a/internal/common/compilation.bzl b/internal/common/compilation.bzl
index 82b86af..db333d5 100644
--- a/internal/common/compilation.bzl
+++ b/internal/common/compilation.bzl
@@ -118,18 +118,24 @@
workspace_segments = label.workspace_root.split("/") if label.workspace_root else []
package_segments = label.package.split("/") if label.package else []
trim = len(workspace_segments) + len(package_segments)
+ create_shim_files = False
+
closure_js_files = []
devmode_js_files = []
declaration_files = []
for input_file in ctx.files.srcs:
- if (input_file.short_path.endswith(".d.ts")):
+ is_dts = input_file.short_path.endswith(".d.ts")
+ if is_dts and not create_shim_files:
continue
basename = "/".join(input_file.short_path.split("/")[trim:])
- dot = basename.rfind(".")
- basename = basename[:dot]
+ for ext in [".d.ts", ".tsx", ".ts"]:
+ if basename.endswith(ext):
+ basename = basename[:-len(ext)]
+ break
closure_js_files += [ctx.new_file(basename + ".closure.js")]
- devmode_js_files += [ctx.new_file(basename + ".js")]
- declaration_files += [ctx.new_file(basename + ".d.ts")]
+ if not is_dts:
+ devmode_js_files += [ctx.new_file(basename + ".js")]
+ declaration_files += [ctx.new_file(basename + ".d.ts")]
return struct(
closure_js = closure_js_files,
devmode_js = devmode_js_files,
diff --git a/internal/tsc_wrapped/compiler_host.ts b/internal/tsc_wrapped/compiler_host.ts
index 3b238c0..a29f668 100644
--- a/internal/tsc_wrapped/compiler_host.ts
+++ b/internal/tsc_wrapped/compiler_host.ts
@@ -79,6 +79,7 @@
transformTypesToClosure: boolean;
addDtsClutzAliases: boolean;
isJsTranspilation: boolean;
+ provideExternalModuleDtsNamespace: boolean;
options: BazelTsOptions;
host: ts.ModuleResolutionHost = this;
@@ -122,6 +123,7 @@
this.transformTypesToClosure = bazelOpts.tsickle;
this.addDtsClutzAliases = bazelOpts.addDtsClutzAliases;
this.isJsTranspilation = Boolean(bazelOpts.isJsTranspilation);
+ this.provideExternalModuleDtsNamespace = !bazelOpts.hasImplementation;
}
/**
diff --git a/internal/tsc_wrapped/tsconfig.ts b/internal/tsc_wrapped/tsconfig.ts
index 30961fb..6f96b86 100644
--- a/internal/tsc_wrapped/tsconfig.ts
+++ b/internal/tsc_wrapped/tsconfig.ts
@@ -150,6 +150,12 @@
* be written. Ignored if isJsTranspilation is false.
*/
transpiledJsOutputFileName?: string;
+
+ /**
+ * Whether the user provided an implementation shim for .d.ts files in the
+ * compilation unit.
+ */
+ hasImplementation?: boolean;
}
export interface ParsedTsConfig {