Skip to content

Commit e83ff62

Browse files
authored
chore: split web op crate (denoland#9635)
This commit starts splitting out the deno_web op crate into multiple smaller crates. This commit splits out WebIDL and URL API, but in the future I want to split out each spec into its own crate. That means we will have (in rough order of loading): `webidl`, `dom`, `streams`, `console`, `encoding`, `url`, `file`, `fetch`, `websocket`, and `webgpu` crates.
1 parent 2f9d7c0 commit e83ff62

37 files changed

+785
-1256
lines changed

Cargo.lock

+18-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ members = [
77
"runtime",
88
"test_plugin",
99
"test_util",
10+
"op_crates/crypto",
1011
"op_crates/fetch",
12+
"op_crates/url",
1113
"op_crates/web",
12-
"op_crates/crypto"
14+
"op_crates/webgpu",
15+
"op_crates/webidl",
16+
"op_crates/websocket",
1317
]
1418
exclude = [
1519
"std/hash/_wasm"

cli/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use deno_core::JsRuntime;
1010
use deno_core::RuntimeOptions;
1111
use deno_runtime::deno_crypto;
1212
use deno_runtime::deno_fetch;
13+
use deno_runtime::deno_url;
1314
use deno_runtime::deno_web;
1415
use deno_runtime::deno_webgpu;
1516
use deno_runtime::deno_websocket;
@@ -61,6 +62,7 @@ fn create_compiler_snapshot(
6162
) {
6263
// libs that are being provided by op crates.
6364
let mut op_crate_libs = HashMap::new();
65+
op_crate_libs.insert("deno.url", deno_url::get_declaration());
6466
op_crate_libs.insert("deno.web", deno_web::get_declaration());
6567
op_crate_libs.insert("deno.fetch", deno_fetch::get_declaration());
6668
op_crate_libs.insert("deno.webgpu", deno_webgpu::get_declaration());
@@ -254,6 +256,10 @@ fn main() {
254256

255257
println!("cargo:rustc-env=TS_VERSION={}", ts_version());
256258
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
259+
println!(
260+
"cargo:rustc-env=DENO_URL_LIB_PATH={}",
261+
deno_url::get_declaration().display()
262+
);
257263
println!(
258264
"cargo:rustc-env=DENO_WEB_LIB_PATH={}",
259265
deno_web::get_declaration().display()

cli/dts/lib.deno.shared_globals.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/// <reference no-default-lib="true" />
77
/// <reference lib="esnext" />
8+
/// <reference lib="deno.url" />
89
/// <reference lib="deno.web" />
910
/// <reference lib="deno.fetch" />
1011
/// <reference lib="deno.websocket" />

cli/main.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ fn print_cache_info(
278278

279279
pub fn get_types(unstable: bool) -> String {
280280
let mut types = format!(
281-
"{}\n{}\n{}\n{}\n{}\n{}\n{}",
281+
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
282282
crate::tsc::DENO_NS_LIB,
283+
crate::tsc::DENO_URL_LIB,
283284
crate::tsc::DENO_WEB_LIB,
284285
crate::tsc::DENO_FETCH_LIB,
285286
crate::tsc::DENO_WEBGPU_LIB,

cli/tsc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use std::sync::Mutex;
2929
// Declaration files
3030

3131
pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts");
32+
pub static DENO_URL_LIB: &str = include_str!(env!("DENO_URL_LIB_PATH"));
3233
pub static DENO_WEB_LIB: &str = include_str!(env!("DENO_WEB_LIB_PATH"));
3334
pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH"));
3435
pub static DENO_WEBGPU_LIB: &str = include_str!(env!("DENO_WEBGPU_LIB_PATH"));

op_crates/crypto/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name = "deno_crypto"
55
version = "0.14.1"
66
edition = "2018"
7-
description = "Collection of WebCrypto APIs"
7+
description = "Web Cryptography API implementation for Deno"
88
authors = ["the Deno authors"]
99
license = "MIT"
1010
readme = "README.md"

op_crates/crypto/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# deno crypto
1+
# deno_crypto
22

3-
Op crate that implements crypto functions.
3+
This crate implements the Web Cryptography API.
4+
5+
Spec: https://www.w3.org/TR/WebCryptoAPI/

op_crates/fetch/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
name = "deno_fetch"
55
version = "0.22.3"
66
edition = "2018"
7-
description = "provides fetch Web API to deno_core"
7+
description = "Fetch API implementation for Deno"
88
authors = ["the Deno authors"]
99
license = "MIT"
1010
readme = "README.md"

op_crates/fetch/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
This crate provides the web standard fetch API to `deno_core`.
1+
# deno_fetch
2+
3+
This crate implements the Fetch API.
4+
5+
Spec: https://fetch.spec.whatwg.org/

op_crates/web/11_url.js op_crates/url/00_url.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
init = init.slice(1);
2929
}
3030

31-
this.#params = core.jsonOpSync("op_parse_url_search_params", init);
31+
this.#params = core.jsonOpSync("op_url_parse_search_params", init);
3232
} else if (
3333
Array.isArray(init) ||
3434
typeof init?.[Symbol.iterator] == "function"
@@ -64,7 +64,7 @@
6464
return;
6565
}
6666
const parseArgs = { href: url.href, setSearch: this.toString() };
67-
parts.set(url, core.jsonOpSync("op_parse_url", parseArgs));
67+
parts.set(url, core.jsonOpSync("op_url_parse", parseArgs));
6868
};
6969

7070
append(name, value) {
@@ -189,7 +189,7 @@
189189
}
190190

191191
toString() {
192-
return core.jsonOpSync("op_stringify_url_search_params", this.#params);
192+
return core.jsonOpSync("op_url_stringify_search_params", this.#params);
193193
}
194194
}
195195

@@ -206,7 +206,7 @@
206206
} else {
207207
base = base !== undefined ? String(base) : base;
208208
const parseArgs = { href: String(url), baseHref: base };
209-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
209+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
210210
}
211211
}
212212

@@ -231,7 +231,7 @@
231231
if (this.#searchParams != null) {
232232
const params = paramLists.get(this.#searchParams);
233233
const newParams = core.jsonOpSync(
234-
"op_parse_url_search_params",
234+
"op_url_parse_search_params",
235235
this.search.slice(1),
236236
);
237237
params.splice(0, params.length, ...newParams);
@@ -245,7 +245,7 @@
245245
set hash(value) {
246246
try {
247247
const parseArgs = { href: this.href, setHash: String(value) };
248-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
248+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
249249
} catch {
250250
/* pass */
251251
}
@@ -258,7 +258,7 @@
258258
set host(value) {
259259
try {
260260
const parseArgs = { href: this.href, setHost: String(value) };
261-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
261+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
262262
} catch {
263263
/* pass */
264264
}
@@ -271,7 +271,7 @@
271271
set hostname(value) {
272272
try {
273273
const parseArgs = { href: this.href, setHostname: String(value) };
274-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
274+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
275275
} catch {
276276
/* pass */
277277
}
@@ -284,7 +284,7 @@
284284
set href(value) {
285285
try {
286286
const parseArgs = { href: String(value) };
287-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
287+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
288288
} catch {
289289
throw new TypeError("Invalid URL");
290290
}
@@ -302,7 +302,7 @@
302302
set password(value) {
303303
try {
304304
const parseArgs = { href: this.href, setPassword: String(value) };
305-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
305+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
306306
} catch {
307307
/* pass */
308308
}
@@ -315,7 +315,7 @@
315315
set pathname(value) {
316316
try {
317317
const parseArgs = { href: this.href, setPathname: String(value) };
318-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
318+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
319319
} catch {
320320
/* pass */
321321
}
@@ -328,7 +328,7 @@
328328
set port(value) {
329329
try {
330330
const parseArgs = { href: this.href, setPort: String(value) };
331-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
331+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
332332
} catch {
333333
/* pass */
334334
}
@@ -341,7 +341,7 @@
341341
set protocol(value) {
342342
try {
343343
const parseArgs = { href: this.href, setProtocol: String(value) };
344-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
344+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
345345
} catch {
346346
/* pass */
347347
}
@@ -354,7 +354,7 @@
354354
set search(value) {
355355
try {
356356
const parseArgs = { href: this.href, setSearch: String(value) };
357-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
357+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
358358
this.#updateSearchParams();
359359
} catch {
360360
/* pass */
@@ -368,7 +368,7 @@
368368
set username(value) {
369369
try {
370370
const parseArgs = { href: this.href, setUsername: String(value) };
371-
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
371+
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
372372
} catch {
373373
/* pass */
374374
}

op_crates/url/Cargo.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
2+
3+
[package]
4+
name = "deno_url"
5+
version = "0.1.0"
6+
edition = "2018"
7+
description = "URL API implementation for Deno"
8+
authors = ["the Deno authors"]
9+
license = "MIT"
10+
readme = "README.md"
11+
repository = "https://github.com/denoland/deno"
12+
13+
[lib]
14+
path = "lib.rs"
15+
16+
[dependencies]
17+
deno_core = { version = "0.80.2", path = "../../core" }
18+
idna = "0.2.1"
19+
serde = { version = "1.0.123", features = ["derive"] }

op_crates/url/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# deno_url
2+
3+
This crate implements the URL API for Deno.
4+
5+
Spec: https://url.spec.whatwg.org/

op_crates/url/internal.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2+
3+
/// <reference no-default-lib="true" />
4+
/// <reference lib="esnext" />
5+
6+
declare namespace globalThis {
7+
declare namespace __bootstrap {
8+
declare var url: {
9+
URL: typeof URL;
10+
URLSearchParams: typeof URLSearchParams;
11+
};
12+
}
13+
}

0 commit comments

Comments
 (0)