diff options
Diffstat (limited to 'cli/tsc/mod.rs')
-rw-r--r-- | cli/tsc/mod.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index cc6350642..b296bf9c6 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -556,7 +556,17 @@ fn op_load(state: &mut OpState, args: Value) -> Result<Value, AnyError> { media_type = MediaType::Json; Some(Cow::Borrowed(&*module.source)) } - Module::External(_) | Module::Npm(_) | Module::Node(_) => None, + Module::Npm(_) | Module::Node(_) => None, + Module::External(module) => { + // means it's Deno code importing an npm module + media_type = MediaType::from(&module.specifier); + let file_path = specifier.to_file_path().unwrap(); + let code = + std::fs::read_to_string(&file_path).with_context(|| { + format!("Unable to load {}", file_path.display()) + })?; + Some(Cow::Owned(code)) + } } } else if state .maybe_npm_resolver @@ -718,7 +728,16 @@ fn resolve_graph_specifier_types( Ok(None) } } - Some(Module::External(_) | Module::Node(_)) | None => Ok(None), + Some(Module::External(module)) => { + // we currently only use "External" for when the module is in an npm package + Ok(state.maybe_npm_resolver.as_ref().map(|npm_resolver| { + NodeResolution::into_specifier_and_media_type( + node::url_to_node_resolution(module.specifier.clone(), npm_resolver) + .ok(), + ) + })) + } + Some(Module::Node(_)) | None => Ok(None), } } |