Skip to content

Commit

Permalink
fix .env loader printing to stderr when running bun bun.lockb (oven-s…
Browse files Browse the repository at this point in the history
…h#13905)

Co-authored-by: Jarred Sumner <[email protected]>
  • Loading branch information
snoglobe and Jarred-Sumner authored Sep 12, 2024
1 parent 173f465 commit 043dfa4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ pub const Printer = struct {

const loader = try allocator.create(DotEnv.Loader);
loader.* = DotEnv.Loader.init(map, allocator);
loader.quiet = true;
break :brk loader;
};

Expand Down
58 changes: 58 additions & 0 deletions test/cli/install/bun-lockb.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { file, listen, Socket, spawn } from "bun";
import { tmpdirSync } from "harness";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, setDefaultTimeout, test } from "bun:test";
import { access, mkdir, readlink, rm, writeFile, copyFile } from "fs/promises";
import { bunEnv, bunExe, bunEnv as env, tempDirWithFiles, toBeValidBin, toBeWorkspaceLink, toHaveBins } from "harness";
import { join, sep } from "path";

it("should not print anything to stderr when running bun.lockb", async () => {
const package_dir = tmpdirSync();

// copy bar-0.0.2.tgz to package_dir
await copyFile(join(__dirname, "bar-0.0.2.tgz"), join(package_dir, "bar-0.0.2.tgz"));

// Create a simple package.json
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "test-package",
version: "1.0.0",
dependencies: {
"dummy-package": "file:./bar-0.0.2.tgz",
},
}),
);

// Run 'bun install' to generate the lockfile
const installResult = spawn({
cmd: [bunExe(), "install"],
cwd: package_dir,
env,
});
await installResult.exited;

// Ensure the lockfile was created
await access(join(package_dir, "bun.lockb"));

// create a .env
await writeFile(join(package_dir, ".env"), "FOO=bar");

// Now test 'bun bun.lockb'
const { stdout, stderr, exited } = spawn({
cmd: [bunExe(), "bun.lockb"],
cwd: package_dir,
stdout: "pipe",
stderr: "inherit",
env,
});

const stdoutOutput = await new Response(stdout).text();
expect(stdoutOutput).toBe(
`# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n# yarn lockfile v1\n# bun ./bun.lockb --hash: 8B7A1C2DA8966A48-f4830e6e283fffe9-DE5BD0E91FD9910F-f0bf88071b3f7ec9\n\n\n\"bar@file:./bar-0.0.2.tgz\":\n version \"./bar-0.0.2.tgz\"\n resolved \"./bar-0.0.2.tgz\"\n`,
);

const stderrOutput = await new Response(stderr).text();
expect(stderrOutput).toBe("");

expect(await exited).toBe(0);
});

0 comments on commit 043dfa4

Please sign in to comment.