1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

refactor: move Console to op_crates/console (#9770)

This commit is contained in:
Luca Casonato 2021-03-12 21:23:59 +01:00 committed by GitHub
parent e83ff62ccb
commit 0770449c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 129 additions and 71 deletions

8
Cargo.lock generated
View file

@ -552,6 +552,13 @@ dependencies = [
"winres",
]
[[package]]
name = "deno_console"
version = "0.1.0"
dependencies = [
"deno_core",
]
[[package]]
name = "deno_core"
version = "0.80.2"
@ -632,6 +639,7 @@ name = "deno_runtime"
version = "0.9.3"
dependencies = [
"atty",
"deno_console",
"deno_core",
"deno_crypto",
"deno_fetch",

View file

@ -8,6 +8,7 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;
use deno_runtime::deno_console;
use deno_runtime::deno_crypto;
use deno_runtime::deno_fetch;
use deno_runtime::deno_url;
@ -62,6 +63,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.console", deno_console::get_declaration());
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());
@ -256,6 +258,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_CONSOLE_LIB_PATH={}",
deno_console::get_declaration().display()
);
println!(
"cargo:rustc-env=DENO_URL_LIB_PATH={}",
deno_url::get_declaration().display()

View file

@ -5,6 +5,7 @@
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
/// <reference lib="deno.console" />
/// <reference lib="deno.url" />
/// <reference lib="deno.web" />
/// <reference lib="deno.fetch" />
@ -391,29 +392,6 @@ interface DOMStringList {
type BufferSource = ArrayBufferView | ArrayBuffer;
declare interface Console {
assert(condition?: boolean, ...data: any[]): void;
clear(): void;
count(label?: string): void;
countReset(label?: string): void;
debug(...data: any[]): void;
dir(item?: any, options?: any): void;
dirxml(...data: any[]): void;
error(...data: any[]): void;
group(...data: any[]): void;
groupCollapsed(...data: any[]): void;
groupEnd(): void;
info(...data: any[]): void;
log(...data: any[]): void;
table(tabularData?: any, properties?: string[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeLog(label?: string, ...data: any[]): void;
timeStamp(label?: string): void;
trace(...data: any[]): void;
warn(...data: any[]): void;
}
declare var console: Console;
interface MessageEventInit<T = any> extends EventInit {

View file

@ -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{}\n{}\n{}",
crate::tsc::DENO_NS_LIB,
crate::tsc::DENO_CONSOLE_LIB,
crate::tsc::DENO_URL_LIB,
crate::tsc::DENO_WEB_LIB,
crate::tsc::DENO_FETCH_LIB,

View file

@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
/* TODO https://github.com/denoland/deno/issues/7540
import { unitTest, assert, assertEquals } from "./test_util.ts";
import { assert, assertEquals, unitTest } from "./test_util.ts";
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function setup() {
@ -27,7 +26,6 @@ function setup() {
};
}
unitTest(function testDomIterable(): void {
const { DomIterable, Base } = setup();
@ -88,4 +86,3 @@ unitTest(function testDomIterableScope(): void {
checkScope(null, window);
checkScope(undefined, window);
});
*/

View file

@ -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_CONSOLE_LIB: &str = include_str!(env!("DENO_CONSOLE_LIB_PATH"));
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"));

View file

@ -1,4 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
"use strict";
((window) => {

View file

@ -3,7 +3,6 @@
((window) => {
const core = window.Deno.core;
const exposeForTest = window.__bootstrap.internals.exposeForTest;
const colors = window.__bootstrap.colors;
function isInvalidDate(x) {
@ -1762,11 +1761,14 @@
}
// Expose these fields to internalObject for tests.
exposeForTest("Console", Console);
exposeForTest("cssToAnsi", cssToAnsi);
exposeForTest("inspectArgs", inspectArgs);
exposeForTest("parseCss", parseCss);
exposeForTest("parseCssColor", parseCssColor);
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
Console,
cssToAnsi,
inspectArgs,
parseCss,
parseCssColor,
};
window.__bootstrap.console = {
CSI,

View file

@ -0,0 +1,17 @@
# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
[package]
name = "deno_console"
version = "0.1.0"
edition = "2018"
description = "Implementation of Console API 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" }

View file

@ -0,0 +1,5 @@
# deno_console
This crate implements the Console API.
Spec: https://console.spec.whatwg.org/

29
op_crates/console/lib.deno_console.d.ts vendored Normal file
View file

@ -0,0 +1,29 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any
/// <reference no-default-lib="true" />
/// <reference lib="esnext" />
declare interface Console {
assert(condition?: boolean, ...data: any[]): void;
clear(): void;
count(label?: string): void;
countReset(label?: string): void;
debug(...data: any[]): void;
dir(item?: any, options?: any): void;
dirxml(...data: any[]): void;
error(...data: any[]): void;
group(...data: any[]): void;
groupCollapsed(...data: any[]): void;
groupEnd(): void;
info(...data: any[]): void;
log(...data: any[]): void;
table(tabularData?: any, properties?: string[]): void;
time(label?: string): void;
timeEnd(label?: string): void;
timeLog(label?: string, ...data: any[]): void;
timeStamp(label?: string): void;
trace(...data: any[]): void;
warn(...data: any[]): void;
}

25
op_crates/console/lib.rs Normal file
View file

@ -0,0 +1,25 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::JsRuntime;
use std::path::PathBuf;
/// Load and execute the javascript code.
pub fn init(isolate: &mut JsRuntime) {
let files = vec![
(
"deno:op_crates/console/01_colors.js",
include_str!("01_colors.js"),
),
(
"deno:op_crates/console/02_console.js",
include_str!("02_console.js"),
),
];
for (url, source_code) in files {
isolate.execute(url, source_code).unwrap();
}
}
pub fn get_declaration() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_console.d.ts")
}

View file

@ -3,7 +3,6 @@
((window) => {
const { requiredArguments } = window.__bootstrap.fetchUtil;
// const { exposeForTest } = window.__bootstrap.internals;
function DomIterableMixin(
Base,
@ -70,7 +69,10 @@
return DomIterable;
}
// exposeForTest("DomIterableMixin", DomIterableMixin);
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
DomIterableMixin,
};
window.__bootstrap.domIterable = {
DomIterableMixin,

View file

@ -19,6 +19,7 @@ path = "examples/hello_runtime.rs"
[build-dependencies]
deno_core = { path = "../core", version = "0.80.2" }
deno_console = { path = "../op_crates/console", version = "0.1.0" }
deno_crypto = { path = "../op_crates/crypto", version = "0.14.1" }
deno_fetch = { path = "../op_crates/fetch", version = "0.22.3" }
deno_web = { path = "../op_crates/web", version = "0.30.3" }
@ -33,6 +34,7 @@ winapi = "0.3.9"
[dependencies]
deno_core = { path = "../core", version = "0.80.2" }
deno_console = { path = "../op_crates/console", version = "0.1.0" }
deno_crypto = { path = "../op_crates/crypto", version = "0.14.1" }
deno_fetch = { path = "../op_crates/fetch", version = "0.22.3" }
deno_web = { path = "../op_crates/web", version = "0.30.3" }

View file

@ -14,6 +14,7 @@ fn create_snapshot(
files: Vec<PathBuf>,
) {
deno_webidl::init(&mut js_runtime);
deno_console::init(&mut js_runtime);
deno_url::init(&mut js_runtime);
deno_web::init(&mut js_runtime);
deno_fetch::init(&mut js_runtime);

View file

@ -1,24 +0,0 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
"use strict";
((window) => {
const internalSymbol = Symbol("Deno.internal");
// The object where all the internal fields for testing will be living.
const internalObject = {};
// Register a field to internalObject for test access,
// through Deno[Deno.internal][name].
function exposeForTest(name, value) {
Object.defineProperty(internalObject, name, {
value,
enumerable: false,
});
}
window.__bootstrap.internals = {
internalSymbol,
internalObject,
exposeForTest,
};
})(this);

View file

@ -3,7 +3,6 @@
((window) => {
const { build } = window.__bootstrap.build;
const internals = window.__bootstrap.internals;
let logDebug = false;
let logSource = "JS";
@ -100,7 +99,10 @@
return pathOrUrl;
}
internals.exposeForTest("pathFromURL", pathFromURL);
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
pathFromURL,
};
function writable(value) {
return {

View file

@ -7,7 +7,6 @@
const { setExitHandler, exit } = window.__bootstrap.os;
const { Console, inspectArgs } = window.__bootstrap.console;
const { stdout } = window.__bootstrap.files;
const { exposeForTest } = window.__bootstrap.internals;
const { metrics } = window.__bootstrap.metrics;
const { assert } = window.__bootstrap.util;
@ -227,8 +226,6 @@ finishing test case.`;
}
}
exposeForTest("reportToConsole", reportToConsole);
// TODO(bartlomieju): already implements AsyncGenerator<RunTestsMessage>, but add as "implements to class"
// TODO(bartlomieju): implements PromiseLike<RunTestsEndResult>
class TestRunner {
@ -327,8 +324,6 @@ finishing test case.`;
};
}
exposeForTest("createFilterFn", createFilterFn);
async function runTests({
exitOnFail = true,
failFast = false,
@ -372,7 +367,12 @@ finishing test case.`;
return endMsg;
}
exposeForTest("runTests", runTests);
window.__bootstrap.internals = {
...window.__bootstrap.internals ?? {},
reportToConsole,
createFilterFn,
runTests,
};
window.__bootstrap.testing = {
test,

View file

@ -20,7 +20,7 @@ delete Object.prototype.__proto__;
const Console = window.__bootstrap.console.Console;
const worker = window.__bootstrap.worker;
const signals = window.__bootstrap.signals;
const { internalSymbol, internalObject } = window.__bootstrap.internals;
const internals = window.__bootstrap.internals;
const performance = window.__bootstrap.performance;
const crypto = window.__bootstrap.crypto;
const url = window.__bootstrap.url;
@ -429,10 +429,12 @@ delete Object.prototype.__proto__;
registerErrors();
const internalSymbol = Symbol("Deno.internal");
const finalDenoNs = {
core,
internal: internalSymbol,
[internalSymbol]: internalObject,
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
...denoNs,
@ -491,10 +493,12 @@ delete Object.prototype.__proto__;
fetch.setBaseUrl(locationHref);
registerErrors();
const internalSymbol = Symbol("Deno.internal");
const finalDenoNs = {
core,
internal: internalSymbol,
[internalSymbol]: internalObject,
[internalSymbol]: internals,
resources: core.resources,
close: core.close,
...denoNs,

View file

@ -7,6 +7,7 @@ extern crate lazy_static;
#[macro_use]
extern crate log;
pub use deno_console;
pub use deno_crypto;
pub use deno_fetch;
pub use deno_url;