mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05: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
6 changed files with 70 additions and 23 deletions
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
|
* an error occurs. It resolves to the number of bytes copied or rejects with
|
||||||
* the first error encountered while copying.
|
* the first error encountered while copying.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode ReadableStream.pipeTo} instead.
|
* @deprecated Use {@linkcode https://deno.land/std/io/copy.ts?s=copy | copy}
|
||||||
* {@linkcode Deno.copy} will be removed in v2.0.0.
|
* instead. {@linkcode Deno.copy} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
*
|
*
|
||||||
|
@ -1848,8 +1848,8 @@ declare namespace Deno {
|
||||||
/**
|
/**
|
||||||
* Turns a Reader, `r`, into an async iterator.
|
* Turns a Reader, `r`, into an async iterator.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode ReadableStream} instead. {@linkcode Deno.iter}
|
* @deprecated Use {@linkcode ReadableStream} instead.
|
||||||
* will be removed in v2.0.0.
|
* {@linkcode Deno.iter} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
*/
|
*/
|
||||||
|
@ -2875,9 +2875,9 @@ declare namespace Deno {
|
||||||
/**
|
/**
|
||||||
* A variable-sized buffer of bytes with `read()` and `write()` methods.
|
* A variable-sized buffer of bytes with `read()` and `write()` methods.
|
||||||
*
|
*
|
||||||
* @deprecated Use the
|
* @deprecated Use
|
||||||
* [Web Streams API]{@link https://developer.mozilla.org/en-US/docs/Web/API/Streams_API}
|
* {@linkcode https://deno.land/std/io/buffer.ts?s=Buffer | Buffer} instead.
|
||||||
* instead. {@linkcode Deno.Buffer} will be removed in v2.0.0.
|
* {@linkcode Deno.Buffer} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
*/
|
*/
|
||||||
|
@ -2951,8 +2951,8 @@ declare namespace Deno {
|
||||||
* Read Reader `r` until EOF (`null`) and resolve to the content as
|
* Read Reader `r` until EOF (`null`) and resolve to the content as
|
||||||
* Uint8Array`.
|
* Uint8Array`.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode ReadableStream} and
|
* @deprecated Use
|
||||||
* [`toArrayBuffer()`](https://deno.land/std/streams/to_array_buffer.ts?s=toArrayBuffer)
|
* {@linkcode https://deno.land/std/io/read_all.ts?s=readAll | readAll}
|
||||||
* instead. {@linkcode Deno.readAll} will be removed in v2.0.0.
|
* instead. {@linkcode Deno.readAll} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
|
@ -2963,8 +2963,8 @@ declare namespace Deno {
|
||||||
* Synchronously reads Reader `r` until EOF (`null`) and returns the content
|
* Synchronously reads Reader `r` until EOF (`null`) and returns the content
|
||||||
* as `Uint8Array`.
|
* as `Uint8Array`.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode ReadableStream} and
|
* @deprecated Use
|
||||||
* [`toArrayBuffer()`](https://deno.land/std/streams/to_array_buffer.ts?s=toArrayBuffer)
|
* {@linkcode https://deno.land/std/io/read_all.ts?s=readAllSync | readAllSync}
|
||||||
* instead. {@linkcode Deno.readAllSync} will be removed in v2.0.0.
|
* instead. {@linkcode Deno.readAllSync} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
|
@ -2974,9 +2974,9 @@ declare namespace Deno {
|
||||||
/**
|
/**
|
||||||
* Write all the content of the array buffer (`arr`) to the writer (`w`).
|
* Write all the content of the array buffer (`arr`) to the writer (`w`).
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode WritableStream}, {@linkcode ReadableStream.from}
|
* @deprecated Use
|
||||||
* and {@linkcode ReadableStream.pipeTo} instead. {@linkcode Deno.writeAll}
|
* {@linkcode https://deno.land/std/io/write_all.ts?s=writeAll | writeAll}
|
||||||
* will be removed in v2.0.0.
|
* instead. {@linkcode Deno.writeAll} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
*/
|
*/
|
||||||
|
@ -2986,9 +2986,9 @@ declare namespace Deno {
|
||||||
* Synchronously write all the content of the array buffer (`arr`) to the
|
* Synchronously write all the content of the array buffer (`arr`) to the
|
||||||
* writer (`w`).
|
* writer (`w`).
|
||||||
*
|
*
|
||||||
* @deprecated Use {@linkcode WritableStream}, {@linkcode ReadableStream.from}
|
* @deprecated Use
|
||||||
* and {@linkcode ReadableStream.pipeTo} instead.
|
* {@linkcode https://deno.land/std/io/write_all.ts?s=writeAllSync | writeAllSync}
|
||||||
* {@linkcode Deno.writeAllSync} will be removed in v2.0.0.
|
* instead. {@linkcode Deno.writeAllSync} will be removed in v2.0.0.
|
||||||
*
|
*
|
||||||
* @category I/O
|
* @category I/O
|
||||||
*/
|
*/
|
||||||
|
@ -4062,7 +4062,7 @@ declare namespace Deno {
|
||||||
/**
|
/**
|
||||||
* Stops watching the file system and closes the watcher resource.
|
* 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>>;
|
return?(value?: any): Promise<IteratorResult<FsEvent>>;
|
||||||
[Symbol.asyncIterator](): AsyncIterableIterator<FsEvent>;
|
[Symbol.asyncIterator](): AsyncIterableIterator<FsEvent>;
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
// Interfaces 100% copied from Go.
|
// Interfaces 100% copied from Go.
|
||||||
// Documentation liberally lifted from them too.
|
// Documentation liberally lifted from them too.
|
||||||
// Thank you! We love Go! <3
|
// Thank you! We love Go! <3
|
||||||
|
import { core, internals, primordials } from "ext:core/mod.js";
|
||||||
import { core, primordials } from "ext:core/mod.js";
|
|
||||||
const {
|
const {
|
||||||
op_stdin_set_raw,
|
op_stdin_set_raw,
|
||||||
op_is_terminal,
|
op_is_terminal,
|
||||||
|
@ -40,6 +39,11 @@ async function copy(
|
||||||
dst,
|
dst,
|
||||||
options,
|
options,
|
||||||
) {
|
) {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.copy()",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `copy()` from `https://deno.land/std/io/copy.ts` instead.",
|
||||||
|
);
|
||||||
let n = 0;
|
let n = 0;
|
||||||
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
||||||
const b = new Uint8Array(bufSize);
|
const b = new Uint8Array(bufSize);
|
||||||
|
@ -65,6 +69,11 @@ async function* iter(
|
||||||
r,
|
r,
|
||||||
options,
|
options,
|
||||||
) {
|
) {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.iter()",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `ReadableStream` instead.",
|
||||||
|
);
|
||||||
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
||||||
const b = new Uint8Array(bufSize);
|
const b = new Uint8Array(bufSize);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -81,6 +90,11 @@ function* iterSync(
|
||||||
r,
|
r,
|
||||||
options,
|
options,
|
||||||
) {
|
) {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.iterSync()",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `ReadableStream` instead.",
|
||||||
|
);
|
||||||
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
const bufSize = options?.bufSize ?? DEFAULT_BUFFER_SIZE;
|
||||||
const b = new Uint8Array(bufSize);
|
const b = new Uint8Array(bufSize);
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
||||||
// https://github.com/golang/go/blob/master/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 {
|
const {
|
||||||
ArrayBufferPrototypeGetByteLength,
|
ArrayBufferPrototypeGetByteLength,
|
||||||
TypedArrayPrototypeSubarray,
|
TypedArrayPrototypeSubarray,
|
||||||
|
@ -45,6 +45,11 @@ class Buffer {
|
||||||
#off = 0; // read at buf[off], write at buf[buf.byteLength]
|
#off = 0; // read at buf[off], write at buf[buf.byteLength]
|
||||||
|
|
||||||
constructor(ab) {
|
constructor(ab) {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"new Deno.Buffer()",
|
||||||
|
new Error().stack,
|
||||||
|
"Use `Buffer` from `https://deno.land/std/io/buffer.ts` instead.",
|
||||||
|
);
|
||||||
if (ab == null) {
|
if (ab == null) {
|
||||||
this.#buf = new Uint8Array(0);
|
this.#buf = new Uint8Array(0);
|
||||||
return;
|
return;
|
||||||
|
@ -230,18 +235,33 @@ class Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function readAll(r) {
|
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();
|
const buf = new Buffer();
|
||||||
await buf.readFrom(r);
|
await buf.readFrom(r);
|
||||||
return buf.bytes();
|
return buf.bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
function readAllSync(r) {
|
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();
|
const buf = new Buffer();
|
||||||
buf.readFromSync(r);
|
buf.readFromSync(r);
|
||||||
return buf.bytes();
|
return buf.bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeAll(w, arr) {
|
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;
|
let nwritten = 0;
|
||||||
while (nwritten < arr.length) {
|
while (nwritten < arr.length) {
|
||||||
nwritten += await w.write(TypedArrayPrototypeSubarray(arr, nwritten));
|
nwritten += await w.write(TypedArrayPrototypeSubarray(arr, nwritten));
|
||||||
|
@ -249,6 +269,11 @@ async function writeAll(w, arr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeAllSync(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;
|
let nwritten = 0;
|
||||||
while (nwritten < arr.length) {
|
while (nwritten < arr.length) {
|
||||||
nwritten += w.writeSync(TypedArrayPrototypeSubarray(arr, nwritten));
|
nwritten += w.writeSync(TypedArrayPrototypeSubarray(arr, nwritten));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// 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 {
|
const {
|
||||||
BadResourcePrototype,
|
BadResourcePrototype,
|
||||||
InterruptedPrototype,
|
InterruptedPrototype,
|
||||||
|
@ -49,6 +49,10 @@ class FsWatcher {
|
||||||
// TODO(kt3k): This is deprecated. Will be removed in v2.0.
|
// TODO(kt3k): This is deprecated. Will be removed in v2.0.
|
||||||
// See https://github.com/denoland/deno/issues/10577 for details
|
// See https://github.com/denoland/deno/issues/10577 for details
|
||||||
return(value) {
|
return(value) {
|
||||||
|
internals.warnOnDeprecatedApi(
|
||||||
|
"Deno.FsWatcher.return()",
|
||||||
|
new Error().stack,
|
||||||
|
);
|
||||||
core.close(this.rid);
|
core.close(this.rid);
|
||||||
return PromiseResolve({ value, done: true });
|
return PromiseResolve({ value, done: true });
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,10 @@ class FsFile extends fs.FsFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
const denoNs = {
|
const denoNs = {
|
||||||
metrics: core.metrics,
|
metrics: () => {
|
||||||
|
internals.warnOnDeprecatedApi("Deno.metrics()", new Error().stack);
|
||||||
|
return core.metrics();
|
||||||
|
},
|
||||||
Process: process.Process,
|
Process: process.Process,
|
||||||
run: process.run,
|
run: process.run,
|
||||||
isatty: tty.isatty,
|
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.",
|
"%c\u251c This API will be removed in Deno 2.0. Make sure to upgrade to a stable API before then.",
|
||||||
"color: yellow;",
|
"color: yellow;",
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let i = 0; i < suggestions.length; i++) {
|
for (let i = 0; i < suggestions.length; i++) {
|
||||||
const suggestion = suggestions[i];
|
const suggestion = suggestions[i];
|
||||||
console.error("%c\u2502", "color: yellow;");
|
console.error("%c\u2502", "color: yellow;");
|
||||||
|
|
Loading…
Add table
Reference in a new issue