Skip to content

Commit

Permalink
src: .env file can override NODE_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Sep 3, 2023
1 parent edaa662 commit 271bebd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void Dotenv::SetEnvironment(node::Environment* env) {

auto existing = env->env_vars()->Get(key.data());

if (existing.IsNothing()) {
if (existing.IsNothing() || strcmp(key.data(), "NODE_OPTIONS") == 0) {
env->env_vars()->Set(
isolate,
v8::String::NewFromUtf8(
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-dotenv-edge-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,17 @@ describe('.env supports edge cases', () => {
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});

it('should override NODE_OPTIONS', async () => {
const code = `
require('assert').strictEqual(process.env.NODE_OPTIONS, '--experimental-permission --allow-fs-read=*');
`.trim();
const child = await common.spawnPromisified(
process.execPath,
[ `--env-file=${relativePath}`, '--eval', code ],
{ cwd: __dirname, env: { NODE_OPTIONS: '--experimental-permission --allow-worker' } },
);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
});

0 comments on commit 271bebd

Please sign in to comment.