Skip to content
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

Check if package.json exists while installing node modules #532

Closed
tarunbhm opened this issue Jun 27, 2023 · 2 comments
Closed

Check if package.json exists while installing node modules #532

tarunbhm opened this issue Jun 27, 2023 · 2 comments

Comments

@tarunbhm
Copy link
Contributor

The install_node_modules function does not check if the package.json file exists in the project directory. This function is used for foundry projects as well to support foundry projects with hardhat dependencies. But dry run fails for the pure foundry projects because they don't have a package.json file.

pub fn install_node_modules(context: &LightContext) -> Result<()> {
if context.root.join("node_modules").try_exists()? {
return Ok(());
}
// smoelius: If a `yarn.lock` file exists, use `yarn`. Otherwise, default to `npm install`.
let mut command = if context.root.join("yarn.lock").try_exists()? {
Command::new("yarn")
} else {
let mut command = Command::new("npm");
command.arg("install");
command
};
command.current_dir(context.root.as_path());
debug!("{:?}", command);
let output = command.output()?;
ensure!(output.status.success(), "{:#?}", output);
Ok(())
}

Adding a check if the package.json file exists will resolve this issue.

@0xPhaze
Copy link
Contributor

0xPhaze commented Jul 10, 2023

Ran into the same issue:

necessist --reset
8782 candidates in 3 test files
test/Endpoint.t.sol: dry running
test/Endpoint.t.sol: Warning: dry run failed: Output {
    status: ExitStatus(
        unix_wait_status(
            65024,
        ),
    ),
    stdout: "",
    stderr: "npm ERR! code ENOENT\nnpm ERR! syscall open\nnpm ERR! path /Users/lain/git/audit/audit-orb/package.json\nnpm ERR! errno -2\nnpm ERR! enoent ENOENT: no such file or directory, open '/Users/lain/git/audit/audit-orb/package.json'\nnpm ERR! enoent This is related to npm not being able to find a file.\nnpm ERR! enoent \n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/lain/.npm/_logs/2023-07-10T13_48_21_424Z-debug-0.log\n",
}
test/Rukh.t.sol: dry running
test/Rukh.t.sol: Warning: dry run failed: Output {
    status: ExitStatus(
        unix_wait_status(
            65024,
        ),
    ),
    stdout: "",
    stderr: "npm ERR! code ENOENT\nnpm ERR! syscall open\nnpm ERR! path /Users/lain/git/audit/audit-orb/package.json\nnpm ERR! errno -2\nnpm ERR! enoent ENOENT: no such file or directory, open '/Users/lain/git/audit/audit-orb/package.json'\nnpm ERR! enoent This is related to npm not being able to find a file.\nnpm ERR! enoent \n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/lain/.npm/_logs/2023-07-10T13_48_21_623Z-debug-0.log\n",
test/Thunderbird.t.sol: dry running
test/Thunderbird.t.sol: Warning: dry run failed: Output {
    status: ExitStatus(
        unix_wait_status(
            65024,
        ),
    ),
    stdout: "",
    stderr: "npm ERR! code ENOENT\nnpm ERR! syscall open\nnpm ERR! path /Users/lain/git/audit/audit-orb/package.json\nnpm ERR! errno -2\nnpm ERR! enoent ENOENT: no such file or directory, open '/Users/lain/git/audit/audit-orb/package.json'\nnpm ERR! enoent This is related to npm not being able to find a file.\nnpm ERR! enoent \n\nnpm ERR! A complete log of this run can be found in:\nnpm ERR!     /Users/lain/.npm/_logs/2023-07-10T13_48_21_818Z-debug-0.log\n",

Created a small PR that implements the suggested check, thanks @tarunbhm

@smoelius
Copy link
Collaborator

Fixed by #580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants