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

module: ignore resolution failures for inspect-brk #30336

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,14 +1091,20 @@ Module.prototype._compile = function(content, filename) {
if (!resolvedArgv) {
// We enter the repl if we're not given a filename argument.
if (process.argv[1]) {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
try {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
} catch {
// We only expect this codepath to be reached in the case of a
// preloaded module (it will fail earlier with the main entry)
assert(Array.isArray(getOptionValue('--require')));
}
} else {
resolvedArgv = 'repl';
}
}

// Set breakpoint on module start
if (!hasPausedEntry && filename === resolvedArgv) {
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
hasPausedEntry = true;
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
}
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions test/fixtures/test-resolution-inspect-brk-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';
// eslint-disable-next-line no-unused-vars
const common = require('../common');

require.extensions['.ext'] = require.extensions['.js'];
29 changes: 29 additions & 0 deletions test/sequential/test-resolution-inspect-brk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();

// A test to ensure that preload modules are given a chance to execute before
// resolving the main entry point with --inspect-brk active.

const assert = require('assert');
const cp = require('child_process');
const path = require('path');

function test(execArgv) {
const child = cp.spawn(process.execPath, execArgv);

child.stderr.once('data', common.mustCall(function() {
child.kill('SIGTERM');
}));

child.on('exit', common.mustCall(function(code, signal) {
assert.strictEqual(signal, 'SIGTERM');
}));
}

test([
'--require',
path.join(__dirname, '../fixtures/test-resolution-inspect-brk-resolver.js'),
'--inspect-brk',
'../fixtures/test-resolution-inspect-resolver-main.ext',
]);