mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
fix(op_crates/web): Use "deno:" URLs for internal script specifiers (#7383)
This commit is contained in:
parent
c14436a424
commit
b17a5fbcfa
10 changed files with 73 additions and 29 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -499,7 +499,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deno_web"
|
name = "deno_web"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"futures",
|
"futures",
|
||||||
|
|
|
@ -21,7 +21,7 @@ path = "./bench/main.rs"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
deno_core = { path = "../core", version = "0.56.0" }
|
deno_core = { path = "../core", version = "0.56.0" }
|
||||||
deno_web = { path = "../op_crates/web", version = "0.7.0" }
|
deno_web = { path = "../op_crates/web", version = "0.7.1" }
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winres = "0.1.11"
|
winres = "0.1.11"
|
||||||
|
|
27
cli/build.rs
27
cli/build.rs
|
@ -15,12 +15,20 @@ use std::path::PathBuf;
|
||||||
fn create_snapshot(
|
fn create_snapshot(
|
||||||
mut isolate: JsRuntime,
|
mut isolate: JsRuntime,
|
||||||
snapshot_path: &Path,
|
snapshot_path: &Path,
|
||||||
files: Vec<String>,
|
files: Vec<PathBuf>,
|
||||||
) {
|
) {
|
||||||
deno_web::init(&mut isolate);
|
deno_web::init(&mut isolate);
|
||||||
|
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
||||||
|
// workspace root.
|
||||||
|
let display_root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
|
||||||
for file in files {
|
for file in files {
|
||||||
println!("cargo:rerun-if-changed={}", file);
|
println!("cargo:rerun-if-changed={}", file.display());
|
||||||
js_check(isolate.execute(&file, &std::fs::read_to_string(&file).unwrap()));
|
let display_path = file.strip_prefix(display_root).unwrap();
|
||||||
|
let display_path_str = display_path.display().to_string();
|
||||||
|
js_check(isolate.execute(
|
||||||
|
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
|
||||||
|
&std::fs::read_to_string(&file).unwrap(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot = isolate.snapshot();
|
let snapshot = isolate.snapshot();
|
||||||
|
@ -30,7 +38,7 @@ fn create_snapshot(
|
||||||
println!("Snapshot written to: {} ", snapshot_path.display());
|
println!("Snapshot written to: {} ", snapshot_path.display());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<String>) {
|
fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<PathBuf>) {
|
||||||
let state = BasicState::new();
|
let state = BasicState::new();
|
||||||
let isolate = JsRuntime::new(state, StartupData::None, true);
|
let isolate = JsRuntime::new(state, StartupData::None, true);
|
||||||
create_snapshot(isolate, snapshot_path, files);
|
create_snapshot(isolate, snapshot_path, files);
|
||||||
|
@ -38,7 +46,7 @@ fn create_runtime_snapshot(snapshot_path: &Path, files: Vec<String>) {
|
||||||
|
|
||||||
fn create_compiler_snapshot(
|
fn create_compiler_snapshot(
|
||||||
snapshot_path: &Path,
|
snapshot_path: &Path,
|
||||||
files: Vec<String>,
|
files: Vec<PathBuf>,
|
||||||
cwd: &Path,
|
cwd: &Path,
|
||||||
) {
|
) {
|
||||||
let mut custom_libs: HashMap<String, PathBuf> = HashMap::new();
|
let mut custom_libs: HashMap<String, PathBuf> = HashMap::new();
|
||||||
|
@ -134,15 +142,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_js_files(d: &str) -> Vec<String> {
|
fn get_js_files(d: &str) -> Vec<PathBuf> {
|
||||||
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||||
let mut js_files = std::fs::read_dir(d)
|
let mut js_files = std::fs::read_dir(d)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.map(|dir_entry| {
|
.map(|dir_entry| {
|
||||||
let file = dir_entry.unwrap();
|
let file = dir_entry.unwrap();
|
||||||
file.path().to_string_lossy().to_string()
|
manifest_dir.join(file.path())
|
||||||
})
|
})
|
||||||
.filter(|filename| filename.ends_with(".js"))
|
.filter(|path| path.extension().unwrap_or_default() == "js")
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<PathBuf>>();
|
||||||
js_files.sort();
|
js_files.sort();
|
||||||
js_files
|
js_files
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,7 +240,7 @@
|
||||||
});
|
});
|
||||||
for (const callSite of mappedCallSites) {
|
for (const callSite of mappedCallSites) {
|
||||||
error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite)));
|
error.__callSiteEvals.push(Object.freeze(evaluateCallSite(callSite)));
|
||||||
const isInternal = callSite.getFileName()?.startsWith("$deno$") ?? false;
|
const isInternal = callSite.getFileName()?.startsWith("deno:") ?? false;
|
||||||
error.__formattedFrames.push(callSiteToString(callSite, isInternal));
|
error.__formattedFrames.push(callSiteToString(callSite, isInternal));
|
||||||
}
|
}
|
||||||
Object.freeze(error.__callSiteEvals);
|
Object.freeze(error.__callSiteEvals);
|
||||||
|
|
2
cli/tests/error_009_op_crates_error.js
Normal file
2
cli/tests/error_009_op_crates_error.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
// Missing arg.
|
||||||
|
new Event();
|
3
cli/tests/error_009_op_crates_error.js.out
Normal file
3
cli/tests/error_009_op_crates_error.js.out
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[WILDCARD]error: Uncaught TypeError: Event requires at least 1 argument, but only 0 present[WILDCARD]
|
||||||
|
at new Event (deno:op_crates/web/[WILDCARD])
|
||||||
|
at [WILDCARD]
|
|
@ -1811,6 +1811,12 @@ itest!(error_008_checkjs {
|
||||||
output: "error_008_checkjs.js.out",
|
output: "error_008_checkjs.js.out",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(error_009_op_crates_error {
|
||||||
|
args: "run error_009_op_crates_error.js",
|
||||||
|
output: "error_009_op_crates_error.js.out",
|
||||||
|
exit_code: 1,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(error_011_bad_module_specifier {
|
itest!(error_011_bad_module_specifier {
|
||||||
args: "run --reload error_011_bad_module_specifier.ts",
|
args: "run --reload error_011_bad_module_specifier.ts",
|
||||||
exit_code: 1,
|
exit_code: 1,
|
||||||
|
|
13
cli/tsc.rs
13
cli/tsc.rs
|
@ -1103,6 +1103,9 @@ impl TsCompiler {
|
||||||
script_name: &str,
|
script_name: &str,
|
||||||
) -> Option<Vec<u8>> {
|
) -> Option<Vec<u8>> {
|
||||||
if let Some(module_specifier) = self.try_to_resolve(script_name) {
|
if let Some(module_specifier) = self.try_to_resolve(script_name) {
|
||||||
|
if module_specifier.as_url().scheme() == "deno" {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
return match self.get_source_map_file(&module_specifier) {
|
return match self.get_source_map_file(&module_specifier) {
|
||||||
Ok(out) => Some(out.source_code.into_bytes()),
|
Ok(out) => Some(out.source_code.into_bytes()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
@ -1848,11 +1851,11 @@ mod tests {
|
||||||
(r#"{ "compilerOptions": { "checkJs": true } } "#, true),
|
(r#"{ "compilerOptions": { "checkJs": true } } "#, true),
|
||||||
// JSON with comment
|
// JSON with comment
|
||||||
(
|
(
|
||||||
r#"{
|
r#"{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
// force .js file compilation by Deno
|
// force .js file compilation by Deno
|
||||||
"checkJs": true
|
"checkJs": true
|
||||||
}
|
}
|
||||||
}"#,
|
}"#,
|
||||||
true,
|
true,
|
||||||
),
|
),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "deno_web"
|
name = "deno_web"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Collection of Web APIs"
|
description = "Collection of Web APIs"
|
||||||
authors = ["the Deno authors"]
|
authors = ["the Deno authors"]
|
||||||
|
|
|
@ -2,30 +2,32 @@
|
||||||
|
|
||||||
use deno_core::js_check;
|
use deno_core::js_check;
|
||||||
use deno_core::JsRuntime;
|
use deno_core::JsRuntime;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub fn init(isolate: &mut JsRuntime) {
|
pub fn init(isolate: &mut JsRuntime) {
|
||||||
|
let manifest_dir = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||||
let files = vec![
|
let files = vec![
|
||||||
get_path("00_dom_exception.js"),
|
manifest_dir.join("00_dom_exception.js"),
|
||||||
get_path("01_event.js"),
|
manifest_dir.join("01_event.js"),
|
||||||
get_path("02_abort_signal.js"),
|
manifest_dir.join("02_abort_signal.js"),
|
||||||
get_path("08_text_encoding.js"),
|
manifest_dir.join("08_text_encoding.js"),
|
||||||
];
|
];
|
||||||
|
// TODO(nayeemrmn): https://github.com/rust-lang/cargo/issues/3946 to get the
|
||||||
|
// workspace root.
|
||||||
|
let display_root = manifest_dir.parent().unwrap().parent().unwrap();
|
||||||
for file in files {
|
for file in files {
|
||||||
println!("cargo:rerun-if-changed={}", file.display());
|
println!("cargo:rerun-if-changed={}", file.display());
|
||||||
|
let display_path = file.strip_prefix(display_root).unwrap();
|
||||||
|
let display_path_str = display_path.display().to_string();
|
||||||
js_check(isolate.execute(
|
js_check(isolate.execute(
|
||||||
&file.to_string_lossy(),
|
&("deno:".to_string() + &display_path_str.replace('\\', "/")),
|
||||||
&std::fs::read_to_string(&file).unwrap(),
|
&std::fs::read_to_string(&file).unwrap(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_declaration() -> PathBuf {
|
pub fn get_declaration() -> PathBuf {
|
||||||
get_path("lib.deno_web.d.ts")
|
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("lib.deno_web.d.ts")
|
||||||
}
|
|
||||||
|
|
||||||
fn get_path(file_name: &str) -> PathBuf {
|
|
||||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(file_name)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -78,6 +80,25 @@ mod tests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_event_error() {
|
||||||
|
run_in_task(|mut cx| {
|
||||||
|
let mut isolate = setup();
|
||||||
|
let result = isolate.execute("foo.js", "new Event()");
|
||||||
|
if let Err(error) = result {
|
||||||
|
let error_string = error.to_string();
|
||||||
|
// Test that the script specifier is a URL: `deno:<repo-relative path>`.
|
||||||
|
assert!(error_string.starts_with("deno:op_crates/web/01_event.js"));
|
||||||
|
assert!(error_string.contains("Uncaught TypeError"));
|
||||||
|
} else {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
if let Poll::Ready(Err(_)) = isolate.poll_unpin(&mut cx) {
|
||||||
|
unreachable!();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_event_target() {
|
fn test_event_target() {
|
||||||
run_in_task(|mut cx| {
|
run_in_task(|mut cx| {
|
||||||
|
|
Loading…
Reference in a new issue