This commit is contained in:
Jarred Sumner
2025-04-10 14:58:46 -07:00
committed by GitHub
parent 27f83c38af
commit f575d3ff24
2 changed files with 38 additions and 2 deletions

View File

@@ -1689,10 +1689,11 @@ fn NewPrinter(
.bun => {
if (record.kind == .dynamic) {
p.print("Promise.resolve(globalThis.Bun)");
} else if (record.kind == .require) {
return;
} else if (record.kind == .require or record.kind == .stmt) {
p.print("globalThis.Bun");
return;
}
return;
},
.bun_test => {
if (record.kind == .dynamic) {

View File

@@ -3,6 +3,41 @@ import { describe, expect } from "bun:test";
import { itBundled } from "./expectBundled";
describe("bundler", () => {
// https://github.com/oven-sh/bun/issues/18899
itBundled("bun/import-bun-format-cjs", {
target: "bun",
format: "cjs",
bytecode: true,
outdir: "/out",
files: {
"/entry.ts": /* js */ `
import {RedisClient} from 'bun';
import * as BunStar from 'bun';
const bunRequire = require("bun");
if (RedisClient.name !== "RedisClient") {
throw new Error("RedisClient.name is not RedisClient");
}
if (BunStar.RedisClient.name !== "RedisClient") {
throw new Error("BunStar.RedisClient.name is not RedisClient");
}
if (bunRequire.RedisClient.name !== "RedisClient") {
throw new Error("bunRequire.RedisClient.name is not RedisClient");
}
console.log(RedisClient.name);
console.log(BunStar.RedisClient.name);
console.log(bunRequire.RedisClient.name);
export class RedisCache {
constructor(config: any) {
this.connectServer(config);
}
}
`,
},
run: { stdout: "RedisClient\nRedisClient\nRedisClient\n" },
});
itBundled("bun/embedded-sqlite-file", {
target: "bun",
outfile: "",