fix(task): handle node_modules/.bin directory with byonm (#21386)

A bit hacky, but it works. Essentially, this will check for all the
scripts in the node_modules/.bin directory then force them to run with
Deno via deno_task_shell.
This commit is contained in:
David Sherret 2023-12-06 16:36:06 -05:00 committed by GitHub
parent 7fdc3c8f1f
commit e372fc73e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 446 additions and 298 deletions

View file

@ -1306,6 +1306,25 @@ impl CliOptions {
&self.flags.strace_ops
}
pub fn take_binary_npm_command_name(&self) -> Option<String> {
match self.sub_command() {
DenoSubcommand::Run(flags) => {
const NPM_CMD_NAME_ENV_VAR_NAME: &str = "DENO_INTERNAL_NPM_CMD_NAME";
match std::env::var(NPM_CMD_NAME_ENV_VAR_NAME) {
Ok(var) => {
// remove the env var so that child sub processes won't pick this up
std::env::remove_var(NPM_CMD_NAME_ENV_VAR_NAME);
Some(var)
}
Err(_) => NpmPackageReqReference::from_str(&flags.script)
.ok()
.map(|req_ref| npm_pkg_req_ref_to_binary_command(&req_ref)),
}
}
_ => None,
}
}
pub fn type_check_mode(&self) -> TypeCheckMode {
self.flags.type_check_mode
}