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 all 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
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -234,8 +234,12 @@ module.exports.node = (scriptPath, args, options = {}) => {
}

const stdio = normalizeStdio.node(options);
const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect'));

const {nodePath = process.execPath, nodeOptions = process.execArgv} = options;
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
54 changes: 54 additions & 0 deletions test/node.js
Expand Up @@ -5,6 +5,23 @@ import execa from '..';

process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH;

async function inspectMacro(t, input) {
const originalArgv = process.execArgv;
process.execArgv = [input, '-e'];
try {
const subprocess = execa.node('console.log("foo")', {
reject: false
});

const {stdout, stderr} = await subprocess;

t.is(stdout, 'foo');
t.is(stderr, '');
} finally {
process.execArgv = originalArgv;
}
}

test('node()', async t => {
const {exitCode} = await execa.node('test/fixtures/noop');
t.is(exitCode, 0);
Expand Down Expand Up @@ -37,6 +54,43 @@ test('node pass on nodeOptions', async t => {
t.is(stdout, 'foo');
});

test.serial(
'node removes --inspect from nodeOptions when defined by parent process',
inspectMacro,
'--inspect'
);
wardpeet marked this conversation as resolved.
Show resolved Hide resolved

test.serial(
'node removes --inspect=9222 from nodeOptions when defined by parent process',
inspectMacro,
'--inspect=9222'
);

test.serial(
'node removes --inspect-brk from nodeOptions when defined by parent process',
inspectMacro,
'--inspect-brk'
);

test.serial(
'node removes --inspect-brk=9222 from nodeOptions when defined by parent process',
inspectMacro,
'--inspect-brk=9222'
);

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

t.is(stdout, 'foo');
t.true(stderr.includes('Debugger listening'));
}
);

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