mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 21:50:00 -05:00
simplify deno_web init (#7313)
This commit is contained in:
parent
b3563e8569
commit
ce63806c64
3 changed files with 30 additions and 107 deletions
77
cli/build.rs
77
cli/build.rs
|
@ -14,6 +14,7 @@ fn create_snapshot(
|
|||
snapshot_path: &Path,
|
||||
files: Vec<String>,
|
||||
) {
|
||||
deno_web::init(&mut isolate);
|
||||
for file in files {
|
||||
println!("cargo:rerun-if-changed={}", file);
|
||||
js_check(isolate.execute(&file, &std::fs::read_to_string(&file).unwrap()));
|
||||
|
@ -38,11 +39,8 @@ fn create_compiler_snapshot(
|
|||
) {
|
||||
let mut runtime_isolate = CoreIsolate::new(StartupData::None, true);
|
||||
let mut custom_libs: HashMap<String, PathBuf> = HashMap::new();
|
||||
let web_scripts = deno_web::get_scripts();
|
||||
custom_libs.insert(
|
||||
"lib.deno.web.d.ts".to_string(),
|
||||
PathBuf::from(web_scripts.declaration),
|
||||
);
|
||||
custom_libs
|
||||
.insert("lib.deno.web.d.ts".to_string(), deno_web::get_declaration());
|
||||
custom_libs.insert(
|
||||
"lib.deno.window.d.ts".to_string(),
|
||||
cwd.join("dts/lib.deno.window.d.ts"),
|
||||
|
@ -96,7 +94,7 @@ fn main() {
|
|||
println!("cargo:rustc-env=TS_VERSION={}", ts_version());
|
||||
println!(
|
||||
"cargo:rustc-env=DENO_WEB_LIB_PATH={}",
|
||||
deno_web::get_scripts().declaration
|
||||
deno_web::get_declaration().display()
|
||||
);
|
||||
|
||||
println!(
|
||||
|
@ -111,7 +109,7 @@ fn main() {
|
|||
let runtime_snapshot_path = o.join("CLI_SNAPSHOT.bin");
|
||||
let compiler_snapshot_path = o.join("COMPILER_SNAPSHOT.bin");
|
||||
|
||||
let js_files = get_js_files_for_rt();
|
||||
let js_files = get_js_files("rt");
|
||||
create_runtime_snapshot(&runtime_snapshot_path, js_files);
|
||||
|
||||
let js_files = get_js_files("tsc");
|
||||
|
@ -141,68 +139,3 @@ fn get_js_files(d: &str) -> Vec<String> {
|
|||
js_files.sort();
|
||||
js_files
|
||||
}
|
||||
|
||||
fn get_js_files_for_rt() -> Vec<String> {
|
||||
let web_scripts = deno_web::get_scripts();
|
||||
|
||||
let f = vec![
|
||||
"rt/00_bootstrap_namespace.js",
|
||||
&web_scripts.dom_exception,
|
||||
"rt/01_build.js",
|
||||
"rt/01_colors.js",
|
||||
"rt/01_errors.js",
|
||||
&web_scripts.event,
|
||||
"rt/01_internals.js",
|
||||
"rt/01_version.js",
|
||||
"rt/01_web_util.js",
|
||||
&web_scripts.abort_signal,
|
||||
"rt/02_console.js",
|
||||
"rt/03_dom_iterable.js",
|
||||
"rt/06_util.js",
|
||||
&web_scripts.text_encoding,
|
||||
"rt/10_dispatch_json.js",
|
||||
"rt/10_dispatch_minimal.js",
|
||||
"rt/11_crypto.js",
|
||||
"rt/11_resources.js",
|
||||
"rt/11_streams.js",
|
||||
"rt/11_timers.js",
|
||||
"rt/11_url.js",
|
||||
"rt/11_workers.js",
|
||||
"rt/12_io.js",
|
||||
"rt/13_buffer.js",
|
||||
"rt/20_blob.js",
|
||||
"rt/20_headers.js",
|
||||
"rt/20_streams_queuing_strategy.js",
|
||||
"rt/21_dom_file.js",
|
||||
"rt/21_filereader.js",
|
||||
"rt/22_form_data.js",
|
||||
"rt/23_multipart.js",
|
||||
"rt/24_body.js",
|
||||
"rt/25_request.js",
|
||||
"rt/26_fetch.js",
|
||||
"rt/30_files.js",
|
||||
"rt/30_fs.js",
|
||||
"rt/30_metrics.js",
|
||||
"rt/30_net.js",
|
||||
"rt/30_os.js",
|
||||
"rt/40_compiler_api.js",
|
||||
"rt/40_diagnostics.js",
|
||||
"rt/40_error_stack.js",
|
||||
"rt/40_fs_events.js",
|
||||
"rt/40_net_unstable.js",
|
||||
"rt/40_performance.js",
|
||||
"rt/40_permissions.js",
|
||||
"rt/40_plugins.js",
|
||||
"rt/40_process.js",
|
||||
"rt/40_read_file.js",
|
||||
"rt/40_repl.js",
|
||||
"rt/40_signals.js",
|
||||
"rt/40_testing.js",
|
||||
"rt/40_tls.js",
|
||||
"rt/40_tty.js",
|
||||
"rt/40_write_file.js",
|
||||
"rt/90_deno_ns.js",
|
||||
"rt/99_main.js",
|
||||
];
|
||||
f.iter().map(|p| p.to_string()).collect()
|
||||
}
|
||||
|
|
|
@ -6,4 +6,4 @@
|
|||
|
||||
// This namespace is removed during runtime bootstrapping process.
|
||||
|
||||
globalThis.__bootstrap = {};
|
||||
globalThis.__bootstrap = globalThis.__bootstrap || {};
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::js_check;
|
||||
use deno_core::CoreIsolate;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub struct WebScripts {
|
||||
pub abort_signal: String,
|
||||
pub declaration: String,
|
||||
pub dom_exception: String,
|
||||
pub event: String,
|
||||
pub text_encoding: String,
|
||||
}
|
||||
|
||||
fn get_str_path(file_name: &str) -> String {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
.join(file_name)
|
||||
.to_string_lossy()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn get_scripts() -> WebScripts {
|
||||
WebScripts {
|
||||
abort_signal: get_str_path("02_abort_signal.js"),
|
||||
declaration: get_str_path("lib.deno_web.d.ts"),
|
||||
dom_exception: get_str_path("00_dom_exception.js"),
|
||||
event: get_str_path("01_event.js"),
|
||||
text_encoding: get_str_path("08_text_encoding.js"),
|
||||
pub fn init(isolate: &mut CoreIsolate) {
|
||||
let files = vec![
|
||||
get_path("00_dom_exception.js"),
|
||||
get_path("01_event.js"),
|
||||
get_path("02_abort_signal.js"),
|
||||
get_path("08_text_encoding.js"),
|
||||
];
|
||||
for file in files {
|
||||
println!("cargo:rerun-if-changed={}", file.display());
|
||||
js_check(isolate.execute(
|
||||
&file.to_string_lossy(),
|
||||
&std::fs::read_to_string(&file).unwrap(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_declaration() -> PathBuf {
|
||||
get_path("lib.deno_web.d.ts")
|
||||
}
|
||||
|
||||
fn get_path(file_name: &str) -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(file_name)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use deno_core::js_check;
|
||||
|
@ -46,18 +47,7 @@ mod tests {
|
|||
|
||||
fn setup() -> CoreIsolate {
|
||||
let mut isolate = CoreIsolate::new(StartupData::None, false);
|
||||
js_check(
|
||||
isolate
|
||||
.execute("00_dom_exception.js", include_str!("00_dom_exception.js")),
|
||||
);
|
||||
js_check(isolate.execute("01_event.js", include_str!("01_event.js")));
|
||||
js_check(
|
||||
isolate.execute("02_abort_signal.js", include_str!("02_abort_signal.js")),
|
||||
);
|
||||
js_check(
|
||||
isolate
|
||||
.execute("08_text_encoding.js", include_str!("08_text_encoding.js")),
|
||||
);
|
||||
crate::init(&mut isolate);
|
||||
isolate
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue