Skip to content

Commit 131d146

Browse files
fs: runtime deprecate fs.Stats constructor
1 parent 16579d7 commit 131d146

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

doc/api/deprecations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3578,12 +3578,15 @@ Please use the [`crypto.createHash()`][] method to create Hash instances.
35783578

35793579
<!-- YAML
35803580
changes:
3581+
- version: REPLACEME
3582+
pr-url: https://github.com/nodejs/node/pull/9999999
3583+
description: Runtime deprecation.
35813584
- version: REPLACEME
35823585
pr-url: https://github.com/nodejs/node/pull/51879
35833586
description: Documentation-only deprecation.
35843587
-->
35853588

3586-
Type: Documentation-only
3589+
Type: Runtime
35873590

35883591
Calling `fs.Stats` class directly with `Stats()` or `new Stats()` is
35893592
deprecated due to being internals, not intended for public use.

lib/internal/fs/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const {
5151
const {
5252
kEmptyObject,
5353
once,
54+
deprecate,
5455
} = require('internal/util');
5556
const { toPathIfFileURL } = require('internal/url');
5657
const {
@@ -1009,7 +1010,7 @@ module.exports = {
10091010
getStatsFromBinding,
10101011
stringToFlags,
10111012
stringToSymlinkType,
1012-
Stats,
1013+
Stats: deprecate(Stats, 'fs.Stats constructor is deprecated.', 'DEP0180'),
10131014
toUnixTimestamp,
10141015
validateBufferArray,
10151016
validateCpOptions,

test/parallel/test-fs-stat.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,28 @@ fs.open(__filename, 'r', undefined, common.mustCall((err, fd) => {
154154

155155
// Should not throw an error
156156
fs.lstat(__filename, undefined, common.mustCall());
157+
158+
{
159+
fs.Stats(
160+
0, // dev
161+
0, // mode
162+
0, // nlink
163+
0, // uid
164+
0, // gid
165+
0, // rdev
166+
0, // blksize
167+
0, // ino
168+
0, // size
169+
0, // blocks
170+
Date.UTC(1970, 0, 1, 0, 0, 0), // atime
171+
Date.UTC(1970, 0, 1, 0, 0, 0), // mtime
172+
Date.UTC(1970, 0, 1, 0, 0, 0), // ctime
173+
Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime
174+
);
175+
common.expectWarning({
176+
DeprecationWarning: [
177+
['fs.Stats constructor is deprecated.',
178+
'DEP0180'],
179+
]
180+
});
181+
}

0 commit comments

Comments
 (0)