-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Preserve symlinks when node is configured to do so #9732
Conversation
344b089
to
e136e74
Compare
@SimenB what can I do to help get the conversation rolling on this PR? |
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'd prefer this to be an option to Jest (added to GlobalConfig
) rather than every file sniffing the environment on their own. I think that'll be easier to reason about. We also need to check for --preserve-symlinks
passed to node and look in NODE_OPTIONS
, so just checking NODE_PRESERVE_SYMLINKS
in the env isn't sufficient.
If the flag is not provided to jest, we can look at process.env
somewhere in jest-config
(normalize
perhaps?) and default it.
Hey @SimenB , Thanks for the response. I think it's actually much easier to reason about as an environment variable rather than jest specific configuration. Especially since this is not really configuring jest, but fixing a bug where jest didn't previously respect the expected behavior of setting this environment variable in node. This is further complicated by the fact that we need to know if preserve symlinks is set during the process of resolving and loading the jest config. Its a little weird to have jest config for loading jest config, and it makes the implementation very complicated. We also need to know about this config in several places where we don't currently have access to the config, such as static methods on the jest resolve package.
I would classify that as a nice to have. Having jest at least respect one way of setting this value would be a massive improvement as it unblocks everyone who wants to use jest with bazel. This could also be added as an incremental improvement. If you are concerned about the repetition involved here, an easy fix would be to create a new package for resolving the real path only if it matches the expected behavior of node. This could just wrap If you are truly hard set on using configuration for this, I would ask that you accept this PR first and update it to use configuration which defaults to the environment variable if not set. This will not introduce any breaking changes, and will help unblock a big portion of the community quickly. Please let me know your thoughts. Thank you! |
Codecov Report
@@ Coverage Diff @@
## master #9732 +/- ##
==========================================
- Coverage 64.24% 64.20% -0.05%
==========================================
Files 292 292
Lines 12466 12490 +24
Branches 3078 3089 +11
==========================================
+ Hits 8009 8019 +10
- Misses 3809 3815 +6
- Partials 648 656 +8
Continue to review full report at Codecov.
|
Hey @SimenB - Have you had some time to consider my comments? |
fc72d60
to
bf0f8b8
Compare
Ping @SimenB - sorry to bother you. Have you had some time to consider my comments? |
94ab7ba
to
e49b38e
Compare
I'm still of the opinion that to only support a single way of toggling this when node has multiple will lead to much confusion for the user - it's easier to say "we don't support it" rather than "if you do it in this way it works, but not in this way". If we only want a single way, it should be an option to Jest and not cherry picking one of the ways Node supports it |
ed29bfd
to
a533a8e
Compare
@SimenB - I've updated the PR to include support for both methods of configuring symlink preservation in node. Hopefully this will address your concerns. It is not something that can easily be put into jest config because we use this when resolving and loading the jest config. |
6cc323d
to
fffe4fc
Compare
35049e4
to
ad27511
Compare
Closing in favor of #9976 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This updates jest to respect the behavior of the running node process with regard to preserving symlink paths. It is compatible with both the NODE_PRESERVE_SYMLINKS environment variable and the --preserve-symlinks flag. When node is configured to preserve symlinks, jest will not resolve symlinks via fs.realpath. Additionally, this fixes some bugs where symlinks were not correctly found during fs crawling.
See: #5356
credit to @Globegitter for getting this started here: #7364. This PR is adapted from that, taking a slightly different
approach.
Test plan
Both integration tests and unit tests were added for the changes.