diff options
Diffstat (limited to 'cli')
-rw-r--r-- | cli/factory.rs | 3 | ||||
-rw-r--r-- | cli/node.rs | 18 | ||||
-rw-r--r-- | cli/standalone/mod.rs | 3 |
3 files changed, 18 insertions, 6 deletions
diff --git a/cli/factory.rs b/cli/factory.rs index cb835181c..330865744 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -475,7 +475,8 @@ impl CliFactory { let caches = self.caches()?; let node_analysis_cache = NodeAnalysisCache::new(caches.node_analysis_db()); - let cjs_esm_analyzer = CliCjsCodeAnalyzer::new(node_analysis_cache); + let cjs_esm_analyzer = + CliCjsCodeAnalyzer::new(node_analysis_cache, self.fs().clone()); Ok(Arc::new(NodeCodeTranslator::new( cjs_esm_analyzer, diff --git a/cli/node.rs b/cli/node.rs index 75e0d9ef9..2a9a84ef9 100644 --- a/cli/node.rs +++ b/cli/node.rs @@ -1,9 +1,12 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +use std::borrow::Cow; + use deno_ast::CjsAnalysis; use deno_ast::MediaType; use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; +use deno_runtime::deno_fs; use deno_runtime::deno_node::analyze::CjsAnalysis as ExtNodeCjsAnalysis; use deno_runtime::deno_node::analyze::CjsCodeAnalyzer; use deno_runtime::deno_node::analyze::NodeCodeTranslator; @@ -34,11 +37,12 @@ pub fn resolve_specifier_into_node_modules( pub struct CliCjsCodeAnalyzer { cache: NodeAnalysisCache, + fs: deno_fs::FileSystemRc, } impl CliCjsCodeAnalyzer { - pub fn new(cache: NodeAnalysisCache) -> Self { - Self { cache } + pub fn new(cache: NodeAnalysisCache, fs: deno_fs::FileSystemRc) -> Self { + Self { cache, fs } } fn inner_cjs_analysis( @@ -83,9 +87,15 @@ impl CjsCodeAnalyzer for CliCjsCodeAnalyzer { fn analyze_cjs( &self, specifier: &ModuleSpecifier, - source: &str, + source: Option<&str>, ) -> Result<ExtNodeCjsAnalysis, AnyError> { - let analysis = self.inner_cjs_analysis(specifier, source)?; + let source = match source { + Some(source) => Cow::Borrowed(source), + None => { + Cow::Owned(self.fs.read_to_string(&specifier.to_file_path().unwrap())?) + } + }; + let analysis = self.inner_cjs_analysis(specifier, &source)?; Ok(ExtNodeCjsAnalysis { exports: analysis.exports, reexports: analysis.reexports, diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index d08df4b12..dfa71cf6f 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -366,7 +366,8 @@ pub async fn run( let cjs_resolutions = Arc::new(CjsResolutionStore::default()); let cache_db = Caches::new(deno_dir_provider.clone()); let node_analysis_cache = NodeAnalysisCache::new(cache_db.node_analysis_db()); - let cjs_esm_code_analyzer = CliCjsCodeAnalyzer::new(node_analysis_cache); + let cjs_esm_code_analyzer = + CliCjsCodeAnalyzer::new(node_analysis_cache, fs.clone()); let node_code_translator = Arc::new(NodeCodeTranslator::new( cjs_esm_code_analyzer, fs.clone(), |