From 05bd547238006f089f05ef046470e00c94317da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 00:02:50 +0100 Subject: [PATCH 1/9] feat(ext/node): export more symbols from streams and timers/promises (#25582) --- ext/node/polyfills/_stream.mjs | 7 +++++- ext/node/polyfills/buffer.ts | 1 + ext/node/polyfills/internal/buffer.mjs | 2 +- ext/node/polyfills/internal/streams/state.mjs | 21 +++++++++++++++--- ext/node/polyfills/stream.ts | 21 +++++++++++++++--- ext/node/polyfills/stream/web.ts | 22 +++++++++++++------ ext/node/polyfills/timers/promises.ts | 1 + 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/ext/node/polyfills/_stream.mjs b/ext/node/polyfills/_stream.mjs index 9d09a6fd77..02640abcd9 100644 --- a/ext/node/polyfills/_stream.mjs +++ b/ext/node/polyfills/_stream.mjs @@ -5277,6 +5277,7 @@ var require_stream = __commonJS({ Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { return Buffer2.from(chunk.buffer, chunk.byteOffset, chunk.byteLength); }; + Stream._isArrayBufferView = isArrayBufferView; }, }); /* End esm.sh bundle */ @@ -5311,11 +5312,15 @@ export const Duplex = CustomStream.Duplex; export const PassThrough = CustomStream.PassThrough; export const Stream = CustomStream.Stream; export const Transform = CustomStream.Transform; +export const _isArrayBufferView = isArrayBufferView; export const _isUint8Array = CustomStream._isUint8Array; export const _uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer; export const addAbortSignal = CustomStream.addAbortSignal; export const pipeline = CustomStream.pipeline; -export { finished }; +export const isDisturbed = CustomStream.isDisturbed; +export const isErrored = CustomStream.isErrored; +export const compose = CustomStream.compose; +export { destroy, finished, isDestroyed, isReadable, isWritable }; function isWritableStream(object) { return object instanceof WritableStream; diff --git a/ext/node/polyfills/buffer.ts b/ext/node/polyfills/buffer.ts index c5a910cb40..8986cf53d7 100644 --- a/ext/node/polyfills/buffer.ts +++ b/ext/node/polyfills/buffer.ts @@ -7,6 +7,7 @@ export { Buffer, constants, default, + INSPECT_MAX_BYTES, isAscii, isUtf8, kMaxLength, diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs index 4964b1956e..48b102a77b 100644 --- a/ext/node/polyfills/internal/buffer.mjs +++ b/ext/node/polyfills/internal/buffer.mjs @@ -65,7 +65,7 @@ const customInspectSymbol = ? Symbol["for"]("nodejs.util.inspect.custom") : null; -const INSPECT_MAX_BYTES = 50; +export const INSPECT_MAX_BYTES = 50; export const constants = { MAX_LENGTH: kMaxLength, diff --git a/ext/node/polyfills/internal/streams/state.mjs b/ext/node/polyfills/internal/streams/state.mjs index 7bedcb3f32..428492306b 100644 --- a/ext/node/polyfills/internal/streams/state.mjs +++ b/ext/node/polyfills/internal/streams/state.mjs @@ -2,9 +2,24 @@ // Copyright Joyent and Node contributors. All rights reserved. MIT license. // deno-lint-ignore-file +// TODO(bartlomieju): this should be 64? +let defaultHighWaterMarkBytes = 16 * 1024; +let defaultHighWaterMarkObjectMode = 16; + function getDefaultHighWaterMark(objectMode) { - return objectMode ? 16 : 16 * 1024; + return objectMode + ? defaultHighWaterMarkObjectMode + : defaultHighWaterMarkBytes; } -export default { getDefaultHighWaterMark }; -export { getDefaultHighWaterMark }; +function setDefaultHighWaterMark(objectMode, value) { + validateInteger(value, "value", 0); + if (objectMode) { + defaultHighWaterMarkObjectMode = value; + } else { + defaultHighWaterMarkBytes = value; + } +} + +export default { getDefaultHighWaterMark, setDefaultHighWaterMark }; +export { getDefaultHighWaterMark, setDefaultHighWaterMark }; diff --git a/ext/node/polyfills/stream.ts b/ext/node/polyfills/stream.ts index 618e5ba113..96262428f0 100644 --- a/ext/node/polyfills/stream.ts +++ b/ext/node/polyfills/stream.ts @@ -4,14 +4,19 @@ // @deno-types="./_stream.d.ts" import { + _isArrayBufferView, _isUint8Array, _uint8ArrayToBuffer, addAbortSignal, - // compose, - // destroy, + compose, + destroy, Duplex, finished, - // isDisturbed, + isDestroyed, + isDisturbed, + isErrored, + isReadable, + isWritable, PassThrough, pipeline, Readable, @@ -21,18 +26,28 @@ import { } from "ext:deno_node/_stream.mjs"; import { getDefaultHighWaterMark, + setDefaultHighWaterMark, } from "ext:deno_node/internal/streams/state.mjs"; export { + _isArrayBufferView, _isUint8Array, _uint8ArrayToBuffer, addAbortSignal, + compose, + destroy, Duplex, finished, getDefaultHighWaterMark, + isDestroyed, + isDisturbed, + isErrored, + isReadable, + isWritable, PassThrough, pipeline, Readable, + setDefaultHighWaterMark, Stream, Transform, Writable, diff --git a/ext/node/polyfills/stream/web.ts b/ext/node/polyfills/stream/web.ts index 5c6127ca6c..9cb361f862 100644 --- a/ext/node/polyfills/stream/web.ts +++ b/ext/node/polyfills/stream/web.ts @@ -19,10 +19,16 @@ import { TextDecoderStream, TextEncoderStream, } from "ext:deno_web/08_text_encoding.js"; +import { + CompressionStream, + DecompressionStream, +} from "ext:deno_web/14_compression.js"; export { ByteLengthQueuingStrategy, + CompressionStream, CountQueuingStrategy, + DecompressionStream, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, @@ -39,19 +45,21 @@ export { }; export default { + ByteLengthQueuingStrategy, + CompressionStream, + CountQueuingStrategy, + DecompressionStream, + ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, - ReadableStreamDefaultReader, - ReadableByteStreamController, ReadableStreamDefaultController, + ReadableStreamDefaultReader, + TextDecoderStream, + TextEncoderStream, TransformStream, TransformStreamDefaultController, WritableStream, - WritableStreamDefaultWriter, WritableStreamDefaultController, - ByteLengthQueuingStrategy, - CountQueuingStrategy, - TextEncoderStream, - TextDecoderStream, + WritableStreamDefaultWriter, }; diff --git a/ext/node/polyfills/timers/promises.ts b/ext/node/polyfills/timers/promises.ts index 2ab2384dc2..68bc059426 100644 --- a/ext/node/polyfills/timers/promises.ts +++ b/ext/node/polyfills/timers/promises.ts @@ -17,4 +17,5 @@ export default { setTimeout, setImmediate, setInterval, + scheduler, }; From 3f6605d123ea5c07c7e0bdb7fd5b06676aa8c8e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 00:12:10 +0100 Subject: [PATCH 2/9] feat(ext/node): export missing constants from 'zlib' module (#25584) That puts us at 99.5% compatibility for this module. --- ext/node/polyfills/zlib.ts | 78 +++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 17 deletions(-) diff --git a/ext/node/polyfills/zlib.ts b/ext/node/polyfills/zlib.ts index a19474cfc8..3fe5f8bbd9 100644 --- a/ext/node/polyfills/zlib.ts +++ b/ext/node/polyfills/zlib.ts @@ -78,20 +78,15 @@ export class ZlibBase { export { constants }; export default { - Options, - BrotliOptions, + brotliCompress, BrotliCompress, + brotliCompressSync, + brotliDecompress, BrotliDecompress, - Deflate, - DeflateRaw, - Gunzip, - Gzip, - Inflate, - InflateRaw, - Unzip, - ZlibBase, - constants, + brotliDecompressSync, + BrotliOptions, codes, + constants, createBrotliCompress, createBrotliDecompress, createDeflate, @@ -101,24 +96,73 @@ export default { createInflate, createInflateRaw, createUnzip, - brotliCompress, - brotliCompressSync, - brotliDecompress, - brotliDecompressSync, deflate, - deflateSync, + Deflate, + DEFLATE: constants.DEFLATE, deflateRaw, + DeflateRaw, + DEFLATERAW: constants.DEFLATERAW, deflateRawSync, + deflateSync, gunzip, + Gunzip, + GUNZIP: constants.GUNZIP, gunzipSync, gzip, + Gzip, + GZIP: constants.GZIP, gzipSync, inflate, - inflateSync, + Inflate, + INFLATE: constants.INFLATE, inflateRaw, + InflateRaw, + INFLATERAW: constants.INFLATERAW, inflateRawSync, + inflateSync, + Options, unzip, + Unzip, + UNZIP: constants.UNZIP, unzipSync, + Z_BEST_COMPRESSION: constants.Z_BEST_COMPRESSION, + Z_BEST_SPEED: constants.Z_BEST_SPEED, + Z_BLOCK: constants.Z_BLOCK, + Z_BUF_ERROR: constants.Z_BUF_ERROR, + Z_DATA_ERROR: constants.Z_DATA_ERROR, + Z_DEFAULT_CHUNK: constants.Z_DEFAULT_CHUNK, + Z_DEFAULT_COMPRESSION: constants.Z_DEFAULT_COMPRESSION, + Z_DEFAULT_LEVEL: constants.Z_DEFAULT_LEVEL, + Z_DEFAULT_MEMLEVEL: constants.Z_DEFAULT_MEMLEVEL, + Z_DEFAULT_STRATEGY: constants.Z_DEFAULT_STRATEGY, + Z_DEFAULT_WINDOWBITS: constants.Z_DEFAULT_WINDOWBITS, + Z_ERRNO: constants.Z_ERRNO, + Z_FILTERED: constants.Z_FILTERED, + Z_FINISH: constants.Z_FINISH, + Z_FIXED: constants.Z_FIXED, + Z_FULL_FLUSH: constants.Z_FULL_FLUSH, + Z_HUFFMAN_ONLY: constants.Z_HUFFMAN_ONLY, + Z_MAX_CHUNK: constants.Z_MAX_CHUNK, + Z_MAX_LEVEL: constants.Z_MAX_LEVEL, + Z_MAX_MEMLEVEL: constants.Z_MAX_MEMLEVEL, + Z_MAX_WINDOWBITS: constants.Z_MAX_WINDOWBITS, + Z_MEM_ERROR: constants.Z_MEM_ERROR, + Z_MIN_CHUNK: constants.Z_MIN_CHUNK, + Z_MIN_LEVEL: constants.Z_MIN_LEVEL, + Z_MIN_MEMLEVEL: constants.Z_MIN_MEMLEVEL, + Z_MIN_WINDOWBITS: constants.Z_MIN_WINDOWBITS, + Z_NEED_DICT: constants.Z_NEED_DICT, + Z_NO_COMPRESSION: constants.Z_NO_COMPRESSION, + Z_NO_FLUSH: constants.Z_NO_FLUSH, + Z_OK: constants.Z_OK, + Z_PARTIAL_FLUSH: constants.Z_PARTIAL_FLUSH, + Z_RLE: constants.Z_RLE, + Z_STREAM_END: constants.Z_STREAM_END, + Z_STREAM_ERROR: constants.Z_STREAM_ERROR, + Z_SYNC_FLUSH: constants.Z_SYNC_FLUSH, + Z_VERSION_ERROR: constants.Z_VERSION_ERROR, + ZLIB_VERNUM: constants.ZLIB_VERNUM, + ZlibBase, }; export { From 3a3837545ce6f585f718069cc05d96f765a05d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 01:25:46 +0100 Subject: [PATCH 3/9] feat(ext/node): export missing symbols from domain, puncode, repl, tls (#25585) --- ext/node/polyfills/async_hooks.ts | 67 +++++++++++++++++++++++++- ext/node/polyfills/domain.ts | 14 ++++++ ext/node/polyfills/internal/buffer.mjs | 1 + ext/node/polyfills/punycode.ts | 5 +- ext/node/polyfills/repl.ts | 7 +++ ext/node/polyfills/tls.ts | 4 ++ 6 files changed, 96 insertions(+), 2 deletions(-) diff --git a/ext/node/polyfills/async_hooks.ts b/ext/node/polyfills/async_hooks.ts index 017e9e9bc7..7a2f153dac 100644 --- a/ext/node/polyfills/async_hooks.ts +++ b/ext/node/polyfills/async_hooks.ts @@ -157,7 +157,72 @@ export function executionAsyncResource() { return {}; } -export const asyncWrapProviders = ObjectFreeze({ __proto__: null }); +export const asyncWrapProviders = ObjectFreeze({ + __proto__: null, + NONE: 0, + DIRHANDLE: 1, + DNSCHANNEL: 2, + ELDHISTOGRAM: 3, + FILEHANDLE: 4, + FILEHANDLECLOSEREQ: 5, + BLOBREADER: 6, + FSEVENTWRAP: 7, + FSREQCALLBACK: 8, + FSREQPROMISE: 9, + GETADDRINFOREQWRAP: 10, + GETNAMEINFOREQWRAP: 11, + HEAPSNAPSHOT: 12, + HTTP2SESSION: 13, + HTTP2STREAM: 14, + HTTP2PING: 15, + HTTP2SETTINGS: 16, + HTTPINCOMINGMESSAGE: 17, + HTTPCLIENTREQUEST: 18, + JSSTREAM: 19, + JSUDPWRAP: 20, + MESSAGEPORT: 21, + PIPECONNECTWRAP: 22, + PIPESERVERWRAP: 23, + PIPEWRAP: 24, + PROCESSWRAP: 25, + PROMISE: 26, + QUERYWRAP: 27, + QUIC_ENDPOINT: 28, + QUIC_LOGSTREAM: 29, + QUIC_PACKET: 30, + QUIC_SESSION: 31, + QUIC_STREAM: 32, + QUIC_UDP: 33, + SHUTDOWNWRAP: 34, + SIGNALWRAP: 35, + STATWATCHER: 36, + STREAMPIPE: 37, + TCPCONNECTWRAP: 38, + TCPSERVERWRAP: 39, + TCPWRAP: 40, + TTYWRAP: 41, + UDPSENDWRAP: 42, + UDPWRAP: 43, + SIGINTWATCHDOG: 44, + WORKER: 45, + WORKERHEAPSNAPSHOT: 46, + WRITEWRAP: 47, + ZLIB: 48, + CHECKPRIMEREQUEST: 49, + PBKDF2REQUEST: 50, + KEYPAIRGENREQUEST: 51, + KEYGENREQUEST: 52, + KEYEXPORTREQUEST: 53, + CIPHERREQUEST: 54, + DERIVEBITSREQUEST: 55, + HASHREQUEST: 56, + RANDOMBYTESREQUEST: 57, + RANDOMPRIMEREQUEST: 58, + SCRYPTREQUEST: 59, + SIGNREQUEST: 60, + TLSWRAP: 61, + VERIFYREQUEST: 62, +}); class AsyncHook { enable() { diff --git a/ext/node/polyfills/domain.ts b/ext/node/polyfills/domain.ts index f9c99f7254..7093779966 100644 --- a/ext/node/polyfills/domain.ts +++ b/ext/node/polyfills/domain.ts @@ -15,9 +15,20 @@ function emitError(e) { this.emit("error", e); } +// TODO(bartlomieju): maybe use this one +// deno-lint-ignore prefer-const +let stack = []; +export const _stack = stack; +export const active = null; + export function create() { return new Domain(); } + +export function createDomain() { + return new Domain(); +} + export class Domain extends EventEmitter { #handler; @@ -85,6 +96,9 @@ export class Domain extends EventEmitter { } } export default { + _stack, create, + active, + createDomain, Domain, }; diff --git a/ext/node/polyfills/internal/buffer.mjs b/ext/node/polyfills/internal/buffer.mjs index 48b102a77b..6e43a49031 100644 --- a/ext/node/polyfills/internal/buffer.mjs +++ b/ext/node/polyfills/internal/buffer.mjs @@ -2606,6 +2606,7 @@ export default { constants, isAscii, isUtf8, + INSPECT_MAX_BYTES, kMaxLength, kStringMaxLength, SlowBuffer, diff --git a/ext/node/polyfills/punycode.ts b/ext/node/polyfills/punycode.ts index e89be15a22..adecdf4f9a 100644 --- a/ext/node/polyfills/punycode.ts +++ b/ext/node/polyfills/punycode.ts @@ -11,6 +11,8 @@ import { deprecate } from "node:util"; import { ucs2 } from "ext:deno_node/internal/idna.ts"; +const version = "2.1.0"; + // deno-lint-ignore no-explicit-any function punyDeprecated(fn: any) { return deprecate( @@ -37,7 +39,7 @@ function encode(domain) { return punyDeprecated(op_node_idna_punycode_encode)(domain); } -export { decode, encode, toASCII, toUnicode, ucs2 }; +export { decode, encode, toASCII, toUnicode, ucs2, version }; export default { decode, @@ -45,4 +47,5 @@ export default { toASCII, toUnicode, ucs2, + version, }; diff --git a/ext/node/polyfills/repl.ts b/ext/node/polyfills/repl.ts index 70fe52ce4f..a7acc5b19a 100644 --- a/ext/node/polyfills/repl.ts +++ b/ext/node/polyfills/repl.ts @@ -1,7 +1,12 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright Joyent and Node contributors. All rights reserved. MIT license. +import { primordials } from "ext:core/mod.js"; import { notImplemented } from "ext:deno_node/_utils.ts"; +const { Symbol } = primordials; + +export const REPL_MODE_SLOPPY = Symbol("repl-sloppy"); +export const REPL_MODE_STRICT = Symbol("repl-strict"); export class REPLServer { constructor() { @@ -61,4 +66,6 @@ export default { builtinModules, _builtinLibs, start, + REPL_MODE_SLOPPY, + REPL_MODE_STRICT, }; diff --git a/ext/node/polyfills/tls.ts b/ext/node/polyfills/tls.ts index 6db2bc68c2..a604690835 100644 --- a/ext/node/polyfills/tls.ts +++ b/ext/node/polyfills/tls.ts @@ -34,6 +34,8 @@ export const rootCertificates = undefined; export const DEFAULT_ECDH_CURVE = "auto"; export const DEFAULT_MAX_VERSION = "TLSv1.3"; export const DEFAULT_MIN_VERSION = "TLSv1.2"; +export const CLIENT_RENEG_LIMIT = 3; +export const CLIENT_RENEG_WINDOW = 600; export class CryptoStream {} export class SecurePair {} @@ -58,6 +60,8 @@ export default { DEFAULT_ECDH_CURVE, DEFAULT_MAX_VERSION, DEFAULT_MIN_VERSION, + CLIENT_RENEG_LIMIT, + CLIENT_RENEG_WINDOW, }; export const checkServerIdentity = tlsWrap.checkServerIdentity; From 8476bbff9af28408bc6a9b0a7b2303cb3803422e Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 12 Sep 2024 10:46:48 +1000 Subject: [PATCH 4/9] feat: stabilize `Deno.createHttpClient()` (#25569) Closes #25518 --- cli/main.rs | 7 - cli/tsc/99_main_compiler.js | 3 - cli/tsc/dts/lib.deno.ns.d.ts | 122 ++++++++++++++++ cli/tsc/dts/lib.deno.unstable.d.ts | 135 ------------------ ext/http/http_next.rs | 7 - runtime/js/90_deno_ns.js | 2 + runtime/lib.rs | 2 +- runtime/ops/http.rs | 2 - tests/integration/js_unit_tests.rs | 3 +- tests/integration/node_unit_tests.rs | 1 - tests/integration/run_tests.rs | 11 -- tests/specs/run/045_proxy/proxy_test.ts | 1 - tests/specs/run/unstable/__test__.jsonc | 5 - tests/specs/run/unstable/http.out | 7 - tests/specs/run/unstable/http.ts | 1 - tests/testdata/run/unstable_http.disabled.out | 4 - tests/testdata/run/unstable_http.enabled.out | 4 - tests/testdata/run/unstable_http.js | 11 -- tools/lint.js | 2 +- 19 files changed, 127 insertions(+), 203 deletions(-) delete mode 100644 tests/specs/run/unstable/http.out delete mode 100644 tests/specs/run/unstable/http.ts delete mode 100644 tests/testdata/run/unstable_http.disabled.out delete mode 100644 tests/testdata/run/unstable_http.enabled.out delete mode 100644 tests/testdata/run/unstable_http.js diff --git a/cli/main.rs b/cli/main.rs index 6caeaa5dde..ca233d43cd 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -364,13 +364,6 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec { "Run again with `--unstable-cron` flag to enable this API.", ), ]; - } else if msg.contains("createHttpClient is not a function") { - return vec![ - FixSuggestion::info("Deno.createHttpClient() is an unstable API."), - FixSuggestion::hint( - "Run again with `--unstable-http` flag to enable this API.", - ), - ]; } else if msg.contains("WebSocketStream is not defined") { return vec![ FixSuggestion::info("new WebSocketStream() is an unstable API."), diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 4044c5fc16..03729b8928 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -32,9 +32,7 @@ delete Object.prototype.__proto__; /** @type {ReadonlySet} */ const unstableDenoProps = new Set([ "AtomicOperation", - "CreateHttpClientOptions", "DatagramConn", - "HttpClient", "Kv", "KvListIterator", "KvU64", @@ -44,7 +42,6 @@ delete Object.prototype.__proto__; "UnsafeFnPointer", "UnixConnectOptions", "UnixListenOptions", - "createHttpClient", "dlopen", "listen", "listenDatagram", diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index 2bc3b36a36..0d5e3eaa19 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -6087,4 +6087,126 @@ declare namespace Deno { filename: string | URL, symbols: S, ): DynamicLibrary; + + /** + * A custom `HttpClient` for use with {@linkcode fetch} function. This is + * designed to allow custom certificates or proxies to be used with `fetch()`. + * + * @example ```ts + * const caCert = await Deno.readTextFile("./ca.pem"); + * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); + * const req = await fetch("https://myserver.com", { client }); + * ``` + * + * @category Fetch + */ + export interface HttpClient extends Disposable { + /** Close the HTTP client. */ + close(): void; + } + + /** + * The options used when creating a {@linkcode Deno.HttpClient}. + * + * @category Fetch + */ + export interface CreateHttpClientOptions { + /** A list of root certificates that will be used in addition to the + * default root certificates to verify the peer's certificate. + * + * Must be in PEM format. */ + caCerts?: string[]; + /** A HTTP proxy to use for new connections. */ + proxy?: Proxy; + /** Sets the maximum number of idle connections per host allowed in the pool. */ + poolMaxIdlePerHost?: number; + /** Set an optional timeout for idle sockets being kept-alive. + * Set to false to disable the timeout. */ + poolIdleTimeout?: number | false; + /** + * Whether HTTP/1.1 is allowed or not. + * + * @default {true} + */ + http1?: boolean; + /** Whether HTTP/2 is allowed or not. + * + * @default {true} + */ + http2?: boolean; + /** Whether setting the host header is allowed or not. + * + * @default {false} + */ + allowHost?: boolean; + } + + /** + * The definition of a proxy when specifying + * {@linkcode Deno.CreateHttpClientOptions}. + * + * @category Fetch + */ + export interface Proxy { + /** The string URL of the proxy server to use. */ + url: string; + /** The basic auth credentials to be used against the proxy server. */ + basicAuth?: BasicAuth; + } + + /** + * Basic authentication credentials to be used with a {@linkcode Deno.Proxy} + * server when specifying {@linkcode Deno.CreateHttpClientOptions}. + * + * @category Fetch + */ + export interface BasicAuth { + /** The username to be used against the proxy server. */ + username: string; + /** The password to be used against the proxy server. */ + password: string; + } + + /** Create a custom HttpClient to use with {@linkcode fetch}. This is an + * extension of the web platform Fetch API which allows Deno to use custom + * TLS certificates and connect via a proxy while using `fetch()`. + * + * @example ```ts + * const caCert = await Deno.readTextFile("./ca.pem"); + * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); + * const response = await fetch("https://myserver.com", { client }); + * ``` + * + * @example ```ts + * const client = Deno.createHttpClient({ + * proxy: { url: "http://myproxy.com:8080" } + * }); + * const response = await fetch("https://myserver.com", { client }); + * ``` + * + * @category Fetch + */ + export function createHttpClient( + options: CreateHttpClientOptions, + ): HttpClient; + + /** + * Create a custom HttpClient to use with {@linkcode fetch}. This is an + * extension of the web platform Fetch API which allows Deno to use custom + * TLS certificates and connect via a proxy while using `fetch()`. + * + * @example ```ts + * const caCert = await Deno.readTextFile("./ca.pem"); + * // Load a client key and certificate that we'll use to connect + * const key = await Deno.readTextFile("./key.key"); + * const cert = await Deno.readTextFile("./cert.crt"); + * const client = Deno.createHttpClient({ caCerts: [ caCert ], key, cert }); + * const response = await fetch("https://myserver.com", { client }); + * ``` + * + * @category Fetch + */ + export function createHttpClient( + options: CreateHttpClientOptions & TlsCertifiedKeyPem, + ): HttpClient; } diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index 88f78b8a55..34531ef390 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -36,141 +36,6 @@ declare namespace Deno { present(): void; } - /** **UNSTABLE**: New API, yet to be vetted. - * - * A custom `HttpClient` for use with {@linkcode fetch} function. This is - * designed to allow custom certificates or proxies to be used with `fetch()`. - * - * @example ```ts - * const caCert = await Deno.readTextFile("./ca.pem"); - * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); - * const req = await fetch("https://myserver.com", { client }); - * ``` - * - * @category Fetch - * @experimental - */ - export interface HttpClient extends Disposable { - /** Close the HTTP client. */ - close(): void; - } - - /** **UNSTABLE**: New API, yet to be vetted. - * - * The options used when creating a {@linkcode Deno.HttpClient}. - * - * @category Fetch - * @experimental - */ - export interface CreateHttpClientOptions { - /** A list of root certificates that will be used in addition to the - * default root certificates to verify the peer's certificate. - * - * Must be in PEM format. */ - caCerts?: string[]; - /** A HTTP proxy to use for new connections. */ - proxy?: Proxy; - /** Sets the maximum number of idle connections per host allowed in the pool. */ - poolMaxIdlePerHost?: number; - /** Set an optional timeout for idle sockets being kept-alive. - * Set to false to disable the timeout. */ - poolIdleTimeout?: number | false; - /** - * Whether HTTP/1.1 is allowed or not. - * - * @default {true} - */ - http1?: boolean; - /** Whether HTTP/2 is allowed or not. - * - * @default {true} - */ - http2?: boolean; - /** Whether setting the host header is allowed or not. - * - * @default {false} - */ - allowHost?: boolean; - } - - /** **UNSTABLE**: New API, yet to be vetted. - * - * The definition of a proxy when specifying - * {@linkcode Deno.CreateHttpClientOptions}. - * - * @category Fetch - * @experimental - */ - export interface Proxy { - /** The string URL of the proxy server to use. */ - url: string; - /** The basic auth credentials to be used against the proxy server. */ - basicAuth?: BasicAuth; - } - - /** **UNSTABLE**: New API, yet to be vetted. - * - * Basic authentication credentials to be used with a {@linkcode Deno.Proxy} - * server when specifying {@linkcode Deno.CreateHttpClientOptions}. - * - * @category Fetch - * @experimental - */ - export interface BasicAuth { - /** The username to be used against the proxy server. */ - username: string; - /** The password to be used against the proxy server. */ - password: string; - } - - /** **UNSTABLE**: New API, yet to be vetted. - * - * Create a custom HttpClient to use with {@linkcode fetch}. This is an - * extension of the web platform Fetch API which allows Deno to use custom - * TLS certificates and connect via a proxy while using `fetch()`. - * - * @example ```ts - * const caCert = await Deno.readTextFile("./ca.pem"); - * const client = Deno.createHttpClient({ caCerts: [ caCert ] }); - * const response = await fetch("https://myserver.com", { client }); - * ``` - * - * @example ```ts - * const client = Deno.createHttpClient({ - * proxy: { url: "http://myproxy.com:8080" } - * }); - * const response = await fetch("https://myserver.com", { client }); - * ``` - * - * @category Fetch - * @experimental - */ - export function createHttpClient( - options: CreateHttpClientOptions, - ): HttpClient; - - /** **UNSTABLE**: New API, yet to be vetted. - * - * Create a custom HttpClient to use with {@linkcode fetch}. This is an - * extension of the web platform Fetch API which allows Deno to use custom - * TLS certificates and connect via a proxy while using `fetch()`. - * - * @example ```ts - * const caCert = await Deno.readTextFile("./ca.pem"); - * // Load a client key and certificate that we'll use to connect - * const key = await Deno.readTextFile("./key.key"); - * const cert = await Deno.readTextFile("./cert.crt"); - * const client = Deno.createHttpClient({ caCerts: [ caCert ], key, cert }); - * const response = await fetch("https://myserver.com", { client }); - * ``` - * - * @category Fetch - * @experimental - */ - export function createHttpClient( - options: CreateHttpClientOptions & TlsCertifiedKeyPem, - ): HttpClient; - /** **UNSTABLE**: New API, yet to be vetted. * * Represents membership of a IPv4 multicast group. diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 9ff449a093..efe1b88c93 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -90,13 +90,6 @@ static USE_WRITEV: Lazy = Lazy::new(|| { false }); -// NOTE(bartlomieju): currently we don't have any unstable HTTP features, -// but let's keep this const here, because: -// a) we still need to support `--unstable-http` flag to not break user's CLI; -// b) we might add more unstable features in the future. -#[allow(dead_code)] -pub const UNSTABLE_FEATURE_NAME: &str = "http"; - /// All HTTP/2 connections start with this byte string. /// /// In HTTP/2, each endpoint is required to send a connection preface as a final confirmation diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index f2de16627a..51b00fa023 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -126,6 +126,8 @@ const denoNs = { uid: os.uid, Command: process.Command, ChildProcess: process.ChildProcess, + httpClient: httpClient.httpClient, + createHttpClient: httpClient.createHttpClient, }; // NOTE(bartlomieju): keep IDs in sync with `cli/main.rs` diff --git a/runtime/lib.rs b/runtime/lib.rs index c8ab099f18..ed3f9fbc6a 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -83,7 +83,7 @@ pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[ UnstableGranularFlag { name: ops::http::UNSTABLE_FEATURE_NAME, help_text: "Enable unstable HTTP APIs", - show_in_help: true, + show_in_help: false, id: 5, }, UnstableGranularFlag { diff --git a/runtime/ops/http.rs b/runtime/ops/http.rs index cde2d5858a..a195a759ee 100644 --- a/runtime/ops/http.rs +++ b/runtime/ops/http.rs @@ -57,8 +57,6 @@ fn op_http_start( .resource_table .take::(tcp_stream_rid) { - super::check_unstable(state, UNSTABLE_FEATURE_NAME, "Deno.serveHttp"); - // This UNIX socket might be used somewhere else. If it's the case, we cannot proceed with the // process of starting a HTTP server on top of this UNIX socket, so we just return a bad // resource error. See also: https://github.com/denoland/deno/pull/16242 diff --git a/tests/integration/js_unit_tests.rs b/tests/integration/js_unit_tests.rs index be2af84a82..5efb0f2686 100644 --- a/tests/integration/js_unit_tests.rs +++ b/tests/integration/js_unit_tests.rs @@ -122,9 +122,8 @@ fn js_unit_test(test: String) { .arg("--no-lock") // TODO(bartlomieju): would be better if we could apply this unstable // flag to particular files, but there's many of them that rely on unstable - // net APIs (`reusePort` in `listen` and `listenTls`; `listenDatagram`, `createHttpClient`) + // net APIs (`reusePort` in `listen` and `listenTls`; `listenDatagram`) .arg("--unstable-net") - .arg("--unstable-http") .arg("--location=http://127.0.0.1:4545/") .arg("--no-prompt"); diff --git a/tests/integration/node_unit_tests.rs b/tests/integration/node_unit_tests.rs index 3bec6bb7df..c8b5b25fb3 100644 --- a/tests/integration/node_unit_tests.rs +++ b/tests/integration/node_unit_tests.rs @@ -112,7 +112,6 @@ fn node_unit_test(test: String) { .arg(deno_config_path()) .arg("--no-lock") .arg("--unstable-broadcast-channel") - .arg("--unstable-http") .arg("--unstable-net") // TODO(kt3k): This option is required to pass tls_test.ts, // but this shouldn't be necessary. tls.connect currently doesn't diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 6f85aaf0b8..7140c2cfa8 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -1829,17 +1829,6 @@ itest!(unstable_cron_enabled { output: "run/unstable_cron.enabled.out", }); -itest!(unstable_http_disabled { - args: "run --quiet --reload --allow-read run/unstable_http.js", - output: "run/unstable_http.disabled.out", -}); - -itest!(unstable_http_enabled { - args: - "run --quiet --reload --allow-read --unstable-http run/unstable_http.js", - output: "run/unstable_http.enabled.out", -}); - itest!(unstable_net_disabled { args: "run --quiet --reload --allow-read run/unstable_net.js", output: "run/unstable_net.disabled.out", diff --git a/tests/specs/run/045_proxy/proxy_test.ts b/tests/specs/run/045_proxy/proxy_test.ts index 8ef7cf3da1..22115a3aa8 100644 --- a/tests/specs/run/045_proxy/proxy_test.ts +++ b/tests/specs/run/045_proxy/proxy_test.ts @@ -108,7 +108,6 @@ async function testFetchProgrammaticProxy() { "--quiet", "--reload", "--allow-net=localhost:4545,localhost:4555", - "--unstable-http", "programmatic_proxy_client.ts", ], }).output(); diff --git a/tests/specs/run/unstable/__test__.jsonc b/tests/specs/run/unstable/__test__.jsonc index 5748c5461a..3ddcdb583c 100644 --- a/tests/specs/run/unstable/__test__.jsonc +++ b/tests/specs/run/unstable/__test__.jsonc @@ -10,11 +10,6 @@ "exitCode": 1, "output": "cron.out" }, - "http": { - "args": "run http.ts", - "exitCode": 1, - "output": "http.out" - }, "http_wss": { "args": "run http_wss.ts", "exitCode": 1, diff --git a/tests/specs/run/unstable/http.out b/tests/specs/run/unstable/http.out deleted file mode 100644 index 55e143c25c..0000000000 --- a/tests/specs/run/unstable/http.out +++ /dev/null @@ -1,7 +0,0 @@ -error: Uncaught (in promise) TypeError: Deno.createHttpClient is not a function -Deno.createHttpClient(); - ^ - at [WILDCARD]http.ts:1:6 - - info: Deno.createHttpClient() is an unstable API. - hint: Run again with `--unstable-http` flag to enable this API. diff --git a/tests/specs/run/unstable/http.ts b/tests/specs/run/unstable/http.ts deleted file mode 100644 index 568d6a7ccb..0000000000 --- a/tests/specs/run/unstable/http.ts +++ /dev/null @@ -1 +0,0 @@ -Deno.createHttpClient(); diff --git a/tests/testdata/run/unstable_http.disabled.out b/tests/testdata/run/unstable_http.disabled.out deleted file mode 100644 index 3562f72fdd..0000000000 --- a/tests/testdata/run/unstable_http.disabled.out +++ /dev/null @@ -1,4 +0,0 @@ -main undefined -main undefined -worker undefined -worker undefined diff --git a/tests/testdata/run/unstable_http.enabled.out b/tests/testdata/run/unstable_http.enabled.out deleted file mode 100644 index f7aa776e9e..0000000000 --- a/tests/testdata/run/unstable_http.enabled.out +++ /dev/null @@ -1,4 +0,0 @@ -main [class HttpClient] -main [Function: createHttpClient] -worker [class HttpClient] -worker [Function: createHttpClient] diff --git a/tests/testdata/run/unstable_http.js b/tests/testdata/run/unstable_http.js deleted file mode 100644 index 7ad09aec57..0000000000 --- a/tests/testdata/run/unstable_http.js +++ /dev/null @@ -1,11 +0,0 @@ -const scope = import.meta.url.slice(-7) === "#worker" ? "worker" : "main"; - -console.log(scope, Deno.HttpClient); -console.log(scope, Deno.createHttpClient); - -if (scope === "worker") { - postMessage("done"); -} else { - const worker = new Worker(`${import.meta.url}#worker`, { type: "module" }); - worker.onmessage = () => Deno.exit(0); -} diff --git a/tools/lint.js b/tools/lint.js index c76589c666..0d7160c3f9 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -220,7 +220,7 @@ async function ensureNoNewITests() { "pm_tests.rs": 0, "publish_tests.rs": 0, "repl_tests.rs": 0, - "run_tests.rs": 338, + "run_tests.rs": 336, "shared_library_tests.rs": 0, "task_tests.rs": 4, "test_tests.rs": 74, From f794781ffba941085343b95dd5a9c1ad74a322a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 01:52:08 +0100 Subject: [PATCH 5/9] feat(ext/node): expose ES modules for _ modules (#25588) Exposes following modules: - `"node:_http_agent"` - `"node:_http_common"` - `"node:_http_outgoing"` - `"node:_http_server"` - `"node:_stream_duplex"` - `"node:_stream_passthrough"` - `"node:_stream_readable"` - `"node:_stream_transform"` - `"node:_stream_writable"` - `"node:_tls_common"` - `"node:_tls_wrap"` --- ext/node/lib.rs | 21 +-- ext/node/polyfills/01_require.js | 22 ++- ext/node/polyfills/_http_common.ts | 61 +++++++- ext/node/polyfills/_http_outgoing.ts | 6 +- ext/node/polyfills/_http_server.ts | 136 ++++++++++++++++ ext/node/polyfills/_tls_wrap.ts | 2 +- ext/node/polyfills/http.ts | 180 +--------------------- ext/node/polyfills/http2.ts | 2 +- ext/node/polyfills/https.ts | 2 +- ext/node/polyfills/internal/crypto/sig.ts | 2 +- ext/node/polyfills/tls.ts | 4 +- tools/core_import_map.json | 19 +-- 12 files changed, 249 insertions(+), 208 deletions(-) create mode 100644 ext/node/polyfills/_http_server.ts diff --git a/ext/node/lib.rs b/ext/node/lib.rs index a589a99be0..9cc5e445b5 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -442,17 +442,12 @@ deno_core::extension!(deno_node, "_fs/_fs_write.mjs", "_fs/_fs_writeFile.ts", "_fs/_fs_writev.mjs", - "_http_agent.mjs", - "_http_common.ts", - "_http_outgoing.ts", "_next_tick.ts", "_process/exiting.ts", "_process/process.ts", "_process/streams.mjs", "_readline.mjs", "_stream.mjs", - "_tls_common.ts", - "_tls_wrap.ts", "_util/_util_callbackify.js", "_util/asserts.ts", "_util/async.ts", @@ -547,15 +542,10 @@ deno_core::extension!(deno_node, "internal/streams/add-abort-signal.mjs", "internal/streams/buffer_list.mjs", "internal/streams/destroy.mjs", - "internal/streams/duplex.mjs", "internal/streams/end-of-stream.mjs", "internal/streams/lazy_transform.mjs", - "internal/streams/passthrough.mjs", - "internal/streams/readable.mjs", "internal/streams/state.mjs", - "internal/streams/transform.mjs", "internal/streams/utils.mjs", - "internal/streams/writable.mjs", "internal/test/binding.ts", "internal/timers.mjs", "internal/url.ts", @@ -576,6 +566,17 @@ deno_core::extension!(deno_node, "path/mod.ts", "path/separator.ts", "readline/promises.ts", + "node:_http_agent" = "_http_agent.mjs", + "node:_http_common" = "_http_common.ts", + "node:_http_outgoing" = "_http_outgoing.ts", + "node:_http_server" = "_http_server.ts", + "node:_stream_duplex" = "internal/streams/duplex.mjs", + "node:_stream_passthrough" = "internal/streams/passthrough.mjs", + "node:_stream_readable" = "internal/streams/readable.mjs", + "node:_stream_transform" = "internal/streams/transform.mjs", + "node:_stream_writable" = "internal/streams/writable.mjs", + "node:_tls_common" = "_tls_common.ts", + "node:_tls_wrap" = "_tls_wrap.ts", "node:assert" = "assert.ts", "node:assert/strict" = "assert/strict.ts", "node:async_hooks" = "async_hooks.ts", diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js index b84765d31d..d9ecce6909 100644 --- a/ext/node/polyfills/01_require.js +++ b/ext/node/polyfills/01_require.js @@ -67,13 +67,17 @@ const { import { nodeGlobals } from "ext:deno_node/00_globals.js"; -import _httpAgent from "ext:deno_node/_http_agent.mjs"; -import _httpOutgoing from "ext:deno_node/_http_outgoing.ts"; -import _streamDuplex from "ext:deno_node/internal/streams/duplex.mjs"; -import _streamPassthrough from "ext:deno_node/internal/streams/passthrough.mjs"; -import _streamReadable from "ext:deno_node/internal/streams/readable.mjs"; -import _streamTransform from "ext:deno_node/internal/streams/transform.mjs"; -import _streamWritable from "ext:deno_node/internal/streams/writable.mjs"; +import _httpAgent from "node:_http_agent"; +import _httpCommon from "node:_http_common"; +import _httpOutgoing from "node:_http_outgoing"; +import _httpServer from "node:_http_server"; +import _streamDuplex from "node:_stream_duplex"; +import _streamPassthrough from "node:_stream_passthrough"; +import _streamReadable from "node:_stream_readable"; +import _streamTransform from "node:_stream_transform"; +import _streamWritable from "node:_stream_writable"; +import _tlsCommon from "node:_tls_common"; +import _tlsWrap from "node:_tls_wrap"; import assert from "node:assert"; import assertStrict from "node:assert/strict"; import asyncHooks from "node:async_hooks"; @@ -163,12 +167,16 @@ const builtinModules = []; function setupBuiltinModules() { const nodeModules = { "_http_agent": _httpAgent, + "_http_common": _httpCommon, "_http_outgoing": _httpOutgoing, + "_http_server": _httpServer, "_stream_duplex": _streamDuplex, "_stream_passthrough": _streamPassthrough, "_stream_readable": _streamReadable, "_stream_transform": _streamTransform, "_stream_writable": _streamWritable, + "_tls_common": _tlsCommon, + "_tls_wrap": _tlsWrap, assert, "assert/strict": assertStrict, "async_hooks": asyncHooks, diff --git a/ext/node/polyfills/_http_common.ts b/ext/node/polyfills/_http_common.ts index 24dae6f300..8fb7758a55 100644 --- a/ext/node/polyfills/_http_common.ts +++ b/ext/node/polyfills/_http_common.ts @@ -2,8 +2,53 @@ // Copyright Joyent and Node contributors. All rights reserved. MIT license. import { primordials } from "ext:core/mod.js"; -const { RegExpPrototypeTest, SafeRegExp } = primordials; +const { + RegExpPrototypeTest, + SafeRegExp, + Symbol, +} = primordials; + +export const CRLF = "\r\n"; +export const kIncomingMessage = Symbol("IncomingMessage"); const tokenRegExp = new SafeRegExp(/^[\^_`a-zA-Z\-0-9!#$%&'*+.|~]+$/); + +export const methods = [ + "ACL", + "BIND", + "CHECKOUT", + "CONNECT", + "COPY", + "DELETE", + "GET", + "HEAD", + "LINK", + "LOCK", + "M-SEARCH", + "MERGE", + "MKACTIVITY", + "MKCALENDAR", + "MKCOL", + "MOVE", + "NOTIFY", + "OPTIONS", + "PATCH", + "POST", + "PROPFIND", + "PROPPATCH", + "PURGE", + "PUT", + "REBIND", + "REPORT", + "SEARCH", + "SOURCE", + "SUBSCRIBE", + "TRACE", + "UNBIND", + "UNLINK", + "UNLOCK", + "UNSUBSCRIBE", +]; + /** * Verifies that the given val is a valid HTTP token * per the rules defined in RFC 7230 @@ -25,7 +70,21 @@ function checkInvalidHeaderChar(val: string) { } export const chunkExpression = new SafeRegExp(/(?:^|\W)chunked(?:$|\W)/i); +export const continueExpression = new SafeRegExp( + /(?:^|\W)100-continue(?:$|\W)/i, +); + export { checkInvalidHeaderChar as _checkInvalidHeaderChar, checkIsHttpToken as _checkIsHttpToken, }; + +export default { + _checkInvalidHeaderChar: checkInvalidHeaderChar, + _checkIsHttpToken: checkIsHttpToken, + chunkExpression, + CRLF, + continueExpression, + kIncomingMessage, + methods, +}; diff --git a/ext/node/polyfills/_http_outgoing.ts b/ext/node/polyfills/_http_outgoing.ts index 3c253f5a6c..4da6b73e87 100644 --- a/ext/node/polyfills/_http_outgoing.ts +++ b/ext/node/polyfills/_http_outgoing.ts @@ -21,7 +21,7 @@ import { _checkInvalidHeaderChar as checkInvalidHeaderChar, _checkIsHttpToken as checkIsHttpToken, chunkExpression as RE_TE_CHUNKED, -} from "ext:deno_node/_http_common.ts"; +} from "node:_http_common"; import { defaultTriggerAsyncIdScope, symbols, @@ -54,6 +54,8 @@ let debug = debuglog("http", (fn) => { const HIGH_WATER_MARK = getDefaultHighWaterMark(); +export const kUniqueHeaders = Symbol("kUniqueHeaders"); +export const kHighWaterMark = Symbol("kHighWaterMark"); const kCorked = Symbol("corked"); const nop = () => {}; @@ -891,6 +893,8 @@ function _onFinish(outmsg: any) { } export default { + kUniqueHeaders, + kHighWaterMark, validateHeaderName, validateHeaderValue, parseUniqueHeadersOption, diff --git a/ext/node/polyfills/_http_server.ts b/ext/node/polyfills/_http_server.ts new file mode 100644 index 0000000000..c2867de0c6 --- /dev/null +++ b/ext/node/polyfills/_http_server.ts @@ -0,0 +1,136 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +export enum STATUS_CODES { + /** RFC 7231, 6.2.1 */ + Continue = 100, + /** RFC 7231, 6.2.2 */ + SwitchingProtocols = 101, + /** RFC 2518, 10.1 */ + Processing = 102, + /** RFC 8297 **/ + EarlyHints = 103, + + /** RFC 7231, 6.3.1 */ + OK = 200, + /** RFC 7231, 6.3.2 */ + Created = 201, + /** RFC 7231, 6.3.3 */ + Accepted = 202, + /** RFC 7231, 6.3.4 */ + NonAuthoritativeInfo = 203, + /** RFC 7231, 6.3.5 */ + NoContent = 204, + /** RFC 7231, 6.3.6 */ + ResetContent = 205, + /** RFC 7233, 4.1 */ + PartialContent = 206, + /** RFC 4918, 11.1 */ + MultiStatus = 207, + /** RFC 5842, 7.1 */ + AlreadyReported = 208, + /** RFC 3229, 10.4.1 */ + IMUsed = 226, + + /** RFC 7231, 6.4.1 */ + MultipleChoices = 300, + /** RFC 7231, 6.4.2 */ + MovedPermanently = 301, + /** RFC 7231, 6.4.3 */ + Found = 302, + /** RFC 7231, 6.4.4 */ + SeeOther = 303, + /** RFC 7232, 4.1 */ + NotModified = 304, + /** RFC 7231, 6.4.5 */ + UseProxy = 305, + /** RFC 7231, 6.4.7 */ + TemporaryRedirect = 307, + /** RFC 7538, 3 */ + PermanentRedirect = 308, + + /** RFC 7231, 6.5.1 */ + BadRequest = 400, + /** RFC 7235, 3.1 */ + Unauthorized = 401, + /** RFC 7231, 6.5.2 */ + PaymentRequired = 402, + /** RFC 7231, 6.5.3 */ + Forbidden = 403, + /** RFC 7231, 6.5.4 */ + NotFound = 404, + /** RFC 7231, 6.5.5 */ + MethodNotAllowed = 405, + /** RFC 7231, 6.5.6 */ + NotAcceptable = 406, + /** RFC 7235, 3.2 */ + ProxyAuthRequired = 407, + /** RFC 7231, 6.5.7 */ + RequestTimeout = 408, + /** RFC 7231, 6.5.8 */ + Conflict = 409, + /** RFC 7231, 6.5.9 */ + Gone = 410, + /** RFC 7231, 6.5.10 */ + LengthRequired = 411, + /** RFC 7232, 4.2 */ + PreconditionFailed = 412, + /** RFC 7231, 6.5.11 */ + RequestEntityTooLarge = 413, + /** RFC 7231, 6.5.12 */ + RequestURITooLong = 414, + /** RFC 7231, 6.5.13 */ + UnsupportedMediaType = 415, + /** RFC 7233, 4.4 */ + RequestedRangeNotSatisfiable = 416, + /** RFC 7231, 6.5.14 */ + ExpectationFailed = 417, + /** RFC 7168, 2.3.3 */ + Teapot = 418, + /** RFC 7540, 9.1.2 */ + MisdirectedRequest = 421, + /** RFC 4918, 11.2 */ + UnprocessableEntity = 422, + /** RFC 4918, 11.3 */ + Locked = 423, + /** RFC 4918, 11.4 */ + FailedDependency = 424, + /** RFC 8470, 5.2 */ + TooEarly = 425, + /** RFC 7231, 6.5.15 */ + UpgradeRequired = 426, + /** RFC 6585, 3 */ + PreconditionRequired = 428, + /** RFC 6585, 4 */ + TooManyRequests = 429, + /** RFC 6585, 5 */ + RequestHeaderFieldsTooLarge = 431, + /** RFC 7725, 3 */ + UnavailableForLegalReasons = 451, + + /** RFC 7231, 6.6.1 */ + InternalServerError = 500, + /** RFC 7231, 6.6.2 */ + NotImplemented = 501, + /** RFC 7231, 6.6.3 */ + BadGateway = 502, + /** RFC 7231, 6.6.4 */ + ServiceUnavailable = 503, + /** RFC 7231, 6.6.5 */ + GatewayTimeout = 504, + /** RFC 7231, 6.6.6 */ + HTTPVersionNotSupported = 505, + /** RFC 2295, 8.1 */ + VariantAlsoNegotiates = 506, + /** RFC 4918, 11.5 */ + InsufficientStorage = 507, + /** RFC 5842, 7.2 */ + LoopDetected = 508, + /** RFC 2774, 7 */ + NotExtended = 510, + /** RFC 6585, 6 */ + NetworkAuthenticationRequired = 511, +} + +export default { + STATUS_CODES, +}; diff --git a/ext/node/polyfills/_tls_wrap.ts b/ext/node/polyfills/_tls_wrap.ts index ed2bdd0a39..a614b45df0 100644 --- a/ext/node/polyfills/_tls_wrap.ts +++ b/ext/node/polyfills/_tls_wrap.ts @@ -10,7 +10,7 @@ import { } from "ext:deno_node/internal/primordials.mjs"; import assert from "ext:deno_node/internal/assert.mjs"; import * as net from "node:net"; -import { createSecureContext } from "ext:deno_node/_tls_common.ts"; +import { createSecureContext } from "node:_tls_common"; import { kStreamBaseField } from "ext:deno_node/internal_binding/stream_wrap.ts"; import { connResetException } from "ext:deno_node/internal/errors.ts"; import { emitWarning } from "node:process"; diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index a9eee00191..f3f6f86ed8 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -36,16 +36,16 @@ import { Writable as NodeWritable, } from "node:stream"; import { + kUniqueHeaders, OutgoingMessage, parseUniqueHeadersOption, validateHeaderName, validateHeaderValue, -} from "ext:deno_node/_http_outgoing.ts"; +} from "node:_http_outgoing"; import { ok as assert } from "node:assert"; import { kOutHeaders } from "ext:deno_node/internal/http.ts"; -import { _checkIsHttpToken as checkIsHttpToken } from "ext:deno_node/_http_common.ts"; -import { Agent, globalAgent } from "ext:deno_node/_http_agent.mjs"; -// import { chunkExpression as RE_TE_CHUNKED } from "ext:deno_node/_http_common.ts"; +import { _checkIsHttpToken as checkIsHttpToken } from "node:_http_common"; +import { Agent, globalAgent } from "node:_http_agent"; import { urlToHttpOptions } from "ext:deno_node/internal/url.ts"; import { kEmptyObject } from "ext:deno_node/internal/util.mjs"; import { constants, TCP } from "ext:deno_node/internal_binding/tcp_wrap.ts"; @@ -67,178 +67,12 @@ import { timerId } from "ext:deno_web/03_abort_signal.js"; import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js"; import { resourceForReadableStream } from "ext:deno_web/06_streams.js"; import { TcpConn } from "ext:deno_net/01_net.js"; +import { STATUS_CODES } from "node:_http_server"; +import { methods as METHODS } from "node:_http_common"; const { internalRidSymbol } = core; const { ArrayIsArray } = primordials; -enum STATUS_CODES { - /** RFC 7231, 6.2.1 */ - Continue = 100, - /** RFC 7231, 6.2.2 */ - SwitchingProtocols = 101, - /** RFC 2518, 10.1 */ - Processing = 102, - /** RFC 8297 **/ - EarlyHints = 103, - - /** RFC 7231, 6.3.1 */ - OK = 200, - /** RFC 7231, 6.3.2 */ - Created = 201, - /** RFC 7231, 6.3.3 */ - Accepted = 202, - /** RFC 7231, 6.3.4 */ - NonAuthoritativeInfo = 203, - /** RFC 7231, 6.3.5 */ - NoContent = 204, - /** RFC 7231, 6.3.6 */ - ResetContent = 205, - /** RFC 7233, 4.1 */ - PartialContent = 206, - /** RFC 4918, 11.1 */ - MultiStatus = 207, - /** RFC 5842, 7.1 */ - AlreadyReported = 208, - /** RFC 3229, 10.4.1 */ - IMUsed = 226, - - /** RFC 7231, 6.4.1 */ - MultipleChoices = 300, - /** RFC 7231, 6.4.2 */ - MovedPermanently = 301, - /** RFC 7231, 6.4.3 */ - Found = 302, - /** RFC 7231, 6.4.4 */ - SeeOther = 303, - /** RFC 7232, 4.1 */ - NotModified = 304, - /** RFC 7231, 6.4.5 */ - UseProxy = 305, - /** RFC 7231, 6.4.7 */ - TemporaryRedirect = 307, - /** RFC 7538, 3 */ - PermanentRedirect = 308, - - /** RFC 7231, 6.5.1 */ - BadRequest = 400, - /** RFC 7235, 3.1 */ - Unauthorized = 401, - /** RFC 7231, 6.5.2 */ - PaymentRequired = 402, - /** RFC 7231, 6.5.3 */ - Forbidden = 403, - /** RFC 7231, 6.5.4 */ - NotFound = 404, - /** RFC 7231, 6.5.5 */ - MethodNotAllowed = 405, - /** RFC 7231, 6.5.6 */ - NotAcceptable = 406, - /** RFC 7235, 3.2 */ - ProxyAuthRequired = 407, - /** RFC 7231, 6.5.7 */ - RequestTimeout = 408, - /** RFC 7231, 6.5.8 */ - Conflict = 409, - /** RFC 7231, 6.5.9 */ - Gone = 410, - /** RFC 7231, 6.5.10 */ - LengthRequired = 411, - /** RFC 7232, 4.2 */ - PreconditionFailed = 412, - /** RFC 7231, 6.5.11 */ - RequestEntityTooLarge = 413, - /** RFC 7231, 6.5.12 */ - RequestURITooLong = 414, - /** RFC 7231, 6.5.13 */ - UnsupportedMediaType = 415, - /** RFC 7233, 4.4 */ - RequestedRangeNotSatisfiable = 416, - /** RFC 7231, 6.5.14 */ - ExpectationFailed = 417, - /** RFC 7168, 2.3.3 */ - Teapot = 418, - /** RFC 7540, 9.1.2 */ - MisdirectedRequest = 421, - /** RFC 4918, 11.2 */ - UnprocessableEntity = 422, - /** RFC 4918, 11.3 */ - Locked = 423, - /** RFC 4918, 11.4 */ - FailedDependency = 424, - /** RFC 8470, 5.2 */ - TooEarly = 425, - /** RFC 7231, 6.5.15 */ - UpgradeRequired = 426, - /** RFC 6585, 3 */ - PreconditionRequired = 428, - /** RFC 6585, 4 */ - TooManyRequests = 429, - /** RFC 6585, 5 */ - RequestHeaderFieldsTooLarge = 431, - /** RFC 7725, 3 */ - UnavailableForLegalReasons = 451, - - /** RFC 7231, 6.6.1 */ - InternalServerError = 500, - /** RFC 7231, 6.6.2 */ - NotImplemented = 501, - /** RFC 7231, 6.6.3 */ - BadGateway = 502, - /** RFC 7231, 6.6.4 */ - ServiceUnavailable = 503, - /** RFC 7231, 6.6.5 */ - GatewayTimeout = 504, - /** RFC 7231, 6.6.6 */ - HTTPVersionNotSupported = 505, - /** RFC 2295, 8.1 */ - VariantAlsoNegotiates = 506, - /** RFC 4918, 11.5 */ - InsufficientStorage = 507, - /** RFC 5842, 7.2 */ - LoopDetected = 508, - /** RFC 2774, 7 */ - NotExtended = 510, - /** RFC 6585, 6 */ - NetworkAuthenticationRequired = 511, -} - -const METHODS = [ - "ACL", - "BIND", - "CHECKOUT", - "CONNECT", - "COPY", - "DELETE", - "GET", - "HEAD", - "LINK", - "LOCK", - "M-SEARCH", - "MERGE", - "MKACTIVITY", - "MKCALENDAR", - "MKCOL", - "MOVE", - "NOTIFY", - "OPTIONS", - "PATCH", - "POST", - "PROPFIND", - "PROPPATCH", - "PURGE", - "PUT", - "REBIND", - "REPORT", - "SEARCH", - "SOURCE", - "SUBSCRIBE", - "TRACE", - "UNBIND", - "UNLINK", - "UNLOCK", - "UNSUBSCRIBE", -]; - type Chunk = string | Buffer | Uint8Array; const ENCODER = new TextEncoder(); @@ -283,8 +117,6 @@ function validateHost(host, name) { const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/; const kError = Symbol("kError"); -const kUniqueHeaders = Symbol("kUniqueHeaders"); - class FakeSocket extends EventEmitter { constructor( opts: { diff --git a/ext/node/polyfills/http2.ts b/ext/node/polyfills/http2.ts index b4cda65f84..cab7aa26c0 100644 --- a/ext/node/polyfills/http2.ts +++ b/ext/node/polyfills/http2.ts @@ -67,7 +67,7 @@ import { ERR_SOCKET_CLOSED, ERR_STREAM_WRITE_AFTER_END, } from "ext:deno_node/internal/errors.ts"; -import { _checkIsHttpToken } from "ext:deno_node/_http_common.ts"; +import { _checkIsHttpToken } from "node:_http_common"; const { StringPrototypeTrim, FunctionPrototypeBind, diff --git a/ext/node/polyfills/https.ts b/ext/node/polyfills/https.ts index c1f1237b1a..f60c5e471a 100644 --- a/ext/node/polyfills/https.ts +++ b/ext/node/polyfills/https.ts @@ -11,7 +11,7 @@ import { IncomingMessageForClient as IncomingMessage, type RequestOptions, } from "node:http"; -import { Agent as HttpAgent } from "ext:deno_node/_http_agent.mjs"; +import { Agent as HttpAgent } from "node:_http_agent"; import { createHttpClient } from "ext:deno_fetch/22_http_client.js"; import { type ServerHandler, ServerImpl as HttpServer } from "node:http"; import { validateObject } from "ext:deno_node/internal/validators.mjs"; diff --git a/ext/node/polyfills/internal/crypto/sig.ts b/ext/node/polyfills/internal/crypto/sig.ts index bcbcb469b9..a05f16478d 100644 --- a/ext/node/polyfills/internal/crypto/sig.ts +++ b/ext/node/polyfills/internal/crypto/sig.ts @@ -20,7 +20,7 @@ import { } from "ext:deno_node/internal/validators.mjs"; import { Buffer } from "node:buffer"; import type { WritableOptions } from "ext:deno_node/_stream.d.ts"; -import Writable from "ext:deno_node/internal/streams/writable.mjs"; +import Writable from "node:_stream_writable"; import type { BinaryLike, BinaryToTextEncoding, diff --git a/ext/node/polyfills/tls.ts b/ext/node/polyfills/tls.ts index a604690835..7d00bc6e51 100644 --- a/ext/node/polyfills/tls.ts +++ b/ext/node/polyfills/tls.ts @@ -5,8 +5,8 @@ // deno-lint-ignore-file prefer-primordials import { notImplemented } from "ext:deno_node/_utils.ts"; -import tlsCommon from "ext:deno_node/_tls_common.ts"; -import tlsWrap from "ext:deno_node/_tls_wrap.ts"; +import tlsCommon from "node:_tls_common"; +import tlsWrap from "node:_tls_wrap"; // openssl -> rustls const cipherMap = { diff --git a/tools/core_import_map.json b/tools/core_import_map.json index 15affc2b7f..aae4e63a45 100644 --- a/tools/core_import_map.json +++ b/tools/core_import_map.json @@ -40,9 +40,10 @@ "ext:deno_node/_fs/_fs_write.mjs": "../ext/node/polyfills/_fs/_fs_write.mjs", "ext:deno_node/_fs/_fs_writev.mjs": "../ext/node/polyfills/_fs/_fs_writev.mjs", "ext:deno_node/_global.d.ts": "../ext/node/polyfills/_global.d.ts", - "ext:deno_node/_http_agent.mjs": "../ext/node/polyfills/_http_agent.mjs", - "ext:deno_node/_http_common.ts": "../ext/node/polyfills/_http_common.ts", - "ext:deno_node/_http_outgoing.ts": "../ext/node/polyfills/_http_outgoing.ts", + "node:_http_agent": "../ext/node/polyfills/_http_agent.mjs", + "node:_http_common": "../ext/node/polyfills/_http_common.ts", + "node:_http_outgoing": "../ext/node/polyfills/_http_outgoing.ts", + "node:_http_server": "../ext/node/polyfills/_http_server.ts", "ext:deno_node/_next_tick.ts": "../ext/node/polyfills/_next_tick.ts", "ext:deno_node/_process/exiting.ts": "../ext/node/polyfills/_process/exiting.ts", "ext:deno_node/_process/process.ts": "../ext/node/polyfills/_process/process.ts", @@ -50,7 +51,7 @@ "ext:deno_node/_readline_shared_types.d.ts": "../ext/node/polyfills/_readline_shared_types.d.ts", "ext:deno_node/_stream.d.ts": "../ext/node/polyfills/_stream.d.ts", "ext:deno_node/_stream.mjs": "../ext/node/polyfills/_stream.mjs", - "ext:deno_node/_tls_common.ts": "../ext/node/polyfills/_tls_common.ts", + "node:_tls_common": "../ext/node/polyfills/_tls_common.ts", "ext:deno_node/_util/asserts.ts": "../ext/node/polyfills/_util/asserts.ts", "ext:deno_node/_util/async.ts": "../ext/node/polyfills/_util/async.ts", "ext:deno_node/_util/os.ts": "../ext/node/polyfills/_util/os.ts", @@ -154,15 +155,15 @@ "ext:deno_node/internal/streams/add-abort-signal.mjs": "../ext/node/polyfills/internal/streams/add-abort-signal.mjs", "ext:deno_node/internal/streams/buffer_list.mjs": "../ext/node/polyfills/internal/streams/buffer_list.mjs", "ext:deno_node/internal/streams/destroy.mjs": "../ext/node/polyfills/internal/streams/destroy.mjs", - "ext:deno_node/internal/streams/duplex.mjs": "../ext/node/polyfills/internal/streams/duplex.mjs", + "node:_stream_duplex": "../ext/node/polyfills/internal/streams/duplex.mjs", "ext:deno_node/internal/streams/end-of-stream.mjs": "../ext/node/polyfills/internal/streams/end-of-stream.mjs", "ext:deno_node/internal/streams/lazy_transform.mjs": "../ext/node/polyfills/internal/streams/lazy_transform.mjs", - "ext:deno_node/internal/streams/passthrough.mjs": "../ext/node/polyfills/internal/streams/passthrough.mjs", - "ext:deno_node/internal/streams/readable.mjs": "../ext/node/polyfills/internal/streams/readable.mjs", + "node:_stream_readable": "../ext/node/polyfills/internal/streams/readable.mjs", + "node:_stream_passthrough": "../ext/node/polyfills/internal/streams/passthrough.mjs", "ext:deno_node/internal/streams/state.mjs": "../ext/node/polyfills/internal/streams/state.mjs", - "ext:deno_node/internal/streams/transform.mjs": "../ext/node/polyfills/internal/streams/transform.mjs", "ext:deno_node/internal/streams/utils.mjs": "../ext/node/polyfills/internal/streams/utils.mjs", - "ext:deno_node/internal/streams/writable.mjs": "../ext/node/polyfills/internal/streams/writable.mjs", + "node:_stream_transform": "../ext/node/polyfills/internal/streams/transform.mjs", + "node:_stream_writable": "../ext/node/polyfills/internal/streams/writable.mjs", "ext:deno_node/internal/test/binding.ts": "../ext/node/polyfills/internal/test/binding.ts", "ext:deno_node/internal/timers.mjs": "../ext/node/polyfills/internal/timers.mjs", "ext:deno_node/internal/url.ts": "../ext/node/polyfills/internal/url.ts", From 025e4bdaaca3ce029602ba3fef63865f6573e5e4 Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Thu, 12 Sep 2024 03:59:05 +0300 Subject: [PATCH 6/9] fix(ext/webgpu): sync category comment (#25580) Signed-off-by: Victor Turansky --- cli/tsc/dts/lib.deno_webgpu.d.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/cli/tsc/dts/lib.deno_webgpu.d.ts b/cli/tsc/dts/lib.deno_webgpu.d.ts index fc2676b2e3..3a602d78a4 100644 --- a/cli/tsc/dts/lib.deno_webgpu.d.ts +++ b/cli/tsc/dts/lib.deno_webgpu.d.ts @@ -600,16 +600,10 @@ declare interface GPUPipelineErrorInit { reason: GPUPipelineErrorReason; } -/** - * @category GPU - * @ - */ +/** @category GPU */ declare type GPUPipelineErrorReason = "validation" | "internal"; -/** - * @category GPU - * @ - */ +/** @category GPU */ declare class GPUShaderModule implements GPUObjectBase { label: string; } @@ -1150,10 +1144,7 @@ declare interface GPURenderPassColorAttachment { storeOp: GPUStoreOp; } -/** - * @category GPU - * @ - */ +/** @category GPU */ declare interface GPURenderPassDepthStencilAttachment { view: GPUTextureView; From 57556ade8c128aeea7340d463b35c86afe1fb4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 02:20:45 +0100 Subject: [PATCH 7/9] v2.0.0-rc.2 (#25583) --- Cargo.lock | 2 +- cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0453719a47..8fa148651f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1146,7 +1146,7 @@ dependencies = [ [[package]] name = "deno" -version = "2.0.0-rc.1" +version = "2.0.0-rc.2" dependencies = [ "anstream", "async-trait", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 882c8d8bc1..db9fd0f03d 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno" -version = "2.0.0-rc.1" +version = "2.0.0-rc.2" authors.workspace = true default-run = "deno" edition.workspace = true From 3285801429eb7a40e022b571b7e3007c3e60250c Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 12 Sep 2024 11:30:12 +1000 Subject: [PATCH 8/9] test: remove `DENO_FUTURE` (#25587) --- tests/unit/fetch_test.ts | 3 +- tests/unit/files_test.ts | 3 +- tests/unit/globals_test.ts | 41 ++------------------------- tests/unit/serve_test.ts | 3 +- tests/unit/test_util.ts | 3 -- tests/unit/timers_test.ts | 57 ++------------------------------------ tests/unit/tls_test.ts | 5 ++-- tests/unit/tty_test.ts | 13 +-------- 8 files changed, 11 insertions(+), 117 deletions(-) diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index 35517911cc..48cde90ab6 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -9,7 +9,6 @@ import { assertStringIncludes, assertThrows, delay, - DENO_FUTURE, fail, unimplemented, } from "./test_util.ts"; @@ -1359,7 +1358,7 @@ Deno.test( ); Deno.test( - { permissions: { read: true, net: true }, ignore: DENO_FUTURE }, + { permissions: { read: true, net: true } }, async function fetchCustomClientPrivateKey(): Promise< void > { diff --git a/tests/unit/files_test.ts b/tests/unit/files_test.ts index 3bbfc3855c..a847104c28 100644 --- a/tests/unit/files_test.ts +++ b/tests/unit/files_test.ts @@ -5,7 +5,6 @@ import { assertEquals, assertRejects, assertThrows, - DENO_FUTURE, } from "./test_util.ts"; import { copy } from "@std/io/copy"; @@ -21,7 +20,7 @@ Deno.test(function filesStdioFileDescriptors() { }); Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, + { permissions: { read: true } }, async function filesCopyToStdout() { const filename = "tests/testdata/assets/fixture.json"; using file = await Deno.open(filename); diff --git a/tests/unit/globals_test.ts b/tests/unit/globals_test.ts index 7e648d38db..45a0458357 100644 --- a/tests/unit/globals_test.ts +++ b/tests/unit/globals_test.ts @@ -1,12 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -// deno-lint-ignore-file no-window-prefix no-window import { assert, assertEquals, assertRejects, assertThrows, - DENO_FUTURE, } from "./test_util.ts"; Deno.test(function globalThisExists() { @@ -20,34 +18,18 @@ Deno.test(function noInternalGlobals() { } }); -Deno.test({ ignore: DENO_FUTURE }, function windowExists() { - assert(window != null); -}); - Deno.test(function selfExists() { assert(self != null); }); -Deno.test({ ignore: DENO_FUTURE }, function windowWindowExists() { - assert(window.window === window); -}); - -Deno.test({ ignore: DENO_FUTURE }, function windowSelfExists() { - assert(window.self === window); -}); - -Deno.test({ ignore: DENO_FUTURE }, function globalThisEqualsWindow() { - assert(globalThis === window); +Deno.test(function globalThisWindowEqualsUndefined() { + assert(globalThis.window === undefined); }); Deno.test(function globalThisEqualsSelf() { assert(globalThis === self); }); -Deno.test({ ignore: DENO_FUTURE }, function globalThisInstanceofWindow() { - assert(globalThis instanceof Window); -}); - Deno.test(function globalThisConstructorLength() { assert(globalThis.constructor.length === 0); }); @@ -66,10 +48,6 @@ Deno.test(function DenoNamespaceExists() { assert(Deno != null); }); -Deno.test({ ignore: DENO_FUTURE }, function DenoNamespaceEqualsWindowDeno() { - assert(Deno === window.Deno); -}); - Deno.test(function DenoNamespaceIsNotFrozen() { assert(!Object.isFrozen(Deno)); }); @@ -120,11 +98,7 @@ Deno.test(async function windowQueueMicrotask() { res(); }; }); - if (DENO_FUTURE) { - globalThis.queueMicrotask(resolve1!); - } else { - window.queueMicrotask(resolve1!); - } + globalThis.queueMicrotask(resolve1!); setTimeout(resolve2!, 0); await p1; await p2; @@ -143,18 +117,9 @@ Deno.test(function webApiGlobalThis() { Deno.test(function windowNameIsDefined() { assertEquals(typeof globalThis.name, "string"); assertEquals(name, ""); - if (!DENO_FUTURE) { - assertEquals(window.name, name); - } name = "foobar"; - if (!DENO_FUTURE) { - assertEquals(window.name, "foobar"); - } assertEquals(name, "foobar"); name = ""; - if (!DENO_FUTURE) { - assertEquals(window.name, ""); - } assertEquals(name, ""); }); diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 13f8ba867a..4a19d8df2f 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -12,7 +12,6 @@ import { assertThrows, curlRequest, curlRequestWithStdErr, - DENO_FUTURE, execCode, execCode3, fail, @@ -20,7 +19,7 @@ import { } from "./test_util.ts"; // Since these tests may run in parallel, ensure this port is unique to this file -const servePort = DENO_FUTURE ? 4511 : 4502; +const servePort = 4511; const { upgradeHttpRaw, diff --git a/tests/unit/test_util.ts b/tests/unit/test_util.ts index 3f41b90a28..a987cb5427 100644 --- a/tests/unit/test_util.ts +++ b/tests/unit/test_util.ts @@ -25,9 +25,6 @@ export { delay } from "@std/async/delay"; export { readLines } from "@std/io/read-lines"; export { parseArgs } from "@std/cli/parse-args"; -// TODO(2.0): remove this and all the tests that depend on it. -export const DENO_FUTURE = true; - export function pathToAbsoluteFileUrl(path: string): URL { path = resolve(path); diff --git a/tests/unit/timers_test.ts b/tests/unit/timers_test.ts index 212f197ccf..580d8c524e 100644 --- a/tests/unit/timers_test.ts +++ b/tests/unit/timers_test.ts @@ -7,7 +7,6 @@ import { assertEquals, assertNotEquals, delay, - DENO_FUTURE, execCode, unreachable, } from "./test_util.ts"; @@ -312,62 +311,10 @@ Deno.test(async function timeoutCallbackThis() { }; setTimeout(obj.foo, 1); await promise; - if (!DENO_FUTURE) { - assertEquals(capturedThis, window); - } else { - assertEquals(capturedThis, globalThis); - } + assertEquals(capturedThis, globalThis); }); -Deno.test({ ignore: DENO_FUTURE }, async function timeoutBindThis() { - const thisCheckPassed = [null, undefined, globalThis, window]; - - const thisCheckFailed = [ - 0, - "", - true, - false, - {}, - [], - "foo", - () => {}, - Object.prototype, - ]; - - for (const thisArg of thisCheckPassed) { - const { promise, resolve } = Promise.withResolvers(); - let hasThrown = 0; - try { - setTimeout.call(thisArg, () => resolve(), 1); - hasThrown = 1; - } catch (err) { - if (err instanceof TypeError) { - hasThrown = 2; - } else { - hasThrown = 3; - } - } - await promise; - assertEquals(hasThrown, 1); - } - - for (const thisArg of thisCheckFailed) { - let hasThrown = 0; - try { - setTimeout.call(thisArg, () => {}, 1); - hasThrown = 1; - } catch (err) { - if (err instanceof TypeError) { - hasThrown = 2; - } else { - hasThrown = 3; - } - } - assertEquals(hasThrown, 2); - } -}); - -Deno.test({ ignore: !DENO_FUTURE }, async function timeoutBindThis() { +Deno.test(async function timeoutBindThis() { const thisCheckPassed = [null, undefined, globalThis]; const thisCheckFailed = [ diff --git a/tests/unit/tls_test.ts b/tests/unit/tls_test.ts index 0f6ffc15f2..aba4d254ce 100644 --- a/tests/unit/tls_test.ts +++ b/tests/unit/tls_test.ts @@ -6,7 +6,6 @@ import { assertRejects, assertStrictEquals, assertThrows, - DENO_FUTURE, } from "./test_util.ts"; import { BufReader, BufWriter } from "@std/io"; import { readAll } from "@std/io/read-all"; @@ -1042,7 +1041,7 @@ Deno.test( ); Deno.test( - { permissions: { read: true, net: true }, ignore: DENO_FUTURE }, + { permissions: { read: true, net: true } }, async function connectTLSBadCertKey(): Promise { await assertRejects(async () => { await Deno.connectTls({ @@ -1074,7 +1073,7 @@ Deno.test( ); Deno.test( - { permissions: { read: true, net: true }, ignore: DENO_FUTURE }, + { permissions: { read: true, net: true } }, async function connectTLSNotKey(): Promise { await assertRejects(async () => { await Deno.connectTls({ diff --git a/tests/unit/tty_test.ts b/tests/unit/tty_test.ts index 4183fe530e..1d29a0b706 100644 --- a/tests/unit/tty_test.ts +++ b/tests/unit/tty_test.ts @@ -2,7 +2,7 @@ // deno-lint-ignore-file no-deprecated-deno-api -import { assert, DENO_FUTURE } from "./test_util.ts"; +import { assert } from "./test_util.ts"; // Note tests for Deno.stdin.setRaw is in integration tests. @@ -15,17 +15,6 @@ Deno.test(function consoleSize() { assert(typeof result.rows !== "undefined"); }); -Deno.test( - { ignore: DENO_FUTURE, permissions: { read: true } }, - function isatty() { - // CI not under TTY, so cannot test stdin/stdout/stderr. - const f = Deno.openSync("tests/testdata/assets/hello.txt"); - // @ts-ignore `Deno.isatty()` was soft-removed in Deno 2. - assert(!Deno.isatty(f.rid)); - f.close(); - }, -); - Deno.test(function isattyError() { let caught = false; try { From 46d5f38a0f839db34ecce67f3483469e82cb593d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 12 Sep 2024 03:03:57 +0100 Subject: [PATCH 9/9] fix(ext/node): export request and response clases from `http2` module (#25592) Closes https://github.com/denoland/deno/issues/20612 Closes https://github.com/denoland/deno/issues/23326 This makes `qwik` work. --- ext/node/polyfills/http2.ts | 4 ++-- tests/unit_node/http2_test.ts | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ext/node/polyfills/http2.ts b/ext/node/polyfills/http2.ts index cab7aa26c0..a9ced2bd9e 100644 --- a/ext/node/polyfills/http2.ts +++ b/ext/node/polyfills/http2.ts @@ -2295,7 +2295,7 @@ function onStreamTimeout(kind) { }; } -class Http2ServerRequest extends Readable { +export class Http2ServerRequest extends Readable { readableEnded = false; constructor(stream, headers, options, rawHeaders) { @@ -2523,7 +2523,7 @@ function isConnectionHeaderAllowed(name, value) { value === "trailers"; } -class Http2ServerResponse extends Stream { +export class Http2ServerResponse extends Stream { writable = false; req = null; diff --git a/tests/unit_node/http2_test.ts b/tests/unit_node/http2_test.ts index 1dfac8f8c3..cb939646be 100644 --- a/tests/unit_node/http2_test.ts +++ b/tests/unit_node/http2_test.ts @@ -378,3 +378,8 @@ Deno.test("[node/http2 client] connection states", async () => { assertEquals(actual, expected); }); + +Deno.test("request and response exports", () => { + assert(http2.Http2ServerRequest); + assert(http2.Http2ServerResponse); +});