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

feat: Add warnings for more deprecated APIs #21992

Merged
merged 21 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ declare namespace Deno {
* an error occurs. It resolves to the number of bytes copied or rejects with
* the first error encountered while copying.
*
* @deprecated Use {@linkcode ReadableStream.pipeTo} instead.
* {@linkcode Deno.copy} will be removed in v2.0.0.
* @deprecated Use {@linkcode https://deno.land/std/io/copy.ts?s=copy | copy}
* instead. {@linkcode Deno.copy} will be removed in v2.0.0.
*
* @category I/O
*
Expand All @@ -1848,8 +1848,8 @@ declare namespace Deno {
/**
* Turns a Reader, `r`, into an async iterator.
*
* @deprecated Use {@linkcode ReadableStream} instead. {@linkcode Deno.iter}
* will be removed in v2.0.0.
* @deprecated Use {@linkcode ReadableStream} instead.
* {@linkcode Deno.iter} will be removed in v2.0.0.
*
* @category I/O
*/
Expand Down Expand Up @@ -2875,9 +2875,9 @@ declare namespace Deno {
/**
* A variable-sized buffer of bytes with `read()` and `write()` methods.
*
* @deprecated Use the
* [Web Streams API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API}
* instead. {@linkcode Deno.Buffer} will be removed in v2.0.0.
* @deprecated Use
* {@linkcode https://deno.land/std/io/buffer.ts?s=Buffer | Buffer} instead.
* {@linkcode Deno.Buffer} will be removed in v2.0.0.
*
* @category I/O
*/
Expand Down Expand Up @@ -2951,8 +2951,8 @@ declare namespace Deno {
* Read Reader `r` until EOF (`null`) and resolve to the content as
* Uint8Array`.
*
* @deprecated Use {@linkcode ReadableStream} and
* [`toArrayBuffer()`](https://deno.land/std/streams/to_array_buffer.ts?s=toArrayBuffer)
* @deprecated Use
* {@linkcode https://deno.land/std/io/read_all.ts?s=readAll | readAll}
* instead. {@linkcode Deno.readAll} will be removed in v2.0.0.
*
* @category I/O
Expand All @@ -2963,8 +2963,8 @@ declare namespace Deno {
* Synchronously reads Reader `r` until EOF (`null`) and returns the content
* as `Uint8Array`.
*
* @deprecated Use {@linkcode ReadableStream} and
* [`toArrayBuffer()`](https://deno.land/std/streams/to_array_buffer.ts?s=toArrayBuffer)
* @deprecated Use
* {@linkcode https://deno.land/std/io/read_all.ts?s=readAllSync | readAllSync}
* instead. {@linkcode Deno.readAllSync} will be removed in v2.0.0.
*
* @category I/O
Expand All @@ -2974,9 +2974,9 @@ declare namespace Deno {
/**
* Write all the content of the array buffer (`arr`) to the writer (`w`).
*
* @deprecated Use {@linkcode WritableStream}, {@linkcode ReadableStream.from}
* and {@linkcode ReadableStream.pipeTo} instead. {@linkcode Deno.writeAll}
* will be removed in v2.0.0.
* @deprecated Use
* {@linkcode https://deno.land/std/io/write_all.ts?s=writeAll | writeAll}
* instead. {@linkcode Deno.writeAll} will be removed in v2.0.0.
*
* @category I/O
*/
Expand All @@ -2986,9 +2986,9 @@ declare namespace Deno {
* Synchronously write all the content of the array buffer (`arr`) to the
* writer (`w`).
*
* @deprecated Use {@linkcode WritableStream}, {@linkcode ReadableStream.from}
* and {@linkcode ReadableStream.pipeTo} instead.
* {@linkcode Deno.writeAllSync} will be removed in v2.0.0.
* @deprecated Use
* {@linkcode https://deno.land/std/io/write_all.ts?s=writeAllSync | writeAllSync}
* instead. {@linkcode Deno.writeAllSync} will be removed in v2.0.0.
*
* @category I/O
*/
Expand Down Expand Up @@ -4062,7 +4062,7 @@ declare namespace Deno {
/**
* Stops watching the file system and closes the watcher resource.
*
* @deprecated Will be removed in v2.0.0.
* @deprecated {@linkcode Deno.FsWatcher.return} will be removed in v2.0.0.
*/
return?(value?: any): Promise<IteratorResult<FsEvent>>;
[Symbol.asyncIterator](): AsyncIterableIterator<FsEvent>;
Expand Down
18 changes: 16 additions & 2 deletions ext/io/12_io.js
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise doing this all in runtime/js/90_deno_ns.js will be cleaner.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
// Interfaces 100% copied from Go.
// Documentation liberally lifted from them too.
// Thank you! We love Go! <3

import { core, primordials } from "ext:core/mod.js";
import { core, internals, primordials } from "ext:core/mod.js";
const {
op_stdin_set_raw,
op_is_terminal,
Expand Down Expand Up @@ -40,6 +39,11 @@ async function copy(
dst,
options,
) {
internals.warnOnDeprecatedApi(
"Deno.copy()",
new Error().stack,
"Use `copy()` from `https://deno.land/std/io/copy.ts` instead.",
);
let n = 0;
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
const b = new Uint8Array(bufSize);
Expand All @@ -65,6 +69,11 @@ async function* iter(
r,
options,
) {
internals.warnOnDeprecatedApi(
"Deno.iter()",
new Error().stack,
"Use `ReadableStream` instead.",
);
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
const b = new Uint8Array(bufSize);
while (true) {
Expand All @@ -81,6 +90,11 @@ function* iterSync(
r,
options,
) {
internals.warnOnDeprecatedApi(
"Deno.iterSync()",
new Error().stack,
"Use `ReadableStream` instead.",
);
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
const b = new Uint8Array(bufSize);
while (true) {
Expand Down
27 changes: 26 additions & 1 deletion runtime/js/13_buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE

import { primordials } from "ext:core/mod.js";
import { internals, primordials } from "ext:core/mod.js";
const {
ArrayBufferPrototypeGetByteLength,
TypedArrayPrototypeSubarray,
Expand Down Expand Up @@ -45,6 +45,11 @@ class Buffer {
#off = 0; // read at buf[off], write at buf[buf.byteLength]

constructor(ab) {
internals.warnOnDeprecatedApi(
"new Deno.Buffer()",
new Error().stack,
"Use `Buffer` from `https://deno.land/std/io/buffer.ts` instead.",
);
if (ab == null) {
this.#buf = new Uint8Array(0);
return;
Expand Down Expand Up @@ -230,25 +235,45 @@ class Buffer {
}

async function readAll(r) {
internals.warnOnDeprecatedApi(
"Deno.readAll()",
new Error().stack,
"Use `readAll()` from `https://deno.land/std/io/read_all.ts` instead.",
);
const buf = new Buffer();
await buf.readFrom(r);
return buf.bytes();
}

function readAllSync(r) {
internals.warnOnDeprecatedApi(
"Deno.readAllSync()",
new Error().stack,
"Use `readAllSync()` from `https://deno.land/std/io/read_all.ts` instead.",
);
const buf = new Buffer();
buf.readFromSync(r);
return buf.bytes();
}

async function writeAll(w, arr) {
internals.warnOnDeprecatedApi(
"Deno.writeAll()",
new Error().stack,
"Use `writeAll()` from `https://deno.land/std/io/write_all.ts` instead.",
);
let nwritten = 0;
while (nwritten < arr.length) {
nwritten += await w.write(TypedArrayPrototypeSubarray(arr, nwritten));
}
}

function writeAllSync(w, arr) {
internals.warnOnDeprecatedApi(
"Deno.writeAllSync()",
new Error().stack,
"Use `writeAllSync()` from `https://deno.land/std/io/write_all.ts` instead.",
);
let nwritten = 0;
while (nwritten < arr.length) {
nwritten += w.writeSync(TypedArrayPrototypeSubarray(arr, nwritten));
Expand Down
6 changes: 5 additions & 1 deletion runtime/js/40_fs_events.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, primordials } from "ext:core/mod.js";
import { core, internals, primordials } from "ext:core/mod.js";
const {
BadResourcePrototype,
InterruptedPrototype,
Expand Down Expand Up @@ -49,6 +49,10 @@ class FsWatcher {
// TODO(kt3k): This is deprecated. Will be removed in v2.0.
// See https://github.com/denoland/deno/issues/10577 for details
return(value) {
internals.warnOnDeprecatedApi(
"Deno.FsWatcher.return()",
new Error().stack,
);
core.close(this.rid);
return PromiseResolve({ value, done: true });
}
Expand Down
5 changes: 4 additions & 1 deletion runtime/js/90_deno_ns.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class FsFile extends fs.FsFile {
}

const denoNs = {
metrics: core.metrics,
metrics: () => {
internals.warnOnDeprecatedApi("Deno.metrics()", new Error().stack);
return core.metrics();
},
Process: process.Process,
run: process.run,
isatty: tty.isatty,
Expand Down
10 changes: 6 additions & 4 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ function warnOnDeprecatedApi(apiName, stack, suggestion) {
"color: yellow;",
);
console.error("%c\u2502", "color: yellow;");
console.error(
`%c\u251c Suggestion: ${suggestion}`,
"color: yellow;",
);
if (suggestion) {
console.error(
`%c\u251c Suggestion: ${suggestion}`,
"color: yellow;",
);
}
if (isFromRemoteDependency) {
console.error("%c\u2502", "color: yellow;");
console.error(
Expand Down