Skip to content

Commit

Permalink
fs: runtime deprecate dirent.path
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Dec 5, 2023
1 parent a49b77b commit b056421
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3535,12 +3535,15 @@ The [`util.types.isWebAssemblyCompiledModule`][] API is deprecated. Please use

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51050
description: Runtime deprecation.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51020
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime

The [`dirent.path`][] is deprecated due to its lack of consistency across
release lines. Please use [`dirent.parentPath`][] instead.
Expand Down
6 changes: 5 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6658,13 +6658,17 @@ added:
- v20.1.0
- v18.17.0
deprecated: REPLACEME
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51050
description: Accessing this property emits a warning. It is now read-only.
-->
> Stability: 0 - Deprecated: Use [`dirent.parentPath`][] instead.
* {string}
Alias for `dirent.parentPath`.
Alias for `dirent.parentPath`. Read-only.
### Class: `fs.FSWatcher`
Expand Down
12 changes: 11 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
NumberIsFinite,
MathMin,
MathRound,
ObjectDefineProperty,
ObjectIs,
ObjectSetPrototypeOf,
ReflectApply,
Expand Down Expand Up @@ -47,6 +48,7 @@ const {
isUint8Array,
} = require('internal/util/types');
const {
deprecate,
kEmptyObject,
once,
} = require('internal/util');
Expand Down Expand Up @@ -166,7 +168,6 @@ class Dirent {
constructor(name, type, path) {
this.name = name;
this.parentPath = path;
this.path = path;
this[kType] = type;
}

Expand Down Expand Up @@ -215,6 +216,15 @@ for (const name of ReflectOwnKeys(Dirent.prototype)) {
};
}

ObjectDefineProperty(Dirent.prototype, 'path', {
__proto__: null,
get: deprecate(function() {
return this.parentPath;
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
configurable: true,
enumerable: false,
});

function copyObject(source) {
const target = {};
for (const key in source)
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-fs-utils-get-dirents.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ const filename = 'foo';
common.mustCall((err, dirent) => {
assert.strictEqual(err, null);
assert.strictEqual(dirent.name, filenameBuffer);
common.expectWarning(
'DeprecationWarning',
'dirent.path is deprecated in favor of dirent.parentPath',
'DEP0178');
assert.deepStrictEqual(dirent.path, Buffer.from(tmpdir.resolve(`${filename}/`)));
},
));
}
Expand Down

0 comments on commit b056421

Please sign in to comment.