Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
chore: allow the node entrypoint to be a builtin module
Browse files Browse the repository at this point in the history
This floats two patches onto the node 12 branch that I don't think we can upstream.

#### `run_main_module.js`

The default behavior of node is to `path.resolve(firstArg)` to figure out what JS file to load.  Issue here is that we use that for `browser/init.js` which now doesn't exist on disk.  This adds an exception that won't affect user code to allow node to boot-up internal modules (in this case anything in the `electron/js2c` scope.

#### `loader.js`

Similar to the above, the loader uses `process.argv[1]` to figure out when to break for `--inspect-brk` this updates the logic to use an Electron provided `process._firstFileName`
  • Loading branch information
MarshallOfSound committed Jun 3, 2019
1 parent 82d9c3c commit b823596
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/internal/main/run_main_module.js
Expand Up @@ -5,8 +5,11 @@ const {
} = require('internal/bootstrap/pre_execution');

// Expand process.argv[1] into a full path.
// Allow direct module name loads if it is a built-in electron module
if (!process.argv[1] || !process.argv[1].startsWith('electron/js2c')) {
const path = require('path');
process.argv[1] = path.resolve(process.argv[1]);
}

prepareMainThreadExecution();

Expand Down
7 changes: 7 additions & 0 deletions lib/internal/modules/cjs/loader.js
Expand Up @@ -781,6 +781,13 @@ Module.prototype._compile = function(content, filename) {
if (process._breakFirstLine && process._eval == null) {
if (!resolvedArgv) {
// We enter the repl if we're not given a filename argument.
// process._firstFileName is used by Embedders to tell node what
// the first "real" file is when they use themselves as the entry
// point
if (process._firstFileName) {
resolvedArgv = process._firstFileName
delete process._firstFileName
} else
if (process.argv[1]) {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);
} else {
Expand Down

0 comments on commit b823596

Please sign in to comment.