-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Add NODE_PRESERVE_SYMLINKS environment variable #8749
Conversation
@@ -277,6 +277,12 @@ added: v0.11.15 | |||
Data path for ICU (Intl object) data. Will extend linked-in data when compiled | |||
with small-icu support. | |||
|
|||
### `NODE_PRESERVE_SYMLINKS=true` | |||
<!-- YAML | |||
added: v6.7.0. |
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.
There should be no .
here, and generally it’s easiest to simply use added: REPLACEME
(this likely won’t end up in v6.7.0, which is going to be a security release on Tuesday).
<!-- YAML | ||
added: v6.7.0. | ||
--> | ||
Instructs the module loader to preserve symbolic links when resolving and |
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.
nit: Could you leave an empty line before this?
b88ef6f
to
3cf619e
Compare
Fixed |
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
// Allow for environment set preserving symlinks | ||
if (secure_getenv("NODE_PRESERVE_SYMLINKS")) { | ||
config_preserve_symlinks = true; | ||
} |
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.
Please punctuate the comment and can you add a blank line after the block?
The way it's currently written means env NODE_PRESERVE_SYMLINKS= node
will turn on the flag. Most seasoned UNIX users probably won't expect that.
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.
Syntax fixed.
What you suggest is the best way to parse the flag, any value except for empty string? Should it handle env NODE_PRESERVE_SYMLINKS=false
?
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 write it as e.g.:
if (auto var = secure_getenv("NODE_PRESERVE_SYMLINKS"))
config_preserve_symlinks = (*var != '\0');
An empty string is false, everything else is true. That includes blank strings but I think that is an acceptable functionality vs. complexity trade-off.
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.
Done
3cf619e
to
3c08bdb
Compare
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
3c08bdb
to
3531431
Compare
Uncertain we should make more new env variables for people to rely on here, not sure we will be supporting this with ES Modules... Don't need more to break than already will. 😐 |
Ideally we should support a |
Config file support gets brought up from time to time but node has always been a self-contained binary and IMO it should stay that way. |
I understand and am not trying to push one way or another, just buying into what is already there. Any more changes before this can be merged? Can this be pulled into the 6.x series also? |
@@ -4188,6 +4188,11 @@ void Init(int* argc, | |||
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1); | |||
#endif | |||
|
|||
// Allow for environment set preserving symlinks. | |||
if (auto preserve_symlinks = secure_getenv("NODE_PRESERVE_SYMLINKS")) { |
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.
Does this work on Windows?
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.
Which part of this commit are you concerned will not work on windows?
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.
ah, disregard. I misread it. Thanks!
@Fishrock123 ... I understand the concern but this really doesn't add a new thing that would be broken as much as it adds a new switch to enable an existing thing (that would be broken). Given that, it's likely less of a concern. If it helps, I would be +1 on leaving this undocumented. |
I would prefer we document all features then have hidden ones to use at your own risk. @Fishrock123 are you ok with merging this as is? |
@nodejs/ctc ... any thoughts on this? |
@@ -4188,6 +4188,11 @@ void Init(int* argc, | |||
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1); | |||
#endif | |||
|
|||
// Allow for environment set preserving symlinks. | |||
if (auto preserve_symlinks = secure_getenv("NODE_PRESERVE_SYMLINKS")) { | |||
config_preserve_symlinks = (*preserve_symlinks != '\0'); |
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.
Indentation seems to be off here and I'm having second thoughts about interpreting NODE_PRESERVE_SYMLINKS=0
as "yes please, enable this feature." Perhaps a more robust atoi or strtol-based parser is in order.
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.
Whatever you prefer I will gladly change to. Just let me know.
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.
For consistency with other env variables, it should be enabled when set to 1
and disabled otherwise.
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.
So you are suggesting:
config_preserve_symlinks = (*preserve_symlinks == '1');
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.
NODE_PRESERVE_SYMLINKS=1
This what we do NODE_DISABLE_COLORS=1
and NODE_TTY_UNSAFE_ASYNC=1
.
See https://nodejs.org/dist/latest-v6.x/docs/api/cli.html#cli_environment_variables
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.
Tested and updated
I somewhat agree with @Fishrock123 that more knobs are not necessarily a good thing. More ways to shoot yourself in the foot, more baggage for us to maintain. |
@bnoordhuis My reason for this commit is although the ability to set a flag is great, without a way to always enable this feature it becomes very error prone. The errors associated with a missing symlink flag are often non-obvious to a non-expert. The reason we want to use symlinks is to provide a set of build tools in an enterprise environment without our large number of projects installing a huge redundant sets of dependencies (costs include extra time, dependency management, and inodes). In general, good symlink support is a huge benefit to our enterprise environments. That being said, aside from wrapping node in script named node (which seems hacky and likely to cause issues when people want to try new versions of node) how else should we maintain certain flags to always be set? |
e69f324
to
baaac09
Compare
Oh god I can't wait until this goes in. Then it can work with react-native as well! So close to actually being able to develop with symlinks! |
One more use case is the IED package manager, which makes heavy use of symlinks |
@bnoordhuis does this look good to you now? Any further changes? |
Technical side LGTM but needs a few regression tests. You can look at test/parallel/test-require-symlink.js for examples. |
baaac09
to
98e7567
Compare
Thanks for the tip @bnoordhuis . Let me know if you have any further comments. It seemed to me like it should go in the same test file as it is testing another variant of the same thing. Copying and pasting the whole case seemed to not be DRY. I could make it two test cases in this file if that is better. |
Raising visibility: @nodejs/collaborators |
I'm generally in favour of any node CLI option being able to be controlled via environment. Rather than doing this on an ad-hoc, CLI argument by argument basis, I wish that the PR to add an env variable from which any CLI option had progressed. It apparently didn't complete, and I can't find it in https://github.com/nodejs/node-v0.x-archive or here. @Fishrock123 @misterdjules Do you remember the PR I'm talking about? It proposed a EDIT: actually, found it, and it didn't, it did only the minimal CLI option thing: #881 Anyhow, I know its frustrating to not get a feature you need now, because of some unspecified maybe in the future feature would be better, so I guess I'd have to be +1 on this. |
Landing:
|
Add a way through environment variables to set the --preserve-symlinks flag. Any non-null value of NODE_PRESERVE_SYMLINKS will enable symlinks. PR-URL: nodejs#8749 Fixes: nodejs#8509 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
@imyller thanks for merging! Can this be pulled into the 6.x branch also? |
I've thrown an lts watch and lts-agenda tag on here. We will discuss it at the next meeting. |
Thanks! |
Add a way through environment variables to set the --preserve-symlinks flag. Any non-null value of NODE_PRESERVE_SYMLINKS will enable symlinks. PR-URL: #8749 Fixes: #8509 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
@Fishrock123, you said
Do you mean the preserve symlinks feature might get deprecated? I am one of the contributors at pnpm and the preserve symlinks option is the only reason pnpm can still compete with yarn. (We use a single storage for packages in the file system) If there's a discussion somewhere about the possibility of |
What are the chances of rewriting the commit message ( |
@MylesBorins are there notes on why this was not going to land on 4/6? |
@mlucool too high a probability of behavior changes |
@mlucool I edited the description to match behaviour and docs |
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected core subsystem(s)
cli
Description of change
Add a way through environment variables to set the --preserve-symlinks
flag. A value of '1' for NODE_PRESERVE_SYMLINKS will enable symlinks.
Fixes: #8509