mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
fs: load rimraf lazily in fs/promises
Avoid the potential circular dependency and make fs/promises load faster when rimraf is not used. PR-URL: https://github.com/nodejs/node/pull/51617 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
f871bc6ddc
commit
287a02c4b2
1 file changed
+6
-3
@@ -43,7 +43,7 @@ const {
|
||||
aggregateTwoErrors,
|
||||
} = require('internal/errors');
|
||||
const { isArrayBufferView } = require('internal/util/types');
|
||||
const { rimrafPromises } = require('internal/fs/rimraf');
|
||||
|
||||
const {
|
||||
constants: {
|
||||
kIoMaxLength,
|
||||
@@ -92,6 +92,7 @@ const {
|
||||
kEmptyObject,
|
||||
lazyDOMException,
|
||||
promisify,
|
||||
getLazy,
|
||||
} = require('internal/util');
|
||||
const { EventEmitterMixin } = require('internal/event_target');
|
||||
const { StringDecoder } = require('string_decoder');
|
||||
@@ -135,6 +136,8 @@ function lazyFsStreams() {
|
||||
return fsStreams ??= require('internal/fs/streams');
|
||||
}
|
||||
|
||||
const lazyRimRaf = getLazy(() => require('internal/fs/rimraf').rimrafPromises);
|
||||
|
||||
class FileHandle extends EventEmitterMixin(JSTransferable) {
|
||||
/**
|
||||
* @param {InternalFSBinding.FileHandle | undefined} filehandle
|
||||
@@ -749,7 +752,7 @@ async function ftruncate(handle, len = 0) {
|
||||
async function rm(path, options) {
|
||||
path = pathModule.toNamespacedPath(getValidatedPath(path));
|
||||
options = await validateRmOptionsPromise(path, options, false);
|
||||
return rimrafPromises(path, options);
|
||||
return lazyRimRaf()(path, options);
|
||||
}
|
||||
|
||||
async function rmdir(path, options) {
|
||||
@@ -760,7 +763,7 @@ async function rmdir(path, options) {
|
||||
emitRecursiveRmdirWarning();
|
||||
const stats = await stat(path);
|
||||
if (stats.isDirectory()) {
|
||||
return rimrafPromises(path, options);
|
||||
return lazyRimRaf()(path, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user