Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: runtime deprecate fs.Stats constructor #52067

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3578,12 +3578,15 @@ Please use the [`crypto.createHash()`][] method to create Hash instances.

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/52067
description: Runtime deprecation.
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/51879
description: Documentation-only deprecation.
-->

Type: Documentation-only
Type: Runtime

Calling `fs.Stats` class directly with `Stats()` or `new Stats()` is
deprecated due to being internals, not intended for public use.
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const {
const {
kEmptyObject,
once,
deprecate,
} = require('internal/util');
const { toPathIfFileURL } = require('internal/url');
const {
Expand Down Expand Up @@ -1009,7 +1010,7 @@ module.exports = {
getStatsFromBinding,
stringToFlags,
stringToSymlinkType,
Stats,
Stats: deprecate(Stats, 'fs.Stats constructor is deprecated.', 'DEP0180'),
toUnixTimestamp,
validateBufferArray,
validateCpOptions,
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-fs-stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,28 @@ fs.open(__filename, 'r', undefined, common.mustCall((err, fd) => {

// Should not throw an error
fs.lstat(__filename, undefined, common.mustCall());

{
fs.Stats(
0, // dev
0, // mode
0, // nlink
0, // uid
0, // gid
0, // rdev
0, // blksize
0, // ino
0, // size
0, // blocks
Date.UTC(1970, 0, 1, 0, 0, 0), // atime
Date.UTC(1970, 0, 1, 0, 0, 0), // mtime
Date.UTC(1970, 0, 1, 0, 0, 0), // ctime
Date.UTC(1970, 0, 1, 0, 0, 0) // birthtime
);
common.expectWarning({
DeprecationWarning: [
['fs.Stats constructor is deprecated.',
'DEP0180'],
]
});
}