mirror of
https://github.com/denoland/deno
synced 2024-08-25 02:57:22 +00:00
feat: Add warnings for more deprecated APIs (#21992)
Follow up to https://github.com/denoland/deno/pull/21939 that adds deprecation warnings to more `Deno` APIs: - `Deno.copy()` - `Deno.iter()` - `Deno.iterSync()` - `new Deno.Buffer()` - `Deno.readAll()` - `Deno.readAllSync()` - `Deno.writeAll()` - `Deno.writeAllSync()` - `Deno.FsWatcher.return` - `Deno.serveHttp()` - `Deno.metrics()` --------- Signed-off-by: Asher Gomez <ashersaupingomez@gmail.com> Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
745333f073
commit
064a6c048a
36
cli/tsc/dts/lib.deno.ns.d.ts
vendored
36
cli/tsc/dts/lib.deno.ns.d.ts
vendored
|
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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>;
|
||||
|
|
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -230,18 +235,33 @@ 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));
|
||||
|
@ -249,6 +269,11 @@ async function writeAll(w, arr) {
|
|||
}
|
||||
|
||||
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));
|
||||
|
|
|
@ -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,
|
||||
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -155,6 +155,7 @@ function warnOnDeprecatedApi(apiName, stack, ...suggestions) {
|
|||
"%c\u251c This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.",
|
||||
"color: yellow;",
|
||||
);
|
||||
|
||||
for (let i = 0; i < suggestions.length; i++) {
|
||||
const suggestion = suggestions[i];
|
||||
console.error("%c\u2502", "color: yellow;");
|
||||
|
|
Loading…
Reference in a new issue