summaryrefslogtreecommitdiff
path: root/cli/args
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-23 17:34:46 -0400
committerGitHub <noreply@github.com>2024-07-23 17:34:46 -0400
commit6055629ee7f48a4e887392ccac13788aa4008249 (patch)
tree453a06a5926a19814902ade6259ddc3631a1b181 /cli/args
parentf0df54fc70ec1781a3ffec232fefc38cabf39c37 (diff)
refactor: update to use deno_package_json (#24688)
This is in preparation for extracting out node resolution code from ext/node (which is something I'm going to do gradually over time). Uses https://github.com/denoland/deno_package_json
Diffstat (limited to 'cli/args')
-rw-r--r--cli/args/deno_json.rs56
-rw-r--r--cli/args/mod.rs5
-rw-r--r--cli/args/package_json.rs2
3 files changed, 58 insertions, 5 deletions
diff --git a/cli/args/deno_json.rs b/cli/args/deno_json.rs
index 2b3261a0b..cbc33aa0b 100644
--- a/cli/args/deno_json.rs
+++ b/cli/args/deno_json.rs
@@ -7,6 +7,62 @@ use deno_semver::jsr::JsrDepPackageReq;
use deno_semver::jsr::JsrPackageReqReference;
use deno_semver::npm::NpmPackageReqReference;
+#[cfg(test)] // happens to only be used by the tests at the moment
+pub struct DenoConfigFsAdapter<'a>(
+ pub &'a dyn deno_runtime::deno_fs::FileSystem,
+);
+
+#[cfg(test)]
+impl<'a> deno_config::fs::DenoConfigFs for DenoConfigFsAdapter<'a> {
+ fn read_to_string_lossy(
+ &self,
+ path: &std::path::Path,
+ ) -> Result<String, std::io::Error> {
+ self
+ .0
+ .read_text_file_lossy_sync(path, None)
+ .map_err(|err| err.into_io_error())
+ }
+
+ fn stat_sync(
+ &self,
+ path: &std::path::Path,
+ ) -> Result<deno_config::fs::FsMetadata, std::io::Error> {
+ self
+ .0
+ .stat_sync(path)
+ .map(|stat| deno_config::fs::FsMetadata {
+ is_file: stat.is_file,
+ is_directory: stat.is_directory,
+ is_symlink: stat.is_symlink,
+ })
+ .map_err(|err| err.into_io_error())
+ }
+
+ fn read_dir(
+ &self,
+ path: &std::path::Path,
+ ) -> Result<Vec<deno_config::fs::FsDirEntry>, std::io::Error> {
+ self
+ .0
+ .read_dir_sync(path)
+ .map_err(|err| err.into_io_error())
+ .map(|entries| {
+ entries
+ .into_iter()
+ .map(|e| deno_config::fs::FsDirEntry {
+ path: path.join(e.name),
+ metadata: deno_config::fs::FsMetadata {
+ is_file: e.is_file,
+ is_directory: e.is_directory,
+ is_symlink: e.is_symlink,
+ },
+ })
+ .collect()
+ })
+ }
+}
+
pub fn deno_json_deps(
config: &deno_config::deno_json::ConfigFile,
) -> HashSet<JsrDepPackageReq> {
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index c2ea3be4d..ba2e06e06 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -25,8 +25,6 @@ use deno_npm::npm_rc::NpmRc;
use deno_npm::npm_rc::ResolvedNpmRc;
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
use deno_npm::NpmSystemInfo;
-use deno_runtime::deno_fs::DenoConfigFsAdapter;
-use deno_runtime::deno_fs::RealFs;
use deno_runtime::deno_permissions::PermissionsContainer;
use deno_runtime::deno_tls::RootCertStoreProvider;
use deno_semver::npm::NpmPackageReqReference;
@@ -835,7 +833,6 @@ impl CliOptions {
pub fn from_flags(flags: Flags) -> Result<Self, AnyError> {
let initial_cwd =
std::env::current_dir().with_context(|| "Failed getting cwd.")?;
- let config_fs_adapter = DenoConfigFsAdapter::new(&RealFs);
let maybe_vendor_override = flags.vendor.map(|v| match v {
true => VendorEnablement::Enable { cwd: &initial_cwd },
false => VendorEnablement::Disable,
@@ -860,7 +857,7 @@ impl CliOptions {
log::debug!("package.json auto-discovery is disabled");
}
WorkspaceDiscoverOptions {
- fs: &config_fs_adapter,
+ fs: Default::default(), // use real fs
deno_json_cache: None,
pkg_json_cache: Some(
&deno_runtime::deno_node::PackageJsonThreadLocalCache,
diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs
index 170f8b677..eedd0a194 100644
--- a/cli/args/package_json.rs
+++ b/cli/args/package_json.rs
@@ -3,8 +3,8 @@
use std::path::PathBuf;
use std::sync::Arc;
-use deno_config::package_json::PackageJsonDepValue;
use deno_config::workspace::Workspace;
+use deno_package_json::PackageJsonDepValue;
use deno_semver::package::PackageReq;
#[derive(Debug)]