Skip to content

Conversation

@robobun
Copy link
Collaborator

@robobun robobun commented Nov 8, 2025

Summary

Adds support for fs.mkdtempDisposable() in node:fs/promises and fs.mkdtempDisposableSync() in node:fs.

These functions create temporary directories that automatically clean themselves up when disposed using the await using and using keywords respectively.

Implementation details

  • mkdtempDisposable(): Returns a promise that resolves to a disposable object with:

    • path: The created temporary directory path
    • remove(): Async function to manually remove the directory
    • [Symbol.asyncDispose](): Automatic cleanup for await using
  • mkdtempDisposableSync(): Returns a disposable object with:

    • path: The created temporary directory path
    • remove(): Sync function to manually remove the directory
    • [Symbol.dispose](): Automatic cleanup for using

Both functions stash the full path at creation time to handle process.chdir() correctly, and recursively remove directory contents on disposal.

Test plan

Passing all upstream Node.js tests:

test/js/node/test/parallel/test-fs-promises-mkdtempDisposable.js
test/js/node/test/parallel/test-fs-mkdtempDisposableSync.js

Tests cover:

  • Automatic cleanup with await using and using
  • Manual remove() calls (both sync and async)
  • Encoding options
  • Cleanup of directories with nested contents
  • Error handling

Fixes #24499

🤖 Generated with Claude Code

@robobun
Copy link
Collaborator Author

robobun commented Nov 8, 2025

Updated 12:37 AM PT - Nov 8th, 2025

❌ Your commit 5eb08789 has 6 failures in Build #31330 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 24500

That installs a local version of the PR into your bun-24500 executable, so you can run:

bun-24500 --bun

@github-actions github-actions bot added the claude label Nov 8, 2025
Implements fs.mkdtempDisposable() in node:fs/promises and
fs.mkdtempDisposableSync() in node:fs.

These functions create temporary directories that automatically
clean themselves up when disposed using the `await using` and
`using` keywords respectively.

The returned object has a `path` property containing the created
directory path, a `remove()` method for manual cleanup, and
implements Symbol.asyncDispose (async) or Symbol.dispose (sync)
for automatic cleanup.

Tests:
- test/js/node/test/parallel/test-fs-promises-mkdtempDisposable.js ✅
- test/js/node/test/parallel/test-fs-mkdtempDisposableSync.js ✅

Fixes #24499

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@robobun robobun force-pushed the claude/add-mkdtemp-disposable branch from 0bedabf to 5eb0878 Compare November 8, 2025 05:10
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Warning

Rate limit exceeded

@robobun has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 0bedabf and 5eb0878.

📒 Files selected for processing (4)
  • src/js/node/fs.promises.ts (1 hunks)
  • src/js/node/fs.ts (3 hunks)
  • test/js/node/test/parallel/test-fs-mkdtempDisposableSync.js (1 hunks)
  • test/js/node/test/parallel/test-fs-promises-mkdtempDisposable.js (1 hunks)

Walkthrough

Adds mkdtempDisposable and mkdtempDisposableSync APIs to the filesystem module. These create temporary directories and return disposable objects with cleanup hooks via Symbol.asyncDispose and Symbol.dispose, enabling use with async/sync using statements. Full path resolution ensures cleanup works correctly regardless of working directory changes.

Changes

Cohort / File(s) Summary
Async Disposable API
src/js/node/fs.promises.ts
Introduces mkdtempDisposable(prefix, options) exported function that wraps mkdtemp, returns an object with path, remove() method, and [SymbolAsyncDispose]() hook for automatic cleanup via fs.rm with recursive removal.
Sync Disposable API
src/js/node/fs.ts
Introduces mkdtempDisposableSync(prefix, options) function that wraps mkdtempSync, returns an object with path, remove() method, and [Symbol.dispose]() hook for synchronous cleanup via fs.rmSync. Added to module exports and name registry.
Test Coverage
test/regression/issue/24499.test.ts
Comprehensive test suite covering both async and sync disposable APIs with using statement syntax, manual cleanup via remove(), encoding options, nested directory cleanup, and path validation.

Pre-merge checks

✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding two new disposable mkdtemp APIs (async and sync variants) to the fs module.
Description check ✅ Passed The PR description covers both required template sections: 'What does this PR do?' with detailed implementation details and 'How did you verify your code works?' with a comprehensive test plan.
Linked Issues check ✅ Passed The implementation fully addresses issue #24499 by providing mkdtempDisposable() in node:fs/promises and mkdtempDisposableSync() in node:fs, matching Node.js v24 API surface with proper disposal symbol support.
Out of Scope Changes check ✅ Passed All changes are directly in scope: two new disposable mkdtemp APIs in fs.promises and fs modules, plus comprehensive regression tests. No unrelated modifications detected.

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.mkdtempDisposable() not found in module node:fs/promises

2 participants