-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
src: add --run-from
runtime flag
#57523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4416cc0
b93de16
d08981b
f374130
94717dd
6e5d7d5
7b23a7d
6194d3d
fc6a438
d4aa938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1216,6 +1216,9 @@ PerProcessOptionsParser::PerProcessOptionsParser( | |
AddOption("--run", | ||
"Run a script specified in package.json", | ||
&PerProcessOptions::run); | ||
AddOption("--run-from", | ||
"Run a package.json script in a specific working directory", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change the working directory of the Node process, or is it only about where to find the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It sets the Node process's working directory There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm... the naming here was discussed in the linked issue. The name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That said, the documentation update would imply that it only works with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it has a more general effect of setting the initial cwd for the process, and assuming we are ok with such a flag, I think it should be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the use case for setting the initial cwd for the process? Aside from telling Node where to find |
||
&PerProcessOptions::run_from); | ||
AddOption( | ||
"--disable-wasm-trap-handler", | ||
"Disable trap-handler-based WebAssembly bound checks. V8 will insert " | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,7 +206,30 @@ void ProcessRunner::OnExit(int64_t exit_status, int term_signal) { | |
|
||
void ProcessRunner::Run() { | ||
// keeps the string alive until destructor | ||
cwd = package_json_path_.parent_path().string(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will not work since this doesn't add the current node_modules to path environment variable. |
||
if (!node::per_process::cli_options->run_from.empty()) { | ||
cwd = node::per_process::cli_options->run_from; | ||
if (!std::filesystem::is_directory(cwd)) { | ||
// If the given path is a file and the file name is package.json, the | ||
// parent directory is used | ||
std::filesystem::path p(cwd); | ||
if (std::filesystem::is_regular_file(p) && | ||
p.filename() == "package.json") { | ||
cwd = p.parent_path().string(); | ||
} else { | ||
fprintf(stderr, "Error: %s is not a directory\n", cwd.c_str()); | ||
init_result->exit_code_ = ExitCode::kGenericUserError; | ||
return; | ||
} | ||
} | ||
// Adding node_modules/.bin under cwd to PATH environment variable | ||
std::filesystem::path nmBin = | ||
std::filesystem::path(cwd) / "node_modules" / ".bin"; | ||
if (std::filesystem::is_directory(nmBin)) { | ||
path_env_var_ = nmBin.string() + env_var_separator + path_env_var_; | ||
} | ||
Comment on lines
+224
to
+229
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @anonrig I tried to process the path given with --run-from and add the |
||
} else { | ||
cwd = package_json_path_.parent_path().string(); | ||
} | ||
options_.cwd = cwd.c_str(); | ||
if (int r = uv_spawn(loop_, &process_, &options_)) { | ||
fprintf(stderr, "Error: %s\n", uv_strerror(r)); | ||
|
Uh oh!
There was an error while loading. Please reload this page.