Skip to content

Commit 60a5b51

Browse files
Marc Udoffevanlucas
Marc Udoff
authored andcommitted
src: add NODE_PRESERVE_SYMLINKS environment variable
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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 44427cc commit 60a5b51

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

doc/api/cli.md

+7
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ added: v0.11.15
287287
Data path for ICU (Intl object) data. Will extend linked-in data when compiled
288288
with small-icu support.
289289

290+
### `NODE_PRESERVE_SYMLINKS=1`
291+
<!-- YAML
292+
added: REPLACEME
293+
-->
294+
295+
When set to `1`, instructs the module loader to preserve symbolic links when
296+
resolving and caching modules.
290297

291298
### `NODE_REPL_HISTORY=file`
292299
<!-- YAML

src/node.cc

+5
Original file line numberDiff line numberDiff line change
@@ -4192,6 +4192,11 @@ void Init(int* argc,
41924192
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1);
41934193
#endif
41944194

4195+
// Allow for environment set preserving symlinks.
4196+
if (auto preserve_symlinks = secure_getenv("NODE_PRESERVE_SYMLINKS")) {
4197+
config_preserve_symlinks = (*preserve_symlinks == '1');
4198+
}
4199+
41954200
// Parse a few arguments which are specific to Node.
41964201
int v8_argc;
41974202
const char** v8_argv;

test/parallel/test-require-symlink.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const path = require('path');
66
const fs = require('fs');
77
const exec = require('child_process').exec;
88
const spawn = require('child_process').spawn;
9+
const util = require('util');
910

1011
common.refreshTmpDir();
1112

@@ -53,7 +54,16 @@ function test() {
5354
const node = process.execPath;
5455
const child = spawn(node, ['--preserve-symlinks', linkScript]);
5556
child.on('close', function(code, signal) {
56-
assert(!code);
57+
assert.strictEqual(code, 0);
58+
assert(!signal);
59+
});
60+
61+
// Also verify that symlinks works for setting preserve via env variables
62+
const childEnv = spawn(node, [linkScript], {
63+
env: util._extend(process.env, {NODE_PRESERVE_SYMLINKS: '1'})
64+
});
65+
childEnv.on('close', function(code, signal) {
66+
assert.strictEqual(code, 0);
5767
assert(!signal);
5868
});
5969
}

0 commit comments

Comments
 (0)