Skip to content

Commit

Permalink
src: allow specifying entry point script
Browse files Browse the repository at this point in the history
Introduce a `--js-entry-point=` CLI option that allows pointing
the node executable to a main entry point that’s not
`lib/internal/bootstrap_node.js`.
  • Loading branch information
addaleax committed Dec 5, 2016
1 parent a5dd8bd commit 991e955
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ static const char* icu_data_dir = nullptr;
#endif

const char* internal_modules_source_dir = nullptr;
const char* js_entry_point = nullptr;

// used by C++ modules as well
bool no_deprecation = false;
Expand Down Expand Up @@ -3762,6 +3763,8 @@ static void ParseArgs(int* argc,
#endif
} else if (strncmp(arg, "--internal-modules-source-dir=", 30) == 0) {
internal_modules_source_dir = arg + 30;
} else if (strncmp(arg, "--js-entry-point=", 17) == 0) {
js_entry_point = arg + 17;
} else if (strcmp(arg, "--expose-internals") == 0 ||
strcmp(arg, "--expose_internals") == 0) {
// consumed in js
Expand Down
3 changes: 3 additions & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ extern bool v8_initialized;
// Source file directory to load instead of the ones baked into the executable
// for hacking.
extern const char* internal_modules_source_dir;
// Source file to load instead of the `bootstrap_node.js` one baked into the
// executable.
extern const char* js_entry_point;

// Forward declaration
class Environment;
Expand Down
4 changes: 4 additions & 0 deletions src/node_javascript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static MaybeLocal<String> MaybeLoadSourceFromDisk(Environment* env,
}

Local<String> MainSource(Environment* env) {
if (js_entry_point != nullptr) {
return InternalModuleReadFile(env, js_entry_point).ToLocalChecked();
}

auto maybe_disk_src =
MaybeLoadSourceFromDisk(env,
internal_bootstrap_node_name,
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-internal-modules-src-dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ assert.strictEqual(
child_process.spawnSync(process.execPath,
[`--internal-modules-source-dir=${bootstrap_node}`,
'-p', '0']).status);

const entry = path.join(bootstrap_node, 'internal/bootstrap_node.js');

assert.strictEqual(
42,
child_process.spawnSync(process.execPath,
[`--js-entry-point=${entry}`,
'-p', '0']).status);

0 comments on commit 991e955

Please sign in to comment.