diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-11-10 17:57:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 17:57:10 +0100 |
commit | 53e974b276b095faf52918c4c6e988e9d2788cef (patch) | |
tree | 44b9807d87e90005f02192bb01e96ef053096f1a /ext/node/lib.rs | |
parent | fd32f75da997b805a4ba95c68b4aaeed9f020cb1 (diff) |
feat: remove --unstable flag requirement for npm: specifiers (#16473)
This commit makes "npm:" specifiers not require "--unstable" flag.
At the moment some APIs used by Node polyfills still require
"--unstable" which will be addressed in follow up PRs.
Diffstat (limited to 'ext/node/lib.rs')
-rw-r--r-- | ext/node/lib.rs | 65 |
1 files changed, 8 insertions, 57 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs index ca3fe3c08..b0d5485b4 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -74,10 +74,7 @@ pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| { set }); -struct Unstable(pub bool); - pub fn init<P: NodePermissions + 'static>( - unstable: bool, maybe_npm_resolver: Option<Rc<dyn RequireNpmResolver>>, ) -> Extension { Extension::builder() @@ -110,7 +107,6 @@ pub fn init<P: NodePermissions + 'static>( op_require_package_imports_resolve::decl::<P>(), ]) .state(move |state| { - state.put(Unstable(unstable)); if let Some(npm_resolver) = maybe_npm_resolver.clone() { state.put(npm_resolver); } @@ -119,15 +115,6 @@ pub fn init<P: NodePermissions + 'static>( .build() } -fn check_unstable(state: &OpState) { - let unstable = state.borrow::<Unstable>(); - - if !unstable.0 { - eprintln!("Unstable API 'require'. The --unstable flag must be provided.",); - std::process::exit(70); - } -} - fn ensure_read_permission<P>( state: &mut OpState, file_path: &Path, @@ -147,9 +134,7 @@ where } #[op] -pub fn op_require_init_paths(state: &mut OpState) -> Vec<String> { - check_unstable(state); - +pub fn op_require_init_paths() -> Vec<String> { // todo(dsherret): this code is node compat mode specific and // we probably don't want it for small mammal, so ignore it for now @@ -206,7 +191,6 @@ pub fn op_require_node_module_paths<P>( where P: NodePermissions + 'static, { - check_unstable(state); // Guarantee that "from" is absolute. let from = deno_core::resolve_path(&from) .unwrap() @@ -254,8 +238,7 @@ where } #[op] -fn op_require_proxy_path(state: &mut OpState, filename: String) -> String { - check_unstable(state); +fn op_require_proxy_path(filename: String) -> String { // Allow a directory to be passed as the filename let trailing_slash = if cfg!(windows) { filename.ends_with('\\') @@ -272,11 +255,7 @@ fn op_require_proxy_path(state: &mut OpState, filename: String) -> String { } #[op] -fn op_require_is_request_relative( - state: &mut OpState, - request: String, -) -> bool { - check_unstable(state); +fn op_require_is_request_relative(request: String) -> bool { if request.starts_with("./") || request.starts_with("../") || request == ".." { return true; @@ -301,7 +280,6 @@ fn op_require_resolve_deno_dir( request: String, parent_filename: String, ) -> Option<String> { - check_unstable(state); let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>(); resolver .resolve_package_folder_from_package( @@ -315,19 +293,16 @@ fn op_require_resolve_deno_dir( #[op] fn op_require_is_deno_dir_package(state: &mut OpState, path: String) -> bool { - check_unstable(state); let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>(); resolver.in_npm_package(&PathBuf::from(path)) } #[op] fn op_require_resolve_lookup_paths( - state: &mut OpState, request: String, maybe_parent_paths: Option<Vec<String>>, parent_filename: String, ) -> Option<Vec<String>> { - check_unstable(state); if !request.starts_with('.') || (request.len() > 1 && !request.starts_with("..") @@ -364,8 +339,7 @@ fn op_require_resolve_lookup_paths( } #[op] -fn op_require_path_is_absolute(state: &mut OpState, p: String) -> bool { - check_unstable(state); +fn op_require_path_is_absolute(p: String) -> bool { PathBuf::from(p).is_absolute() } @@ -377,7 +351,6 @@ fn op_require_stat<P>( where P: NodePermissions + 'static, { - check_unstable(state); let path = PathBuf::from(path); ensure_read_permission::<P>(state, &path)?; if let Ok(metadata) = std::fs::metadata(&path) { @@ -399,7 +372,6 @@ fn op_require_real_path<P>( where P: NodePermissions + 'static, { - check_unstable(state); let path = PathBuf::from(request); ensure_read_permission::<P>(state, &path)?; let mut canonicalized_path = path.canonicalize()?; @@ -426,17 +398,12 @@ fn path_resolve(parts: Vec<String>) -> String { } #[op] -fn op_require_path_resolve(state: &mut OpState, parts: Vec<String>) -> String { - check_unstable(state); +fn op_require_path_resolve(parts: Vec<String>) -> String { path_resolve(parts) } #[op] -fn op_require_path_dirname( - state: &mut OpState, - request: String, -) -> Result<String, AnyError> { - check_unstable(state); +fn op_require_path_dirname(request: String) -> Result<String, AnyError> { let p = PathBuf::from(request); if let Some(parent) = p.parent() { Ok(parent.to_string_lossy().to_string()) @@ -446,11 +413,7 @@ fn op_require_path_dirname( } #[op] -fn op_require_path_basename( - state: &mut OpState, - request: String, -) -> Result<String, AnyError> { - check_unstable(state); +fn op_require_path_basename(request: String) -> Result<String, AnyError> { let p = PathBuf::from(request); if let Some(path) = p.file_name() { Ok(path.to_string_lossy().to_string()) @@ -469,7 +432,6 @@ fn op_require_try_self_parent_path<P>( where P: NodePermissions + 'static, { - check_unstable(state); if !has_parent { return Ok(None); } @@ -495,7 +457,6 @@ fn op_require_try_self( parent_path: Option<String>, request: String, ) -> Result<Option<String>, AnyError> { - check_unstable(state); if parent_path.is_none() { return Ok(None); } @@ -554,19 +515,13 @@ fn op_require_read_file<P>( where P: NodePermissions + 'static, { - check_unstable(state); let file_path = PathBuf::from(file_path); ensure_read_permission::<P>(state, &file_path)?; Ok(std::fs::read_to_string(file_path)?) } #[op] -pub fn op_require_as_file_path( - state: &mut OpState, - file_or_url: String, -) -> String { - check_unstable(state); - +pub fn op_require_as_file_path(file_or_url: String) -> String { if let Ok(url) = Url::parse(&file_or_url) { if let Ok(p) = url.to_file_path() { return p.to_string_lossy().to_string(); @@ -585,7 +540,6 @@ fn op_require_resolve_exports( expansion: String, parent_path: String, ) -> Result<Option<String>, AnyError> { - check_unstable(state); let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone(); let pkg_path = if resolver.in_npm_package(&PathBuf::from(&modules_path)) { @@ -623,7 +577,6 @@ fn op_require_read_closest_package_json<P>( where P: NodePermissions + 'static, { - check_unstable(state); ensure_read_permission::<P>( state, PathBuf::from(&filename).parent().unwrap(), @@ -640,7 +593,6 @@ fn op_require_read_package_scope( state: &mut OpState, package_json_path: String, ) -> Option<PackageJson> { - check_unstable(state); let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone(); let package_json_path = PathBuf::from(package_json_path); PackageJson::load(&*resolver, package_json_path).ok() @@ -655,7 +607,6 @@ fn op_require_package_imports_resolve<P>( where P: NodePermissions + 'static, { - check_unstable(state); let parent_path = PathBuf::from(&parent_filename); ensure_read_permission::<P>(state, &parent_path)?; let resolver = state.borrow::<Rc<dyn RequireNpmResolver>>().clone(); |