Browse Source

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: https://github.com/nodejs/node/pull/8749
Fixes: https://github.com/nodejs/node/issues/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>
v7.x
Marc Udoff 8 years ago
committed by Evan Lucas
parent
commit
60a5b515b8
  1. 7
      doc/api/cli.md
  2. 5
      src/node.cc
  3. 12
      test/parallel/test-require-symlink.js

7
doc/api/cli.md

@ -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

5
src/node.cc

@ -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;

12
test/parallel/test-require-symlink.js

@ -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();
@ -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);
});
}

Loading…
Cancel
Save