From b6855ff7c5c6bcb293aefeb6e84170b79b997948 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 30 Nov 2023 15:20:56 +0100 Subject: [PATCH 1/2] fs: runtime deprecate `dirent.path` --- doc/api/deprecations.md | 5 ++++- doc/api/fs.md | 6 +++++- lib/internal/fs/utils.js | 11 ++++++++++- test/parallel/test-fs-utils-get-dirents.js | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 75e3468a9c9129..7501428035ca10 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3551,6 +3551,9 @@ Please use `value instanceof WebAssembly.Module` instead. -Type: Documentation-only +Type: Runtime The [`dirent.path`][] is deprecated due to its lack of consistency across release lines. Please use [`dirent.parentPath`][] instead. diff --git a/doc/api/fs.md b/doc/api/fs.md index de86c355efecd9..b0b94c1b08ed2e 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -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` diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 4666a1d78d81a7..adb0b9629b7371 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -49,6 +49,7 @@ const { isUint8Array, } = require('internal/util/types'); const { + deprecate, kEmptyObject, once, deprecate, @@ -171,7 +172,6 @@ class Dirent { constructor(name, type, path) { this.name = name; this.parentPath = path; - this.path = path; this[kType] = type; } @@ -220,6 +220,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) diff --git a/test/parallel/test-fs-utils-get-dirents.js b/test/parallel/test-fs-utils-get-dirents.js index 9c53a4146a6768..dfc851090b269d 100644 --- a/test/parallel/test-fs-utils-get-dirents.js +++ b/test/parallel/test-fs-utils-get-dirents.js @@ -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}/`))); }, )); } From a3b7d4f4cf800befde6ea9869a5d691882e6735f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 14 Apr 2024 12:04:12 +0200 Subject: [PATCH 2/2] fixup! fs: runtime deprecate `dirent.path` --- lib/internal/fs/utils.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index adb0b9629b7371..9fd96e92158cdd 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -49,7 +49,6 @@ const { isUint8Array, } = require('internal/util/types'); const { - deprecate, kEmptyObject, once, deprecate,