From 635ff858102ce2e6ccd67738fa02b634af0f698e Mon Sep 17 00:00:00 2001 From: Vasilios Pantazopoulos Date: Tue, 16 Aug 2022 17:51:40 -0400 Subject: [PATCH] fix: `ts_project` fail if `root_dir` used deep in source tree --- nodejs/private/ts_lib.bzl | 2 +- .../typescript/test/ts_project/rootdir_with_value/BUILD.bazel | 1 + .../ts_project/rootdir_with_value/subdir/deep/subdir/b.ts | 1 + .../typescript/test/ts_project/rootdir_with_value/verify.js | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packages/typescript/test/ts_project/rootdir_with_value/subdir/deep/subdir/b.ts diff --git a/nodejs/private/ts_lib.bzl b/nodejs/private/ts_lib.bzl index 329acff22e..32817b19cf 100644 --- a/nodejs/private/ts_lib.bzl +++ b/nodejs/private/ts_lib.bzl @@ -169,7 +169,7 @@ def _out_paths(srcs, out_dir, root_dir, allow_js, ext_map): outs = [] for f in srcs: if _is_ts_src(f, allow_js): - out = _join(out_dir, f[:f.rindex(".")].replace(rootdir_replace_pattern, "") + _replace_ext(f, ext_map)) + out = _join(out_dir, f[:f.rindex(".")].replace(rootdir_replace_pattern, "", 1) + _replace_ext(f, ext_map)) # Don't declare outputs that collide with inputs # for example, a.js -> a.js diff --git a/packages/typescript/test/ts_project/rootdir_with_value/BUILD.bazel b/packages/typescript/test/ts_project/rootdir_with_value/BUILD.bazel index 972c7bf1c2..d14db037be 100644 --- a/packages/typescript/test/ts_project/rootdir_with_value/BUILD.bazel +++ b/packages/typescript/test/ts_project/rootdir_with_value/BUILD.bazel @@ -5,6 +5,7 @@ load("//packages/typescript:index.bzl", "ts_project") SRCS = [ "subdir/a.ts", "subdir/file.json", + "subdir/deep/subdir/b.ts", ] ts_project( diff --git a/packages/typescript/test/ts_project/rootdir_with_value/subdir/deep/subdir/b.ts b/packages/typescript/test/ts_project/rootdir_with_value/subdir/deep/subdir/b.ts new file mode 100644 index 0000000000..2b5157dcdd --- /dev/null +++ b/packages/typescript/test/ts_project/rootdir_with_value/subdir/deep/subdir/b.ts @@ -0,0 +1 @@ +export const a: string = 'so many folders...'; diff --git a/packages/typescript/test/ts_project/rootdir_with_value/verify.js b/packages/typescript/test/ts_project/rootdir_with_value/verify.js index 3ac11b00c9..002cf90b60 100644 --- a/packages/typescript/test/ts_project/rootdir_with_value/verify.js +++ b/packages/typescript/test/ts_project/rootdir_with_value/verify.js @@ -2,3 +2,7 @@ const assert = require('assert'); const files = process.argv.slice(2); assert.ok(files.some(f => f.endsWith('rootdir_with_value/a.js')), 'Missing a.js'); + +// Test that the only the top-level matching "rootdir" is removed. +// NOTE: This should never fail directly, as the bug being fixed is a build-time error. +assert.ok(files.some(f => f.endsWith('rootdir_with_value/deep/subdir/b.js')), 'Missing b.js');