From 559d1a4793de0cd6fd27e9487d47a0a94c32eb97 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 28 Mar 2021 11:12:04 +1000 Subject: [PATCH] fix(esbuild): files not being found when building external repo An esbuild rule that ran fine in a local repo (eg bazel build //:my_esbuild_rule) fails when built externally (eg bazel build @other_workspace//:my_esbuild_rule). By prepending the workspace root to the bin path, the resulting base URL works correctly in both local and remote repo invocations, allowing esbuild output to be consumed by a different repo. This change fixes remote repos in Bazel 4.0.0. 3.7.0 seems to require a workspace_root.replace("external/", "") call first in order to get the correct location. So while this patch should not break anything that was not already broken, it only fixes/adds support for remote repos in 4.0+. --- ts/esbuild/helpers.bzl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ts/esbuild/helpers.bzl b/ts/esbuild/helpers.bzl index b7f483e89..bc2e1855f 100644 --- a/ts/esbuild/helpers.bzl +++ b/ts/esbuild/helpers.bzl @@ -89,8 +89,9 @@ def write_jsconfig_file(ctx, path_alias_mappings): File object reference for the jsconfig file """ - # The package path - rule_path = paths.dirname(ctx.build_file_path) + # The package path, including an "external/repo_name/" prefix if the package is in + # an external repo. + rule_path = paths.join(ctx.label.workspace_root, paths.dirname(ctx.build_file_path)) # Replace all segments in the path with .. join them with "/" and postfix # it with another / to get a relative path from the build file dir