Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/bun-types/bun.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4551,6 +4551,16 @@ declare module "bun" {
* @default true
*/
shared?: boolean;
/**
* Byte offset into the file where the mapping starts.
* @default 0
*/
offset?: number;
/**
* Maximum number of bytes to map. Clamped to the file size
* (minus `offset`). Defaults to mapping the rest of the file.
*/
size?: number;
}
/**
* Open a file as a live-updating `Uint8Array` without copying memory
Expand Down
31 changes: 31 additions & 0 deletions test/integration/bun-types/bun-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@
});
});

// Runs on debug builds too: spawning tsc over a single file is cheap,
// unlike the in-process LanguageService runs above.
describe("Bun.mmap", () => {
test("MMapOptions accepts offset and size", async () => {
const checkDir = join(TEMP_DIR, "mmap-options-check");
const tsconfig = structuredClone(sourceTsconfig);
tsconfig.include = ["mmap-options.ts"];
tsconfig.compilerOptions.typeRoots = [join(BASE_FIXTURE_DIR, "node_modules", "@types")];
await mkdir(checkDir, { recursive: true });
await makeTree(checkDir, {
"tsconfig.json": JSON.stringify(tsconfig, null, 2),
"mmap-options.ts": `const view = Bun.mmap("./data.bin", { shared: true, sync: false, offset: 4096, size: 1024 });
view satisfies Uint8Array<ArrayBuffer>;`,
});

await using proc = Bun.spawn({
cmd: [bunExe(), join(BASE_FIXTURE_DIR, "node_modules", "typescript", "bin", "tsc"), "-p", "."],
env: bunEnv,
cwd: checkDir,
stdout: "pipe",
stderr: "pipe",
});

const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(stderr.trim()).toBe("");
expect(stdout.trim()).toBe("");
expect(exitCode).toBe(0);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}, 60_000);

Check warning on line 389 in test/integration/bun-types/bun-types.test.ts

View check run for this annotation

Claude / Claude Code Review

Explicit per-test timeout violates test/CLAUDE.md convention

Per `test/CLAUDE.md` ("**CRITICAL**: Do not set a timeout on tests. Bun already has timeouts.") and REVIEW.md ("Don't raise per-test timeouts to make a slow test pass"), drop the trailing `, 60_000` here — the sibling tsgo spawn test just above does comparable spawned-tsc work and doesn't set one, and this is now the only test in `test/integration/` with an explicit per-test timeout.
Comment thread
robobun marked this conversation as resolved.
Outdated
});

describe("Test Globals", () => {
const code = `
const test_shouldBeAFunction: Function = test;
Expand Down
11 changes: 11 additions & 0 deletions test/integration/bun-types/fixture/bun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ tsd
}),
)
.is<Promise<boolean>>();

tsd
.expectType(
Bun.mmap("./data.bin", {
shared: true,
sync: false,
offset: 4096,
size: 1024,
}),
)
.is<Uint8Array<ArrayBuffer>>();
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Loading