summaryrefslogtreecommitdiff
path: root/cli/proc_state.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-02-22 23:21:05 +0100
committerGitHub <noreply@github.com>2023-02-22 23:21:05 +0100
commit1c14127c4f54d815b3e1be48bddd5198dcb33a50 (patch)
tree56dbbea5e9a39fc95d3c722811b47bce08e21b59 /cli/proc_state.rs
parentc18e0d1d37878bb4441f7f8d339cc23ac8e68448 (diff)
feat: support bare specifier resolution with package.json (#17864)
This commit enables resolution of "bare specifiers" (eg. "import express from 'express';") if a "package.json" file is discovered. It's a step towards being able to run projects authored for Node.js without any changes. With this commit we are able to successfully run Vite projects without any changes to the user code. --------- Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'cli/proc_state.rs')
-rw-r--r--cli/proc_state.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/cli/proc_state.rs b/cli/proc_state.rs
index 86af11ec3..9f1e7320c 100644
--- a/cli/proc_state.rs
+++ b/cli/proc_state.rs
@@ -329,6 +329,11 @@ impl ProcState {
self.file_fetcher.clone(),
root_permissions,
dynamic_permissions,
+ self
+ .options
+ .resolve_local_node_modules_folder()
+ .with_context(|| "Resolving local node_modules folder.")?
+ .map(|path| ModuleSpecifier::from_file_path(path).unwrap()),
);
let maybe_imports = self.options.to_maybe_imports()?;
let graph_resolver = self.resolver.as_graph_resolver();
@@ -627,20 +632,25 @@ impl ProcState {
}
/// Creates the default loader used for creating a graph.
- pub fn create_graph_loader(&self) -> cache::FetchCacher {
- cache::FetchCacher::new(
+ pub fn create_graph_loader(&self) -> Result<cache::FetchCacher, AnyError> {
+ Ok(cache::FetchCacher::new(
self.emit_cache.clone(),
self.file_fetcher.clone(),
PermissionsContainer::allow_all(),
PermissionsContainer::allow_all(),
- )
+ self
+ .options
+ .resolve_local_node_modules_folder()
+ .with_context(|| "Resolving local node_modules folder.")?
+ .map(|path| ModuleSpecifier::from_file_path(path).unwrap()),
+ ))
}
pub async fn create_graph(
&self,
roots: Vec<ModuleSpecifier>,
) -> Result<deno_graph::ModuleGraph, AnyError> {
- let mut cache = self.create_graph_loader();
+ let mut cache = self.create_graph_loader()?;
self.create_graph_with_loader(roots, &mut cache).await
}