Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --inspect & --inspect-brk from execArgv #435

Merged
merged 6 commits into from Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion index.js
Expand Up @@ -235,7 +235,24 @@ module.exports.node = (scriptPath, args, options = {}) => {

const stdio = normalizeStdio.node(options);

const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
// Filter out `--inspect` & `--inspect-brk` from default `execArgv`.
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
const defaultExecArgv = process.execArgv.filter(arg => {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
if (
arg === '--inspect' ||
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
arg.startsWith('--inspect=') ||
arg === '--inspect-brk' ||
arg.startsWith('--inspect-brk=')
) {
return false;
}

return true;
});

const {
nodePath = process.execPath,
nodeOptions = defaultExecArgv
} = options;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on doing it no matter what? I don't really see any good reason users would want to override it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes you want to set inspect on a subprocess when your main process is just a small wrapper. We could also tell people to move towards https://nodejs.org/api/inspector.html instead for this functionality.

I'm okay either way, just remember that changing this would be a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sometimes you want to set inspect on a subprocess when your main process is just a small wrapper.

Yes, it looks to me that could be the case, and this change would then be a breaking change if any users is doing this. Based on this, I personally think only doing this as a default value (what the PR currently does) might be better?


return execa(
nodePath,
Expand Down
104 changes: 98 additions & 6 deletions test/node.js
Expand Up @@ -3,7 +3,8 @@ import test from 'ava';
import pEvent from 'p-event';
import execa from '..';

process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
process.env.PATH =
path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

test('node()', async t => {
const {exitCode} = await execa.node('test/fixtures/noop');
Expand All @@ -19,11 +20,14 @@ test('node pipe stdout', async t => {
});

test('node correctly use nodePath', async t => {
const {stdout} = await execa.node(process.platform === 'win32' ? 'hello.cmd' : 'hello.sh', {
stdout: 'pipe',
nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash',
nodeOptions: process.platform === 'win32' ? ['/c'] : []
});
const {stdout} = await execa.node(
process.platform === 'win32' ? 'hello.cmd' : 'hello.sh',
{
stdout: 'pipe',
nodePath: process.platform === 'win32' ? 'cmd.exe' : 'bash',
nodeOptions: process.platform === 'win32' ? ['/c'] : []
}
);
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

t.is(stdout, 'Hello World');
});
Expand All @@ -37,6 +41,94 @@ test('node pass on nodeOptions', async t => {
t.is(stdout, 'foo');
});

test.serial(
'node removes --inspect from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect', '-e'];
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe'
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
});
process.execArgv = originalArgv;
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

t.is(stdout, 'foo');
t.is(stderr, '');
}
);
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

test.serial(
'node removes --inspect=9222 from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect=9222', '-e'];
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;

t.is(stdout, 'foo');
t.is(stderr, '');
}
);

test.serial(
'node removes --inspect-brk from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect-brk', '-e'];
const childProc = execa.node('console.log("foo")', {
stdout: 'pipe'
});
process.execArgv = originalArgv;
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

setTimeout(() => {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
childProc.cancel();
}, 1000);

const {stdout, stderr} = await childProc.catch(error => error);

t.is(stdout, 'foo');
t.is(stderr, '');
}
);

test.serial(
'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
async t => {
const originalArgv = process.execArgv;
process.execArgv = ['--inspect-brk=9222', '-e'];
const childProc = execa.node('console.log("foo")', {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
stdout: 'pipe'
});
process.execArgv = originalArgv;

setTimeout(() => {
childProc.cancel();
}, 1000);

const {stdout, stderr} = await childProc.catch(error => error);

t.is(stdout, 'foo');
t.is(stderr, '');
}
);

test.serial(
'node should not remove --inspect when passed through nodeOptions',
async t => {
const {stdout, stderr} = await execa.node('console.log("foo")', {
stdout: 'pipe',
nodeOptions: ['--inspect', '-e']
});

t.is(stdout, 'foo');
t.regex(
stderr,
/^Debugger listening on ws:\/\/127.0.0.1:9229\/.*[\r\n]+For help, see: https:\/\/nodejs.org\/en\/docs\/inspector$/
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
);
}
);

test('node\'s forked script has a communication channel', async t => {
const subprocess = execa.node('test/fixtures/send');
subprocess.send('ping');
Expand Down