diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2024-01-24 14:57:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-24 14:57:54 +0100 |
commit | 064a6c048ab420302cbb822bedd3fc365b4259a7 (patch) | |
tree | 1aa6ee2716f2cc30e74dd97818330a5e2d154a07 /runtime/js | |
parent | 745333f073aba4c97e7d06c731063105493cde5a (diff) |
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>
Diffstat (limited to 'runtime/js')
-rw-r--r-- | runtime/js/13_buffer.js | 27 | ||||
-rw-r--r-- | runtime/js/40_fs_events.js | 6 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 5 | ||||
-rw-r--r-- | runtime/js/99_main.js | 1 |
4 files changed, 36 insertions, 3 deletions
diff --git a/runtime/js/13_buffer.js b/runtime/js/13_buffer.js index 36d979e75..cac1a6694 100644 --- a/runtime/js/13_buffer.js +++ b/runtime/js/13_buffer.js @@ -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)); diff --git a/runtime/js/40_fs_events.js b/runtime/js/40_fs_events.js index 13cacc36b..0bc614335 100644 --- a/runtime/js/40_fs_events.js +++ b/runtime/js/40_fs_events.js @@ -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 }); } diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 5bcc68a57..bba1f30d7 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -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, diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 3fee1109b..7057f6d62 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -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;"); |