Skip to content

Commit 5a8af3d

Browse files
joyeecheungtargos
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 <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>
1 parent 8235c26 commit 5a8af3d

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎lib/internal/fs/promises.js‎

Lines changed: 6 additions & 3 deletions
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,
@@ -93,6 +93,7 @@ const {
9393
kEmptyObject,
9494
lazyDOMException,
9595
promisify,
96+
getLazy,
9697
}=require('internal/util');
9798
constEventEmitter=require('events');
9899
const{ StringDecoder }=require('string_decoder');
@@ -136,6 +137,8 @@ function lazyFsStreams() {
136137
returnfsStreams??=require('internal/fs/streams');
137138
}
138139

140+
constlazyRimRaf=getLazy(()=>require('internal/fs/rimraf').rimrafPromises);
141+
139142
// By the time the C++ land creates an error for a promise rejection (likely from a
140143
// libuv callback), there is already no JS frames on the stack. So we need to
141144
// wait until V8 resumes execution back to JS land before we have enough information
@@ -804,7 +807,7 @@ async function ftruncate(handle, len = 0) {
804807
asyncfunctionrm(path,options){
805808
path=pathModule.toNamespacedPath(getValidatedPath(path));
806809
options=awaitvalidateRmOptionsPromise(path,options,false);
807-
returnrimrafPromises(path,options);
810+
returnlazyRimRaf()(path,options);
808811
}
809812

810813
asyncfunctionrmdir(path,options){
@@ -815,7 +818,7 @@ async function rmdir(path, options) {
815818
emitRecursiveRmdirWarning();
816819
conststats=awaitstat(path);
817820
if(stats.isDirectory()){
818-
returnrimrafPromises(path,options);
821+
returnlazyRimRaf()(path,options);
819822
}
820823
}
821824

0 commit comments

Comments
 (0)