Skip to content

Commit

Permalink
chore: split web op crate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lucacasonato committed Mar 12, 2021
1 parent 2f9d7c0 commit e521dd7
Show file tree
Hide file tree
Showing 33 changed files with 784 additions and 647 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ members = [
"runtime",
"test_plugin",
"test_util",
"op_crates/crypto",
"op_crates/fetch",
"op_crates/url",
"op_crates/web",
"op_crates/crypto"
"op_crates/webgpu",
"op_crates/webidl",
"op_crates/websocket",
]
exclude = [
"std/hash/_wasm"
Expand Down
6 changes: 6 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use deno_core::JsRuntime;
use deno_core::RuntimeOptions;
use deno_runtime::deno_crypto;
use deno_runtime::deno_fetch;
use deno_runtime::deno_url;
use deno_runtime::deno_web;
use deno_runtime::deno_webgpu;
use deno_runtime::deno_websocket;
Expand Down Expand Up @@ -61,6 +62,7 @@ fn create_compiler_snapshot(
) {
// libs that are being provided by op crates.
let mut op_crate_libs = HashMap::new();
op_crate_libs.insert("deno.url", deno_url::get_declaration());
op_crate_libs.insert("deno.web", deno_web::get_declaration());
op_crate_libs.insert("deno.fetch", deno_fetch::get_declaration());
op_crate_libs.insert("deno.webgpu", deno_webgpu::get_declaration());
Expand Down Expand Up @@ -254,6 +256,10 @@ fn main() {

println!("cargo:rustc-env=TS_VERSION={}", ts_version());
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_commit_hash());
println!(
"cargo:rustc-env=DENO_URL_LIB_PATH={}",
deno_url::get_declaration().display()
);
println!(
"cargo:rustc-env=DENO_WEB_LIB_PATH={}",
deno_web::get_declaration().display()
Expand Down
3 changes: 2 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ fn print_cache_info(

pub fn get_types(unstable: bool) -> String {
let mut types = format!(
"{}\n{}\n{}\n{}\n{}\n{}\n{}",
"{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}",
crate::tsc::DENO_NS_LIB,
crate::tsc::DENO_URL_LIB,
crate::tsc::DENO_WEB_LIB,
crate::tsc::DENO_FETCH_LIB,
crate::tsc::DENO_WEBGPU_LIB,
Expand Down
1 change: 1 addition & 0 deletions cli/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::sync::Mutex;
// Declaration files

pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts");
pub static DENO_URL_LIB: &str = include_str!(env!("DENO_URL_LIB_PATH"));
pub static DENO_WEB_LIB: &str = include_str!(env!("DENO_WEB_LIB_PATH"));
pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH"));
pub static DENO_WEBGPU_LIB: &str = include_str!(env!("DENO_WEBGPU_LIB_PATH"));
Expand Down
2 changes: 1 addition & 1 deletion op_crates/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name = "deno_crypto"
version = "0.14.1"
edition = "2018"
description = "Collection of WebCrypto APIs"
description = "Web Cryptography API implementation for Deno"
authors = ["the Deno authors"]
license = "MIT"
readme = "README.md"
Expand Down
6 changes: 4 additions & 2 deletions op_crates/crypto/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# deno crypto
# deno_crypto

Op crate that implements crypto functions.
This crate implements the Web Cryptography API.

Spec: https://www.w3.org/TR/WebCryptoAPI/
2 changes: 1 addition & 1 deletion op_crates/fetch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name = "deno_fetch"
version = "0.22.3"
edition = "2018"
description = "provides fetch Web API to deno_core"
description = "Fetch API implementation for Deno"
authors = ["the Deno authors"]
license = "MIT"
readme = "README.md"
Expand Down
6 changes: 5 additions & 1 deletion op_crates/fetch/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
This crate provides the web standard fetch API to `deno_core`.
# deno_fetch

This crate implements the Fetch API.

Spec: https://fetch.spec.whatwg.org/
30 changes: 15 additions & 15 deletions op_crates/web/11_url.js → op_crates/url/00_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
init = init.slice(1);
}

this.#params = core.jsonOpSync("op_parse_url_search_params", init);
this.#params = core.jsonOpSync("op_url_parse_search_params", init);
} else if (
Array.isArray(init) ||
typeof init?.[Symbol.iterator] == "function"
Expand Down Expand Up @@ -64,7 +64,7 @@
return;
}
const parseArgs = { href: url.href, setSearch: this.toString() };
parts.set(url, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(url, core.jsonOpSync("op_url_parse", parseArgs));
};

append(name, value) {
Expand Down Expand Up @@ -189,7 +189,7 @@
}

toString() {
return core.jsonOpSync("op_stringify_url_search_params", this.#params);
return core.jsonOpSync("op_url_stringify_search_params", this.#params);
}
}

Expand All @@ -206,7 +206,7 @@
} else {
base = base !== undefined ? String(base) : base;
const parseArgs = { href: String(url), baseHref: base };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
}
}

Expand All @@ -231,7 +231,7 @@
if (this.#searchParams != null) {
const params = paramLists.get(this.#searchParams);
const newParams = core.jsonOpSync(
"op_parse_url_search_params",
"op_url_parse_search_params",
this.search.slice(1),
);
params.splice(0, params.length, ...newParams);
Expand All @@ -245,7 +245,7 @@
set hash(value) {
try {
const parseArgs = { href: this.href, setHash: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -258,7 +258,7 @@
set host(value) {
try {
const parseArgs = { href: this.href, setHost: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -271,7 +271,7 @@
set hostname(value) {
try {
const parseArgs = { href: this.href, setHostname: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -284,7 +284,7 @@
set href(value) {
try {
const parseArgs = { href: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
throw new TypeError("Invalid URL");
}
Expand All @@ -302,7 +302,7 @@
set password(value) {
try {
const parseArgs = { href: this.href, setPassword: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -315,7 +315,7 @@
set pathname(value) {
try {
const parseArgs = { href: this.href, setPathname: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -328,7 +328,7 @@
set port(value) {
try {
const parseArgs = { href: this.href, setPort: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -341,7 +341,7 @@
set protocol(value) {
try {
const parseArgs = { href: this.href, setProtocol: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand All @@ -354,7 +354,7 @@
set search(value) {
try {
const parseArgs = { href: this.href, setSearch: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
this.#updateSearchParams();
} catch {
/* pass */
Expand All @@ -368,7 +368,7 @@
set username(value) {
try {
const parseArgs = { href: this.href, setUsername: String(value) };
parts.set(this, core.jsonOpSync("op_parse_url", parseArgs));
parts.set(this, core.jsonOpSync("op_url_parse", parseArgs));
} catch {
/* pass */
}
Expand Down
19 changes: 19 additions & 0 deletions op_crates/url/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

[package]
name = "deno_url"
version = "0.1.0"
edition = "2018"
description = "URL API implementation for Deno"
authors = ["the Deno authors"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/denoland/deno"

[lib]
path = "lib.rs"

[dependencies]
deno_core = { version = "0.80.2", path = "../../core" }
idna = "0.2.1"
serde = { version = "1.0.123", features = ["derive"] }
5 changes: 5 additions & 0 deletions op_crates/url/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# deno_url

This crate implements the URL API for Deno.

Spec: https://url.spec.whatwg.org/
13 changes: 13 additions & 0 deletions op_crates/url/internal.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

/// <reference no-default-lib="true" />
/// <reference lib="esnext" />

declare namespace globalThis {
declare namespace __bootstrap {
declare var url: {
URL: typeof URL;
URLSearchParams: typeof URLSearchParams;
};
}
}
Loading

0 comments on commit e521dd7

Please sign in to comment.