Skip to content

Commit 15e7563

Browse files
authoredMay 5, 2024··
fs: runtime deprecate dirent.path
PR-URL: #51050 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 77db391 commit 15e7563

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed
 

Diff for: ‎doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,9 @@ Please use `value instanceof WebAssembly.Module` instead.
35543554

35553555
<!-- YAML
35563556
changes:
3557+
- version: REPLACEME
3558+
pr-url: https://github.com/nodejs/node/pull/51050
3559+
description: Runtime deprecation.
35573560
- version:
35583561
- v21.5.0
35593562
- v20.12.0
@@ -3562,7 +3565,7 @@ changes:
35623565
description: Documentation-only deprecation.
35633566
-->
35643567

3565-
Type: Documentation-only
3568+
Type: Runtime
35663569

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

Diff for: ‎doc/api/fs.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6763,13 +6763,17 @@ deprecated:
67636763
- v21.5.0
67646764
- v20.12.0
67656765
- v18.20.0
6766+
changes:
6767+
- version: REPLACEME
6768+
pr-url: https://github.com/nodejs/node/pull/51050
6769+
description: Accessing this property emits a warning. It is now read-only.
67666770
-->
67676771
67686772
> Stability: 0 - Deprecated: Use [`dirent.parentPath`][] instead.
67696773
67706774
* {string}
67716775
6772-
Alias for `dirent.parentPath`.
6776+
Alias for `dirent.parentPath`. Read-only.
67736777
67746778
### Class: `fs.FSWatcher`
67756779

Diff for: ‎lib/internal/fs/utils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ class Dirent {
166166
constructor(name, type, path) {
167167
this.name = name;
168168
this.parentPath = path;
169-
this.path = path;
170169
this[kType] = type;
171170
}
172171

@@ -215,6 +214,15 @@ for (const name of ReflectOwnKeys(Dirent.prototype)) {
215214
};
216215
}
217216

217+
ObjectDefineProperty(Dirent.prototype, 'path', {
218+
__proto__: null,
219+
get: deprecate(function() {
220+
return this.parentPath;
221+
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
222+
configurable: true,
223+
enumerable: false,
224+
});
225+
218226
function copyObject(source) {
219227
const target = {};
220228
for (const key in source)

Diff for: ‎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)
Please sign in to comment.