Skip to content

Commit b056421

Browse files
committed
fs: runtime deprecate dirent.path
1 parent a49b77b commit b056421

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3535,12 +3535,15 @@ The [`util.types.isWebAssemblyCompiledModule`][] API is deprecated. Please use
35353535

35363536
<!-- YAML
35373537
changes:
3538+
- version: REPLACEME
3539+
pr-url: https://github.com/nodejs/node/pull/51050
3540+
description: Runtime deprecation.
35383541
- version: REPLACEME
35393542
pr-url: https://github.com/nodejs/node/pull/51020
35403543
description: Documentation-only deprecation.
35413544
-->
35423545

3543-
Type: Documentation-only
3546+
Type: Runtime
35443547

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

doc/api/fs.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6658,13 +6658,17 @@ added:
66586658
- v20.1.0
66596659
- v18.17.0
66606660
deprecated: REPLACEME
6661+
changes:
6662+
- version: REPLACEME
6663+
pr-url: https://github.com/nodejs/node/pull/51050
6664+
description: Accessing this property emits a warning. It is now read-only.
66616665
-->
66626666
66636667
> Stability: 0 - Deprecated: Use [`dirent.parentPath`][] instead.
66646668
66656669
* {string}
66666670
6667-
Alias for `dirent.parentPath`.
6671+
Alias for `dirent.parentPath`. Read-only.
66686672
66696673
### Class: `fs.FSWatcher`
66706674

lib/internal/fs/utils.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
NumberIsFinite,
1313
MathMin,
1414
MathRound,
15+
ObjectDefineProperty,
1516
ObjectIs,
1617
ObjectSetPrototypeOf,
1718
ReflectApply,
@@ -47,6 +48,7 @@ const {
4748
isUint8Array,
4849
} = require('internal/util/types');
4950
const {
51+
deprecate,
5052
kEmptyObject,
5153
once,
5254
} = require('internal/util');
@@ -166,7 +168,6 @@ class Dirent {
166168
constructor(name, type, path) {
167169
this.name = name;
168170
this.parentPath = path;
169-
this.path = path;
170171
this[kType] = type;
171172
}
172173

@@ -215,6 +216,15 @@ for (const name of ReflectOwnKeys(Dirent.prototype)) {
215216
};
216217
}
217218

219+
ObjectDefineProperty(Dirent.prototype, 'path', {
220+
__proto__: null,
221+
get: deprecate(function() {
222+
return this.parentPath;
223+
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
224+
configurable: true,
225+
enumerable: false,
226+
});
227+
218228
function copyObject(source) {
219229
const target = {};
220230
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)