diff options
Diffstat (limited to 'cli/args')
-rw-r--r-- | cli/args/flags.rs | 7 | ||||
-rw-r--r-- | cli/args/mod.rs | 13 | ||||
-rw-r--r-- | cli/args/package_json.rs | 27 |
3 files changed, 44 insertions, 3 deletions
diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 3d88cda91..fa28241a3 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -527,8 +527,11 @@ impl Flags { .ok() } Task(_) | Check(_) | Coverage(_) | Cache(_) | Info(_) | Eval(_) - | Test(_) | Bench(_) | Repl(_) => std::env::current_dir().ok(), - _ => None, + | Test(_) | Bench(_) | Repl(_) | Compile(_) => { + std::env::current_dir().ok() + } + Bundle(_) | Completions(_) | Doc(_) | Fmt(_) | Init(_) | Install(_) + | Uninstall(_) | Lsp | Lint(_) | Types | Upgrade(_) | Vendor(_) => None, } } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index b5975536a..31035fdd0 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -33,6 +33,7 @@ pub use config_file::TsTypeLib; pub use flags::*; pub use lockfile::Lockfile; pub use lockfile::LockfileError; +pub use package_json::PackageJsonDepsProvider; use deno_ast::ModuleSpecifier; use deno_core::anyhow::anyhow; @@ -556,7 +557,7 @@ struct CliOptionOverrides { import_map_specifier: Option<Option<ModuleSpecifier>>, } -/// Holds the resolved options of many sources used by sub commands +/// Holds the resolved options of many sources used by subcommands /// and provides some helper function for creating common objects. pub struct CliOptions { // the source of the options is a detail the rest of the @@ -1303,6 +1304,16 @@ fn has_flag_env_var(name: &str) -> bool { matches!(value.as_ref().map(|s| s.as_str()), Ok("1")) } +pub fn npm_pkg_req_ref_to_binary_command( + req_ref: &NpmPackageReqReference, +) -> String { + let binary_name = req_ref + .sub_path + .as_deref() + .unwrap_or(req_ref.req.name.as_str()); + binary_name.to_string() +} + #[cfg(test)] mod test { use super::*; 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 |