2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2019-08-14 11:03:02 -04:00
|
|
|
|
2023-04-17 15:36:23 -04:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2023-04-21 21:02:46 -04:00
|
|
|
use crate::npm::CliNpmResolver;
|
2022-09-28 13:04:16 -04:00
|
|
|
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
|
|
|
|
2023-04-21 21:02:46 -04:00
|
|
|
pub fn cli_exts(npm_resolver: Arc<CliNpmResolver>) -> Vec<Extension> {
|
2023-08-05 19:47:15 -04:00
|
|
|
vec![
|
|
|
|
#[cfg(not(feature = "__runtime_js_sources"))]
|
|
|
|
cli::init_ops(npm_resolver),
|
|
|
|
#[cfg(feature = "__runtime_js_sources")]
|
|
|
|
cli::init_ops_and_esm(npm_resolver),
|
|
|
|
]
|
2021-12-29 08:30:08 -05:00
|
|
|
}
|
|
|
|
|
2023-08-05 19:47:15 -04:00
|
|
|
// ESM parts duplicated in `../build.rs`. Keep in sync!
|
|
|
|
deno_core::extension!(cli,
|
|
|
|
deps = [runtime],
|
2023-03-17 14:22:15 -04:00
|
|
|
ops = [op_npm_process_state],
|
2023-08-05 19:47:15 -04:00
|
|
|
esm_entry_point = "ext:cli/99_main.js",
|
|
|
|
esm = [
|
|
|
|
dir "js",
|
|
|
|
"40_testing.js",
|
|
|
|
"99_main.js"
|
|
|
|
],
|
2023-03-17 18:15:27 -04:00
|
|
|
options = {
|
2023-04-21 21:02:46 -04:00
|
|
|
npm_resolver: Arc<CliNpmResolver>,
|
2023-03-17 14:22:15 -04:00
|
|
|
},
|
2023-03-17 18:15:27 -04:00
|
|
|
state = |state, options| {
|
2023-04-17 15:36:23 -04:00
|
|
|
state.put(options.npm_resolver);
|
2023-03-17 14:22:15 -04:00
|
|
|
},
|
2023-08-05 19:47:15 -04:00
|
|
|
customizer = |ext: &mut deno_core::Extension| {
|
|
|
|
ext.esm_files.to_mut().push(deno_core::ExtensionFileSource {
|
|
|
|
specifier: "ext:cli/runtime/js/99_main.js",
|
|
|
|
code: deno_core::ExtensionFileSourceCode::LoadedFromFsDuringSnapshot(
|
|
|
|
deno_runtime::js::PATH_FOR_99_MAIN_JS,
|
|
|
|
),
|
|
|
|
});
|
|
|
|
},
|
2023-03-17 14:22:15 -04:00
|
|
|
);
|
2022-09-28 13:04:16 -04:00
|
|
|
|
|
|
|
#[op]
|
|
|
|
fn op_npm_process_state(state: &mut OpState) -> Result<String, AnyError> {
|
2023-04-21 21:02:46 -04:00
|
|
|
let npm_resolver = state.borrow_mut::<Arc<CliNpmResolver>>();
|
2023-04-17 15:36:23 -04:00
|
|
|
Ok(npm_resolver.get_npm_process_state())
|
2022-09-28 13:04:16 -04:00
|
|
|
}
|