summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock13
-rw-r--r--cli/Cargo.toml1
-rw-r--r--cli/node/errors.rs50
-rw-r--r--cli/node/mod.rs14
-rw-r--r--ext/node/errors.rs21
-rw-r--r--ext/node/lib.rs8
6 files changed, 32 insertions, 75 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9e85b8065..7a35eafd2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -831,7 +831,6 @@ dependencies = [
"mitata",
"monch",
"nix",
- "node_resolver",
"notify",
"once_cell",
"os_pipe",
@@ -2791,18 +2790,6 @@ dependencies = [
]
[[package]]
-name = "node_resolver"
-version = "0.1.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1012fcb4f5cc14c272731f4baf6ba8a2d40c650908f4d2531f7ed17f214e5ae"
-dependencies = [
- "anyhow",
- "path-clean",
- "serde",
- "serde_json",
-]
-
-[[package]]
name = "notify"
version = "5.0.0-pre.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index a2b9bafae..d37dc6488 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -80,7 +80,6 @@ libc = "=0.2.126"
log = { version = "=0.4.17", features = ["serde"] }
mitata = "=0.0.7"
monch = "=0.2.0"
-node_resolver = "=0.1.1"
notify = "=5.0.0-pre.15"
once_cell = "=1.12.0"
os_pipe = "=1.0.1"
diff --git a/cli/node/errors.rs b/cli/node/errors.rs
deleted file mode 100644
index f14e6e92e..000000000
--- a/cli/node/errors.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-
-use deno_core::error::generic_error;
-use deno_core::error::type_error;
-use deno_core::error::AnyError;
-use deno_core::url::Url;
-
-pub fn err_invalid_module_specifier(
- request: &str,
- reason: &str,
- maybe_base: Option<String>,
-) -> AnyError {
- let mut msg = format!(
- "[ERR_INVALID_MODULE_SPECIFIER] Invalid module \"{}\" {}",
- request, reason
- );
-
- if let Some(base) = maybe_base {
- msg = format!("{} imported from {}", msg, base);
- }
-
- type_error(msg)
-}
-
-pub fn err_module_not_found(path: &str, base: &str, typ: &str) -> AnyError {
- generic_error(format!(
- "[ERR_MODULE_NOT_FOUND] Cannot find {} \"{}\" imported from \"{}\"",
- typ, path, base
- ))
-}
-
-pub fn err_unsupported_dir_import(path: &str, base: &str) -> AnyError {
- generic_error(format!("[ERR_UNSUPPORTED_DIR_IMPORT] Directory import '{}' is not supported resolving ES modules imported from {}", path, base))
-}
-
-pub fn err_unsupported_esm_url_scheme(url: &Url) -> AnyError {
- let mut msg =
- "[ERR_UNSUPPORTED_ESM_URL_SCHEME] Only file and data URLS are supported by the default ESM loader"
- .to_string();
-
- if cfg!(window) && url.scheme().len() == 2 {
- msg = format!(
- "{}. On Windows, absolute path must be valid file:// URLs",
- msg
- );
- }
-
- msg = format!("{}. Received protocol '{}'", msg, url.scheme());
- generic_error(msg)
-}
diff --git a/cli/node/mod.rs b/cli/node/mod.rs
index c64ba6132..6e8b4bf13 100644
--- a/cli/node/mod.rs
+++ b/cli/node/mod.rs
@@ -17,6 +17,7 @@ use deno_core::serde_json::Value;
use deno_core::url::Url;
use deno_core::JsRuntime;
use deno_graph::source::ResolveResponse;
+use deno_runtime::deno_node::errors;
use deno_runtime::deno_node::get_closest_package_json;
use deno_runtime::deno_node::legacy_main_resolve;
use deno_runtime::deno_node::package_exports_resolve;
@@ -37,19 +38,18 @@ use crate::npm::NpmPackageReq;
use crate::npm::NpmPackageResolver;
mod analyze;
-pub mod errors;
pub use analyze::esm_code_with_node_globals;
-pub struct NodeModulePolyfill {
+struct NodeModulePolyfill {
/// Name of the module like "assert" or "timers/promises"
- pub name: &'static str,
+ name: &'static str,
/// Specifier relative to the root of `deno_std` repo, like "node/asser.ts"
- pub specifier: &'static str,
+ specifier: &'static str,
}
-pub(crate) static SUPPORTED_MODULES: &[NodeModulePolyfill] = &[
+static SUPPORTED_MODULES: &[NodeModulePolyfill] = &[
NodeModulePolyfill {
name: "assert",
specifier: "node/assert.ts",
@@ -224,7 +224,7 @@ pub(crate) static SUPPORTED_MODULES: &[NodeModulePolyfill] = &[
},
];
-pub(crate) static NODE_COMPAT_URL: Lazy<Url> = Lazy::new(|| {
+static NODE_COMPAT_URL: Lazy<Url> = Lazy::new(|| {
if let Ok(url_str) = std::env::var("DENO_NODE_COMPAT_URL") {
let url = Url::parse(&url_str).expect(
"Malformed DENO_NODE_COMPAT_URL value, make sure it's a file URL ending with a slash"
@@ -238,7 +238,7 @@ pub(crate) static NODE_COMPAT_URL: Lazy<Url> = Lazy::new(|| {
pub static MODULE_ALL_URL: Lazy<Url> =
Lazy::new(|| NODE_COMPAT_URL.join("node/module_all.ts").unwrap());
-pub fn try_resolve_builtin_module(specifier: &str) -> Option<Url> {
+fn try_resolve_builtin_module(specifier: &str) -> Option<Url> {
for module in SUPPORTED_MODULES {
if module.name == specifier {
let module_url = NODE_COMPAT_URL.join(module.specifier).unwrap();
diff --git a/ext/node/errors.rs b/ext/node/errors.rs
index 9dc6c7e7e..4b55d1982 100644
--- a/ext/node/errors.rs
+++ b/ext/node/errors.rs
@@ -3,6 +3,7 @@
use deno_core::error::generic_error;
use deno_core::error::type_error;
use deno_core::error::AnyError;
+use deno_core::url::Url;
pub fn err_invalid_module_specifier(
request: &str,
@@ -120,3 +121,23 @@ pub fn err_package_import_not_defined(
type_error(msg)
}
+
+pub fn err_unsupported_dir_import(path: &str, base: &str) -> AnyError {
+ generic_error(format!("[ERR_UNSUPPORTED_DIR_IMPORT] Directory import '{}' is not supported resolving ES modules imported from {}", path, base))
+}
+
+pub fn err_unsupported_esm_url_scheme(url: &Url) -> AnyError {
+ let mut msg =
+ "[ERR_UNSUPPORTED_ESM_URL_SCHEME] Only file and data URLS are supported by the default ESM loader"
+ .to_string();
+
+ if cfg!(window) && url.scheme().len() == 2 {
+ msg = format!(
+ "{}. On Windows, absolute path must be valid file:// URLs",
+ msg
+ );
+ }
+
+ msg = format!("{}. Received protocol '{}'", msg, url.scheme());
+ generic_error(msg)
+}
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 6f3173470..99df93be5 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -11,6 +11,10 @@ use std::path::Path;
use std::path::PathBuf;
use std::rc::Rc;
+pub mod errors;
+mod package_json;
+mod resolution;
+
pub use package_json::PackageJson;
pub use resolution::get_closest_package_json;
pub use resolution::get_package_scope_config;
@@ -42,10 +46,6 @@ pub trait DenoDirNpmResolver {
fn ensure_read_permission(&self, path: &Path) -> Result<(), AnyError>;
}
-mod errors;
-mod package_json;
-mod resolution;
-
pub const MODULE_ES_SHIM: &str = include_str!("./module_es_shim.js");
struct Unstable(pub bool);