From 48c19d0bab5c1977e0d61a83d8e13c2bc26ef398 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 25 Jan 2024 04:53:20 +1100 Subject: [PATCH] feat: deprecate `Deno.fstat()` and `Deno.fstatSync()` (#22068) For removal in Deno v2. --- cli/tests/unit_node/_fs/_fs_fstat_test.ts | 10 +++++++--- cli/tsc/dts/lib.deno.ns.d.ts | 6 ++++++ ext/node/polyfills/_fs/_fs_fstat.ts | 5 +++-- runtime/js/90_deno_ns.js | 18 ++++++++++++++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/cli/tests/unit_node/_fs/_fs_fstat_test.ts b/cli/tests/unit_node/_fs/_fs_fstat_test.ts index 963f79abcc..220b9589a7 100644 --- a/cli/tests/unit_node/_fs/_fs_fstat_test.ts +++ b/cli/tests/unit_node/_fs/_fs_fstat_test.ts @@ -18,7 +18,7 @@ Deno.test({ }) .then( (stat) => { - assertStats(stat, Deno.fstatSync(file.rid)); + assertStats(stat, file.statSync()); }, () => fail(), ) @@ -45,7 +45,7 @@ Deno.test({ ); }) .then( - (stat) => assertStatsBigInt(stat, Deno.fstatSync(file.rid)), + (stat) => assertStatsBigInt(stat, file.statSync()), () => fail(), ) .finally(() => { @@ -61,7 +61,7 @@ Deno.test({ using file = Deno.openSync(filePath); try { - assertStats(fstatSync(file.rid), Deno.fstatSync(file.rid)); + assertStats(fstatSync(file.rid), file.statSync()); } finally { Deno.removeSync(filePath); } @@ -75,10 +75,14 @@ Deno.test({ using file = Deno.openSync(filePath); try { + // HEAD + assertStatsBigInt(fstatSync(file.rid, { bigint: true }), file.statSync()); + // assertStatsBigInt( fstatSync(file.rid, { bigint: true }), Deno.fstatSync(file.rid), ); + //main } finally { Deno.removeSync(filePath); } diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 175276b66c..9ec90a2d68 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -5448,6 +5448,9 @@ declare namespace Deno { * assert(fileInfo.isFile); * ``` * + * @deprecated Use `file.stat()` instead. + * {@linkcode Deno.fstat} will be removed in Deno 2.0. + * * @category File System */ export function fstat(rid: number): Promise; @@ -5464,6 +5467,9 @@ declare namespace Deno { * assert(fileInfo.isFile); * ``` * + * @deprecated Use `file.statSync()` instead. + * {@linkcode Deno.fstatSync} will be removed in Deno 2.0. + * * @category File System */ export function fstatSync(rid: number): FileInfo; diff --git a/ext/node/polyfills/_fs/_fs_fstat.ts b/ext/node/polyfills/_fs/_fs_fstat.ts index bc4cf3c42b..fe97235bff 100644 --- a/ext/node/polyfills/_fs/_fs_fstat.ts +++ b/ext/node/polyfills/_fs/_fs_fstat.ts @@ -11,6 +11,7 @@ import { statOptions, Stats, } from "ext:deno_node/_fs/_fs_stat.ts"; +import { FsFile } from "ext:deno_fs/30_fs.js"; export function fstat(fd: number, callback: statCallback): void; export function fstat( @@ -40,7 +41,7 @@ export function fstat( if (!callback) throw new Error("No callback function supplied"); - Deno.fstat(fd).then( + new FsFile(fd).stat().then( (stat) => callback(null, CFISBIS(stat, options.bigint)), (err) => callback(err), ); @@ -59,6 +60,6 @@ export function fstatSync( fd: number, options?: statOptions, ): Stats | BigIntStats { - const origin = Deno.fstatSync(fd); + const origin = new FsFile(fd).statSync(); return CFISBIS(origin, options?.bigint || false); } diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 638e7afe70..4340abc951 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -209,8 +209,22 @@ const denoNs = { ); net.shutdown(rid); }, - fstatSync: fs.fstatSync, - fstat: fs.fstat, + fstatSync(rid) { + internals.warnOnDeprecatedApi( + "Deno.fstatSync()", + new Error().stack, + "Use `Deno.FsFile.statSync()` instead.", + ); + return fs.fstatSync(rid); + }, + fstat(rid) { + internals.warnOnDeprecatedApi( + "Deno.fstat()", + new Error().stack, + "Use `Deno.FsFile.stat()` instead.", + ); + return fs.fstat(rid); + }, fsyncSync(rid) { internals.warnOnDeprecatedApi( "Deno.fsyncSync()",