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 /ext/node/package_json.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 'ext/node/package_json.rs')
-rw-r--r-- | ext/node/package_json.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/ext/node/package_json.rs b/ext/node/package_json.rs index b05362890..4fa3025bf 100644 --- a/ext/node/package_json.rs +++ b/ext/node/package_json.rs @@ -4,12 +4,14 @@ use crate::NodeModuleKind; use crate::NodePermissions; use super::RequireNpmResolver; + use deno_core::anyhow; use deno_core::anyhow::bail; use deno_core::error::AnyError; use deno_core::serde_json; use deno_core::serde_json::Map; use deno_core::serde_json::Value; +use indexmap::IndexMap; use serde::Serialize; use std::cell::RefCell; use std::collections::HashMap; @@ -35,6 +37,7 @@ pub struct PackageJson { pub types: Option<String>, pub dependencies: Option<HashMap<String, String>>, pub dev_dependencies: Option<HashMap<String, String>>, + pub scripts: Option<IndexMap<String, String>>, } impl PackageJson { @@ -53,6 +56,7 @@ impl PackageJson { types: None, dependencies: None, dev_dependencies: None, + scripts: None, } } @@ -144,6 +148,10 @@ impl PackageJson { } }); + let scripts: Option<IndexMap<String, String>> = package_json + .get("scripts") + .and_then(|d| serde_json::from_value(d.to_owned()).ok()); + // Ignore unknown types for forwards compatibility let typ = if let Some(t) = type_val { if let Some(t) = t.as_str() { @@ -179,6 +187,7 @@ impl PackageJson { bin, dependencies, dev_dependencies, + scripts, }; CACHE.with(|cache| { |