From 28aa489de9cd4f995ec2fc02e2c9d224e89f4c01 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 10 May 2023 20:06:59 -0400 Subject: feat(compile): unstable npm and node specifier support (#19005) This is the initial support for npm and node specifiers in `deno compile`. The npm packages are included in the binary and read from it via a virtual file system. This also supports the `--node-modules-dir` flag, dependencies specified in a package.json, and npm binary commands (ex. `deno compile --unstable npm:cowsay`) Closes #16632 --- cli/args/package_json.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'cli/args/package_json.rs') diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index c4d4ce956..a8c6eaad4 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -28,6 +28,33 @@ pub enum PackageJsonDepValueParseError { pub type PackageJsonDeps = BTreeMap>; +#[derive(Debug, Default)] +pub struct PackageJsonDepsProvider(Option); + +impl PackageJsonDepsProvider { + pub fn new(deps: Option) -> Self { + Self(deps) + } + + pub fn deps(&self) -> Option<&PackageJsonDeps> { + self.0.as_ref() + } + + pub fn reqs(&self) -> Vec<&NpmPackageReq> { + match &self.0 { + Some(deps) => { + let mut package_reqs = deps + .values() + .filter_map(|r| r.as_ref().ok()) + .collect::>(); + package_reqs.sort(); // deterministic resolution + package_reqs + } + None => Vec::new(), + } + } +} + /// Gets an application level package.json's npm package requirements. /// /// Note that this function is not general purpose. It is specifically for -- cgit v1.2.3