mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Enable node:vfs by default. --no-experimental-vfs disables node:vfs exposure and --vfs-load. Assisted-by: pi Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/66318 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>
58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
FunctionPrototypeSymbolHasInstance,
|
|
} = primordials;
|
|
|
|
const { emitExperimentalWarning } = require('internal/util');
|
|
emitExperimentalWarning('VirtualFileSystem');
|
|
|
|
const { VirtualFileSystem } = require('internal/vfs/file_system');
|
|
const { VirtualProvider } = require('internal/vfs/provider');
|
|
const { MemoryProvider } = require('internal/vfs/providers/memory');
|
|
const { ComposableProvider } = require('internal/vfs/providers/composable');
|
|
const { RealFSProvider } = require('internal/vfs/providers/real');
|
|
const { ZipProvider } = require('internal/vfs/providers/ziparchive');
|
|
const { registerProvider } = require('internal/vfs/provider_registry');
|
|
const { getVfsRoot } = require('internal/vfs/router');
|
|
|
|
/**
|
|
* 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);
|
|
}
|
|
|
|
/**
|
|
* Returns the directory that holds the mount points of every mounted virtual
|
|
* file system.
|
|
* @returns {string} The absolute path of the reserved root directory
|
|
*/
|
|
function vfsBase() {
|
|
return getVfsRoot();
|
|
}
|
|
|
|
module.exports = {
|
|
create,
|
|
vfsBase,
|
|
registerProvider,
|
|
VirtualFileSystem,
|
|
VirtualProvider,
|
|
MemoryProvider,
|
|
ComposableProvider,
|
|
RealFSProvider,
|
|
ZipProvider,
|
|
};
|