2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2019-08-14 11:03:02 -04:00
|
|
|
|
2021-12-29 08:30:08 -05:00
|
|
|
use crate::proc_state::ProcState;
|
2022-09-28 13:04:16 -04:00
|
|
|
use deno_core::anyhow::bail;
|
|
|
|
use deno_core::error::AnyError;
|
|
|
|
use deno_core::op;
|
2021-12-29 08:30:08 -05:00
|
|
|
use deno_core::Extension;
|
2022-09-28 13:04:16 -04:00
|
|
|
use deno_core::OpState;
|
2021-12-29 08:30:08 -05:00
|
|
|
|
2022-03-11 17:07:02 -05:00
|
|
|
pub mod bench;
|
2021-04-28 14:17:04 -04:00
|
|
|
pub mod testing;
|
2020-09-10 09:57:45 -04:00
|
|
|
|
2022-05-17 13:50:31 -04:00
|
|
|
pub fn cli_exts(ps: ProcState) -> Vec<Extension> {
|
|
|
|
vec![init_proc_state(ps)]
|
2021-12-29 08:30:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn init_proc_state(ps: ProcState) -> Extension {
|
|
|
|
Extension::builder()
|
2022-09-28 13:04:16 -04:00
|
|
|
.ops(vec![op_npm_process_state::decl()])
|
2021-12-29 08:30:08 -05:00
|
|
|
.state(move |state| {
|
|
|
|
state.put(ps.clone());
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.build()
|
|
|
|
}
|
2022-09-28 13:04:16 -04:00
|
|
|
|
|
|
|
#[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())
|
|
|
|
}
|