From 13caf8b92158a562d55563a0c20bb723b9c9b8a9 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 27 Mar 2020 13:14:31 -0700 Subject: [PATCH] fix(typescript): pass rootDir to ts_project tsc actions (#1748) --- packages/typescript/src/internal/ts_project.bzl | 3 +++ packages/typescript/test/ts_project/rootdir/BUILD.bazel | 4 ++++ packages/typescript/test/ts_project/rootdir/subdir/a.ts | 1 + packages/typescript/test/ts_project/rootdir/tsconfig.json | 1 + 4 files changed, 9 insertions(+) create mode 100644 packages/typescript/test/ts_project/rootdir/BUILD.bazel create mode 100644 packages/typescript/test/ts_project/rootdir/subdir/a.ts create mode 100644 packages/typescript/test/ts_project/rootdir/tsconfig.json diff --git a/packages/typescript/src/internal/ts_project.bzl b/packages/typescript/src/internal/ts_project.bzl index 228f57d9bb..caa791fb5f 100644 --- a/packages/typescript/src/internal/ts_project.bzl +++ b/packages/typescript/src/internal/ts_project.bzl @@ -47,6 +47,9 @@ def _ts_project_impl(ctx): ctx.file.tsconfig.short_path, "--outDir", "/".join([ctx.bin_dir.path, ctx.label.package]), + # Make sure TypeScript writes outputs to same directory structure as inputs + "--rootDir", + ctx.label.package if ctx.label.package else ".", ]) if len(ctx.outputs.typings_outs) > 0: arguments.add_all([ diff --git a/packages/typescript/test/ts_project/rootdir/BUILD.bazel b/packages/typescript/test/ts_project/rootdir/BUILD.bazel new file mode 100644 index 0000000000..6c12018c32 --- /dev/null +++ b/packages/typescript/test/ts_project/rootdir/BUILD.bazel @@ -0,0 +1,4 @@ +load("@npm_bazel_typescript//:index.bzl", "ts_project") + +# Ensure that subdir/a.ts produces outDir/subdir/a.js +ts_project() diff --git a/packages/typescript/test/ts_project/rootdir/subdir/a.ts b/packages/typescript/test/ts_project/rootdir/subdir/a.ts new file mode 100644 index 0000000000..a668b7e336 --- /dev/null +++ b/packages/typescript/test/ts_project/rootdir/subdir/a.ts @@ -0,0 +1 @@ +export const a: string = 'hello'; diff --git a/packages/typescript/test/ts_project/rootdir/tsconfig.json b/packages/typescript/test/ts_project/rootdir/tsconfig.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/typescript/test/ts_project/rootdir/tsconfig.json @@ -0,0 +1 @@ +{}