2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-08-09 15:06:01 -04:00
|
|
|
|
2024-03-09 10:21:31 -05:00
|
|
|
#![deny(clippy::print_stderr)]
|
|
|
|
#![deny(clippy::print_stdout)]
|
|
|
|
|
2023-05-08 11:02:02 -04:00
|
|
|
use std::collections::HashSet;
|
|
|
|
use std::path::Path;
|
|
|
|
|
2022-08-09 15:06:01 -04:00
|
|
|
use deno_core::error::AnyError;
|
2023-02-10 10:26:39 -05:00
|
|
|
use deno_core::located_script_name;
|
2023-09-14 02:29:44 -04:00
|
|
|
use deno_core::op2;
|
2023-05-27 09:42:20 -04:00
|
|
|
use deno_core::url::Url;
|
2023-07-05 13:15:10 -04:00
|
|
|
#[allow(unused_imports)]
|
|
|
|
use deno_core::v8;
|
2023-07-19 04:30:04 -04:00
|
|
|
use deno_core::v8::ExternalReference;
|
2023-02-10 10:26:39 -05:00
|
|
|
use deno_core::JsRuntime;
|
2023-11-11 12:01:48 -05:00
|
|
|
use deno_core::OpState;
|
2023-05-08 11:02:02 -04:00
|
|
|
use deno_fs::sync::MaybeSend;
|
|
|
|
use deno_fs::sync::MaybeSync;
|
2024-07-25 19:08:14 -04:00
|
|
|
use node_resolver::NpmResolverRc;
|
2022-09-08 16:01:48 -04:00
|
|
|
use once_cell::sync::Lazy;
|
2022-08-20 11:31:33 -04:00
|
|
|
|
2023-11-11 09:20:12 -05:00
|
|
|
extern crate libz_sys as zlib;
|
|
|
|
|
2023-07-19 04:30:04 -04:00
|
|
|
mod global;
|
2023-02-10 10:26:39 -05:00
|
|
|
mod ops;
|
|
|
|
mod polyfill;
|
2022-09-05 06:36:35 -04:00
|
|
|
|
2024-07-23 17:34:46 -04:00
|
|
|
pub use deno_package_json::PackageJson;
|
2024-07-25 19:08:14 -04:00
|
|
|
pub use node_resolver::PathClean;
|
2023-12-15 05:50:05 -05:00
|
|
|
pub use ops::ipc::ChildPipeFd;
|
2023-12-19 07:37:22 -05:00
|
|
|
pub use ops::ipc::IpcJsonStreamResource;
|
2024-07-30 19:13:24 -04:00
|
|
|
pub use ops::ipc::IpcRefTracker;
|
2024-06-12 13:02:54 -04:00
|
|
|
use ops::vm;
|
|
|
|
pub use ops::vm::create_v8_context;
|
|
|
|
pub use ops::vm::init_global_template;
|
|
|
|
pub use ops::vm::ContextInitMode;
|
2024-06-12 23:49:33 -04:00
|
|
|
pub use ops::vm::VM_CONTEXT_INDEX;
|
2023-02-10 10:26:39 -05:00
|
|
|
pub use polyfill::is_builtin_node_module;
|
|
|
|
pub use polyfill::SUPPORTED_BUILTIN_NODE_MODULES;
|
2023-07-02 14:19:30 -04:00
|
|
|
pub use polyfill::SUPPORTED_BUILTIN_NODE_MODULES_WITH_PREFIX;
|
2022-08-20 11:31:33 -04:00
|
|
|
|
2023-07-19 04:30:04 -04:00
|
|
|
use crate::global::global_object_middleware;
|
|
|
|
use crate::global::global_template_middleware;
|
|
|
|
|
2022-08-24 12:07:49 -04:00
|
|
|
pub trait NodePermissions {
|
2023-05-27 09:42:20 -04:00
|
|
|
fn check_net_url(
|
|
|
|
&mut self,
|
|
|
|
url: &Url,
|
|
|
|
api_name: &str,
|
|
|
|
) -> Result<(), AnyError>;
|
2023-12-04 16:05:40 -05:00
|
|
|
#[inline(always)]
|
2024-06-06 23:37:53 -04:00
|
|
|
fn check_read(&mut self, path: &Path) -> Result<(), AnyError> {
|
2023-12-04 16:05:40 -05:00
|
|
|
self.check_read_with_api_name(path, None)
|
|
|
|
}
|
|
|
|
fn check_read_with_api_name(
|
2024-06-06 23:37:53 -04:00
|
|
|
&mut self,
|
2023-12-04 16:05:40 -05:00
|
|
|
path: &Path,
|
|
|
|
api_name: Option<&str>,
|
|
|
|
) -> Result<(), AnyError>;
|
2024-06-06 23:37:53 -04:00
|
|
|
fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError>;
|
2024-01-05 07:58:33 -05:00
|
|
|
fn check_write_with_api_name(
|
2024-06-06 23:37:53 -04:00
|
|
|
&mut self,
|
2024-01-05 07:58:33 -05:00
|
|
|
path: &Path,
|
|
|
|
api_name: Option<&str>,
|
|
|
|
) -> Result<(), AnyError>;
|
2022-08-24 12:07:49 -04:00
|
|
|
}
|
|
|
|
|
2024-06-06 23:37:53 -04:00
|
|
|
impl NodePermissions for deno_permissions::PermissionsContainer {
|
|
|
|
#[inline(always)]
|
|
|
|
fn check_net_url(
|
|
|
|
&mut self,
|
|
|
|
url: &Url,
|
|
|
|
api_name: &str,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
deno_permissions::PermissionsContainer::check_net_url(self, url, api_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn check_read_with_api_name(
|
|
|
|
&mut self,
|
|
|
|
path: &Path,
|
|
|
|
api_name: Option<&str>,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
deno_permissions::PermissionsContainer::check_read_with_api_name(
|
|
|
|
self, path, api_name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
fn check_write_with_api_name(
|
|
|
|
&mut self,
|
|
|
|
path: &Path,
|
|
|
|
api_name: Option<&str>,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
deno_permissions::PermissionsContainer::check_write_with_api_name(
|
|
|
|
self, path, api_name,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_sys(&mut self, kind: &str, api_name: &str) -> Result<(), AnyError> {
|
|
|
|
deno_permissions::PermissionsContainer::check_sys(self, kind, api_name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-08 11:02:02 -04:00
|
|
|
#[allow(clippy::disallowed_types)]
|
2024-07-25 19:08:14 -04:00
|
|
|
pub type NpmProcessStateProviderRc =
|
|
|
|
deno_fs::sync::MaybeArc<dyn NpmProcessStateProvider>;
|
2023-05-08 11:02:02 -04:00
|
|
|
|
2024-07-25 19:08:14 -04:00
|
|
|
pub trait NpmProcessStateProvider:
|
|
|
|
std::fmt::Debug + MaybeSend + MaybeSync
|
|
|
|
{
|
2023-11-11 12:01:48 -05:00
|
|
|
/// Gets a string containing the serialized npm state of the process.
|
|
|
|
///
|
|
|
|
/// This will be set on the `DENO_DONT_USE_INTERNAL_NODE_COMPAT_STATE` environment
|
|
|
|
/// variable when doing a `child_process.fork`. The implementor can then check this environment
|
|
|
|
/// variable on startup to repopulate the internal npm state.
|
|
|
|
fn get_npm_process_state(&self) -> String {
|
|
|
|
// This method is only used in the CLI.
|
|
|
|
String::new()
|
|
|
|
}
|
2024-07-25 19:08:14 -04:00
|
|
|
}
|
2023-11-11 12:01:48 -05:00
|
|
|
|
2024-07-25 19:08:14 -04:00
|
|
|
#[allow(clippy::disallowed_types)]
|
|
|
|
pub type NodeRequireResolverRc =
|
|
|
|
deno_fs::sync::MaybeArc<dyn NodeRequireResolver>;
|
2022-08-20 11:31:33 -04:00
|
|
|
|
2024-07-25 19:08:14 -04:00
|
|
|
pub trait NodeRequireResolver: std::fmt::Debug + MaybeSend + MaybeSync {
|
2023-01-10 08:35:44 -05:00
|
|
|
fn ensure_read_permission(
|
|
|
|
&self,
|
2024-06-06 23:37:53 -04:00
|
|
|
permissions: &mut dyn NodePermissions,
|
2023-01-10 08:35:44 -05:00
|
|
|
path: &Path,
|
|
|
|
) -> Result<(), AnyError>;
|
2022-08-20 11:31:33 -04:00
|
|
|
}
|
|
|
|
|
2022-09-14 11:59:20 -04:00
|
|
|
pub static NODE_ENV_VAR_ALLOWLIST: Lazy<HashSet<String>> = Lazy::new(|| {
|
|
|
|
// The full list of environment variables supported by Node.js is available
|
|
|
|
// at https://nodejs.org/api/cli.html#environment-variables
|
|
|
|
let mut set = HashSet::new();
|
|
|
|
set.insert("NODE_DEBUG".to_string());
|
|
|
|
set.insert("NODE_OPTIONS".to_string());
|
|
|
|
set
|
|
|
|
});
|
|
|
|
|
2023-09-14 02:29:44 -04:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
2023-02-14 11:38:45 -05:00
|
|
|
fn op_node_build_os() -> String {
|
2023-08-05 19:47:15 -04:00
|
|
|
env!("TARGET").split('-').nth(2).unwrap().to_string()
|
2023-02-14 11:38:45 -05:00
|
|
|
}
|
|
|
|
|
2023-11-11 12:01:48 -05:00
|
|
|
#[op2]
|
|
|
|
#[string]
|
|
|
|
fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
|
2024-07-25 19:08:14 -04:00
|
|
|
let npm_resolver = state.borrow_mut::<NpmProcessStateProviderRc>();
|
2023-11-11 12:01:48 -05:00
|
|
|
Ok(npm_resolver.get_npm_process_state())
|
|
|
|
}
|
|
|
|
|
2024-07-25 19:08:14 -04:00
|
|
|
pub struct NodeExtInitServices {
|
|
|
|
pub node_require_resolver: NodeRequireResolverRc,
|
|
|
|
pub node_resolver: NodeResolverRc,
|
|
|
|
pub npm_process_state_provider: NpmProcessStateProviderRc,
|
|
|
|
pub npm_resolver: NpmResolverRc,
|
|
|
|
}
|
|
|
|
|
2023-03-17 14:22:15 -04:00
|
|
|
deno_core::extension!(deno_node,
|
|
|
|
deps = [ deno_io, deno_fs ],
|
2023-05-04 08:36:38 -04:00
|
|
|
parameters = [P: NodePermissions],
|
2023-03-17 14:22:15 -04:00
|
|
|
ops = [
|
2024-06-18 06:46:13 -04:00
|
|
|
ops::blocklist::op_socket_address_parse,
|
|
|
|
ops::blocklist::op_socket_address_get_serialization,
|
|
|
|
|
|
|
|
ops::blocklist::op_blocklist_new,
|
|
|
|
ops::blocklist::op_blocklist_add_address,
|
|
|
|
ops::blocklist::op_blocklist_add_range,
|
|
|
|
ops::blocklist::op_blocklist_add_subnet,
|
|
|
|
ops::blocklist::op_blocklist_check,
|
|
|
|
|
2024-05-21 18:50:59 -04:00
|
|
|
ops::buffer::op_is_ascii,
|
|
|
|
ops::buffer::op_is_utf8,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_check_prime_async,
|
|
|
|
ops::crypto::op_node_check_prime_bytes_async,
|
|
|
|
ops::crypto::op_node_check_prime_bytes,
|
|
|
|
ops::crypto::op_node_check_prime,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_cipheriv_encrypt,
|
|
|
|
ops::crypto::op_node_cipheriv_final,
|
2023-09-06 01:31:50 -04:00
|
|
|
ops::crypto::op_node_cipheriv_set_aad,
|
2024-08-09 06:58:20 -04:00
|
|
|
ops::crypto::op_node_cipheriv_take,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_create_cipheriv,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_create_decipheriv,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_create_hash,
|
|
|
|
ops::crypto::op_node_decipheriv_decrypt,
|
|
|
|
ops::crypto::op_node_decipheriv_final,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_decipheriv_set_aad,
|
2024-08-08 09:04:10 -04:00
|
|
|
ops::crypto::op_node_decipheriv_take,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_dh_compute_secret,
|
|
|
|
ops::crypto::op_node_diffie_hellman,
|
|
|
|
ops::crypto::op_node_ecdh_compute_public_key,
|
|
|
|
ops::crypto::op_node_ecdh_compute_secret,
|
|
|
|
ops::crypto::op_node_ecdh_encode_pubkey,
|
|
|
|
ops::crypto::op_node_ecdh_generate_keys,
|
|
|
|
ops::crypto::op_node_fill_random_async,
|
|
|
|
ops::crypto::op_node_fill_random,
|
|
|
|
ops::crypto::op_node_gen_prime_async,
|
|
|
|
ops::crypto::op_node_gen_prime,
|
|
|
|
ops::crypto::op_node_get_hashes,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_hash_clone,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_hash_digest_hex,
|
|
|
|
ops::crypto::op_node_hash_digest,
|
|
|
|
ops::crypto::op_node_hash_update_str,
|
|
|
|
ops::crypto::op_node_hash_update,
|
|
|
|
ops::crypto::op_node_hkdf_async,
|
|
|
|
ops::crypto::op_node_hkdf,
|
|
|
|
ops::crypto::op_node_pbkdf2_async,
|
|
|
|
ops::crypto::op_node_pbkdf2,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_private_decrypt,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_private_encrypt,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::op_node_public_encrypt,
|
|
|
|
ops::crypto::op_node_random_int,
|
|
|
|
ops::crypto::op_node_scrypt_async,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_scrypt_sync,
|
|
|
|
ops::crypto::op_node_sign,
|
2024-08-09 06:58:20 -04:00
|
|
|
ops::crypto::op_node_sign_ed25519,
|
2024-08-08 05:35:29 -04:00
|
|
|
ops::crypto::op_node_verify,
|
2024-08-09 06:58:20 -04:00
|
|
|
ops::crypto::op_node_verify_ed25519,
|
2024-08-07 02:43:58 -04:00
|
|
|
ops::crypto::keys::op_node_create_private_key,
|
2024-08-23 12:36:28 -04:00
|
|
|
ops::crypto::keys::op_node_create_ed_raw,
|
2024-08-28 11:26:11 -04:00
|
|
|
ops::crypto::keys::op_node_create_rsa_jwk,
|
2024-08-28 10:24:49 -04:00
|
|
|
ops::crypto::keys::op_node_create_ec_jwk,
|
2024-08-07 02:43:58 -04:00
|
|
|
ops::crypto::keys::op_node_create_public_key,
|
|
|
|
ops::crypto::keys::op_node_create_secret_key,
|
|
|
|
ops::crypto::keys::op_node_derive_public_key_from_private_key,
|
|
|
|
ops::crypto::keys::op_node_dh_keys_generate_and_export,
|
|
|
|
ops::crypto::keys::op_node_export_private_key_der,
|
|
|
|
ops::crypto::keys::op_node_export_private_key_pem,
|
|
|
|
ops::crypto::keys::op_node_export_public_key_der,
|
|
|
|
ops::crypto::keys::op_node_export_public_key_pem,
|
2024-08-28 11:03:02 -04:00
|
|
|
ops::crypto::keys::op_node_export_public_key_jwk,
|
2024-08-07 02:43:58 -04:00
|
|
|
ops::crypto::keys::op_node_export_secret_key_b64url,
|
|
|
|
ops::crypto::keys::op_node_export_secret_key,
|
|
|
|
ops::crypto::keys::op_node_generate_dh_group_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_dh_group_key,
|
|
|
|
ops::crypto::keys::op_node_generate_dh_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_dh_key,
|
|
|
|
ops::crypto::keys::op_node_generate_dsa_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_dsa_key,
|
|
|
|
ops::crypto::keys::op_node_generate_ec_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_ec_key,
|
|
|
|
ops::crypto::keys::op_node_generate_ed25519_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_ed25519_key,
|
|
|
|
ops::crypto::keys::op_node_generate_rsa_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_rsa_key,
|
|
|
|
ops::crypto::keys::op_node_generate_rsa_pss_key,
|
|
|
|
ops::crypto::keys::op_node_generate_rsa_pss_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_secret_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_secret_key,
|
|
|
|
ops::crypto::keys::op_node_generate_x25519_key_async,
|
|
|
|
ops::crypto::keys::op_node_generate_x25519_key,
|
|
|
|
ops::crypto::keys::op_node_get_asymmetric_key_details,
|
|
|
|
ops::crypto::keys::op_node_get_asymmetric_key_type,
|
|
|
|
ops::crypto::keys::op_node_get_private_key_from_pair,
|
|
|
|
ops::crypto::keys::op_node_get_public_key_from_pair,
|
|
|
|
ops::crypto::keys::op_node_get_symmetric_key_size,
|
|
|
|
ops::crypto::keys::op_node_key_type,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::crypto::x509::op_node_x509_parse,
|
|
|
|
ops::crypto::x509::op_node_x509_ca,
|
|
|
|
ops::crypto::x509::op_node_x509_check_email,
|
|
|
|
ops::crypto::x509::op_node_x509_fingerprint,
|
|
|
|
ops::crypto::x509::op_node_x509_fingerprint256,
|
|
|
|
ops::crypto::x509::op_node_x509_fingerprint512,
|
|
|
|
ops::crypto::x509::op_node_x509_get_issuer,
|
|
|
|
ops::crypto::x509::op_node_x509_get_subject,
|
|
|
|
ops::crypto::x509::op_node_x509_get_valid_from,
|
|
|
|
ops::crypto::x509::op_node_x509_get_valid_to,
|
|
|
|
ops::crypto::x509::op_node_x509_get_serial_number,
|
|
|
|
ops::crypto::x509::op_node_x509_key_usage,
|
2024-08-11 09:28:54 -04:00
|
|
|
ops::crypto::x509::op_node_x509_public_key,
|
2023-12-04 16:05:40 -05:00
|
|
|
ops::fs::op_node_fs_exists_sync<P>,
|
2024-07-17 08:35:51 -04:00
|
|
|
ops::fs::op_node_fs_exists<P>,
|
2024-01-05 07:58:33 -05:00
|
|
|
ops::fs::op_node_cp_sync<P>,
|
|
|
|
ops::fs::op_node_cp<P>,
|
2024-07-05 14:32:51 -04:00
|
|
|
ops::fs::op_node_lchown_sync<P>,
|
|
|
|
ops::fs::op_node_lchown<P>,
|
2024-07-02 22:33:32 -04:00
|
|
|
ops::fs::op_node_lutimes_sync<P>,
|
|
|
|
ops::fs::op_node_lutimes<P>,
|
2024-03-13 06:57:59 -04:00
|
|
|
ops::fs::op_node_statfs<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::winerror::op_node_sys_to_uv_error,
|
|
|
|
ops::v8::op_v8_cached_data_version_tag,
|
|
|
|
ops::v8::op_v8_get_heap_statistics,
|
2024-04-09 11:54:25 -04:00
|
|
|
ops::vm::op_vm_create_script,
|
|
|
|
ops::vm::op_vm_create_context,
|
|
|
|
ops::vm::op_vm_script_run_in_context,
|
|
|
|
ops::vm::op_vm_is_context,
|
2024-08-06 08:52:53 -04:00
|
|
|
ops::vm::op_vm_compile_function,
|
|
|
|
ops::vm::op_vm_script_get_source_map_url,
|
|
|
|
ops::vm::op_vm_script_create_cached_data,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::idna::op_node_idna_domain_to_ascii,
|
|
|
|
ops::idna::op_node_idna_domain_to_unicode,
|
2024-03-11 18:49:43 -04:00
|
|
|
ops::idna::op_node_idna_punycode_to_ascii,
|
|
|
|
ops::idna::op_node_idna_punycode_to_unicode,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::idna::op_node_idna_punycode_decode,
|
|
|
|
ops::idna::op_node_idna_punycode_encode,
|
|
|
|
ops::zlib::op_zlib_new,
|
|
|
|
ops::zlib::op_zlib_close,
|
|
|
|
ops::zlib::op_zlib_close_if_pending,
|
|
|
|
ops::zlib::op_zlib_write,
|
|
|
|
ops::zlib::op_zlib_init,
|
|
|
|
ops::zlib::op_zlib_reset,
|
2023-06-24 10:12:08 -04:00
|
|
|
ops::zlib::brotli::op_brotli_compress,
|
|
|
|
ops::zlib::brotli::op_brotli_compress_async,
|
|
|
|
ops::zlib::brotli::op_create_brotli_compress,
|
|
|
|
ops::zlib::brotli::op_brotli_compress_stream,
|
|
|
|
ops::zlib::brotli::op_brotli_compress_stream_end,
|
|
|
|
ops::zlib::brotli::op_brotli_decompress,
|
|
|
|
ops::zlib::brotli::op_brotli_decompress_async,
|
|
|
|
ops::zlib::brotli::op_create_brotli_decompress,
|
|
|
|
ops::zlib::brotli::op_brotli_decompress_stream,
|
|
|
|
ops::zlib::brotli::op_brotli_decompress_stream_end,
|
2023-05-27 09:42:20 -04:00
|
|
|
ops::http::op_node_http_request<P>,
|
2024-07-30 08:34:52 -04:00
|
|
|
ops::http::op_node_http_fetch_response_upgrade,
|
|
|
|
ops::http::op_node_http_fetch_send,
|
2023-09-15 15:51:25 -04:00
|
|
|
ops::http2::op_http2_connect,
|
|
|
|
ops::http2::op_http2_poll_client_connection,
|
|
|
|
ops::http2::op_http2_client_request,
|
|
|
|
ops::http2::op_http2_client_get_response,
|
|
|
|
ops::http2::op_http2_client_get_response_body_chunk,
|
|
|
|
ops::http2::op_http2_client_send_data,
|
|
|
|
ops::http2::op_http2_client_reset_stream,
|
|
|
|
ops::http2::op_http2_client_send_trailers,
|
|
|
|
ops::http2::op_http2_client_get_response_trailers,
|
|
|
|
ops::http2::op_http2_accept,
|
|
|
|
ops::http2::op_http2_listen,
|
|
|
|
ops::http2::op_http2_send_response,
|
2023-07-31 16:29:09 -04:00
|
|
|
ops::os::op_node_os_get_priority<P>,
|
|
|
|
ops::os::op_node_os_set_priority<P>,
|
|
|
|
ops::os::op_node_os_username<P>,
|
2023-11-10 13:49:57 -05:00
|
|
|
ops::os::op_geteuid<P>,
|
2024-07-05 14:32:51 -04:00
|
|
|
ops::os::op_getegid<P>,
|
2023-12-27 22:38:50 -05:00
|
|
|
ops::os::op_cpus<P>,
|
2024-05-16 01:22:40 -04:00
|
|
|
ops::os::op_homedir<P>,
|
2023-03-17 14:22:15 -04:00
|
|
|
op_node_build_os,
|
2023-11-11 12:01:48 -05:00
|
|
|
op_npm_process_state,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_init_paths,
|
2023-05-04 08:36:38 -04:00
|
|
|
ops::require::op_require_node_module_paths<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_proxy_path,
|
|
|
|
ops::require::op_require_is_deno_dir_package,
|
|
|
|
ops::require::op_require_resolve_deno_dir,
|
|
|
|
ops::require::op_require_is_request_relative,
|
|
|
|
ops::require::op_require_resolve_lookup_paths,
|
2023-05-04 08:36:38 -04:00
|
|
|
ops::require::op_require_try_self_parent_path<P>,
|
|
|
|
ops::require::op_require_try_self<P>,
|
|
|
|
ops::require::op_require_real_path<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_path_is_absolute,
|
|
|
|
ops::require::op_require_path_dirname,
|
2023-05-04 08:36:38 -04:00
|
|
|
ops::require::op_require_stat<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_path_resolve,
|
|
|
|
ops::require::op_require_path_basename,
|
2023-05-04 08:36:38 -04:00
|
|
|
ops::require::op_require_read_file<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_as_file_path,
|
2023-05-04 08:36:38 -04:00
|
|
|
ops::require::op_require_resolve_exports<P>,
|
|
|
|
ops::require::op_require_read_closest_package_json<P>,
|
|
|
|
ops::require::op_require_read_package_scope<P>,
|
|
|
|
ops::require::op_require_package_imports_resolve<P>,
|
2023-04-24 06:22:21 -04:00
|
|
|
ops::require::op_require_break_on_next_statement,
|
2023-10-30 11:53:08 -04:00
|
|
|
ops::util::op_node_guess_handle_type,
|
2024-03-19 23:42:22 -04:00
|
|
|
ops::worker_threads::op_worker_threads_filename<P>,
|
2023-12-15 05:50:05 -05:00
|
|
|
ops::ipc::op_node_child_ipc_pipe,
|
2023-12-13 05:14:16 -05:00
|
|
|
ops::ipc::op_node_ipc_write,
|
|
|
|
ops::ipc::op_node_ipc_read,
|
2024-07-30 19:13:24 -04:00
|
|
|
ops::ipc::op_node_ipc_ref,
|
|
|
|
ops::ipc::op_node_ipc_unref,
|
2024-04-20 09:25:07 -04:00
|
|
|
ops::process::op_node_process_kill,
|
|
|
|
ops::process::op_process_abort,
|
2023-03-17 14:22:15 -04:00
|
|
|
],
|
2023-03-20 14:05:13 -04:00
|
|
|
esm_entry_point = "ext:deno_node/02_init.js",
|
2023-03-17 14:22:15 -04:00
|
|
|
esm = [
|
2023-02-14 11:38:45 -05:00
|
|
|
dir "polyfills",
|
2023-03-20 14:05:13 -04:00
|
|
|
"00_globals.js",
|
|
|
|
"02_init.js",
|
2023-06-24 10:12:08 -04:00
|
|
|
"_brotli.js",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_events.mjs",
|
|
|
|
"_fs/_fs_access.ts",
|
|
|
|
"_fs/_fs_appendFile.ts",
|
|
|
|
"_fs/_fs_chmod.ts",
|
|
|
|
"_fs/_fs_chown.ts",
|
|
|
|
"_fs/_fs_close.ts",
|
|
|
|
"_fs/_fs_common.ts",
|
|
|
|
"_fs/_fs_constants.ts",
|
|
|
|
"_fs/_fs_copy.ts",
|
2024-01-05 07:58:33 -05:00
|
|
|
"_fs/_fs_cp.js",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_fs/_fs_dir.ts",
|
|
|
|
"_fs/_fs_dirent.ts",
|
|
|
|
"_fs/_fs_exists.ts",
|
|
|
|
"_fs/_fs_fdatasync.ts",
|
|
|
|
"_fs/_fs_fstat.ts",
|
|
|
|
"_fs/_fs_fsync.ts",
|
|
|
|
"_fs/_fs_ftruncate.ts",
|
|
|
|
"_fs/_fs_futimes.ts",
|
2024-07-05 14:32:51 -04:00
|
|
|
"_fs/_fs_lchown.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_fs/_fs_link.ts",
|
|
|
|
"_fs/_fs_lstat.ts",
|
2024-07-02 22:33:32 -04:00
|
|
|
"_fs/_fs_lutimes.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_fs/_fs_mkdir.ts",
|
|
|
|
"_fs/_fs_mkdtemp.ts",
|
|
|
|
"_fs/_fs_open.ts",
|
|
|
|
"_fs/_fs_opendir.ts",
|
|
|
|
"_fs/_fs_read.ts",
|
|
|
|
"_fs/_fs_readdir.ts",
|
|
|
|
"_fs/_fs_readFile.ts",
|
|
|
|
"_fs/_fs_readlink.ts",
|
2024-04-01 23:42:49 -04:00
|
|
|
"_fs/_fs_readv.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_fs/_fs_realpath.ts",
|
|
|
|
"_fs/_fs_rename.ts",
|
|
|
|
"_fs/_fs_rm.ts",
|
|
|
|
"_fs/_fs_rmdir.ts",
|
|
|
|
"_fs/_fs_stat.ts",
|
2024-03-13 06:57:59 -04:00
|
|
|
"_fs/_fs_statfs.js",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_fs/_fs_symlink.ts",
|
|
|
|
"_fs/_fs_truncate.ts",
|
|
|
|
"_fs/_fs_unlink.ts",
|
|
|
|
"_fs/_fs_utimes.ts",
|
|
|
|
"_fs/_fs_watch.ts",
|
|
|
|
"_fs/_fs_write.mjs",
|
|
|
|
"_fs/_fs_writeFile.ts",
|
|
|
|
"_fs/_fs_writev.mjs",
|
|
|
|
"_http_agent.mjs",
|
|
|
|
"_http_common.ts",
|
|
|
|
"_http_outgoing.ts",
|
|
|
|
"_next_tick.ts",
|
|
|
|
"_process/exiting.ts",
|
|
|
|
"_process/process.ts",
|
|
|
|
"_process/streams.mjs",
|
|
|
|
"_readline.mjs",
|
|
|
|
"_stream.mjs",
|
|
|
|
"_tls_common.ts",
|
|
|
|
"_tls_wrap.ts",
|
2024-01-31 22:21:10 -05:00
|
|
|
"_util/_util_callbackify.js",
|
2023-02-14 11:38:45 -05:00
|
|
|
"_util/asserts.ts",
|
|
|
|
"_util/async.ts",
|
|
|
|
"_util/os.ts",
|
|
|
|
"_util/std_asserts.ts",
|
|
|
|
"_util/std_fmt_colors.ts",
|
|
|
|
"_util/std_testing_diff.ts",
|
|
|
|
"_utils.ts",
|
|
|
|
"_zlib_binding.mjs",
|
|
|
|
"_zlib.mjs",
|
|
|
|
"assertion_error.ts",
|
|
|
|
"internal_binding/_libuv_winerror.ts",
|
|
|
|
"internal_binding/_listen.ts",
|
|
|
|
"internal_binding/_node.ts",
|
|
|
|
"internal_binding/_timingSafeEqual.ts",
|
|
|
|
"internal_binding/_utils.ts",
|
|
|
|
"internal_binding/ares.ts",
|
|
|
|
"internal_binding/async_wrap.ts",
|
|
|
|
"internal_binding/buffer.ts",
|
|
|
|
"internal_binding/cares_wrap.ts",
|
|
|
|
"internal_binding/connection_wrap.ts",
|
|
|
|
"internal_binding/constants.ts",
|
|
|
|
"internal_binding/crypto.ts",
|
|
|
|
"internal_binding/handle_wrap.ts",
|
|
|
|
"internal_binding/mod.ts",
|
|
|
|
"internal_binding/node_file.ts",
|
|
|
|
"internal_binding/node_options.ts",
|
|
|
|
"internal_binding/pipe_wrap.ts",
|
|
|
|
"internal_binding/stream_wrap.ts",
|
|
|
|
"internal_binding/string_decoder.ts",
|
|
|
|
"internal_binding/symbols.ts",
|
|
|
|
"internal_binding/tcp_wrap.ts",
|
|
|
|
"internal_binding/types.ts",
|
|
|
|
"internal_binding/udp_wrap.ts",
|
|
|
|
"internal_binding/util.ts",
|
|
|
|
"internal_binding/uv.ts",
|
|
|
|
"internal/assert.mjs",
|
|
|
|
"internal/async_hooks.ts",
|
2024-06-18 06:46:13 -04:00
|
|
|
"internal/blocklist.mjs",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/buffer.mjs",
|
|
|
|
"internal/child_process.ts",
|
|
|
|
"internal/cli_table.ts",
|
|
|
|
"internal/console/constructor.mjs",
|
|
|
|
"internal/constants.ts",
|
|
|
|
"internal/crypto/_keys.ts",
|
|
|
|
"internal/crypto/_randomBytes.ts",
|
2023-09-23 04:04:55 -04:00
|
|
|
"internal/crypto/_randomFill.mjs",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/crypto/_randomInt.ts",
|
|
|
|
"internal/crypto/certificate.ts",
|
|
|
|
"internal/crypto/cipher.ts",
|
|
|
|
"internal/crypto/constants.ts",
|
|
|
|
"internal/crypto/diffiehellman.ts",
|
|
|
|
"internal/crypto/hash.ts",
|
|
|
|
"internal/crypto/hkdf.ts",
|
|
|
|
"internal/crypto/keygen.ts",
|
|
|
|
"internal/crypto/keys.ts",
|
|
|
|
"internal/crypto/pbkdf2.ts",
|
|
|
|
"internal/crypto/random.ts",
|
|
|
|
"internal/crypto/scrypt.ts",
|
|
|
|
"internal/crypto/sig.ts",
|
|
|
|
"internal/crypto/util.ts",
|
|
|
|
"internal/crypto/x509.ts",
|
|
|
|
"internal/dgram.ts",
|
|
|
|
"internal/dns/promises.ts",
|
|
|
|
"internal/dns/utils.ts",
|
|
|
|
"internal/dtrace.ts",
|
|
|
|
"internal/error_codes.ts",
|
|
|
|
"internal/errors.ts",
|
|
|
|
"internal/event_target.mjs",
|
2024-09-05 03:22:52 -04:00
|
|
|
"internal/events/abort_listener.mjs",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/fixed_queue.ts",
|
|
|
|
"internal/fs/streams.mjs",
|
|
|
|
"internal/fs/utils.mjs",
|
feat(node_compat): Added base implementation of FileHandle (#19294)
<!--
Before submitting a PR, please read https://deno.com/manual/contributing
1. Give the PR a descriptive title.
Examples of good title:
- fix(std/http): Fix race condition in server
- docs(console): Update docstrings
- feat(doc): Handle nested reexports
Examples of bad title:
- fix #7123
- update docs
- fix bugs
2. Ensure there is a related issue and it is referenced in the PR text.
3. Ensure there are tests that cover the changes.
4. Ensure `cargo test` passes.
5. Ensure `./tools/format.js` passes without changing files.
6. Ensure `./tools/lint.js` passes.
7. Open as a draft PR if your work is still in progress. The CI won't
run
all steps, but you can add '[ci]' to a commit message to force it to.
8. If you would like to run the benchmarks on the CI, add the 'ci-bench'
label.
-->
## WHY
ref: https://github.com/denoland/deno/issues/19165
Node's fs/promises includes a FileHandle class, but deno does not. The
open function in Node's fs/promises returns a FileHandle, which provides
an IO interface to the file. However, deno's open function returns a
resource id.
### deno
```js
> const fs = await import("node:fs/promises");
undefined
> const file3 = await fs.open("./README.md");
undefined
> file3
3
> file3.read
undefined
Node:
```
### Node
```js
> const fs = await import("fs/promises");
undefined
> const file3 = await fs.open("./tests/e2e_unit/testdata/file.txt");
undefined
> file3
FileHandle {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
close: [Function: close],
[Symbol(kCapture)]: false,
[Symbol(kHandle)]: FileHandle {},
[Symbol(kFd)]: 24,
[Symbol(kRefs)]: 1,
[Symbol(kClosePromise)]: null
}
> file3.read
[Function: read]
```
To be compatible with Node, deno's open function should also return a
FileHandle.
## WHAT
I have implemented the first step in adding a FileHandle.
- Changed the return value of the open function to a FileHandle object
- Implemented the readFile method in FileHandle
- Add test code
## What to do next
This PR is the first step in adding a FileHandle, and there are things
that should be done next.
- Add functionality equivalent to Node's FileHandle to FileHandle
(currently there is only readFile)
---------
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
2023-06-02 10:28:05 -04:00
|
|
|
"internal/fs/handle.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/hide_stack_frames.ts",
|
|
|
|
"internal/http.ts",
|
|
|
|
"internal/idna.ts",
|
|
|
|
"internal/net.ts",
|
|
|
|
"internal/normalize_encoding.mjs",
|
|
|
|
"internal/options.ts",
|
|
|
|
"internal/primordials.mjs",
|
|
|
|
"internal/process/per_thread.mjs",
|
2023-12-01 01:36:11 -05:00
|
|
|
"internal/process/report.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/querystring.ts",
|
|
|
|
"internal/readline/callbacks.mjs",
|
|
|
|
"internal/readline/emitKeypressEvents.mjs",
|
|
|
|
"internal/readline/interface.mjs",
|
|
|
|
"internal/readline/promises.mjs",
|
|
|
|
"internal/readline/symbols.mjs",
|
|
|
|
"internal/readline/utils.mjs",
|
|
|
|
"internal/stream_base_commons.ts",
|
|
|
|
"internal/streams/add-abort-signal.mjs",
|
|
|
|
"internal/streams/buffer_list.mjs",
|
|
|
|
"internal/streams/destroy.mjs",
|
|
|
|
"internal/streams/duplex.mjs",
|
|
|
|
"internal/streams/end-of-stream.mjs",
|
|
|
|
"internal/streams/lazy_transform.mjs",
|
|
|
|
"internal/streams/passthrough.mjs",
|
|
|
|
"internal/streams/readable.mjs",
|
|
|
|
"internal/streams/state.mjs",
|
|
|
|
"internal/streams/transform.mjs",
|
|
|
|
"internal/streams/utils.mjs",
|
|
|
|
"internal/streams/writable.mjs",
|
|
|
|
"internal/test/binding.ts",
|
|
|
|
"internal/timers.mjs",
|
|
|
|
"internal/url.ts",
|
|
|
|
"internal/util.mjs",
|
|
|
|
"internal/util/comparisons.ts",
|
|
|
|
"internal/util/debuglog.ts",
|
|
|
|
"internal/util/inspect.mjs",
|
2023-11-29 01:42:58 -05:00
|
|
|
"internal/util/parse_args/parse_args.js",
|
|
|
|
"internal/util/parse_args/utils.js",
|
2023-02-14 11:38:45 -05:00
|
|
|
"internal/util/types.ts",
|
|
|
|
"internal/validators.mjs",
|
|
|
|
"path/_constants.ts",
|
|
|
|
"path/_interface.ts",
|
|
|
|
"path/_util.ts",
|
2023-04-18 04:44:25 -04:00
|
|
|
"path/_posix.ts",
|
|
|
|
"path/_win32.ts",
|
2023-02-14 11:38:45 -05:00
|
|
|
"path/common.ts",
|
|
|
|
"path/mod.ts",
|
|
|
|
"path/separator.ts",
|
|
|
|
"readline/promises.ts",
|
2024-02-04 19:03:14 -05:00
|
|
|
"node:assert" = "assert.ts",
|
|
|
|
"node:assert/strict" = "assert/strict.ts",
|
|
|
|
"node:async_hooks" = "async_hooks.ts",
|
|
|
|
"node:buffer" = "buffer.ts",
|
|
|
|
"node:child_process" = "child_process.ts",
|
|
|
|
"node:cluster" = "cluster.ts",
|
|
|
|
"node:console" = "console.ts",
|
|
|
|
"node:constants" = "constants.ts",
|
|
|
|
"node:crypto" = "crypto.ts",
|
|
|
|
"node:dgram" = "dgram.ts",
|
2024-06-14 18:07:02 -04:00
|
|
|
"node:diagnostics_channel" = "diagnostics_channel.js",
|
2024-02-04 19:03:14 -05:00
|
|
|
"node:dns" = "dns.ts",
|
|
|
|
"node:dns/promises" = "dns/promises.ts",
|
|
|
|
"node:domain" = "domain.ts",
|
|
|
|
"node:events" = "events.ts",
|
|
|
|
"node:fs" = "fs.ts",
|
|
|
|
"node:fs/promises" = "fs/promises.ts",
|
|
|
|
"node:http" = "http.ts",
|
|
|
|
"node:http2" = "http2.ts",
|
|
|
|
"node:https" = "https.ts",
|
2024-08-14 08:33:42 -04:00
|
|
|
"node:inspector" = "inspector.ts",
|
2024-02-04 19:03:14 -05:00
|
|
|
"node:module" = "01_require.js",
|
|
|
|
"node:net" = "net.ts",
|
|
|
|
"node:os" = "os.ts",
|
|
|
|
"node:path" = "path.ts",
|
|
|
|
"node:path/posix" = "path/posix.ts",
|
|
|
|
"node:path/win32" = "path/win32.ts",
|
|
|
|
"node:perf_hooks" = "perf_hooks.ts",
|
|
|
|
"node:process" = "process.ts",
|
|
|
|
"node:punycode" = "punycode.ts",
|
|
|
|
"node:querystring" = "querystring.js",
|
|
|
|
"node:readline" = "readline.ts",
|
2024-07-28 15:41:10 -04:00
|
|
|
"node:readline/promises" = "readline/promises.ts",
|
2024-02-04 19:03:14 -05:00
|
|
|
"node:repl" = "repl.ts",
|
|
|
|
"node:stream" = "stream.ts",
|
|
|
|
"node:stream/consumers" = "stream/consumers.mjs",
|
|
|
|
"node:stream/promises" = "stream/promises.mjs",
|
|
|
|
"node:stream/web" = "stream/web.ts",
|
|
|
|
"node:string_decoder" = "string_decoder.ts",
|
|
|
|
"node:sys" = "sys.ts",
|
|
|
|
"node:test" = "testing.ts",
|
|
|
|
"node:timers" = "timers.ts",
|
|
|
|
"node:timers/promises" = "timers/promises.ts",
|
|
|
|
"node:tls" = "tls.ts",
|
|
|
|
"node:tty" = "tty.js",
|
|
|
|
"node:url" = "url.ts",
|
|
|
|
"node:util" = "util.ts",
|
|
|
|
"node:util/types" = "util/types.ts",
|
|
|
|
"node:v8" = "v8.ts",
|
2024-08-06 08:52:53 -04:00
|
|
|
"node:vm" = "vm.js",
|
2024-08-21 23:33:52 -04:00
|
|
|
"node:wasi" = "wasi.ts",
|
2024-02-04 19:03:14 -05:00
|
|
|
"node:worker_threads" = "worker_threads.ts",
|
|
|
|
"node:zlib" = "zlib.ts",
|
2023-03-17 14:22:15 -04:00
|
|
|
],
|
2023-03-17 18:15:27 -04:00
|
|
|
options = {
|
2024-07-25 19:08:14 -04:00
|
|
|
maybe_init: Option<NodeExtInitServices>,
|
2023-05-08 11:02:02 -04:00
|
|
|
fs: deno_fs::FileSystemRc,
|
2023-03-17 14:22:15 -04:00
|
|
|
},
|
2023-03-17 18:15:27 -04:00
|
|
|
state = |state, options| {
|
2024-06-06 23:37:53 -04:00
|
|
|
state.put(options.fs.clone());
|
|
|
|
|
2024-07-25 19:08:14 -04:00
|
|
|
if let Some(init) = &options.maybe_init {
|
|
|
|
state.put(init.node_require_resolver.clone());
|
|
|
|
state.put(init.node_resolver.clone());
|
|
|
|
state.put(init.npm_resolver.clone());
|
|
|
|
state.put(init.npm_process_state_provider.clone());
|
2023-03-17 14:22:15 -04:00
|
|
|
}
|
2023-07-19 04:30:04 -04:00
|
|
|
},
|
|
|
|
global_template_middleware = global_template_middleware,
|
|
|
|
global_object_middleware = global_object_middleware,
|
2023-07-31 14:19:15 -04:00
|
|
|
customizer = |ext: &mut deno_core::Extension| {
|
2024-08-23 20:41:49 -04:00
|
|
|
let external_references = [
|
|
|
|
vm::QUERY_MAP_FN.with(|query| {
|
|
|
|
ExternalReference {
|
|
|
|
named_query: *query,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::GETTER_MAP_FN.with(|getter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_getter: *getter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::SETTER_MAP_FN.with(|setter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_setter: *setter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::DESCRIPTOR_MAP_FN.with(|descriptor| {
|
|
|
|
ExternalReference {
|
|
|
|
named_getter: *descriptor,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::DELETER_MAP_FN.with(|deleter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_deleter: *deleter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::ENUMERATOR_MAP_FN.with(|enumerator| {
|
|
|
|
ExternalReference {
|
|
|
|
enumerator: *enumerator,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::DEFINER_MAP_FN.with(|definer| {
|
|
|
|
ExternalReference {
|
|
|
|
named_definer: *definer,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
vm::INDEXED_QUERY_MAP_FN.with(|query| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_query: *query,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_GETTER_MAP_FN.with(|getter| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_getter: *getter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_SETTER_MAP_FN.with(|setter| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_setter: *setter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_DESCRIPTOR_MAP_FN.with(|descriptor| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_getter: *descriptor,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_DELETER_MAP_FN.with(|deleter| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_deleter: *deleter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_DEFINER_MAP_FN.with(|definer| {
|
|
|
|
ExternalReference {
|
|
|
|
indexed_definer: *definer,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
vm::INDEXED_ENUMERATOR_MAP_FN.with(|enumerator| {
|
|
|
|
ExternalReference {
|
|
|
|
enumerator: *enumerator,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
global::GETTER_MAP_FN.with(|getter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_getter: *getter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::SETTER_MAP_FN.with(|setter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_setter: *setter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::QUERY_MAP_FN.with(|query| {
|
|
|
|
ExternalReference {
|
|
|
|
named_query: *query,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::DELETER_MAP_FN.with(|deleter| {
|
|
|
|
ExternalReference {
|
|
|
|
named_deleter: *deleter,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::ENUMERATOR_MAP_FN.with(|enumerator| {
|
|
|
|
ExternalReference {
|
|
|
|
enumerator: *enumerator,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::DEFINER_MAP_FN.with(|definer| {
|
|
|
|
ExternalReference {
|
|
|
|
named_definer: *definer,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
global::DESCRIPTOR_MAP_FN.with(|descriptor| {
|
|
|
|
ExternalReference {
|
|
|
|
named_getter: *descriptor,
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
2023-07-31 14:19:15 -04:00
|
|
|
ext.external_references.to_mut().extend(external_references);
|
2023-07-19 04:30:04 -04:00
|
|
|
},
|
2023-03-17 14:22:15 -04:00
|
|
|
);
|
2023-03-09 09:56:19 -05:00
|
|
|
|
2023-02-10 10:26:39 -05:00
|
|
|
pub fn load_cjs_module(
|
|
|
|
js_runtime: &mut JsRuntime,
|
|
|
|
module: &str,
|
|
|
|
main: bool,
|
|
|
|
inspect_brk: bool,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
fn escape_for_single_quote_string(text: &str) -> String {
|
|
|
|
text.replace('\\', r"\\").replace('\'', r"\'")
|
|
|
|
}
|
|
|
|
|
2023-03-21 18:33:12 -04:00
|
|
|
let source_code = format!(
|
2023-03-20 14:05:13 -04:00
|
|
|
r#"(function loadCjsModule(moduleName, isMain, inspectBrk) {{
|
|
|
|
Deno[Deno.internal].node.loadCjsModule(moduleName, isMain, inspectBrk);
|
|
|
|
}})('{module}', {main}, {inspect_brk});"#,
|
2023-02-10 10:26:39 -05:00
|
|
|
main = main,
|
|
|
|
module = escape_for_single_quote_string(module),
|
|
|
|
inspect_brk = inspect_brk,
|
2024-03-04 20:17:39 -05:00
|
|
|
);
|
2023-02-10 10:26:39 -05:00
|
|
|
|
2023-03-21 18:33:12 -04:00
|
|
|
js_runtime.execute_script(located_script_name!(), source_code)?;
|
2023-02-10 10:26:39 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2024-07-25 19:08:14 -04:00
|
|
|
|
|
|
|
pub type NodeResolver = node_resolver::NodeResolver<DenoFsNodeResolverEnv>;
|
|
|
|
#[allow(clippy::disallowed_types)]
|
|
|
|
pub type NodeResolverRc =
|
|
|
|
deno_fs::sync::MaybeArc<node_resolver::NodeResolver<DenoFsNodeResolverEnv>>;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct DenoFsNodeResolverEnv {
|
|
|
|
fs: deno_fs::FileSystemRc,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DenoFsNodeResolverEnv {
|
|
|
|
pub fn new(fs: deno_fs::FileSystemRc) -> Self {
|
|
|
|
Self { fs }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl node_resolver::env::NodeResolverEnv for DenoFsNodeResolverEnv {
|
|
|
|
fn is_builtin_node_module(&self, specifier: &str) -> bool {
|
|
|
|
is_builtin_node_module(specifier)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn realpath_sync(
|
|
|
|
&self,
|
|
|
|
path: &std::path::Path,
|
|
|
|
) -> std::io::Result<std::path::PathBuf> {
|
|
|
|
self
|
|
|
|
.fs
|
|
|
|
.realpath_sync(path)
|
|
|
|
.map_err(|err| err.into_io_error())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn stat_sync(
|
|
|
|
&self,
|
|
|
|
path: &std::path::Path,
|
|
|
|
) -> std::io::Result<node_resolver::env::NodeResolverFsStat> {
|
|
|
|
self
|
|
|
|
.fs
|
|
|
|
.stat_sync(path)
|
|
|
|
.map(|stat| node_resolver::env::NodeResolverFsStat {
|
|
|
|
is_file: stat.is_file,
|
|
|
|
is_dir: stat.is_directory,
|
|
|
|
is_symlink: stat.is_symlink,
|
|
|
|
})
|
|
|
|
.map_err(|err| err.into_io_error())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn exists_sync(&self, path: &std::path::Path) -> bool {
|
|
|
|
self.fs.exists_sync(path)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pkg_json_fs(&self) -> &dyn deno_package_json::fs::DenoPkgJsonFs {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl deno_package_json::fs::DenoPkgJsonFs for DenoFsNodeResolverEnv {
|
|
|
|
fn read_to_string_lossy(
|
|
|
|
&self,
|
|
|
|
path: &std::path::Path,
|
|
|
|
) -> Result<String, std::io::Error> {
|
|
|
|
self
|
|
|
|
.fs
|
|
|
|
.read_text_file_lossy_sync(path, None)
|
|
|
|
.map_err(|err| err.into_io_error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DenoPkgJsonFsAdapter<'a>(pub &'a dyn deno_fs::FileSystem);
|
|
|
|
|
|
|
|
impl<'a> deno_package_json::fs::DenoPkgJsonFs for DenoPkgJsonFsAdapter<'a> {
|
|
|
|
fn read_to_string_lossy(
|
|
|
|
&self,
|
|
|
|
path: &Path,
|
|
|
|
) -> Result<String, std::io::Error> {
|
|
|
|
self
|
|
|
|
.0
|
|
|
|
.read_text_file_lossy_sync(path, None)
|
|
|
|
.map_err(|err| err.into_io_error())
|
|
|
|
}
|
|
|
|
}
|
2024-07-31 19:22:34 -04:00
|
|
|
|
|
|
|
pub fn create_host_defined_options<'s>(
|
|
|
|
scope: &mut v8::HandleScope<'s>,
|
|
|
|
) -> v8::Local<'s, v8::Data> {
|
|
|
|
let host_defined_options = v8::PrimitiveArray::new(scope, 1);
|
|
|
|
let value = v8::Boolean::new(scope, true);
|
|
|
|
host_defined_options.set(scope, 0, value.into());
|
|
|
|
host_defined_options.into()
|
|
|
|
}
|