From d660ca109fcf86fe0dbfb9908faaefb0e30c25a0 Mon Sep 17 00:00:00 2001 From: Long Ho Date: Mon, 29 Jun 2020 17:15:48 -0400 Subject: [PATCH] feat(typescript): add OutputGroupInfo to ts_project with type definitions fix #1978 --- packages/typescript/internal/ts_project.bzl | 1 + .../test/ts_project/output_group/BUILD.bazel | 23 +++++++++++++++++++ .../ts_project/output_group/index.golden.d.ts | 1 + .../test/ts_project/output_group/index.ts | 1 + .../ts_project/output_group/tsconfig.json | 6 +++++ 5 files changed, 32 insertions(+) create mode 100644 packages/typescript/test/ts_project/output_group/BUILD.bazel create mode 100644 packages/typescript/test/ts_project/output_group/index.golden.d.ts create mode 100644 packages/typescript/test/ts_project/output_group/index.ts create mode 100644 packages/typescript/test/ts_project/output_group/tsconfig.json diff --git a/packages/typescript/internal/ts_project.bzl b/packages/typescript/internal/ts_project.bzl index 63890e433f..5b1208f09d 100644 --- a/packages/typescript/internal/ts_project.bzl +++ b/packages/typescript/internal/ts_project.bzl @@ -143,6 +143,7 @@ def _ts_project_impl(ctx): # Improves error messaging if a ts_project needs declaration = True if len(typings_outputs) or len(ctx.attr.deps): providers.append(declaration_info(depset(typings_outputs), ctx.attr.deps)) + providers.append(OutputGroupInfo(types = depset(typings_outputs))) return providers diff --git a/packages/typescript/test/ts_project/output_group/BUILD.bazel b/packages/typescript/test/ts_project/output_group/BUILD.bazel new file mode 100644 index 0000000000..f7db0bce94 --- /dev/null +++ b/packages/typescript/test/ts_project/output_group/BUILD.bazel @@ -0,0 +1,23 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "generated_file_test") +load("//packages/typescript:index.bzl", "ts_project") + +# This uses defaults for all attributes. +# It will find `index.ts` and produce `index.js` & `index.d.ts` +ts_project( + name = "tsconfig", + srcs = ["index.ts"], + declaration = True, +) + +filegroup( + name = "types", + srcs = [":tsconfig"], + output_group = "types", +) + +generated_file_test( + name = "test", + src = "index.golden.d.ts", + # Refers to the output from filegroup above + generated = ":types", +) diff --git a/packages/typescript/test/ts_project/output_group/index.golden.d.ts b/packages/typescript/test/ts_project/output_group/index.golden.d.ts new file mode 100644 index 0000000000..106d610ab9 --- /dev/null +++ b/packages/typescript/test/ts_project/output_group/index.golden.d.ts @@ -0,0 +1 @@ +export declare const a: string; diff --git a/packages/typescript/test/ts_project/output_group/index.ts b/packages/typescript/test/ts_project/output_group/index.ts new file mode 100644 index 0000000000..a668b7e336 --- /dev/null +++ b/packages/typescript/test/ts_project/output_group/index.ts @@ -0,0 +1 @@ +export const a: string = 'hello'; diff --git a/packages/typescript/test/ts_project/output_group/tsconfig.json b/packages/typescript/test/ts_project/output_group/tsconfig.json new file mode 100644 index 0000000000..1e6e3b3652 --- /dev/null +++ b/packages/typescript/test/ts_project/output_group/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "types": [], + "declaration": true + } +} \ No newline at end of file