From f1ba26661346a83b6e7fe5e7ffeed4553a9571ae Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:37:36 -0700 Subject: fix(node): Don't error out if we fail to statically analyze CJS re-export (#25748) Fixes rsbuild running in deno. You can look at the test to see what was failing, the gist is that we were trying to statically analyze the re-exports of a CJS script, and if we couldn't find the source for the re-exported file we would fail. Instead, we should just treat these as if they were too dynamic to analyze, and let it fail (or succeed) at runtime. This aligns with node's behavior. --- cli/node.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'cli') diff --git a/cli/node.rs b/cli/node.rs index 0fd18e299..766da1c01 100644 --- a/cli/node.rs +++ b/cli/node.rs @@ -125,10 +125,23 @@ impl CjsCodeAnalyzer for CliCjsCodeAnalyzer { let source = match source { Some(source) => source, None => { - self - .fs - .read_text_file_lossy_async(specifier.to_file_path().unwrap(), None) - .await? + if let Ok(path) = specifier.to_file_path() { + if let Ok(source_from_file) = + self.fs.read_text_file_lossy_async(path, None).await + { + source_from_file + } else { + return Ok(ExtNodeCjsAnalysis::Cjs(CjsAnalysisExports { + exports: vec![], + reexports: vec![], + })); + } + } else { + return Ok(ExtNodeCjsAnalysis::Cjs(CjsAnalysisExports { + exports: vec![], + reexports: vec![], + })); + } } }; let analysis = self.inner_cjs_analysis(specifier, &source).await?; -- cgit v1.2.3