Skip to content

Implement missing opendir API methods#1108

Merged
streamich merged 5 commits intomasterfrom
copilot/fix-663
Jul 25, 2025
Merged

Implement missing opendir API methods#1108
streamich merged 5 commits intomasterfrom
copilot/fix-663

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jul 25, 2025

This PR implements the missing opendir API methods that were requested in issue #663. All variants of the Node.js opendir method are now available on the fs export:

  • fs.opendir(path[, options], callback)
  • fs.opendirSync(path[, options])
  • fs.promises.opendir(path[, options]) (was already working)

Root Cause

The opendir functionality was already fully implemented in the Volume class, including:

  • opendirBase() - Core implementation
  • opendir() - Callback version
  • opendirSync() - Synchronous version
  • Dir class - Complete fs.Dir implementation
  • ✅ Promise support via FsPromises class

However, the callback and synchronous methods were not exposed in the fs export because they were missing from the API binding lists.

Changes Made

Fixed the API exposure by adding the missing methods to the binding lists:

  • Added 'opendir' to fsCallbackApiList.ts
  • Added 'opendirSync' to fsSynchronousApiList.ts

Added comprehensive tests in src/__tests__/volume/opendir.test.ts to verify:

  • All three API variants work correctly
  • Options parameter support (encoding, bufferSize, recursive)
  • Proper fs.Dir object interface
  • Integration with the main fs export

API Compliance

All implementations fully comply with the Node.js fs API specification:

// Callback version
fs.opendir('/path', { encoding: 'utf8' }, (err, dir) => {
  // Handle directory operations
});

// Synchronous version  
const dir = fs.opendirSync('/path', { bufferSize: 32 });

// Promise version
const dir = await fs.promises.opendir('/path');

The returned fs.Dir objects provide all required methods: read(), readSync(), close(), closeSync(), and async iteration support.

Testing

  • ✅ All existing tests continue to pass (54 test suites, 1006 tests)
  • ✅ Added 5 new tests specifically for opendir functionality
  • ✅ Verified API compliance with Node.js specification
  • ✅ Tested all option parameters and edge cases

Fixes #663.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 25, 2025 16:20
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement opendir API Implement missing opendir API methods Jul 25, 2025
Copilot AI requested a review from streamich July 25, 2025 16:27
Comment thread yarn.lock
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert changes to yarn.lock.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted yarn.lock changes as requested in commit e48fb6d. The opendir functionality remains intact and all tests pass.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copilot AI requested a review from streamich July 25, 2025 16:38
Copy link
Copy Markdown
Owner

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier check yarn prettier:check is failing, run yarn prettier to reformat codebase.

Commitlint CI check is failing, submit your PR using Angular-style commit mesasges, like feat: implemented such an such.

Co-authored-by: streamich <9773803+streamich@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jul 25, 2025

Prettier check yarn prettier:check is failing, run yarn prettier to reformat codebase.

Commitlint CI check is failing, submit your PR using Angular-style commit mesasges, like `feat: implemente...

Fixed prettier formatting issues and updated to use Angular-style commit messages as requested. The yarn prettier:check now passes and all tests continue to work. Changes applied in commit 432a35d.

Copilot AI requested a review from streamich July 25, 2025 16:57
@streamich streamich marked this pull request as ready for review July 25, 2025 17:11
Copy link
Copy Markdown
Owner

@streamich streamich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@streamich streamich merged commit 7412d71 into master Jul 25, 2025
12 of 13 checks passed
@streamich streamich deleted the copilot/fix-663 branch July 25, 2025 17:14
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 4.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

Implement opendir API

2 participants