summaryrefslogtreecommitdiff
path: root/cli/args/package_json.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-05-10 20:06:59 -0400
committerGitHub <noreply@github.com>2023-05-10 20:06:59 -0400
commit28aa489de9cd4f995ec2fc02e2c9d224e89f4c01 (patch)
treeb316937a47fe9c8f9f6768bc13b9a686c07cf42f /cli/args/package_json.rs
parent5fd74bfa1c5ed514c3e19fdb2e8590fe251d3ee6 (diff)
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
Diffstat (limited to 'cli/args/package_json.rs')
-rw-r--r--cli/args/package_json.rs27
1 files changed, 27 insertions, 0 deletions
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<String, Result<NpmPackageReq, PackageJsonDepValueParseError>>;
+#[derive(Debug, Default)]
+pub struct PackageJsonDepsProvider(Option<PackageJsonDeps>);
+
+impl PackageJsonDepsProvider {
+ pub fn new(deps: Option<PackageJsonDeps>) -> 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::<Vec<_>>();
+ 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