Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 69ec9be

Browse filesBrowse files
arcanisMylesBorins
authored andcommitted
module: ignore resolution failures for inspect-brk
The resolution for the main entry point may fail when the resolution requires a preloaded module to be executed first (for example when adding new extensions to the resolution process). Silently skipping such failures allow us to defer the resolution as long as needed without having any adverse change (since the main entry point won't resolve anyway if it really can't be resolved at all). PR-URL: #30336 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 3d4c24d commit 69ec9be
Copy full SHA for 69ec9be

File tree

Expand file treeCollapse file tree

4 files changed

+42
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+42
-2
lines changed
Open diff view settings
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,14 +1104,20 @@ Module.prototype._compile = function(content, filename) {
11041104
if (!resolvedArgv) {
11051105
// We enter the repl if we're not given a filename argument.
11061106
if (process.argv[1]) {
1107-
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1107+
try {
1108+
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1109+
} catch {
1110+
// We only expect this codepath to be reached in the case of a
1111+
// preloaded module (it will fail earlier with the main entry)
1112+
assert(Array.isArray(getOptionValue('--require')));
1113+
}
11081114
} else {
11091115
resolvedArgv = 'repl';
11101116
}
11111117
}
11121118

11131119
// Set breakpoint on module start
1114-
if (!hasPausedEntry && filename === resolvedArgv) {
1120+
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
11151121
hasPausedEntry = true;
11161122
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
11171123
}
Collapse file

‎test/fixtures/test-resolution-inspect-brk-main.ext‎

Copy file name to clipboardExpand all lines: test/fixtures/test-resolution-inspect-brk-main.ext
Whitespace-only changes.
Collapse file
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
// eslint-disable-next-line no-unused-vars
3+
const common = require('../common');
4+
5+
require.extensions['.ext'] = require.extensions['.js'];
Collapse file
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
const common = require('../common');
3+
common.skipIfInspectorDisabled();
4+
5+
// A test to ensure that preload modules are given a chance to execute before
6+
// resolving the main entry point with --inspect-brk active.
7+
8+
const assert = require('assert');
9+
const cp = require('child_process');
10+
const path = require('path');
11+
12+
function test(execArgv) {
13+
const child = cp.spawn(process.execPath, execArgv);
14+
15+
child.stderr.once('data', common.mustCall(function() {
16+
child.kill('SIGTERM');
17+
}));
18+
19+
child.on('exit', common.mustCall(function(code, signal) {
20+
assert.strictEqual(signal, 'SIGTERM');
21+
}));
22+
}
23+
24+
test([
25+
'--require',
26+
path.join(__dirname, '../fixtures/test-resolution-inspect-brk-resolver.js'),
27+
'--inspect-brk',
28+
'../fixtures/test-resolution-inspect-resolver-main.ext',
29+
]);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.