/
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 69da327588799cde0421596ce4c6225890cc297b..522a97cf299d4df21132f0f9ef9a3f0f607d0bd9 100644
--- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js
@@ -95,11 +95,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 6f06043e6636b48e924cab63f510c805a8ade9b8..1d1fb975ff0bfca6c40d0a95adf2617dff94f18c 100644
--- a/lib/internal/modules/cjs/loader.js
+++ b/lib/internal/modules/cjs/loader.js
@@ -1077,6 +1077,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);