Skip to content

Commit

Permalink
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.

Fixes: nodejs#8509
  • Loading branch information
Marc Udoff committed Oct 14, 2016
1 parent 2b5acda commit 61d92fa
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 @@ -277,6 +277,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 @@ -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")) {

This comment has been minimized.

Copy link
@refack

refack Jan 9, 2017

I tried to track down the answer, but couldn't find the exact answer...
Why is this behind secure_getenv 🤔?
P.S. (love the PR in general)

This comment has been minimized.

Copy link
@mlucool

mlucool Jan 9, 2017

Owner

Other code in this file did it like that, so I choose to maintain status quo

This comment has been minimized.

Copy link
@refack

refack Jan 9, 2017

Gotya. Was confused by the output of search resaults
👍

This comment has been minimized.

Copy link
@mlucool

mlucool Jan 12, 2017

Owner

Np - strange that the other line doesn't come up there

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 61d92fa

Please sign in to comment.