Fix browser bundled string_decoder (#3693)

* Fix #3660

* doc fix
This commit is contained in:
dave caruso
2023-07-19 17:37:20 -07:00
committed by GitHub
parent 9b6dc49575
commit dd58508684
3 changed files with 29 additions and 4 deletions

View File

@@ -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[];

View File

@@ -1,2 +1 @@
export * from "string_decoder";
export * as default from "string_decoder";
export { StringDecoder, StringDecoder as default } from "string_decoder";

View File

@@ -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: "你好" },
});
});