Skip to content

Commit d479570

Browse files
committed
module: simplify --inspect-brk handling
Previously in the CommonJS loader, --inspect-brk is implemented checking whether the module points to the result of re-resolving process.argv[1] to determine whether the module is the entry point. This is unnecessarily complex, especially now that we store that information in the module as kIsMainSymbol. This patch updates it to simply check that symbol property instead.
1 parent 2505e21 commit d479570

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

lib/internal/modules/cjs/loader.js

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,15 +1340,6 @@ Module.prototype.require = function(id) {
13401340
}
13411341
};
13421342

1343-
/**
1344-
* Resolved path to `process.argv[1]` will be lazily placed here
1345-
* (needed for setting breakpoint when called with `--inspect-brk`).
1346-
* @type {string | undefined}
1347-
*/
1348-
let resolvedArgv;
1349-
let hasPausedEntry = false;
1350-
/** @type {import('vm').Script} */
1351-
13521343
/**
13531344
* Resolve and evaluate it synchronously as ESM if it's ESM.
13541345
* @param {Module} mod CJS module instance
@@ -1530,32 +1521,6 @@ Module.prototype._compile = function(content, filename, format) {
15301521
return;
15311522
}
15321523

1533-
// TODO(joyeecheung): the detection below is unnecessarily complex. Using the
1534-
// kIsMainSymbol, or a kBreakOnStartSymbol that gets passed from
1535-
// higher level instead of doing hacky detection here.
1536-
let inspectorWrapper = null;
1537-
if (getOptionValue('--inspect-brk') && process._eval == null) {
1538-
if (!resolvedArgv) {
1539-
// We enter the repl if we're not given a filename argument.
1540-
if (process.argv[1]) {
1541-
try {
1542-
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1543-
} catch {
1544-
// We only expect this codepath to be reached in the case of a
1545-
// preloaded module (it will fail earlier with the main entry)
1546-
assert(ArrayIsArray(getOptionValue('--require')));
1547-
}
1548-
} else {
1549-
resolvedArgv = 'repl';
1550-
}
1551-
}
1552-
1553-
// Set breakpoint on module start
1554-
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
1555-
hasPausedEntry = true;
1556-
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
1557-
}
1558-
}
15591524
const dirname = path.dirname(filename);
15601525
const require = makeRequireFunction(this, redirects);
15611526
let result;
@@ -1565,9 +1530,10 @@ Module.prototype._compile = function(content, filename, format) {
15651530
if (requireDepth === 0) { statCache = new SafeMap(); }
15661531
setHasStartedUserCJSExecution();
15671532
this[kIsExecuting] = true;
1568-
if (inspectorWrapper) {
1569-
result = inspectorWrapper(compiledWrapper, thisValue, exports,
1570-
require, module, filename, dirname);
1533+
if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {
1534+
const { callAndPauseOnStart } = internalBinding('inspector');
1535+
result = callAndPauseOnStart(compiledWrapper, thisValue, exports,
1536+
require, module, filename, dirname);
15711537
} else {
15721538
result = ReflectApply(compiledWrapper, thisValue,
15731539
[exports, require, module, filename, dirname]);

0 commit comments

Comments
 (0)