fs: make dirent.path writable

PR-URL: https://github.com/nodejs/node/pull/55547
Refs: https://github.com/nodejs/node/issues/55538
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: LiviaMedeiros <livia@cirno.name>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
This commit is contained in:
Antoine du Hamel authored and RafaelGSS committed 2024-11-01 16:00:11 -03:00
1 parent fa61dced44
commit f628fc43cb
3 files changed
+20 -1

No files matched your search

+4 -1
View File
@@ -6822,6 +6822,9 @@ deprecated:
- v20.12.0
- v18.20.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/55547
description: The property is no longer read-only.
- version: v23.0.0
pr-url: https://github.com/nodejs/node/pull/51050
description: Accessing this property emits a warning. It is now read-only.
@@ -6831,7 +6834,7 @@ changes:
* {string}
Alias for `dirent.parentPath`. Read-only.
Alias for `dirent.parentPath`.
### Class: `fs.FSWatcher`
+4
View File
@@ -49,6 +49,7 @@ const {
once,
deprecate,
isWindows,
setOwnProperty,
} = require('internal/util');
const { toPathIfFileURL } = require('internal/url');
const {
@@ -214,6 +215,9 @@ ObjectDefineProperty(Dirent.prototype, 'path', {
get: deprecate(function() {
return this.parentPath;
}, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'),
set(value) {
setOwnProperty(this, 'path', value);
},
configurable: true,
enumerable: false,
});
@@ -78,6 +78,18 @@ const filename = 'foo';
},
));
}
{
// Reassigning `.path` property should not trigger a warning
const dirent = getDirent(
tmpdir.path,
filename,
UV_DIRENT_UNKNOWN,
);
assert.strictEqual(dirent.name, filename);
dirent.path = 'some other value';
assert.strictEqual(dirent.parentPath, tmpdir.path);
assert.strictEqual(dirent.path, 'some other value');
}
{
// string + Buffer
const filenameBuffer = Buffer.from(filename);