GeezerVison is showing github.com — fs: make `dirent.path` writable · nodejs/node@f628fc4
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/fs.md +4-1Lines changed: 4 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -6822,6 +6822,9 @@ deprecated: | 6822 | 6822 | - v20.12.0 | 6823 | 6823 | - v18.20.0 | 6824 | 6824 | changes: | | 6825 | + - version: REPLACEME | | 6826 | + pr-url: https://github.com/nodejs/node/pull/55547 | | 6827 | + description: The property is no longer read-only. | 6825 | 6828 | - version: v23.0.0 | 6826 | 6829 | pr-url: https://github.com/nodejs/node/pull/51050 | 6827 | 6830 | description: Accessing this property emits a warning. It is now read-only. | @@ -6831,7 +6834,7 @@ changes: | 6831 | 6834 |
| 6832 | 6835 | * {string} | 6833 | 6836 |
| 6834 | | -Alias for `dirent.parentPath`. Read-only. | | 6837 | +Alias for `dirent.parentPath`. | 6835 | 6838 |
| 6836 | 6839 | ### Class: `fs.FSWatcher` | 6837 | 6840 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/fs/utils.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,6 +49,7 @@ const { | 49 | 49 | once, | 50 | 50 | deprecate, | 51 | 51 | isWindows, | | 52 | + setOwnProperty, | 52 | 53 | } = require('internal/util'); | 53 | 54 | const { toPathIfFileURL } = require('internal/url'); | 54 | 55 | const { | @@ -214,6 +215,9 @@ ObjectDefineProperty(Dirent.prototype, 'path', { | 214 | 215 | get: deprecate(function() { | 215 | 216 | return this.parentPath; | 216 | 217 | }, 'dirent.path is deprecated in favor of dirent.parentPath', 'DEP0178'), | | 218 | + set(value) { | | 219 | + setOwnProperty(this, 'path', value); | | 220 | + }, | 217 | 221 | configurable: true, | 218 | 222 | enumerable: false, | 219 | 223 | }); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-fs-utils-get-dirents.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,6 +78,18 @@ const filename = 'foo'; | 78 | 78 | }, | 79 | 79 | )); | 80 | 80 | } | | 81 | +{ | | 82 | + // Reassigning `.path` property should not trigger a warning | | 83 | + const dirent = getDirent( | | 84 | + tmpdir.path, | | 85 | + filename, | | 86 | + UV_DIRENT_UNKNOWN, | | 87 | + ); | | 88 | + assert.strictEqual(dirent.name, filename); | | 89 | + dirent.path = 'some other value'; | | 90 | + assert.strictEqual(dirent.parentPath, tmpdir.path); | | 91 | + assert.strictEqual(dirent.path, 'some other value'); | | 92 | +} | 81 | 93 | { | 82 | 94 | // string + Buffer | 83 | 95 | const filenameBuffer = Buffer.from(filename); | |
|