diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2023-02-23 10:58:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-23 10:58:10 -0500 |
commit | 344317ec501fa124f0c74b44035fa4516999dce6 (patch) | |
tree | 3a0e4ca3d83b1a47a0903f08648ef1b896b32195 /cli/tsc | |
parent | 214bdbbc2b09ab3f56f0ffe1ad5930d48ec0c76f (diff) |
feat(npm): support bare specifiers from package.json in more subcommands and language server (#17891)
Diffstat (limited to 'cli/tsc')
-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), } } |