Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: runtime deprecate dirent.path #51050

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3551,6 +3551,9 @@ Please use `value instanceof WebAssembly.Module` instead.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51050
description: Runtime deprecation.
- version:
- v21.5.0
- v20.12.0
Expand All @@ -3559,7 +3562,7 @@ changes:
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 @@ -6763,13 +6763,17 @@ deprecated:
- v21.5.0
- v20.12.0
- v18.20.0
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
10 changes: 9 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ class Dirent {
constructor(name, type, path) {
this.name = name;
this.parentPath = path;
this.path = path;
this[kType] = type;
}

Expand Down Expand Up @@ -220,6 +219,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