Skip to content

Commit 30fef14

Browse files
committed
src: include filesystem root in package search
Move the root termination check after processing the current directory so node --run can find package.json and node_modules/.bin at the filesystem root. Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
1 parent b9dacd4 commit 30fef14

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/node_task_runner.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,9 @@ FindPackageJson(const std::filesystem::path& cwd) {
221221
std::string raw_content;
222222
std::string path_env_var;
223223
auto root_path = cwd.root_path();
224+
auto directory_path = cwd;
224225

225-
for (auto directory_path = cwd;
226-
!std::filesystem::equivalent(root_path, directory_path);
227-
directory_path = directory_path.parent_path()) {
226+
while (true) {
228227
// Append "path/node_modules/.bin" to the env var, if it is a directory.
229228
auto node_modules_bin = directory_path / "node_modules" / ".bin";
230229
if (std::filesystem::is_directory(node_modules_bin)) {
@@ -238,10 +237,16 @@ FindPackageJson(const std::filesystem::path& cwd) {
238237
std::string contents = package_json_path.string();
239238
USE(ReadFileSync(&raw_content, contents.c_str()) > 0);
240239
}
240+
241+
// Include the root directory in the search before stopping traversal.
242+
if (std::filesystem::equivalent(root_path, directory_path)) {
243+
break;
244+
}
245+
directory_path = directory_path.parent_path();
241246
}
242247

243-
// This means that there is no package.json until the root directory.
244-
// In this case, we just return nullopt, which will terminate the process..
248+
// This means that there is no package.json in cwd or its parent directories.
249+
// In this case, return nullopt, which will terminate the process.
245250
if (raw_content.empty()) {
246251
return std::nullopt;
247252
}

0 commit comments

Comments
 (0)