Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: load rimraf lazily in fs/promises #51617

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const {
aggregateTwoErrors,
} = require('internal/errors');
const { isArrayBufferView } = require('internal/util/types');
const { rimrafPromises } = require('internal/fs/rimraf');

const {
constants: {
kIoMaxLength,
Expand Down Expand Up @@ -93,6 +93,7 @@ const {
kEmptyObject,
lazyDOMException,
promisify,
getLazy,
} = require('internal/util');
const EventEmitter = require('events');
const { StringDecoder } = require('string_decoder');
Expand Down Expand Up @@ -136,6 +137,8 @@ function lazyFsStreams() {
return fsStreams ??= require('internal/fs/streams');
}

const lazyRimRaf = getLazy(() => require('internal/fs/rimraf').rimrafPromises);

// By the time the C++ land creates an error for a promise rejection (likely from a
// libuv callback), there is already no JS frames on the stack. So we need to
// wait until V8 resumes execution back to JS land before we have enough information
Expand Down Expand Up @@ -803,7 +806,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) {
Expand All @@ -814,7 +817,7 @@ async function rmdir(path, options) {
emitRecursiveRmdirWarning();
const stats = await stat(path);
if (stats.isDirectory()) {
return rimrafPromises(path, options);
return lazyRimRaf()(path, options);
}
}

Expand Down
Loading