Skip to content

Commit

Permalink
BREAKING(fs): remove Deno.FsFile.prototype.rid (#25499)
Browse files Browse the repository at this point in the history
Towards #22079

---------

Signed-off-by: Asher Gomez <[email protected]>
  • Loading branch information
iuioiua authored Sep 10, 2024
1 parent f9007d3 commit a69b1e6
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 44 deletions.
15 changes: 3 additions & 12 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1815,15 +1815,6 @@ declare namespace Deno {
* @category File System
*/
export class FsFile implements Seeker, SeekerSync, Disposable {
/**
* The resource ID associated with the file instance. The resource ID
* should be considered an opaque reference to resource.
*
* @deprecated This will be removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*/
readonly rid: number;
/** A {@linkcode ReadableStream} instance representing to the byte contents
* of the file. This makes it easy to interoperate with other web streams
* based APIs.
Expand Down Expand Up @@ -1973,7 +1964,7 @@ declare namespace Deno {
* resolves to the new position within the resource (bytes from the start).
*
* ```ts
* // Given file pointing to file with "Hello world", which is 11 bytes long:
* // Given the file contains "Hello world" text, which is 11 bytes long:
* using file = await Deno.open(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
Expand All @@ -1991,7 +1982,7 @@ declare namespace Deno {
* The seek modes work as follows:
*
* ```ts
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
* // Given the file contains "Hello world" text, which is 11 bytes long:
* const file = await Deno.open(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
Expand Down Expand Up @@ -2028,7 +2019,7 @@ declare namespace Deno {
* The seek modes work as follows:
*
* ```ts
* // Given file.rid pointing to file with "Hello world", which is 11 bytes long:
* // Given the file contains "Hello world" text, which is 11 bytes long:
* using file = Deno.openSync(
* "hello.txt",
* { read: true, write: true, truncate: true, create: true },
Expand Down
11 changes: 1 addition & 10 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

import { core, internals, primordials } from "ext:core/mod.js";
import { core, primordials } from "ext:core/mod.js";
const {
isDate,
internalRidSymbol,
Expand Down Expand Up @@ -581,15 +581,6 @@ class FsFile {
}
}

get rid() {
internals.warnOnDeprecatedApi(
"Deno.FsFile.rid",
new Error().stack,
"Use `Deno.FsFile` methods directly instead.",
);
return this.#rid;
}

write(p) {
return write(this.#rid, p);
}
Expand Down
5 changes: 0 additions & 5 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
}
if (internals.future) {
delete globalThis.window;
delete Deno.FsFile.prototype.rid;
}
} else {
// Warmup
Expand Down Expand Up @@ -930,10 +929,6 @@ function bootstrapWorkerRuntime(
nodeDebug,
});
}

if (internals.future) {
delete Deno.FsFile.prototype.rid;
}
} else {
// Warmup
return;
Expand Down
4 changes: 0 additions & 4 deletions tests/specs/future/runtime_api/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
console.log("window is", globalThis.window);
console.log(
"Deno.FsFile.prototype.rid is",
Deno.openSync(import.meta.filename).rid,
);

// TCP
// Since these tests may run in parallel, ensure this port is unique to this file
Expand Down
1 change: 0 additions & 1 deletion tests/specs/future/runtime_api/main.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
window is undefined
Deno.FsFile.prototype.rid is undefined
Deno.Listener.prototype.rid is undefined
Deno.TlsListener.prototype.rid is undefined
Deno.FsFile constructor is illegal
Expand Down
1 change: 0 additions & 1 deletion tests/unit/files_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Deno.test(
const filename = "tests/testdata/assets/fixture.json";
using file = await Deno.open(filename);
assert(file instanceof Deno.FsFile);
assert(file.rid > 2);
const bytesWritten = await copy(file, Deno.stdout);
const fileSize = Deno.statSync(filename).size;
assertEquals(bytesWritten, fileSize);
Expand Down
14 changes: 6 additions & 8 deletions tests/unit/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
assertStrictEquals,
assertStringIncludes,
assertThrows,
DENO_FUTURE,
} from "./test_util.ts";

Deno.test(
Expand Down Expand Up @@ -363,8 +362,6 @@ Deno.test(

Deno.test(
{
// Ignoring because uses `file.rid`
ignore: DENO_FUTURE,
permissions: { run: true, write: true, read: true },
},
async function runRedirectStdoutStderr() {
Expand All @@ -382,10 +379,12 @@ Deno.test(
"eval",
"Deno.stderr.write(new TextEncoder().encode('error\\n')); Deno.stdout.write(new TextEncoder().encode('output\\n'));",
],
stdout: file.rid,
stderr: file.rid,
stdout: "piped",
stderr: "piped",
});

await p.stdout.readable.pipeTo(file.writable, { preventClose: true });
await p.stderr.readable.pipeTo(file.writable);
await p.status();
p.close();

Expand All @@ -402,8 +401,6 @@ Deno.test(

Deno.test(
{
// Ignoring because uses `file.rid`
ignore: DENO_FUTURE,
permissions: { run: true, write: true, read: true },
},
async function runRedirectStdin() {
Expand All @@ -425,9 +422,10 @@ Deno.test(
}
`,
],
stdin: file.rid,
stdin: "piped",
});

await file.readable.pipeTo(p.stdin.writable);
const status = await p.status();
assertEquals(status.code, 0);
p.close();
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_node/_fs/_fs_appendFile_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Deno.test({
read: true,
});
await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
appendFile(file.rid, "hello world", (err) => {
if (err) reject();
else resolve();
Expand Down Expand Up @@ -166,6 +167,7 @@ Deno.test({
write: true,
read: true,
});
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
appendFileSync(file.rid, "hello world");
const data = Deno.readFileSync(tempFile);
assertEquals(decoder.decode(data), "hello world");
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_node/_fs/_fs_close_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Deno.test({
const file: Deno.FsFile = await Deno.open(tempFile);

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
close(file.rid, (err) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -45,6 +46,7 @@ Deno.test({

let foo: string;
const promise = new Promise<void>((resolve) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
close(file.rid, () => {
assert(foo === "bar");
resolve();
Expand All @@ -66,6 +68,7 @@ Deno.test({
const tempFile: string = Deno.makeTempFileSync();
const file: Deno.FsFile = Deno.openSync(tempFile);

// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
closeSync(file.rid);
Deno.removeSync(tempFile);
},
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_node/_fs/_fs_fdatasync_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Deno.test({
await file.write(data);

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fdatasync(file.rid, (err: Error | null) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -55,6 +56,7 @@ Deno.test({
file.writeSync(data);

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fdatasyncSync(file.rid);
assertEquals(Deno.readFileSync(filePath), data);
} finally {
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_node/_fs/_fs_fstat_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Deno.test({
using file = await Deno.open(filePath);

await new Promise<Stats>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fstat(file.rid, (err: Error | null, stat: Stats) => {
if (err) reject(err);
resolve(stat);
Expand Down Expand Up @@ -43,6 +44,7 @@ Deno.test({

await new Promise<BigIntStats>((resolve, reject) => {
fstat(
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
file.rid,
{ bigint: true },
(err: Error | null, stat: BigIntStats) => {
Expand Down Expand Up @@ -71,6 +73,7 @@ Deno.test({
using file = Deno.openSync(filePath);

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
assertStats(fstatSync(file.rid), file.statSync());
} finally {
Deno.removeSync(filePath);
Expand All @@ -89,9 +92,11 @@ Deno.test({

try {
// HEAD
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
assertStatsBigInt(fstatSync(file.rid, { bigint: true }), file.statSync());
//
assertStatsBigInt(
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fstatSync(file.rid, { bigint: true }),
file.statSync(),
);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_node/_fs/_fs_fsync_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Deno.test({
await file.truncate(size);

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fsync(file.rid, (err: Error | null) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -53,6 +54,7 @@ Deno.test({
file.truncateSync(size);

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
fsyncSync(file.rid);
assertEquals(Deno.statSync(filePath).size, size);
} finally {
Expand Down
4 changes: 4 additions & 0 deletions tests/unit_node/_fs/_fs_ftruncate_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Deno.test({
});

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
ftruncate(file.rid, (err: Error | null) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -66,6 +67,7 @@ Deno.test({
});

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
ftruncate(file.rid, 3, (err: Error | null) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -101,6 +103,7 @@ Deno.test({
});

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
ftruncateSync(file.rid);
const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 0);
Expand All @@ -125,6 +128,7 @@ Deno.test({
});

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
ftruncateSync(file.rid, 3);
const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 3);
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_node/_fs/_fs_futimes_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Deno.test({
using file = await Deno.open(filePath, { create: true, write: true });

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
futimes(file.rid, randomDate, randomDate, (err: Error | null) => {
if (err !== null) reject();
else resolve();
Expand Down Expand Up @@ -73,6 +74,7 @@ Deno.test({
using file = Deno.openSync(filePath, { create: true, write: true });

try {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
futimesSync(file.rid, randomDate, randomDate);

const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
Expand Down
3 changes: 3 additions & 0 deletions tests/unit_node/_fs/_fs_writeFile_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Deno.test(
});

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
writeFile(file.rid, "hello world", (err) => {
if (err) return reject(err);
resolve();
Expand Down Expand Up @@ -234,6 +235,7 @@ Deno.test(
});

await new Promise<void>((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
writeFile(file.rid, "hello world", { mode: 0o777 }, (err) => {
if (err) return reject(err);
resolve();
Expand Down Expand Up @@ -288,6 +290,7 @@ Deno.test(
read: true,
});

// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
writeFileSync(file.rid, "hello world");

const data = Deno.readFileSync(tempFile);
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_node/_fs/_fs_write_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Deno.test({
});
const buffer = Buffer.from("hello world");
const bytesWrite = await new Promise((resolve, reject) => {
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
write(file.rid, buffer, 0, 5, (err: unknown, nwritten: number) => {
if (err) return reject(err);
resolve(nwritten);
Expand Down Expand Up @@ -49,6 +50,7 @@ Deno.test({
read: true,
});
const buffer = Buffer.from("hello world");
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
const bytesWrite = writeSync(file.rid, buffer, 0, 5);

const data = Deno.readFileSync(tempFile);
Expand All @@ -75,6 +77,7 @@ Deno.test({

const str = "hello world";
const buffer = Buffer.from(str);
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
const bytesWritten = writeSync(file.rid, buffer, 0, str.length, 4);

const data = Deno.readFileSync(tempFile);
Expand Down Expand Up @@ -122,6 +125,7 @@ Deno.test({
for (let i = 0; i < bytes.length; i++) {
buffer[offset + i] = i;
}
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
let nWritten = writeSync(file.rid, buffer, offset, bytes.length, 0);

let data = Deno.readFileSync(tempFile);
Expand All @@ -131,6 +135,7 @@ Deno.test({
assertEquals(data, new Uint8Array(bytes));
nWritten = await new Promise((resolve, reject) =>
write(
// @ts-ignore (iuioiua) `file.rid` should no longer be needed once FDs are used
file.rid,
buffer,
offset,
Expand Down
3 changes: 0 additions & 3 deletions tests/unit_node/tty_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ Deno.test("[node/tty isatty] returns true when fd is a tty, false otherwise", ()
assert(Deno.stdin.isTerminal() === isatty((Deno as any).stdin.rid));
assert(Deno.stdout.isTerminal() === isatty((Deno as any).stdout.rid));
assert(Deno.stderr.isTerminal() === isatty((Deno as any).stderr.rid));

using file = Deno.openSync("README.md");
assert(!isatty(file.rid));
});

Deno.test("[node/tty isatty] returns false for irrelevant values", () => {
Expand Down

0 comments on commit a69b1e6

Please sign in to comment.