mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
chore: temporarily disable ext/node
and use unstable ops (#15438)
This commit is contained in:
parent
d6f789eb05
commit
04d402116c
4 changed files with 61 additions and 15 deletions
|
@ -5,9 +5,12 @@ use deno_core::include_js_files;
|
||||||
use deno_core::normalize_path;
|
use deno_core::normalize_path;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
|
use deno_core::OpState;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn init() -> Extension {
|
pub struct Unstable(pub bool);
|
||||||
|
|
||||||
|
pub fn init(unstable: bool) -> Extension {
|
||||||
Extension::builder()
|
Extension::builder()
|
||||||
.js(include_js_files!(
|
.js(include_js_files!(
|
||||||
prefix "deno:ext/node",
|
prefix "deno:ext/node",
|
||||||
|
@ -29,11 +32,26 @@ pub fn init() -> Extension {
|
||||||
op_require_path_basename::decl(),
|
op_require_path_basename::decl(),
|
||||||
op_require_read_file::decl(),
|
op_require_read_file::decl(),
|
||||||
])
|
])
|
||||||
|
.state(move |state| {
|
||||||
|
state.put(Unstable(unstable));
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.build()
|
.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_require_init_paths() -> Vec<String> {
|
pub fn op_require_init_paths(state: &mut OpState) -> Vec<String> {
|
||||||
|
check_unstable(state);
|
||||||
|
|
||||||
let (home_dir, node_path) = if cfg!(windows) {
|
let (home_dir, node_path) = if cfg!(windows) {
|
||||||
(
|
(
|
||||||
std::env::var("USERPROFILE").unwrap_or_else(|_| "".into()),
|
std::env::var("USERPROFILE").unwrap_or_else(|_| "".into()),
|
||||||
|
@ -80,7 +98,11 @@ pub fn op_require_init_paths() -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_require_node_module_paths(from: String) -> Vec<String> {
|
pub fn op_require_node_module_paths(
|
||||||
|
state: &mut OpState,
|
||||||
|
from: String,
|
||||||
|
) -> Vec<String> {
|
||||||
|
check_unstable(state);
|
||||||
// Guarantee that "from" is absolute.
|
// Guarantee that "from" is absolute.
|
||||||
let from = deno_core::resolve_path(&from)
|
let from = deno_core::resolve_path(&from)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -126,7 +148,8 @@ pub fn op_require_node_module_paths(from: String) -> Vec<String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_proxy_path(filename: String) -> String {
|
fn op_require_proxy_path(state: &mut OpState, filename: String) -> String {
|
||||||
|
check_unstable(state);
|
||||||
// Allow a directory to be passed as the filename
|
// Allow a directory to be passed as the filename
|
||||||
let trailing_slash = if cfg!(windows) {
|
let trailing_slash = if cfg!(windows) {
|
||||||
filename.ends_with('\\')
|
filename.ends_with('\\')
|
||||||
|
@ -143,7 +166,11 @@ fn op_require_proxy_path(filename: String) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_is_request_relative(request: String) -> bool {
|
fn op_require_is_request_relative(
|
||||||
|
state: &mut OpState,
|
||||||
|
request: String,
|
||||||
|
) -> bool {
|
||||||
|
check_unstable(state);
|
||||||
if request.starts_with("./") {
|
if request.starts_with("./") {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -167,10 +194,12 @@ fn op_require_is_request_relative(request: String) -> bool {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_resolve_lookup_paths(
|
fn op_require_resolve_lookup_paths(
|
||||||
|
state: &mut OpState,
|
||||||
request: String,
|
request: String,
|
||||||
maybe_parent_paths: Option<Vec<String>>,
|
maybe_parent_paths: Option<Vec<String>>,
|
||||||
parent_filename: String,
|
parent_filename: String,
|
||||||
) -> Option<Vec<String>> {
|
) -> Option<Vec<String>> {
|
||||||
|
check_unstable(state);
|
||||||
if !request.starts_with('.')
|
if !request.starts_with('.')
|
||||||
|| (request.len() > 1
|
|| (request.len() > 1
|
||||||
&& !request.starts_with("..")
|
&& !request.starts_with("..")
|
||||||
|
@ -207,12 +236,14 @@ fn op_require_resolve_lookup_paths(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_is_absolute(p: String) -> bool {
|
fn op_require_path_is_absolute(state: &mut OpState, p: String) -> bool {
|
||||||
|
check_unstable(state);
|
||||||
PathBuf::from(p).is_absolute()
|
PathBuf::from(p).is_absolute()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_stat(filename: String) -> i32 {
|
fn op_require_stat(state: &mut OpState, filename: String) -> i32 {
|
||||||
|
check_unstable(state);
|
||||||
if let Ok(metadata) = std::fs::metadata(&filename) {
|
if let Ok(metadata) = std::fs::metadata(&filename) {
|
||||||
if metadata.is_file() {
|
if metadata.is_file() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -225,7 +256,11 @@ fn op_require_stat(filename: String) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_real_path(request: String) -> Result<String, AnyError> {
|
fn op_require_real_path(
|
||||||
|
state: &mut OpState,
|
||||||
|
request: String,
|
||||||
|
) -> Result<String, AnyError> {
|
||||||
|
check_unstable(state);
|
||||||
let mut canonicalized_path = PathBuf::from(request).canonicalize()?;
|
let mut canonicalized_path = PathBuf::from(request).canonicalize()?;
|
||||||
if cfg!(windows) {
|
if cfg!(windows) {
|
||||||
canonicalized_path = PathBuf::from(
|
canonicalized_path = PathBuf::from(
|
||||||
|
@ -239,7 +274,8 @@ fn op_require_real_path(request: String) -> Result<String, AnyError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_resolve(parts: Vec<String>) -> String {
|
fn op_require_path_resolve(state: &mut OpState, parts: Vec<String>) -> String {
|
||||||
|
check_unstable(state);
|
||||||
assert!(!parts.is_empty());
|
assert!(!parts.is_empty());
|
||||||
let mut p = PathBuf::from(&parts[0]);
|
let mut p = PathBuf::from(&parts[0]);
|
||||||
if parts.len() > 1 {
|
if parts.len() > 1 {
|
||||||
|
@ -251,23 +287,27 @@ fn op_require_path_resolve(parts: Vec<String>) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_dirname(request: String) -> String {
|
fn op_require_path_dirname(state: &mut OpState, request: String) -> String {
|
||||||
|
check_unstable(state);
|
||||||
let p = PathBuf::from(request);
|
let p = PathBuf::from(request);
|
||||||
p.parent().unwrap().to_string_lossy().to_string()
|
p.parent().unwrap().to_string_lossy().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_path_basename(request: String) -> String {
|
fn op_require_path_basename(state: &mut OpState, request: String) -> String {
|
||||||
|
check_unstable(state);
|
||||||
let p = PathBuf::from(request);
|
let p = PathBuf::from(request);
|
||||||
p.file_name().unwrap().to_string_lossy().to_string()
|
p.file_name().unwrap().to_string_lossy().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_try_self_parent_path(
|
fn op_require_try_self_parent_path(
|
||||||
|
state: &mut OpState,
|
||||||
has_parent: bool,
|
has_parent: bool,
|
||||||
maybe_parent_filename: Option<String>,
|
maybe_parent_filename: Option<String>,
|
||||||
maybe_parent_id: Option<String>,
|
maybe_parent_id: Option<String>,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
|
check_unstable(state);
|
||||||
if !has_parent {
|
if !has_parent {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -288,10 +328,12 @@ fn op_require_try_self_parent_path(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_try_self(
|
fn op_require_try_self(
|
||||||
|
state: &mut OpState,
|
||||||
has_parent: bool,
|
has_parent: bool,
|
||||||
maybe_parent_filename: Option<String>,
|
maybe_parent_filename: Option<String>,
|
||||||
maybe_parent_id: Option<String>,
|
maybe_parent_id: Option<String>,
|
||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
|
check_unstable(state);
|
||||||
if !has_parent {
|
if !has_parent {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -311,6 +353,10 @@ fn op_require_try_self(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_require_read_file(_filename: String) -> Result<String, AnyError> {
|
fn op_require_read_file(
|
||||||
|
state: &mut OpState,
|
||||||
|
_filename: String,
|
||||||
|
) -> Result<String, AnyError> {
|
||||||
|
check_unstable(state);
|
||||||
todo!("not implemented");
|
todo!("not implemented");
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,7 +158,7 @@ mod not_docs {
|
||||||
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
|
||||||
false, // No --unstable.
|
false, // No --unstable.
|
||||||
),
|
),
|
||||||
deno_node::init(),
|
// deno_node::init(), // todo(dsherret): re-enable
|
||||||
deno_ffi::init::<Permissions>(false),
|
deno_ffi::init::<Permissions>(false),
|
||||||
deno_net::init::<Permissions>(
|
deno_net::init::<Permissions>(
|
||||||
None, false, // No --unstable.
|
None, false, // No --unstable.
|
||||||
|
|
|
@ -419,7 +419,7 @@ impl WebWorker {
|
||||||
unstable,
|
unstable,
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_node::init(),
|
// deno_node::init(), // todo(dsherret): re-enable
|
||||||
ops::os::init_for_worker(),
|
ops::os::init_for_worker(),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init(),
|
ops::process::init(),
|
||||||
|
|
|
@ -161,7 +161,7 @@ impl MainWorker {
|
||||||
unstable,
|
unstable,
|
||||||
options.unsafely_ignore_certificate_errors.clone(),
|
options.unsafely_ignore_certificate_errors.clone(),
|
||||||
),
|
),
|
||||||
deno_node::init(),
|
// deno_node::init() // todo(dsherret): re-enable,
|
||||||
ops::os::init(exit_code.clone()),
|
ops::os::init(exit_code.clone()),
|
||||||
ops::permissions::init(),
|
ops::permissions::init(),
|
||||||
ops::process::init(),
|
ops::process::init(),
|
||||||
|
|
Loading…
Reference in a new issue