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. --- tests/specs/run/cjs_reexport_non_analyzable/__test__.jsonc | 9 +++++++++ tests/specs/run/cjs_reexport_non_analyzable/deno.json | 3 +++ tests/specs/run/cjs_reexport_non_analyzable/main.ts | 3 +++ tests/specs/run/cjs_reexport_non_analyzable/node_modules/foo.cjs | 5 +++++ 4 files changed, 20 insertions(+) create mode 100644 tests/specs/run/cjs_reexport_non_analyzable/__test__.jsonc create mode 100644 tests/specs/run/cjs_reexport_non_analyzable/deno.json create mode 100644 tests/specs/run/cjs_reexport_non_analyzable/main.ts create mode 100644 tests/specs/run/cjs_reexport_non_analyzable/node_modules/foo.cjs (limited to 'tests/specs') diff --git a/tests/specs/run/cjs_reexport_non_analyzable/__test__.jsonc b/tests/specs/run/cjs_reexport_non_analyzable/__test__.jsonc new file mode 100644 index 000000000..81f29b685 --- /dev/null +++ b/tests/specs/run/cjs_reexport_non_analyzable/__test__.jsonc @@ -0,0 +1,9 @@ +{ + "tempDir": true, + "steps": [ + { + "args": "run -A main.ts", + "output": "" + } + ] +} diff --git a/tests/specs/run/cjs_reexport_non_analyzable/deno.json b/tests/specs/run/cjs_reexport_non_analyzable/deno.json new file mode 100644 index 000000000..fde86a1ef --- /dev/null +++ b/tests/specs/run/cjs_reexport_non_analyzable/deno.json @@ -0,0 +1,3 @@ +{ + "nodeModulesDir": "manual" +} diff --git a/tests/specs/run/cjs_reexport_non_analyzable/main.ts b/tests/specs/run/cjs_reexport_non_analyzable/main.ts new file mode 100644 index 000000000..a9e32af4e --- /dev/null +++ b/tests/specs/run/cjs_reexport_non_analyzable/main.ts @@ -0,0 +1,3 @@ +import assert from "./node_modules/foo.cjs"; + +assert.equal(1 + 1, 2); diff --git a/tests/specs/run/cjs_reexport_non_analyzable/node_modules/foo.cjs b/tests/specs/run/cjs_reexport_non_analyzable/node_modules/foo.cjs new file mode 100644 index 000000000..924d8a96a --- /dev/null +++ b/tests/specs/run/cjs_reexport_non_analyzable/node_modules/foo.cjs @@ -0,0 +1,5 @@ +try { + module.exports = require("nonexistent"); +} catch(_e) { + module.exports = require("assert"); +} -- cgit v1.2.3