node/lib/vfs.js
Matteo Collina c9562ddb82
vfs: add minimal node:vfs subsystem
Adds the node:vfs builtin module with VirtualFileSystem and
provider classes. No integration with fs, modules, or SEA.

Assisted-by: Claude-Opus4.7
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: https://github.com/nodejs/node/pull/63115
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2026-05-23 18:43:31 +00:00

37 lines
1.2 KiB
JavaScript

'use strict';
const {
FunctionPrototypeSymbolHasInstance,
} = primordials;
const { VirtualFileSystem } = require('internal/vfs/file_system');
const { VirtualProvider } = require('internal/vfs/provider');
const { MemoryProvider } = require('internal/vfs/providers/memory');
const { RealFSProvider } = require('internal/vfs/providers/real');
/**
* Creates a new VirtualFileSystem instance.
* @param {VirtualProvider} [provider] The provider to use (defaults to MemoryProvider)
* @param {object} [options] Configuration options
* @param {boolean} [options.moduleHooks] Whether to enable require/import hooks (default: true)
* @param {boolean} [options.virtualCwd] Whether to enable virtual working directory
* @returns {VirtualFileSystem}
*/
function create(provider, options) {
// Handle case where first arg is options (no provider)
if (provider != null &&
!FunctionPrototypeSymbolHasInstance(VirtualProvider, provider) &&
typeof provider === 'object') {
options = provider;
provider = undefined;
}
return new VirtualFileSystem(provider, options);
}
module.exports = {
create,
VirtualFileSystem,
VirtualProvider,
MemoryProvider,
RealFSProvider,
};