Skip to content

Commit 5b165f2

Browse files
committed
fs: runtime deprecate dirent.path
1 parent 64c6d97 commit 5b165f2

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3549,12 +3549,15 @@ Please use `value instanceof WebAssembly.Module` instead.
35493549

35503550
<!-- YAML
35513551
changes:
3552+
- version: REPLACEME
3553+
pr-url: https://github.com/nodejs/node/pull/51050
3554+
description: Runtime deprecation.
35523555
- version: v21.5.0
35533556
pr-url: https://github.com/nodejs/node/pull/51020
35543557
description: Documentation-only deprecation.
35553558
-->
35563559

3557-
Type: Documentation-only
3560+
Type: Runtime
35583561

35593562
The [`dirent.path`][] is deprecated due to its lack of consistency across
35603563
release lines. Please use [`dirent.parentPath`][] instead.

doc/api/fs.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6661,13 +6661,17 @@ added:
66616661
- v20.1.0
66626662
- v18.17.0
66636663
deprecated: v21.5.0
6664+
changes:
6665+
- version: REPLACEME
6666+
pr-url: https://github.com/nodejs/node/pull/51050
6667+
description: Accessing this property emits a warning. It is now read-only.
66646668
-->
66656669
66666670
> Stability: 0 - Deprecated: Use [`dirent.parentPath`][] instead.
66676671
66686672
* {string}
66696673
6670-
Alias for `dirent.parentPath`.
6674+
Alias for `dirent.parentPath`. Read-only.
66716675
66726676
### Class: `fs.FSWatcher`
66736677

lib/internal/fs/utils.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const {
4949
isUint8Array,
5050
} = require('internal/util/types');
5151
const {
52+
deprecate,
5253
kEmptyObject,
5354
once,
5455
} = require('internal/util');
@@ -168,7 +169,6 @@ class Dirent {
168169
constructor(name, type, path) {
169170
this.name = name;
170171
this.parentPath = path;
171-
this.path = path;
172172
this[kType] = type;
173173
}
174174

@@ -217,6 +217,15 @@ for (const name of ReflectOwnKeys(Dirent.prototype)) {
217217
};
218218
}
219219

220+
ObjectDefineProperty(Dirent.prototype, 'path', {
221+
__proto__: null,
222+
get: deprecate(function() {
223+
return this.parentPath;
224+
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
225+
configurable: true,
226+
enumerable: false,
227+
});
228+
220229
function copyObject(source) {
221230
const target = {};
222231
for (const key in source)

test/parallel/test-fs-utils-get-dirents.js

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ const filename = 'foo';
8888
common.mustCall((err, dirent) => {
8989
assert.strictEqual(err, null);
9090
assert.strictEqual(dirent.name, filenameBuffer);
91+
common.expectWarning(
92+
'DeprecationWarning',
93+
'dirent.path is deprecated in favor of dirent.parentPath',
94+
'DEP0178');
95+
assert.deepStrictEqual(dirent.path, Buffer.from(tmpdir.resolve(`${filename}/`)));
9196
},
9297
));
9398
}

0 commit comments

Comments
 (0)