Skip to content

fix: resolve chdir inside the tree the launcher leaves us in - #2995

Merged
acozzette merged 3 commits into
mainfrom
chdir-cleanup
Aug 31, 2026
Merged

fix: resolve chdir inside the tree the launcher leaves us in#2995
acozzette merged 3 commits into
mainfrom
chdir-cleanup

Conversation

@acozzette

Copy link
Copy Markdown
Contributor

Currently we have an inconsistency in the way js_binary(chdir) is handled. If the js_binary target that sets chdir is in the main module, then we just cd directly from there into a subdirectory. However, if it is in a foreign module, then we cd to an absolute path within the bin directory. In the case of bazel run or a js_test that means we cd out of the runfiles tree in that situation.

This change fixes the problem by making sure we stay within the current directory regardless of whether the chdir came from a foreign module or the main module.

I also cleaned up the launcher script slightly by removing the behavior of falling back on JS_BINARY__BINDIR when BAZEL_BINDIR is unset.


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

Always resolve chdir inside the tree the launcher leaves us in.

Test plan

  • Covered by existing test cases
  • New test cases added

acozzette and others added 2 commits August 28, 2026 15:57
Currently we have an inconsistency in the way `js_binary(chdir)` is handled. If
the `js_binary` target that sets `chdir` is in the main module, then we just cd
directly from there into a subdirectory. However, if it is in a foreign module,
then we cd to an absolute path within the bin directory. In the case of `bazel
run` or a `js_test` that means we cd out of the runfiles tree in that
situation.

This change fixes the problem by making sure we stay within the current
directory regardless of whether the `chdir` came from a foreign module or the
main module.

I also cleaned up the launcher script slightly by removing the behavior of
falling back on `JS_BINARY__BINDIR` when `BAZEL_BINDIR` is unset.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@acozzette
acozzette marked this pull request as ready for review August 29, 2026 15:49
@acozzette
acozzette requested a review from jbedard August 29, 2026 15:49

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad26bd7f4b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread js/private/node-bootstrap/bootstrap.cjs
Comment thread js/private/js_binary.sh.tpl
@acozzette
acozzette merged commit ec399c6 into main Aug 31, 2026
186 checks passed
@acozzette
acozzette deleted the chdir-cleanup branch August 31, 2026 20:31
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