-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
js_run_devserver symlinks scoped node_modules to bazel-out instead of runfiles (unscoped node_modules are already linked to bazel-out) #1210
Conversation
Did you have an example we can put in a test or in the examples directory? |
Hmm, the only example I have is the reproduction I made here: https://github.com/gregjacobs/rules-js-devserver-multiple-react-reproduction. Check out the 'packages' directory which has a library called '@my-org/button', and a webpack 'app'. The '@my-org/button' component only shows up when running the app if this multiple node_modules trees issue is solved (the button says "If you see me, you have fixed the issue!"). See here: https://github.com/gregjacobs/rules-js-devserver-multiple-react-reproduction/blob/main/packages/app/src/app.tsx Was thinking about a test which launches the webpack app and then looks for the button to be on the screen using puppeteer or playwright. That would be a good full integration test. But otherwise, could possibly have a lower-level test which just checks that both unscoped and scoped node_modules symlink to the bin directory rather than the runfiles directory? Or do you have another recommendation? |
Ok so I came up with a test for this actually, although it may be a little complex and may not be immediately clear exactly what it's testing. The test basically replicates the reproduction that I made. It creates a webpack app with a single component, and then uses Puppeteer to check that the component rendered on the page. If the component doesn't display, one reason could be that there are multiple copies of React in the bundle and the component is throwing an error by trying to use a hook. However, the webpack compilation could also be broken for other reasons as well (of which we'll see the error from the test script). I checked that the test properly fails when removing the fix I had made in Totally open to simpler ideas if you think of any though! |
Update: ended up writing both tests: explicit tests for the node_modules' symlinks, and an integration test to make sure a Webpack compilation works within |
Hey @gregmagolan, can you take a quick look at this PR? This is basically the extension of what you did in #1043, but just to handle node modules like '@org/pkg' in addition to 'pkg' |
Btw if you feel the webpack compilation in the test and all is too complex, I can remove. I think just having the test that checks the node_modules symlinks at this point is good enough |
That is a lot of code and a complicated test for such a simple fix, so I'm not sure if it's worth it. The tests in If we can't find an easier test I think we can probably live without one. WDYT? Either way thank you for giving the test a try! 👍 |
No worries! I'll simplify to just leave the test of the symlinks then and remove the webpack test 👍 Will ping back in a bit |
Oh nice. Thanks for fixing this! I overlooked the For testing this change I think it would be sufficient to export the function |
@gregmagolan Hah, just saw this after I pushed my latest simplification 😄 I did go with an integration test to ensure the proper symlinks get all the way to the file system inside the devserver's sandbox. Check it out and let me know what you think :) Best, |
I think I'd say the same as @gregmagolan, I feel like modifying the rule to expose things is a bit much for what is really a fairly simple change. If the util method is exported can we do something super simple similar to other tests in |
Hmm, the only problem with just exporting the util method and testing it directly is that the Testing that the correct symlinks make it to the sandbox's file system has the advantage of ensuring that the behavior of the script is correct, regardless of how it may be refactored or internally coded in the future. For instance, someone could remove the Maybe in order to remove the need for a new attribute on def js_run_devserver(
name,
**kwargs):
"""
(Original macro docs with all args documented here)
"""
js_run_devserver_internal(
name = name,
rule_to_execute = _js_run_devserver,
**kwargs,
)
def js_run_devserver_internal(
name,
rule_to_execute,
tool = None,
command = None,
grant_sandbox_write_permissions = False,
use_execroot_entry_point = True,
allow_execroot_entry_point_with_no_copy_data_to_bin = False,
**kwargs):
rule_to_execute(
name,
# ... Original logic of js_run_devserver here with selects() and such ...
**kwargs,
) That would leave the public API of |
Just pushed the above idea so you guys can take a look. Let me know what you think. Btw, I would say not to focus on the fact that the particular fix in this PR is small - I think adding a test rule for Or was your comment above more about just not using jasmine in the .spec.js file and having a "one test per Bazel target" kind of thing? |
Ok so I made the test target specific to just checking Lmk if that's okay to leave in, or if you really prefer it out (I'm okay either way :)) |
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.
🚀
I had another read after your recent changes and I think your test here is great and very creatively wired up. Lets go with your approach. Like you said above, I think the pattern could be used in the future for more js_run_devserver assertions. Looks like some CI failures and a buildifier failure to cleanup and this is good to go. |
Thanks for that @gregmagolan, and glad you like the approach! I fixed the buildifier errors, and I believe the CI failures as well. I did have to add an interesting workaround inside What I did instead was pop the parameter off kwargs instead. See here: https://github.com/aspect-build/rules_js/pull/1210/files#diff-f43ca342bae64f71d41f4b9f371a8ff5b6eb168883d58438c35b41eaaa8b8403R285. Any insights on this would def be appreciated, although it does seem to work 🙂 |
Awesome, looks like everything passed now! |
Great! Thanks for greening it up. Before landing, I'll do some local testing do try to understand the |
Yes, definitely a strange one. But awesome, sounds good! Let me know if you need any help recreating it. I was running the e2e/js_run_devserver on this commit and seeing the problem: 4c5326c |
Oh I see, you had rule_to_execute as a require 2nd parameter:
So starlark must have taken that as
|
The |
Actually, with that pattern you don't even need an |
Pushed a commit to your branch that removes |
…rinting docs for the lib
Good call on not needing
Omg I can't believe I missed that! I added positional arguments to the Best, |
Fix for #1204
It seems there was code in
js_run_devserver.mjs
that symlinked non-scoped node modules (such as 'lodash') to the bazel-out directory (instead of the runfiles directory), but it didn't handle scoped node modules like '@babel/core'This fix solves the issue of two node_modules trees seen by bundlers when using scoped node modules
Type of change
Test plan