Skip to content

Commit 287a02c

Browse files
joyeecheungrichardlau
authored andcommitted
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: #51617 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent f871bc6 commit 287a02c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/internal/fs/promises.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const {
4343
aggregateTwoErrors,
4444
} = require('internal/errors');
4545
const { isArrayBufferView } = require('internal/util/types');
46-
const { rimrafPromises } = require('internal/fs/rimraf');
46+
4747
const {
4848
constants: {
4949
kIoMaxLength,
@@ -92,6 +92,7 @@ const {
9292
kEmptyObject,
9393
lazyDOMException,
9494
promisify,
95+
getLazy,
9596
} = require('internal/util');
9697
const { EventEmitterMixin } = require('internal/event_target');
9798
const { StringDecoder } = require('string_decoder');
@@ -135,6 +136,8 @@ function lazyFsStreams() {
135136
return fsStreams ??= require('internal/fs/streams');
136137
}
137138

139+
const lazyRimRaf = getLazy(() => require('internal/fs/rimraf').rimrafPromises);
140+
138141
class FileHandle extends EventEmitterMixin(JSTransferable) {
139142
/**
140143
* @param {InternalFSBinding.FileHandle | undefined} filehandle
@@ -749,7 +752,7 @@ async function ftruncate(handle, len = 0) {
749752
async function rm(path, options) {
750753
path = pathModule.toNamespacedPath(getValidatedPath(path));
751754
options = await validateRmOptionsPromise(path, options, false);
752-
return rimrafPromises(path, options);
755+
return lazyRimRaf()(path, options);
753756
}
754757

755758
async function rmdir(path, options) {
@@ -760,7 +763,7 @@ async function rmdir(path, options) {
760763
emitRecursiveRmdirWarning();
761764
const stats = await stat(path);
762765
if (stats.isDirectory()) {
763-
return rimrafPromises(path, options);
766+
return lazyRimRaf()(path, options);
764767
}
765768
}
766769

0 commit comments

Comments
 (0)