Skip to content

Commit ebeb627

Browse files
committed
Respect child current-directory search opt-out
1 parent 51f60af commit ebeb627

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/arguments/command-file.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ const resolvePath = parsed => {
9595
pathExt,
9696
};
9797

98-
return shouldSearchCurrentDirectory() ? whichCommandSync(parsed.file, resolveOptions) : resolvePathDirectories(parsed.file, resolveOptions);
98+
return shouldSearchCurrentDirectory(environment) ? whichCommandSync(parsed.file, resolveOptions) : resolvePathDirectories(parsed.file, resolveOptions);
9999
};
100100

101101
const hasWindowsPathSeparator = file => file.includes('/') || file.includes('\\') || file.includes(':');
102102

103-
const shouldSearchCurrentDirectory = () => getWindowsEnvironmentValue(process.env, 'NODEFAULTCURRENTDIRECTORYINEXEPATH') === undefined;
103+
const shouldSearchCurrentDirectory = environment => getWindowsEnvironmentValue(process.env, 'NODEFAULTCURRENTDIRECTORYINEXEPATH') === undefined && getWindowsEnvironmentValue(environment, 'NODEFAULTCURRENTDIRECTORYINEXEPATH') === undefined;
104104

105105
const resolvePathDirectories = (file, {cwd, path: searchPath, pathExt}) => {
106106
for (const directory of searchPath.split(path.delimiter)) {

test/arguments/command-resolution.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ if (isWindows) {
265265
t.is(stdoutSync.toLowerCase(), pathExecutable.toLowerCase());
266266
});
267267

268-
test.serial('Uses the resolved batch file with NoDefaultCurrentDirectoryInExePath', async t => {
268+
test.serial('Uses the resolved batch file when current-directory search is disabled', async t => {
269269
const binaryDirectory = path.join(FIXTURES_DIRECTORY, 'node_modules', '.bin');
270270
await mkdir(binaryDirectory, {recursive: true});
271271
const command = 'batch-current-directory';
@@ -278,7 +278,7 @@ if (isWindows) {
278278

279279
const environmentName = 'NoDefaultCurrentDirectoryInExePath';
280280
const originalValue = process.env[environmentName];
281-
process.env[environmentName] = '1';
281+
delete process.env[environmentName];
282282
t.teardown(async () => {
283283
if (originalValue === undefined) {
284284
delete process.env[environmentName];
@@ -295,13 +295,22 @@ if (isWindows) {
295295
env: {
296296
Path: binaryDirectory,
297297
PathExt: '.CMD',
298+
[environmentName]: '1',
298299
},
299300
};
300301
const {stdout} = await execa(command, options);
301302
t.is(stdout, 'PATH');
302303

303304
const {stdout: stdoutSync} = execaSync(command, options);
304305
t.is(stdoutSync, 'PATH');
306+
307+
delete options.env[environmentName];
308+
process.env[environmentName] = '1';
309+
const {stdout: parentEnvironmentStdout} = await execa(command, options);
310+
t.is(parentEnvironmentStdout, 'PATH');
311+
312+
const {stdout: parentEnvironmentStdoutSync} = execaSync(command, options);
313+
t.is(parentEnvironmentStdoutSync, 'PATH');
305314
});
306315

307316
test('Does not search PATH for drive-relative commands', async t => {

0 commit comments

Comments
 (0)