summaryrefslogtreecommitdiff
path: root/cli/ops/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-09-28 13:04:16 -0400
committerGitHub <noreply@github.com>2022-09-28 13:04:16 -0400
commitd677ba67f50e5edb0491d8ed1e4171473d662081 (patch)
tree9f8740666298ac8e1041fa3e169d8f3a9e074448 /cli/ops/mod.rs
parent23125b275f282f96a6316d11f97e5603dab0d009 (diff)
feat(npm): functionality to support child_process.fork (#15891)
Diffstat (limited to 'cli/ops/mod.rs')
-rw-r--r--cli/ops/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index 98029ab44..df3331353 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -1,7 +1,11 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use crate::proc_state::ProcState;
+use deno_core::anyhow::bail;
+use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::Extension;
+use deno_core::OpState;
pub mod bench;
pub mod testing;
@@ -12,9 +16,21 @@ pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
fn init_proc_state(ps: ProcState) -> Extension {
Extension::builder()
+ .ops(vec![op_npm_process_state::decl()])
.state(move |state| {
state.put(ps.clone());
Ok(())
})
.build()
}
+
+#[op]
+fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
+ let proc_state = state.borrow_mut::<ProcState>();
+ if !proc_state.options.unstable() {
+ bail!(
+ "Unstable use of npm process state. The --unstable flag must be provided."
+ )
+ }
+ Ok(proc_state.npm_resolver.get_npm_process_state())
+}