mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(cli): migrate run and cache to new infrastructure (#7996)
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This commit is contained in:
parent
9fa59f0ca8
commit
7e2c7fb6c5
48 changed files with 1181 additions and 1299 deletions
|
@ -83,7 +83,7 @@ impl ModuleLoader for CliModuleLoader {
|
|||
op_state: Rc<RefCell<OpState>>,
|
||||
module_specifier: &ModuleSpecifier,
|
||||
maybe_referrer: Option<ModuleSpecifier>,
|
||||
_is_dyn_import: bool,
|
||||
_is_dynamic: bool,
|
||||
) -> Pin<Box<deno_core::ModuleSourceFuture>> {
|
||||
let module_specifier = module_specifier.to_owned();
|
||||
let module_url_specified = module_specifier.to_string();
|
||||
|
@ -92,11 +92,10 @@ impl ModuleLoader for CliModuleLoader {
|
|||
state.borrow::<Arc<ProgramState>>().clone()
|
||||
};
|
||||
|
||||
// TODO(bartlomieju): `fetch_compiled_module` should take `load_id` param
|
||||
// TODO(@kitsonk) this shouldn't be async
|
||||
let fut = async move {
|
||||
let compiled_module = program_state
|
||||
.fetch_compiled_module(module_specifier, maybe_referrer)
|
||||
.await?;
|
||||
.fetch_compiled_module(module_specifier, maybe_referrer)?;
|
||||
Ok(deno_core::ModuleSource {
|
||||
// Real module name, might be different from initial specifier
|
||||
// due to redirections.
|
||||
|
@ -113,44 +112,28 @@ impl ModuleLoader for CliModuleLoader {
|
|||
&self,
|
||||
op_state: Rc<RefCell<OpState>>,
|
||||
_load_id: ModuleLoadId,
|
||||
module_specifier: &ModuleSpecifier,
|
||||
maybe_referrer: Option<String>,
|
||||
is_dyn_import: bool,
|
||||
specifier: &ModuleSpecifier,
|
||||
_maybe_referrer: Option<String>,
|
||||
is_dynamic: bool,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), AnyError>>>> {
|
||||
let module_specifier = module_specifier.clone();
|
||||
let specifier = specifier.clone();
|
||||
let target_lib = self.target_lib.clone();
|
||||
let maybe_import_map = self.import_map.clone();
|
||||
let state = op_state.borrow();
|
||||
|
||||
// Only "main" module is loaded without permission check,
|
||||
// ie. module that is associated with "is_main" state
|
||||
// and is not a dynamic import.
|
||||
let permissions = if self.is_main && !is_dyn_import {
|
||||
Permissions::allow_all()
|
||||
} else {
|
||||
state.borrow::<Permissions>().clone()
|
||||
};
|
||||
// The permissions that should be applied to any dynamically imported module
|
||||
let dynamic_permissions = state.borrow::<Permissions>().clone();
|
||||
let program_state = state.borrow::<Arc<ProgramState>>().clone();
|
||||
drop(state);
|
||||
|
||||
// TODO(bartlomieju): I'm not sure if it's correct to ignore
|
||||
// bad referrer - this is the case for `Deno.core.evalContext()` where
|
||||
// `ref_str` is `<unknown>`.
|
||||
let maybe_referrer = if let Some(ref_str) = maybe_referrer {
|
||||
ModuleSpecifier::resolve_url(&ref_str).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// TODO(bartlomieju): `prepare_module_load` should take `load_id` param
|
||||
async move {
|
||||
program_state
|
||||
.prepare_module_load(
|
||||
module_specifier,
|
||||
maybe_referrer,
|
||||
specifier,
|
||||
target_lib,
|
||||
permissions,
|
||||
is_dyn_import,
|
||||
dynamic_permissions,
|
||||
is_dynamic,
|
||||
maybe_import_map,
|
||||
)
|
||||
.await
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue