Skip to content

Commit 8206f6b

Browse files
fs: runtime deprecate fs.Stats constructor
PR-URL: #52067 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
1 parent 4e278f0 commit 8206f6b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

doc/api/deprecations.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3581,12 +3581,15 @@ Please use the [`crypto.createHash()`][] method to create Hash instances.
35813581

35823582
<!-- YAML
35833583
changes:
3584+
- version: REPLACEME
3585+
pr-url: https://github.com/nodejs/node/pull/52067
3586+
description: Runtime deprecation.
35843587
- version: REPLACEME
35853588
pr-url: https://github.com/nodejs/node/pull/51879
35863589
description: Documentation-only deprecation.
35873590
-->
35883591

3589-
Type: Documentation-only
3592+
Type: Runtime
35903593

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

lib/internal/fs/utils.js

+2-1
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 {
@@ -1008,7 +1009,7 @@ module.exports = {
10081009
getStatsFromBinding,
10091010
stringToFlags,
10101011
stringToSymlinkType,
1011-
Stats,
1012+
Stats: deprecate(Stats, 'fs.Stats constructor is deprecated.', 'DEP0180'),
10121013
toUnixTimestamp,
10131014
validateBufferArray,
10141015
validateCpOptions,

test/parallel/test-fs-stat.js

+25
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)