Skip to content

Commit f5f5ef2

Browse files
committed
fs: move rmdir recursive option to end-of-life
Has been runtime deprecated for ~ 5 years now. It's time.
1 parent f58613a commit f5f5ef2

11 files changed

+17
-382
lines changed

β€Ždoc/api/deprecations.mdβ€Ž

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,9 @@ The [`crypto.Certificate()` constructor][] is deprecated. Use
30533053

30543054
<!-- YAML
30553055
changes:
3056+
- version: REPLACEME
3057+
pr-url: https://github.com/nodejs/node/pull/00000
3058+
description: End-of-Life.
30563059
- version: v16.0.0
30573060
pr-url: https://github.com/nodejs/node/pull/37302
30583061
description: Runtime deprecation.
@@ -3064,10 +3067,10 @@ changes:
30643067
description: Documentation-only deprecation.
30653068
-->
30663069

3067-
Type: Runtime
3070+
Type: End-of-Life
30683071

3069-
In future versions of Node.js, `recursive` option will be ignored for
3070-
`fs.rmdir`, `fs.rmdirSync`, and `fs.promises.rmdir`.
3072+
The `fs.rmdir`, `fs.rmdirSync`, and `fs.promises.rmdir` methods used
3073+
to support a `recursive` option. That option has been removed.
30713074

30723075
Use `fs.rm(path, { recursive: true, force: true })`,
30733076
`fs.rmSync(path, { recursive: true, force: true })` or

β€Žlib/fs.jsβ€Ž

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const {
101101
},
102102
copyObject,
103103
Dirent,
104-
emitRecursiveRmdirWarning,
105104
getDirent,
106105
getDirents,
107106
getOptions,
@@ -1125,32 +1124,10 @@ function rmdir(path, options, callback) {
11251124
callback = makeCallback(callback);
11261125
path = getValidatedPath(path);
11271126

1128-
if (options?.recursive) {
1129-
emitRecursiveRmdirWarning();
1130-
validateRmOptions(
1131-
path,
1132-
{ ...options, force: false },
1133-
true,
1134-
(err, options) => {
1135-
if (err === false) {
1136-
const req = new FSReqCallback();
1137-
req.oncomplete = callback;
1138-
binding.rmdir(path, req);
1139-
return;
1140-
}
1141-
if (err) {
1142-
return callback(err);
1143-
}
1144-
1145-
lazyLoadRimraf();
1146-
rimraf(path, options, callback);
1147-
});
1148-
} else {
1149-
validateRmdirOptions(options);
1150-
const req = new FSReqCallback();
1151-
req.oncomplete = callback;
1152-
binding.rmdir(path, req);
1153-
}
1127+
validateRmdirOptions(options);
1128+
const req = new FSReqCallback();
1129+
req.oncomplete = callback;
1130+
binding.rmdir(path, req);
11541131
}
11551132

11561133
/**
@@ -1165,17 +1142,7 @@ function rmdir(path, options, callback) {
11651142
*/
11661143
function rmdirSync(path, options) {
11671144
path = getValidatedPath(path);
1168-
1169-
if (options?.recursive) {
1170-
emitRecursiveRmdirWarning();
1171-
options = validateRmOptionsSync(path, { ...options, force: false }, true);
1172-
if (options !== false) {
1173-
return binding.rmSync(path, options.maxRetries, options.recursive, options.retryDelay);
1174-
}
1175-
} else {
1176-
validateRmdirOptions(options);
1177-
}
1178-
1145+
validateRmdirOptions(options);
11791146
binding.rmdir(path);
11801147
}
11811148

β€Žlib/internal/fs/promises.jsβ€Ž

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const {
5656
kWriteFileMaxChunkSize,
5757
},
5858
copyObject,
59-
emitRecursiveRmdirWarning,
6059
getDirents,
6160
getOptions,
6261
getStatFsFromBinding,
@@ -814,14 +813,6 @@ async function rmdir(path, options) {
814813
path = getValidatedPath(path);
815814
options = validateRmdirOptions(options);
816815

817-
if (options.recursive) {
818-
emitRecursiveRmdirWarning();
819-
const stats = await stat(path);
820-
if (stats.isDirectory()) {
821-
return lazyRimRaf()(path, options);
822-
}
823-
}
824-
825816
return await PromisePrototypeThen(
826817
binding.rmdir(path, kUsePromises),
827818
undefined,

β€Žlib/internal/fs/utils.jsβ€Ž

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ const defaultRmOptions = {
781781
const defaultRmdirOptions = {
782782
retryDelay: 100,
783783
maxRetries: 0,
784-
recursive: false,
785784
};
786785

787786
const validateCpOptions = hideStackFrames((options) => {
@@ -839,6 +838,7 @@ const validateRmOptions = hideStackFrames((path, options, expectDir, cb) => {
839838
const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => {
840839
options = validateRmdirOptions.withoutStackTrace(options, defaultRmOptions);
841840
validateBoolean.withoutStackTrace(options.force, 'options.force');
841+
validateBoolean.withoutStackTrace(options.recursive, 'options.recursive');
842842

843843
if (!options.force || expectDir || !options.recursive) {
844844
const isDirectory = lazyLoadFs()
@@ -862,23 +862,6 @@ const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => {
862862
return options;
863863
});
864864

865-
let recursiveRmdirWarned;
866-
function emitRecursiveRmdirWarning() {
867-
if (recursiveRmdirWarned === undefined) {
868-
// TODO(joyeecheung): use getOptionValue('--no-deprecation') instead.
869-
recursiveRmdirWarned = process.noDeprecation;
870-
}
871-
if (!recursiveRmdirWarned) {
872-
process.emitWarning(
873-
'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' +
874-
'will be removed. Use fs.rm(path, { recursive: true }) instead',
875-
'DeprecationWarning',
876-
'DEP0147',
877-
);
878-
recursiveRmdirWarned = true;
879-
}
880-
}
881-
882865
const validateRmdirOptions = hideStackFrames(
883866
(options, defaults = defaultRmdirOptions) => {
884867
if (options === undefined)
@@ -887,7 +870,6 @@ const validateRmdirOptions = hideStackFrames(
887870

888871
options = { ...defaults, ...options };
889872

890-
validateBoolean.withoutStackTrace(options.recursive, 'options.recursive');
891873
validateInt32.withoutStackTrace(options.retryDelay, 'options.retryDelay', 0);
892874
validateUint32.withoutStackTrace(options.maxRetries, 'options.maxRetries');
893875

@@ -950,7 +932,6 @@ module.exports = {
950932
copyObject,
951933
Dirent,
952934
DirentFromStats,
953-
emitRecursiveRmdirWarning,
954935
getDirent,
955936
getDirents,
956937
getOptions,

β€Žtest/parallel/test-fs-rmdir-recursive-sync-warns-not-found.jsβ€Ž

Lines changed: 0 additions & 22 deletions
This file was deleted.

β€Žtest/parallel/test-fs-rmdir-recursive-sync-warns-on-file.jsβ€Ž

Lines changed: 0 additions & 22 deletions
This file was deleted.

β€Žtest/parallel/test-fs-rmdir-recursive-warns-not-found.jsβ€Ž

Lines changed: 0 additions & 21 deletions
This file was deleted.

β€Žtest/parallel/test-fs-rmdir-recursive-warns-on-file.jsβ€Ž

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
Β (0)