From b15f9e60a040e2e450e7ca9971a5fc07dbf8b94c Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 22 Feb 2023 22:45:35 -0500 Subject: 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 --- ext/node/package_json.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'ext/node/package_json.rs') 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, pub dependencies: Option>, pub dev_dependencies: Option>, + pub scripts: Option>, } 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> = 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| { -- cgit v1.2.3