feat(npm): support bare specifiers from package.json in more subcommands and language server (#17891)

This commit is contained in:
David Sherret 2023-02-23 10:58:10 -05:00 committed by GitHub
parent 214bdbbc2b
commit 344317ec50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 472 additions and 95 deletions

View file

@ -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),
}
}