Skip to content

Commit

Permalink
src: add NODE_PRESERVE_SYMLINKS environment variable
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Marc Udoff authored and evanlucas committed Nov 2, 2016
1 parent 44427cc commit 60a5b51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ 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=1`
<!-- YAML
added: REPLACEME
-->

When set to `1`, instructs the module loader to preserve symbolic links when
resolving and caching modules.

### `NODE_REPL_HISTORY=file`
<!-- YAML
Expand Down
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,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 == '1');
}

// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;
Expand Down
12 changes: 11 additions & 1 deletion test/parallel/test-require-symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const path = require('path');
const fs = require('fs');
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const util = require('util');

common.refreshTmpDir();

Expand Down Expand Up @@ -53,7 +54,16 @@ function test() {
const node = process.execPath;
const child = spawn(node, ['--preserve-symlinks', linkScript]);
child.on('close', function(code, signal) {
assert(!code);
assert.strictEqual(code, 0);
assert(!signal);
});

// Also verify that symlinks works for setting preserve via env variables
const childEnv = spawn(node, [linkScript], {
env: util._extend(process.env, {NODE_PRESERVE_SYMLINKS: '1'})
});
childEnv.on('close', function(code, signal) {
assert.strictEqual(code, 0);
assert(!signal);
});
}

0 comments on commit 60a5b51

Please sign in to comment.