Skip to content

Commit 61d92fa

Browse files
author
Marc Udoff
committed
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. Fixes: nodejs#8509
1 parent 2b5acda commit 61d92fa

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
@@ -277,6 +277,13 @@ added: v0.11.15
277277
Data path for ICU (Intl object) data. Will extend linked-in data when compiled
278278
with small-icu support.
279279

280+
### `NODE_PRESERVE_SYMLINKS=1`
281+
<!-- YAML
282+
added: REPLACEME
283+
-->
284+
285+
When set to `1`, instructs the module loader to preserve symbolic links when
286+
resolving and caching modules.
280287

281288
### `NODE_REPL_HISTORY=file`
282289
<!-- YAML

src/node.cc

+5
Original file line numberDiff line numberDiff line change
@@ -4188,6 +4188,11 @@ void Init(int* argc,
41884188
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1);
41894189
#endif
41904190

4191+
// Allow for environment set preserving symlinks.
4192+
if (auto preserve_symlinks = secure_getenv("NODE_PRESERVE_SYMLINKS")) {
4193+
config_preserve_symlinks = (*preserve_symlinks == '1');
4194+
}
4195+
41914196
// Parse a few arguments which are specific to Node.
41924197
int v8_argc;
41934198
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)