mirror of
https://github.com/denoland/deno.git
synced 2024-12-23 15:49:44 -05:00
refactor(runtime): factor out deno_io extension crate (#18001)
This is a prerequisite to factor out FS ops to a separate crate.
This commit is contained in:
parent
3494c78679
commit
02026506f5
24 changed files with 108 additions and 65 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -1161,6 +1161,17 @@ dependencies = [
|
|||
"tokio-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deno_io"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"deno_core",
|
||||
"nix",
|
||||
"once_cell",
|
||||
"tokio",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "deno_lint"
|
||||
version = "0.41.0"
|
||||
|
@ -1265,6 +1276,7 @@ dependencies = [
|
|||
"deno_ffi",
|
||||
"deno_flash",
|
||||
"deno_http",
|
||||
"deno_io",
|
||||
"deno_napi",
|
||||
"deno_net",
|
||||
"deno_node",
|
||||
|
|
|
@ -21,6 +21,7 @@ members = [
|
|||
"ext/flash",
|
||||
"ext/ffi",
|
||||
"ext/http",
|
||||
"ext/io",
|
||||
"ext/net",
|
||||
"ext/node",
|
||||
"ext/url",
|
||||
|
@ -62,6 +63,7 @@ deno_fetch = { version = "0.115.0", path = "./ext/fetch" }
|
|||
deno_ffi = { version = "0.78.0", path = "./ext/ffi" }
|
||||
deno_flash = { version = "0.27.0", path = "./ext/flash" }
|
||||
deno_http = { version = "0.86.0", path = "./ext/http" }
|
||||
deno_io = { version = "0.1.0", path = "./ext/io" }
|
||||
deno_net = { version = "0.83.0", path = "./ext/net" }
|
||||
deno_node = { version = "0.28.0", path = "./ext/node" }
|
||||
deno_tls = { version = "0.78.0", path = "./ext/tls" }
|
||||
|
|
|
@ -351,6 +351,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) {
|
|||
),
|
||||
deno_napi::init::<PermissionsContainer>(),
|
||||
deno_http::init(),
|
||||
deno_io::init(Default::default()),
|
||||
deno_flash::init::<PermissionsContainer>(false), // No --unstable
|
||||
];
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ use deno_core::futures::StreamExt;
|
|||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::parking_lot::RwLock;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::ops::io::Stdio;
|
||||
use deno_runtime::ops::io::StdioPipe;
|
||||
use deno_runtime::deno_io::Stdio;
|
||||
use deno_runtime::deno_io::StdioPipe;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
use deno_runtime::permissions::PermissionsContainer;
|
||||
use deno_runtime::tokio_util::run_local;
|
||||
|
|
|
@ -31,9 +31,9 @@ use deno_core::futures::StreamExt;
|
|||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::url::Url;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_runtime::deno_io::Stdio;
|
||||
use deno_runtime::deno_io::StdioPipe;
|
||||
use deno_runtime::fmt_errors::format_js_error;
|
||||
use deno_runtime::ops::io::Stdio;
|
||||
use deno_runtime::ops::io::StdioPipe;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
use deno_runtime::permissions::PermissionsContainer;
|
||||
use deno_runtime::tokio_util::run_local;
|
||||
|
|
|
@ -4,6 +4,6 @@ use deno_runtime::ops::tty::ConsoleSize;
|
|||
|
||||
/// Gets the console size.
|
||||
pub fn console_size() -> Option<ConsoleSize> {
|
||||
let stderr = &deno_runtime::ops::io::STDERR_HANDLE;
|
||||
let stderr = &deno_runtime::deno_io::STDERR_HANDLE;
|
||||
deno_runtime::ops::tty::console_size(stderr).ok()
|
||||
}
|
||||
|
|
|
@ -420,7 +420,7 @@ pub async fn create_main_worker_for_test_or_bench(
|
|||
main_module: ModuleSpecifier,
|
||||
permissions: PermissionsContainer,
|
||||
custom_extensions: Vec<Extension>,
|
||||
stdio: deno_runtime::ops::io::Stdio,
|
||||
stdio: deno_runtime::deno_io::Stdio,
|
||||
) -> Result<CliMainWorker, AnyError> {
|
||||
create_main_worker_internal(
|
||||
ps,
|
||||
|
@ -438,7 +438,7 @@ async fn create_main_worker_internal(
|
|||
main_module: ModuleSpecifier,
|
||||
permissions: PermissionsContainer,
|
||||
mut custom_extensions: Vec<Extension>,
|
||||
stdio: deno_runtime::ops::io::Stdio,
|
||||
stdio: deno_runtime::deno_io::Stdio,
|
||||
bench_or_test: bool,
|
||||
) -> Result<CliMainWorker, AnyError> {
|
||||
let (main_module, is_main_cjs) = if let Ok(package_ref) =
|
||||
|
@ -642,7 +642,7 @@ fn create_web_worker_pre_execute_module_callback(
|
|||
|
||||
fn create_web_worker_callback(
|
||||
ps: ProcState,
|
||||
stdio: deno_runtime::ops::io::Stdio,
|
||||
stdio: deno_runtime::deno_io::Stdio,
|
||||
) -> Arc<CreateWebWorkerCb> {
|
||||
Arc::new(move |args| {
|
||||
let maybe_inspector_server = ps.maybe_inspector_server.clone();
|
||||
|
|
25
ext/io/Cargo.toml
Normal file
25
ext/io/Cargo.toml
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
[package]
|
||||
name = "deno_io"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
readme = "README.md"
|
||||
repository.workspace = true
|
||||
description = "IO promitives for Deno extensions"
|
||||
|
||||
[lib]
|
||||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
deno_core.workspace = true
|
||||
once_cell.workspace = true
|
||||
tokio.workspace = true
|
||||
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
nix.workspace = true
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { workspace = true, features = ["winbase"] }
|
4
ext/io/README.md
Normal file
4
ext/io/README.md
Normal file
|
@ -0,0 +1,4 @@
|
|||
# deno_io
|
||||
|
||||
This crate provides IO primitives for other Deno extensions, this includes stdio
|
||||
streams and abstraction over File System files.
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use deno_core::error::resource_unavailable;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::include_js_files;
|
||||
use deno_core::op;
|
||||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::AsyncMutFuture;
|
||||
|
@ -77,46 +78,14 @@ pub static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| {
|
|||
unsafe { StdFile::from_raw_handle(GetStdHandle(winbase::STD_ERROR_HANDLE)) }
|
||||
});
|
||||
|
||||
pub fn init() -> Extension {
|
||||
Extension::builder("deno_io")
|
||||
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
||||
.build()
|
||||
}
|
||||
|
||||
pub enum StdioPipe {
|
||||
Inherit,
|
||||
File(StdFile),
|
||||
}
|
||||
|
||||
impl Default for StdioPipe {
|
||||
fn default() -> Self {
|
||||
Self::Inherit
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for StdioPipe {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
StdioPipe::Inherit => StdioPipe::Inherit,
|
||||
StdioPipe::File(pipe) => StdioPipe::File(pipe.try_clone().unwrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Specify how stdin, stdout, and stderr are piped.
|
||||
/// By default, inherits from the process.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Stdio {
|
||||
pub stdin: StdioPipe,
|
||||
pub stdout: StdioPipe,
|
||||
pub stderr: StdioPipe,
|
||||
}
|
||||
|
||||
pub fn init_stdio(stdio: Stdio) -> Extension {
|
||||
pub fn init(stdio: Stdio) -> Extension {
|
||||
// todo(dsheret): don't do this? Taking out the writers was necessary to prevent invalid handle panics
|
||||
let stdio = Rc::new(RefCell::new(Some(stdio)));
|
||||
|
||||
Extension::builder("deno_stdio")
|
||||
Extension::builder("deno_io")
|
||||
.ops(vec![op_read_sync::decl(), op_write_sync::decl()])
|
||||
.dependencies(vec!["deno_web"])
|
||||
.esm(include_js_files!("12_io.js",))
|
||||
.middleware(|op| match op.name {
|
||||
"op_print" => op_print::decl(),
|
||||
_ => op,
|
||||
|
@ -168,6 +137,35 @@ pub fn init_stdio(stdio: Stdio) -> Extension {
|
|||
.build()
|
||||
}
|
||||
|
||||
pub enum StdioPipe {
|
||||
Inherit,
|
||||
File(StdFile),
|
||||
}
|
||||
|
||||
impl Default for StdioPipe {
|
||||
fn default() -> Self {
|
||||
Self::Inherit
|
||||
}
|
||||
}
|
||||
|
||||
impl Clone for StdioPipe {
|
||||
fn clone(&self) -> Self {
|
||||
match self {
|
||||
StdioPipe::Inherit => StdioPipe::Inherit,
|
||||
StdioPipe::File(pipe) => StdioPipe::File(pipe.try_clone().unwrap()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Specify how stdin, stdout, and stderr are piped.
|
||||
/// By default, inherits from the process.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Stdio {
|
||||
pub stdin: StdioPipe,
|
||||
pub stdout: StdioPipe,
|
||||
pub stderr: StdioPipe,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
use nix::sys::termios;
|
||||
|
|
@ -43,6 +43,7 @@ deno_fetch.workspace = true
|
|||
deno_ffi.workspace = true
|
||||
deno_flash.workspace = true
|
||||
deno_http.workspace = true
|
||||
deno_io.workspace = true
|
||||
deno_net.workspace = true
|
||||
deno_node.workspace = true
|
||||
deno_tls.workspace = true
|
||||
|
@ -70,6 +71,7 @@ deno_fetch.workspace = true
|
|||
deno_ffi.workspace = true
|
||||
deno_flash.workspace = true
|
||||
deno_http.workspace = true
|
||||
deno_io.workspace = true
|
||||
deno_napi.workspace = true
|
||||
deno_net.workspace = true
|
||||
deno_node.workspace = true
|
||||
|
|
|
@ -190,6 +190,7 @@ mod startup_snapshot {
|
|||
"deno_napi",
|
||||
"deno_http",
|
||||
"deno_flash",
|
||||
"deno_io",
|
||||
])
|
||||
.esm(include_js_files!(
|
||||
dir "js",
|
||||
|
@ -199,7 +200,6 @@ mod startup_snapshot {
|
|||
"06_util.js",
|
||||
"10_permissions.js",
|
||||
"11_workers.js",
|
||||
"12_io.js",
|
||||
"13_buffer.js",
|
||||
"30_fs.js",
|
||||
"30_os.js",
|
||||
|
@ -245,6 +245,7 @@ mod startup_snapshot {
|
|||
),
|
||||
deno_napi::init::<Permissions>(),
|
||||
deno_http::init(),
|
||||
deno_io::init(Default::default()),
|
||||
deno_flash::init::<Permissions>(false), // No --unstable
|
||||
runtime_extension,
|
||||
// FIXME(bartlomieju): these extensions are specified last, because they
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const core = globalThis.Deno.core;
|
||||
const ops = core.ops;
|
||||
import { read, readSync, write, writeSync } from "internal:runtime/js/12_io.js";
|
||||
import { read, readSync, write, writeSync } from "internal:deno_io/12_io.js";
|
||||
import {
|
||||
fstat,
|
||||
fstatSync,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
const core = globalThis.Deno.core;
|
||||
const ops = core.ops;
|
||||
import { FsFile } from "internal:runtime/js/40_files.js";
|
||||
import { readAll } from "internal:runtime/js/12_io.js";
|
||||
import { readAll } from "internal:deno_io/12_io.js";
|
||||
import { pathFromURL } from "internal:runtime/js/06_util.js";
|
||||
import { assert } from "internal:deno_web/00_infra.js";
|
||||
const primordials = globalThis.__bootstrap.primordials;
|
||||
|
|
|
@ -14,7 +14,7 @@ import * as build from "internal:runtime/js/01_build.js";
|
|||
import * as errors from "internal:runtime/js/01_errors.js";
|
||||
import * as version from "internal:runtime/js/01_version.ts";
|
||||
import * as permissions from "internal:runtime/js/10_permissions.js";
|
||||
import * as io from "internal:runtime/js/12_io.js";
|
||||
import * as io from "internal:deno_io/12_io.js";
|
||||
import * as buffer from "internal:runtime/js/13_buffer.js";
|
||||
import * as fs from "internal:runtime/js/30_fs.js";
|
||||
import * as os from "internal:runtime/js/30_os.js";
|
||||
|
|
|
@ -9,6 +9,7 @@ pub use deno_fetch;
|
|||
pub use deno_ffi;
|
||||
pub use deno_flash;
|
||||
pub use deno_http;
|
||||
pub use deno_io;
|
||||
pub use deno_napi;
|
||||
pub use deno_net;
|
||||
pub use deno_node;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
// Some deserializer fields are only used on Unix and Windows build fails without it
|
||||
use super::io::StdFileResource;
|
||||
use super::utils::into_string;
|
||||
use crate::fs_util::canonicalize_path;
|
||||
use deno_core::error::custom_error;
|
||||
|
@ -15,6 +14,7 @@ use deno_core::ResourceId;
|
|||
use deno_core::ZeroCopyBuf;
|
||||
use deno_crypto::rand::thread_rng;
|
||||
use deno_crypto::rand::Rng;
|
||||
use deno_io::StdFileResource;
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
pub mod fs;
|
||||
pub mod fs_events;
|
||||
pub mod http;
|
||||
pub mod io;
|
||||
pub mod os;
|
||||
pub mod permissions;
|
||||
pub mod process;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::io::ChildStderrResource;
|
||||
use super::io::ChildStdinResource;
|
||||
use super::io::ChildStdoutResource;
|
||||
use super::io::StdFileResource;
|
||||
use crate::permissions::PermissionsContainer;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::op;
|
||||
use deno_io::ChildStderrResource;
|
||||
use deno_io::ChildStdinResource;
|
||||
use deno_io::ChildStdoutResource;
|
||||
use deno_io::StdFileResource;
|
||||
|
||||
use deno_core::serde_json;
|
||||
use deno_core::AsyncMutFuture;
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::io::ChildStderrResource;
|
||||
use super::io::ChildStdinResource;
|
||||
use super::io::ChildStdoutResource;
|
||||
use super::process::Stdio;
|
||||
use super::process::StdioOrRid;
|
||||
use crate::permissions::PermissionsContainer;
|
||||
|
@ -13,6 +10,9 @@ use deno_core::OpState;
|
|||
use deno_core::Resource;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::ZeroCopyBuf;
|
||||
use deno_io::ChildStderrResource;
|
||||
use deno_io::ChildStdinResource;
|
||||
use deno_io::ChildStdoutResource;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
use std::borrow::Cow;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use super::io::StdFileResource;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::op;
|
||||
use deno_core::Extension;
|
||||
use deno_core::OpState;
|
||||
use deno_io::StdFileResource;
|
||||
use std::io::Error;
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
use crate::colors;
|
||||
use crate::inspector_server::InspectorServer;
|
||||
use crate::ops;
|
||||
use crate::ops::io::Stdio;
|
||||
use crate::permissions::PermissionsContainer;
|
||||
use crate::tokio_util::run_local;
|
||||
use crate::worker::FormatJsErrorFn;
|
||||
|
@ -33,6 +32,7 @@ use deno_core::RuntimeOptions;
|
|||
use deno_core::SharedArrayBufferStore;
|
||||
use deno_core::Snapshot;
|
||||
use deno_core::SourceMapGetter;
|
||||
use deno_io::Stdio;
|
||||
use deno_node::RequireNpmResolver;
|
||||
use deno_tls::rustls::RootCertStore;
|
||||
use deno_web::create_entangled_message_port;
|
||||
|
@ -426,8 +426,7 @@ impl WebWorker {
|
|||
// Extensions providing Deno.* features
|
||||
ops::fs_events::init(),
|
||||
ops::fs::init::<PermissionsContainer>(),
|
||||
ops::io::init(),
|
||||
ops::io::init_stdio(options.stdio),
|
||||
deno_io::init(options.stdio),
|
||||
deno_tls::init(),
|
||||
deno_net::init::<PermissionsContainer>(
|
||||
options.root_cert_store.clone(),
|
||||
|
|
|
@ -28,6 +28,7 @@ use deno_core::RuntimeOptions;
|
|||
use deno_core::SharedArrayBufferStore;
|
||||
use deno_core::Snapshot;
|
||||
use deno_core::SourceMapGetter;
|
||||
use deno_io::Stdio;
|
||||
use deno_node::RequireNpmResolver;
|
||||
use deno_tls::rustls::RootCertStore;
|
||||
use deno_web::BlobStore;
|
||||
|
@ -35,7 +36,6 @@ use log::debug;
|
|||
|
||||
use crate::inspector_server::InspectorServer;
|
||||
use crate::ops;
|
||||
use crate::ops::io::Stdio;
|
||||
use crate::permissions::PermissionsContainer;
|
||||
use crate::BootstrapOptions;
|
||||
|
||||
|
@ -257,8 +257,7 @@ impl MainWorker {
|
|||
ops::spawn::init(),
|
||||
ops::fs_events::init(),
|
||||
ops::fs::init::<PermissionsContainer>(),
|
||||
ops::io::init(),
|
||||
ops::io::init_stdio(options.stdio),
|
||||
deno_io::init(options.stdio),
|
||||
deno_tls::init(),
|
||||
deno_net::init::<PermissionsContainer>(
|
||||
options.root_cert_store.clone(),
|
||||
|
|
Loading…
Reference in a new issue