This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
forked from electron/electron
/
chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch
50 lines (47 loc) · 2.18 KB
/
chore_allow_the_node_entrypoint_to_be_a_builtin_module.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Wed, 22 May 2019 13:34:18 -0700
Subject: chore: allow the node entrypoint to be a builtin_module
This allows embedders to tell Node.js what the first "real" file is when
they use themselves as the entry point. We should try to upstream some form
of this.
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index b184a0d9ae3434af746be269495e9e4c80c58091..899d5a906683e8967746e10a6de452e99e236903 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -103,11 +103,13 @@ function patchProcessObject(expandArgv1) {
if (expandArgv1 && process.argv[1] &&
!StringPrototypeStartsWith(process.argv[1], '-')) {
// Expand process.argv[1] into a full path.
- const path = require('path');
- try {
- process.argv[1] = path.resolve(process.argv[1]);
- } catch {
- // Continue regardless of error.
+ if (!process.argv[1] || !process.argv[1].startsWith('electron/js2c')) {
+ const path = require('path');
+ try {
+ process.argv[1] = path.resolve(process.argv[1]);
+ } catch {
+ // Continue regardless of error.
+ }
}
}
diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js
index 5195ff2da0496f2bfb9112d336c38040f662087b..5c62e367f2dd7d112096551f1c34ee67ce1a5c3a 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1079,6 +1079,13 @@ Module.prototype._compile = function(content, filename) {
if (getOptionValue('--inspect-brk') && 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]) {
try {
resolvedArgv = Module._resolveFilename(process.argv[1], null, false);