Skip to content

Commit

Permalink
Merge branch 'main' into upgrade_deno_core
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Apr 18, 2024
2 parents cfb413d + 3d841ac commit a431f55
Show file tree
Hide file tree
Showing 26 changed files with 427 additions and 242 deletions.
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
[submodule "tests/node_compat/runner/suite"]
path = tests/node_compat/runner/suite
url = https://github.com/denoland/node_test.git
shallow = true
[submodule "cli/bench/testdata/lsp_benchdata"]
path = cli/bench/testdata/lsp_benchdata
url = https://github.com/denoland/deno_lsp_benchdata.git
shallow = true
10 changes: 8 additions & 2 deletions cli/tools/registry/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,14 @@ pub async fn add(flags: Flags, add_flags: AddFlags) -> Result<(), AnyError> {
}
}

let config_file_contents =
tokio::fs::read_to_string(&config_file_path).await.unwrap();
let config_file_contents = {
let contents = tokio::fs::read_to_string(&config_file_path).await.unwrap();
if contents.trim().is_empty() {
"{}\n".into()
} else {
contents
}
};
let ast = jsonc_parser::parse_to_ast(
&config_file_contents,
&Default::default(),
Expand Down
1 change: 1 addition & 0 deletions cli/tools/vendor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ fn update_config_text(
) -> Result<ModifiedResult, AnyError> {
use jsonc_parser::ast::ObjectProp;
use jsonc_parser::ast::Value;
let text = if text.trim().is_empty() { "{}\n" } else { text };
let ast =
jsonc_parser::parse_to_ast(text, &Default::default(), &Default::default())?;
let obj = match ast.value {
Expand Down
33 changes: 27 additions & 6 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6277,11 +6277,23 @@ declare namespace Deno {
* @category HTTP Server
*/
export interface ServeTlsOptions extends ServeOptions {
/** Server private key in PEM format */
cert: string;
/**
* Server private key in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead.
*
* @deprecated This will be removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*/
cert?: string;

/** Cert chain in PEM format */
key: string;
/**
* Cert chain in PEM format. Use {@linkcode TlsCertifiedKeyOptions} instead.
*
* @deprecated This will be removed in Deno 2.0. See the
* {@link https://docs.deno.com/runtime/manual/advanced/migrate_deprecations | Deno 1.x to 2.x Migration Guide}
* for migration instructions.
*/
key?: string;
}

/**
Expand Down Expand Up @@ -6490,7 +6502,10 @@ declare namespace Deno {
* @category HTTP Server
*/
export function serve(
options: ServeOptions | ServeTlsOptions,
options:
| ServeOptions
| ServeTlsOptions
| (ServeTlsOptions & TlsCertifiedKeyOptions),
handler: ServeHandler,
): HttpServer;
/** Serves HTTP requests with the given option bag.
Expand Down Expand Up @@ -6546,6 +6561,12 @@ declare namespace Deno {
* @category HTTP Server
*/
export function serve(
options: ServeInit & (ServeOptions | ServeTlsOptions),
options:
& ServeInit
& (
| ServeOptions
| ServeTlsOptions
| (ServeTlsOptions & TlsCertifiedKeyOptions)
),
): HttpServer;
}
25 changes: 21 additions & 4 deletions cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,6 @@ declare namespace Deno {
caCerts?: string[];
/** A HTTP proxy to use for new connections. */
proxy?: Proxy;
/** Cert chain in PEM format. */
cert?: string;
/** Server private key in PEM format. */
key?: string;
/** Sets the maximum numer of idle connections per host allowed in the pool. */
poolMaxIdlePerHost?: number;
/** Set an optional timeout for idle sockets being kept-alive.
Expand Down Expand Up @@ -962,6 +958,27 @@ declare namespace Deno {
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 API
*/
export function createHttpClient(
options: CreateHttpClientOptions & TlsCertifiedKeyOptions,
): HttpClient;

/** **UNSTABLE**: New API, yet to be vetted.
*
* Represents membership of a IPv4 multicast group.
Expand Down
7 changes: 1 addition & 6 deletions ext/fetch/22_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ const { ObjectDefineProperty } = primordials;
*/
function createHttpClient(options) {
options.caCerts ??= [];
const keyPair = loadTlsKeyPair(
options.cert,
undefined,
options.key,
undefined,
);
const keyPair = loadTlsKeyPair("Deno.createHttpClient", options);
return new HttpClient(
op_fetch_custom_client(
options,
Expand Down
15 changes: 13 additions & 2 deletions ext/http/01_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { core, internals, primordials } from "ext:core/mod.js";
const {
BadResourcePrototype,
InterruptedPrototype,
internalRidSymbol,
} = core;
import {
op_http_accept,
op_http_headers,
op_http_shutdown,
op_http_start,
op_http_upgrade_websocket,
op_http_websocket_accept_header,
op_http_write,
Expand Down Expand Up @@ -71,7 +73,6 @@ import {
readableStreamForRid,
ReadableStreamPrototype,
} from "ext:deno_web/06_streams.js";
import { serve } from "ext:deno_http/00_serve.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js";

const connErrorSymbol = Symbol("connError");
Expand Down Expand Up @@ -557,4 +558,14 @@ function buildCaseInsensitiveCommaValueFinder(checkText) {
internals.buildCaseInsensitiveCommaValueFinder =
buildCaseInsensitiveCommaValueFinder;

export { _ws, HttpConn, serve, upgradeWebSocket };
function serveHttp(conn) {
internals.warnOnDeprecatedApi(
"Deno.serveHttp()",
new Error().stack,
"Use `Deno.serve()` instead.",
);
const rid = op_http_start(conn[internalRidSymbol]);
return new HttpConn(rid, conn.remoteAddr, conn.localAddr);
}

export { _ws, HttpConn, serveHttp, upgradeWebSocket };
Loading

0 comments on commit a431f55

Please sign in to comment.