Skip to content

Commit d6d1479

Browse files
joyeecheungruyadorno
authored andcommitted
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. PR-URL: #55679 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 20483aa commit d6d1479

File tree

1 file changed

+4
-38
lines changed

1 file changed

+4
-38
lines changed

lib/internal/modules/cjs/loader.js

+4-38
Original file line numberDiff line numberDiff line change
@@ -1344,15 +1344,6 @@ Module.prototype.require = function(id) {
13441344
};
13451345

13461346
let emittedRequireModuleWarning = false;
1347-
/**
1348-
* Resolved path to `process.argv[1]` will be lazily placed here
1349-
* (needed for setting breakpoint when called with `--inspect-brk`).
1350-
* @type {string | undefined}
1351-
*/
1352-
let resolvedArgv;
1353-
let hasPausedEntry = false;
1354-
/** @type {import('vm').Script} */
1355-
13561347
/**
13571348
* Resolve and evaluate it synchronously as ESM if it's ESM.
13581349
* @param {Module} mod CJS module instance
@@ -1557,32 +1548,6 @@ Module.prototype._compile = function(content, filename, format) {
15571548
return;
15581549
}
15591550

1560-
// TODO(joyeecheung): the detection below is unnecessarily complex. Using the
1561-
// kIsMainSymbol, or a kBreakOnStartSymbol that gets passed from
1562-
// higher level instead of doing hacky detection here.
1563-
let inspectorWrapper = null;
1564-
if (getOptionValue('--inspect-brk') && process._eval == null) {
1565-
if (!resolvedArgv) {
1566-
// We enter the repl if we're not given a filename argument.
1567-
if (process.argv[1]) {
1568-
try {
1569-
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
1570-
} catch {
1571-
// We only expect this codepath to be reached in the case of a
1572-
// preloaded module (it will fail earlier with the main entry)
1573-
assert(ArrayIsArray(getOptionValue('--require')));
1574-
}
1575-
} else {
1576-
resolvedArgv = 'repl';
1577-
}
1578-
}
1579-
1580-
// Set breakpoint on module start
1581-
if (resolvedArgv && !hasPausedEntry && filename === resolvedArgv) {
1582-
hasPausedEntry = true;
1583-
inspectorWrapper = internalBinding('inspector').callAndPauseOnStart;
1584-
}
1585-
}
15861551
const dirname = path.dirname(filename);
15871552
const require = makeRequireFunction(this, redirects);
15881553
let result;
@@ -1592,9 +1557,10 @@ Module.prototype._compile = function(content, filename, format) {
15921557
if (requireDepth === 0) { statCache = new SafeMap(); }
15931558
setHasStartedUserCJSExecution();
15941559
this[kIsExecuting] = true;
1595-
if (inspectorWrapper) {
1596-
result = inspectorWrapper(compiledWrapper, thisValue, exports,
1597-
require, module, filename, dirname);
1560+
if (this[kIsMainSymbol] && getOptionValue('--inspect-brk')) {
1561+
const { callAndPauseOnStart } = internalBinding('inspector');
1562+
result = callAndPauseOnStart(compiledWrapper, thisValue, exports,
1563+
require, module, filename, dirname);
15981564
} else {
15991565
result = ReflectApply(compiledWrapper, thisValue,
16001566
[exports, require, module, filename, dirname]);

0 commit comments

Comments
 (0)