-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[JS]: Handle optional dependency for @bazel/runfiles #14352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
I have faced this few times. I think this looks good to me. |
Note: If you are running tests with Mocha or Jasmine, this module is not needed.\n | ||
For more details, see: https://github.com/bazelbuild/rules_nodejs/issues/3770` | ||
console.error(errorMessage) | ||
runfiles = null // Set to null if not available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we properly wrap all usages of runfiles
later in this file? Maybe we do a check before we use it, and exit quickly if we know it'll never succeed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check for runfiles
and implemented a safe, silent exit if not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you!
User description
Description
In an npm project, requiring
@bazel/runfiles
withconst { runfiles } = require('@bazel/runfiles')
throws an exception because@bazel/runfiles
is not available outside of Bazel builds.The fix safely attempts to require @bazel/runfiles and logs a message if it fails.
Types of changes
Checklist
PR Type
Bug fix
Description
@bazel/runfiles
which caused exceptions in non-Bazel environments.@bazel/runfiles
.@bazel/runfiles
is not available.runfiles
to null if the module is not available to prevent further issues.Changes walkthrough 📝
index.js
Handle optional dependency for `@bazel/runfiles` in tests
javascript/node/selenium-webdriver/testing/index.js
@bazel/runfiles
.@bazel/runfiles
.@bazel/runfiles
is not available.runfiles
to null if the module is not available.