1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 07:44:48 -05:00
denoland-deno/cli/ops/mod.rs
Bartek Iwańczuk b32a6f8ad2
refactor(core): don't use Result in ExtensionBuilder::state (#18066)
There's no point for this API to expect result. If something fails it should
result in a panic during build time to signal to embedder that setup is
wrong.
2023-03-07 22:37:37 +01:00

29 lines
721 B
Rust

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::proc_state::ProcState;
use deno_core::error::AnyError;
use deno_core::op;
use deno_core::Extension;
use deno_core::OpState;
pub mod bench;
pub mod testing;
pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
vec![init_proc_state(ps)]
}
fn init_proc_state(ps: ProcState) -> Extension {
Extension::builder("deno_cli")
.ops(vec![op_npm_process_state::decl()])
.state(move |state| {
state.put(ps.clone());
})
.build()
}
#[op]
fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
let proc_state = state.borrow_mut::<ProcState>();
Ok(proc_state.npm_resolver.get_npm_process_state())
}