Skip to content

feat: make esbuild_bundle path-mapping-friendly - #289

Merged
jbedard merged 5 commits into
mainfrom
path-mapping
Aug 7, 2026
Merged

feat: make esbuild_bundle path-mapping-friendly#289
jbedard merged 5 commits into
mainfrom
path-mapping

Conversation

@acozzette

@acozzette acozzette commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

BAZEL_BINDIR was baked into the esbuild action's env dict as a literal string, which Bazel's path-mapping feature never rewrites, defeating any cross-compilation-mode cache sharing for esbuild actions.

esbuild_bundle now passes BAZEL_BINDIR to its launcher via aspect_rules_js's js_binary_lib.run_binary_action() helper, which conveys it through a path-mapping-friendly command-line flag instead. That helper only works when the launcher is actually a js_binary, so a small aspect (launcher_kind_aspect in esbuild/private/helpers.bzl) is attached to the launcher to detect this automatically by checking the target's underlying rule kind. When the launcher isn't a js_binary (see e2e/toolchain_from_source, which uses a plain sh_binary), esbuild_bundle falls back to a plain, non-path-mapped BAZEL_BINDIR environment variable and doesn't advertise supports-path-mapping.

Also fixes the bazel-sandbox esbuild plugin, which used to string-match resolved paths against the literal BAZEL_BINDIR value -- under path mapping that value is a generic placeholder while symlink-resolved real paths always contain the true per-config bindir, so it now matches by bindir prefix instead.

Adds an e2e/path_mapping test that proves cache sharing across -c fastbuild/-c opt via a shared disk cache and checks that supports-path-mapping is advertised/not-advertised correctly.


Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: yes
  • Breaking change (forces users to change their own code or config): no
  • Suggested release notes appear below: yes

Make esbuild_bundle support path mapping

Test plan

  • Covered by existing test cases
  • New test cases added

@aspect-workflows

aspect-workflows Bot commented Aug 5, 2026

Copy link
Copy Markdown

✨ Aspect Workflows Tasks

📅 Fri Aug 7 07:03:52 UTC 2026

✅ 28 successful tasks

  • ✅ buildifier · ⏱ 40.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Format complete (clean)
  • ✅ test (test-e2e-bundle-bazel-7) · ⏱ 47.3s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed · 2 cached)
  • ✅ test (test-e2e-bundle-bazel-8) · ⏱ 34.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-bundle-bazel-9) · ⏱ 51.1s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-custom_version-bazel-7) · ⏱ 43.5s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-custom_version-bazel-8) · ⏱ 27s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-custom_version-bazel-9) · ⏱ 1m 31s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-npm-links-bazel-7) · ⏱ 24.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed · 2 cached)
  • ✅ test (test-e2e-npm-links-bazel-8) · ⏱ 31.6s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-npm-links-bazel-9) · ⏱ 1m 29s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (2/2 passed)
  • ✅ test (test-e2e-path_mapping-bazel-7) · ⏱ 49.3s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-path_mapping-bazel-8) · ⏱ 30.5s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-path_mapping-bazel-9) · ⏱ 47.8s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-smoke-bazel-7) · ⏱ 46.3s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-smoke-bazel-8) · ⏱ 32.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-smoke-bazel-9) · ⏱ 51.1s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-sourcemaps-bazel-7) · ⏱ 28.4s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (8/8 passed)
  • ✅ test (test-e2e-sourcemaps-bazel-8) · ⏱ 33.2s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (8/8 passed)
  • ✅ test (test-e2e-sourcemaps-bazel-9) · ⏱ 58.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (8/8 passed)
  • ✅ test (test-e2e-toolchain_from_source-bazel-7) · ⏱ 1m 43s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-toolchain_from_source-bazel-8) · ⏱ 1m 48s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-toolchain_from_source-bazel-9) · ⏱ 1m 23s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (1/1 passed)
  • ✅ test (test-e2e-tsconfig-bazel-7) · ⏱ 43.2s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (3/3 passed)
  • ✅ test (test-e2e-tsconfig-bazel-8) · ⏱ 48s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (3/3 passed)
  • ✅ test (test-e2e-tsconfig-bazel-9) · ⏱ 51.2s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (3/3 passed)
  • ✅ test (test-root-bazel-7) · ⏱ 45s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (29/29 passed · 25 cached)
  • ✅ test (test-root-bazel-8) · ⏱ 33.7s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (29/29 passed)
  • ✅ test (test-root-bazel-9) · ⏱ 1m 40s · 🐙 GitHub Actions · ☑️ Check
    💬 Bazel test complete (29/29 passed)

⏱ Last updated Fri Aug 7 07:06:03 UTC 2026 · 📊 GitHub API quota 5,378/15,000 (36% used, resets in 51m, throttle 4×)
🚀 Powered by Aspect CLI (v2026.24.11)  |  Aspect Build · X · LinkedIn · YouTube

@acozzette
acozzette marked this pull request as ready for review August 5, 2026 23:55
@acozzette
acozzette requested a review from jbedard August 5, 2026 23:56
Comment thread esbuild/private/esbuild.bzl
Comment thread esbuild/private/esbuild.bzl Outdated
Comment thread e2e/bundle/MODULE.bazel Outdated
BAZEL_BINDIR was baked into the esbuild action's env dict as a literal
string, which Bazel's path-mapping feature never rewrites, defeating any
cross-compilation-mode cache sharing for esbuild actions.

esbuild_bundle now passes BAZEL_BINDIR to its launcher via aspect_rules_js's
js_binary_lib.run_binary_action() helper, which conveys it through a
path-mapping-friendly command-line flag instead. That helper only works when
the launcher is actually a js_binary, so a small aspect (launcher_kind_aspect
in esbuild/private/helpers.bzl) is attached to the launcher attribute of both
esbuild_toolchain() and esbuild_bundle() to detect this automatically by
checking the target's underlying rule kind -- no explicit signal needed from
toolchain authors, and it works through macros wrapping js_binary and
alias() targets. When the launcher isn't a js_binary (see
e2e/toolchain_from_source, which uses a plain sh_binary), esbuild_bundle
falls back to a plain, non-path-mapped BAZEL_BINDIR environment variable and
doesn't advertise supports-path-mapping.

Also fixes the bazel-sandbox esbuild plugin, which used to string-match
resolved paths against the literal BAZEL_BINDIR value -- under path mapping
that value is a generic placeholder while symlink-resolved real paths always
contain the true per-config bindir, so it now matches by bindir prefix
instead.

Adds an e2e/path_mapping test (ported from rules_webpack) that proves cache
sharing across -c fastbuild/-c opt via a shared disk cache and checks that
supports-path-mapping is advertised/not-advertised correctly.

Temporarily pins aspect_rules_js via git_override to a commit containing
js_binary_lib.run_binary_action(), since that helper hasn't shipped in a
release yet.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread esbuild/toolchain.bzl Outdated
Comment thread esbuild/private/esbuild.bzl
Comment thread esbuild/private/plugins/bazel-sandbox.js
Comment thread esbuild/private/plugins/bazel-sandbox.js Outdated
@jbedard

jbedard commented Aug 6, 2026

Copy link
Copy Markdown
Member

LGTM, just need the rules_js release 👍

@jbedard
jbedard merged commit 6f8974b into main Aug 7, 2026
66 checks passed
@jbedard
jbedard deleted the path-mapping branch August 7, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants