mirror of
https://github.com/denoland/deno.git
synced 2024-10-29 08:58:01 -04:00
e55b448730
This implements two macros to simplify extension registration and centralize a lot of the boilerplate as a base for future improvements: * `deno_core::ops!` registers a block of `#[op]`s, optionally with type parameters, useful for places where we share lists of ops * `deno_core::extension!` is used to register an extension, and creates two methods that can be used at runtime/snapshot generation time: `init_ops` and `init_ops_and_esm`. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
30 lines
672 B
Rust
30 lines
672 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![deno_cli::init_ops(ps)]
|
|
}
|
|
|
|
deno_core::extension!(deno_cli,
|
|
ops = [op_npm_process_state],
|
|
config = {
|
|
ps: ProcState,
|
|
},
|
|
state = |state, ps| {
|
|
state.put(ps);
|
|
},
|
|
);
|
|
|
|
#[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())
|
|
}
|