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 @@ +{}