Skip to content

Commit

Permalink
fix: set different file modes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jbergstroem committed Dec 31, 2024
1 parent af9f6d2 commit fa1221e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions test/cli/install/bun-lock.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn } from "bun";
import { expect, it } from "bun:test";
import { access, copyFile, open, writeFile } from "fs/promises";
import { bunExe, bunEnv as env, tmpdirSync } from "harness";
import { bunExe, bunEnv as env, isWindows, tmpdirSync } from "harness";
import { join } from "path";

it("should write plaintext lockfiles", async () => {
Expand Down Expand Up @@ -36,8 +36,14 @@ it("should write plaintext lockfiles", async () => {
// Assert that the lockfile has the correct permissions
const file = await open(join(package_dir, "bun.lock"), "r");
const stat = await file.stat();
// 0o644 == 33188
expect(stat.mode).toBe(33188);

// in unix, 0o644 == 33188
let mode = 33188;
// ..but windows is different
if (isWindows) {
mode = 33206;
}
expect(stat.mode).toBe(mode);

expect(await file.readFile({ encoding: "utf8" })).toEqual(
`{\n \"lockfileVersion\": 0,\n \"workspaces\": {\n \"\": {\n \"dependencies\": {\n \"dummy-package\": \"file:./bar-0.0.2.tgz\",\n },\n },\n },\n \"packages\": {\n \"dummy-package\": [\"bar@./bar-0.0.2.tgz\", {}],\n }\n}\n`,
Expand Down
12 changes: 9 additions & 3 deletions test/cli/install/bun-lockb.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { spawn } from "bun";
import { expect, it } from "bun:test";
import { access, copyFile, open, writeFile } from "fs/promises";
import { bunExe, bunEnv as env, tmpdirSync } from "harness";
import { bunExe, bunEnv as env, isWindows, tmpdirSync } from "harness";
import { join } from "path";

it("should not print anything to stderr when running bun.lockb", async () => {
Expand Down Expand Up @@ -36,8 +36,14 @@ it("should not print anything to stderr when running bun.lockb", async () => {
// Assert that the lockfile has the correct permissions
const file = await open(join(package_dir, "bun.lockb"), "r");
const stat = await file.stat();
// 0o755 == 33261
expect(stat.mode).toBe(33261);

// in unix, 0o755 == 33261
let mode = 33261;
// ..but windows is different
if(isWindows) {
mode = 33206;
}
expect(stat.mode).toBe(mode);

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

0 comments on commit fa1221e

Please sign in to comment.