From 8206f6bb7f8e0114bbc4788bef62008eae4ecb81 Mon Sep 17 00:00:00 2001 From: Marco Ippolito Date: Tue, 19 Mar 2024 09:17:36 +0100 Subject: [PATCH] fs: runtime deprecate fs.Stats constructor PR-URL: https://github.com/nodejs/node/pull/52067 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Yagiz Nizipli --- doc/api/deprecations.md | 5 ++++- lib/internal/fs/utils.js | 3 ++- test/parallel/test-fs-stat.js | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 2f3f420d0d36a4..3cd7192081bf1f 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -3581,12 +3581,15 @@ Please use the [`crypto.createHash()`][] method to create Hash instances. -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. diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 968f011f668710..4666a1d78d81a7 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -51,6 +51,7 @@ const { const { kEmptyObject, once, + deprecate, } = require('internal/util'); const { toPathIfFileURL } = require('internal/url'); const { @@ -1008,7 +1009,7 @@ module.exports = { getStatsFromBinding, stringToFlags, stringToSymlinkType, - Stats, + Stats: deprecate(Stats, 'fs.Stats constructor is deprecated.', 'DEP0180'), toUnixTimestamp, validateBufferArray, validateCpOptions, diff --git a/test/parallel/test-fs-stat.js b/test/parallel/test-fs-stat.js index 2b98698df65d36..506c5e5fa97317 100644 --- a/test/parallel/test-fs-stat.js +++ b/test/parallel/test-fs-stat.js @@ -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'], + ] + }); +}