aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-07-19 17:37:20 -0700
committerGravatar GitHub <noreply@github.com> 2023-07-19 17:37:20 -0700
commitdd58508684fd37fb04317c90af714403d2a8ba5d (patch)
treefa60c9da0f8d4cde88631072e81e9ba0140c8645
parent9b6dc49575df5fb953918c284505f24741138130 (diff)
downloadbun-dd58508684fd37fb04317c90af714403d2a8ba5d.tar.gz
bun-dd58508684fd37fb04317c90af714403d2a8ba5d.tar.zst
bun-dd58508684fd37fb04317c90af714403d2a8ba5d.zip
Fix browser bundled string_decoder (#3693)
* Fix #3660 * doc fix
-rw-r--r--docs/bundler/index.md14
-rw-r--r--src/node-fallbacks/string_decoder.js3
-rw-r--r--test/bundler/bundler_regressions.test.ts16
3 files changed, 29 insertions, 4 deletions
diff --git a/docs/bundler/index.md b/docs/bundler/index.md
index e0cd36651..da1c3ecae 100644
--- a/docs/bundler/index.md
+++ b/docs/bundler/index.md
@@ -307,7 +307,7 @@ Depending on the target, Bun will apply different module resolution rules and op
---
- `browser`
-- _Default._ For generating bundles that are intended for execution by a browser. Prioritizes the `"browser"` export condition when resolving imports. An error will be thrown if any Node.js or Bun built-ins are imported or used, e.g. `node:fs` or `Bun.serve`.
+- _Default._ For generating bundles that are intended for execution by a browser. Prioritizes the `"browser"` export condition when resolving imports. Importing any built-in modules, like `node:events` or `node:path` will work, but calling some functions, like `fs.readFile` will not work.
---
@@ -1272,7 +1272,17 @@ interface BuildArtifact extends Blob {
sourcemap?: BuildArtifact;
}
-type Loader = "js" | "jsx" | "ts" | "tsx" | "json" | "toml" | "file" | "napi" | "wasm" | "text";
+type Loader =
+ | "js"
+ | "jsx"
+ | "ts"
+ | "tsx"
+ | "json"
+ | "toml"
+ | "file"
+ | "napi"
+ | "wasm"
+ | "text";
interface BuildOutput {
outputs: BuildArtifact[];
diff --git a/src/node-fallbacks/string_decoder.js b/src/node-fallbacks/string_decoder.js
index c6fd8a2fd..0def823f8 100644
--- a/src/node-fallbacks/string_decoder.js
+++ b/src/node-fallbacks/string_decoder.js
@@ -1,2 +1 @@
-export * from "string_decoder";
-export * as default from "string_decoder";
+export { StringDecoder, StringDecoder as default } from "string_decoder";
diff --git a/test/bundler/bundler_regressions.test.ts b/test/bundler/bundler_regressions.test.ts
index 35cf2f8b2..23aa4c73e 100644
--- a/test/bundler/bundler_regressions.test.ts
+++ b/test/bundler/bundler_regressions.test.ts
@@ -180,4 +180,20 @@ describe("bundler", () => {
file: "/entry.js",
},
});
+
+ // https://github.com/oven-sh/bun/issues/3660
+ itBundled("regression/StringDecoder#3660", {
+ files: {
+ "/entry.js": `
+ import { StringDecoder } from 'string_decoder'
+
+ const decoder = new StringDecoder('utf8')
+ const buf = Buffer.from([0xe4, 0xbd, 0xa0, 0xe5, 0xa5, 0xbd])
+ const str = decoder.write(buf)
+
+ console.log(str)
+ `,
+ },
+ run: { stdout: "你好" },
+ });
});