mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
feat(npm): support bare specifiers from package.json in more subcommands and language server (#17891)
This commit is contained in:
parent
214bdbbc2b
commit
344317ec50
41 changed files with 472 additions and 95 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue