diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-02-22 22:45:35 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 22:45:35 -0500 |
commit | b15f9e60a040e2e450e7ca9971a5fc07dbf8b94c (patch) | |
tree | 4290744b0c0a8f8f5d063322a650fdabf2d3150c /cli/node/mod.rs | |
parent | cc8e4a00aaf4c4fe959944c7400f2e259f7faae8 (diff) |
feat(task): support scripts in package.json (#17887)
This is a super basic initial implementation. We don't create a
`node_modules/.bin` folder at the moment and add it to the PATH like we
should which is necessary to make command name resolution in the
subprocess work properly (ex. you run a script that launches another
script that then tries to launch an "npx command"... this won't work
atm).
Closes #17492
Diffstat (limited to 'cli/node/mod.rs')
-rw-r--r-- | cli/node/mod.rs | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs index a6f40c99e..470003057 100644 --- a/cli/node/mod.rs +++ b/cli/node/mod.rs @@ -285,17 +285,41 @@ pub fn node_resolve_npm_reference( Ok(Some(resolve_response)) } +pub fn node_resolve_binary_commands( + pkg_nv: &NpmPackageNv, + npm_resolver: &NpmPackageResolver, +) -> Result<Vec<String>, AnyError> { + let package_folder = + npm_resolver.resolve_package_folder_from_deno_module(pkg_nv)?; + let package_json_path = package_folder.join("package.json"); + let package_json = PackageJson::load( + npm_resolver, + &mut PermissionsContainer::allow_all(), + package_json_path, + )?; + + Ok(match package_json.bin { + Some(Value::String(_)) => vec![pkg_nv.name.to_string()], + Some(Value::Object(o)) => { + o.into_iter().map(|(key, _)| key).collect::<Vec<_>>() + } + _ => Vec::new(), + }) +} + pub fn node_resolve_binary_export( pkg_nv: &NpmPackageNv, bin_name: Option<&str>, npm_resolver: &NpmPackageResolver, - permissions: &mut dyn NodePermissions, ) -> Result<NodeResolution, AnyError> { let package_folder = npm_resolver.resolve_package_folder_from_deno_module(pkg_nv)?; let package_json_path = package_folder.join("package.json"); - let package_json = - PackageJson::load(npm_resolver, permissions, package_json_path)?; + let package_json = PackageJson::load( + npm_resolver, + &mut PermissionsContainer::allow_all(), + package_json_path, + )?; let bin = match &package_json.bin { Some(bin) => bin, None => bail!( |