Skip to content

Commit

Permalink
fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Sep 15, 2024
1 parent 70b1eda commit 4949809
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
20 changes: 9 additions & 11 deletions src/node_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ std::string EscapeShell(const std::string_view input) {
#endif
}

static const std::string_view forbidden_characters =
static constexpr std::string_view forbidden_characters =
"[\t\n\r \"#$&'()*;<>?\\\\`|~]";

// Check if input contains any forbidden characters
Expand Down Expand Up @@ -191,7 +191,7 @@ std::string EscapeShell(const std::string_view input) {
void ProcessRunner::ExitCallback(uv_process_t* handle,
int64_t exit_status,
int term_signal) {
auto self = reinterpret_cast<ProcessRunner*>(handle->data);
const auto self = static_cast<ProcessRunner*>(handle->data);
uv_close(reinterpret_cast<uv_handle_t*>(handle), nullptr);
self->OnExit(exit_status, term_signal);
}
Expand All @@ -206,8 +206,8 @@ void ProcessRunner::OnExit(int64_t exit_status, int term_signal) {

void ProcessRunner::Run() {
// keeps the string alive until destructor
auto cwd = package_json_path_.parent_path();
options_.cwd = cwd.string().c_str();
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));
}
Expand Down Expand Up @@ -249,7 +249,7 @@ FindPackageJson(const std::filesystem::path& cwd) {
return {{package_json_path, raw_content, path_env_var}};
}

void RunTask(std::shared_ptr<InitializationResultImpl> result,
void RunTask(const std::shared_ptr<InitializationResultImpl>& result,
std::string_view command_id,
const std::vector<std::string_view>& positional_args) {
auto cwd = std::filesystem::current_path();
Expand All @@ -272,16 +272,14 @@ void RunTask(std::shared_ptr<InitializationResultImpl> result,
simdjson::ondemand::parser json_parser;
simdjson::ondemand::document document;
simdjson::ondemand::object main_object;
simdjson::error_code error = json_parser.iterate(raw_json).get(document);

if (error) {
if (json_parser.iterate(raw_json).get(document)) {
fprintf(stderr, "Can't parse %s\n", path.string().c_str());
result->exit_code_ = ExitCode::kGenericUserError;
return;
}
// If document is not an object, throw an error.
auto root_error = document.get_object().get(main_object);
if (root_error) {
if (auto root_error = document.get_object().get(main_object)) {
if (root_error == simdjson::error_code::INCORRECT_TYPE) {
fprintf(stderr,
"Root value unexpected not an object for %s\n\n",
Expand All @@ -304,8 +302,8 @@ void RunTask(std::shared_ptr<InitializationResultImpl> result,

// If the command_id is not found in the scripts object, throw an error.
std::string_view command;
auto command_error = scripts_object[command_id].get_string().get(command);
if (command_error) {
if (auto command_error =
scripts_object[command_id].get_string().get(command)) {
if (command_error == simdjson::error_code::INCORRECT_TYPE) {
fprintf(stderr,
"Script \"%.*s\" is unexpectedly not a string for %s\n\n",
Expand Down
3 changes: 2 additions & 1 deletion src/node_task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ProcessRunner {
std::vector<std::string> env_vars_{};
std::unique_ptr<char* []> env {}; // memory for options_.env
std::unique_ptr<char* []> arg {}; // memory for options_.args
std::string cwd;

// OnExit is the callback function that is called when the process exits.
void OnExit(int64_t exit_status, int term_signal);
Expand Down Expand Up @@ -78,7 +79,7 @@ class ProcessRunner {
std::optional<std::tuple<std::filesystem::path, std::string, std::string>>
FindPackageJson(const std::filesystem::path& cwd);

void RunTask(std::shared_ptr<InitializationResultImpl> result,
void RunTask(const std::shared_ptr<InitializationResultImpl>& result,
std::string_view command_id,
const PositionalArgs& positional_args);
PositionalArgs GetPositionalArgs(const std::vector<std::string>& args);
Expand Down
6 changes: 3 additions & 3 deletions test/parallel/test-node-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('node --run [command]', () => {
assert.strictEqual(child.code, 0);
});

it.only('chdirs into package directory', async () => {
it('chdirs into package directory', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ '--no-warnings', '--run', `pwd${envSuffix}`],
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('node --run [command]', () => {
[ '--no-warnings', '--run', 'test'],
{ cwd: fixtures.path('run-script/cannot-parse') },
);
assert.match(child.stderr, /Can't parse package\.json/);
assert.match(child.stderr, /Can't parse/);
assert.strictEqual(child.stdout, '');
assert.strictEqual(child.code, 1);
});
Expand All @@ -229,7 +229,7 @@ describe('node --run [command]', () => {
[ '--no-warnings', '--run', 'test'],
{ cwd: fixtures.path('run-script/cannot-find-script') },
);
assert.match(child.stderr, /Can't find "scripts" field in package\.json/);
assert.match(child.stderr, /Can't find "scripts" field in/);
assert.strictEqual(child.stdout, '');
assert.strictEqual(child.code, 1);
});
Expand Down

0 comments on commit 4949809

Please sign in to comment.