Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for import assertions and JSON modules #12866

Merged
merged 43 commits into from
Dec 15, 2021
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a5b25bb
add deno_core::ModuleType enum
bartlomieju Sep 24, 2021
0c97bcf
remove atomic in core/modules.rs
bartlomieju Sep 24, 2021
a4ec823
Merge branch 'main' into import_assertions
bartlomieju Oct 5, 2021
2cb253c
Merge branch 'main' into import_assertions
bartlomieju Nov 22, 2021
53016b0
Merge branch 'main' into import_assertions
bartlomieju Dec 9, 2021
cf72c70
Merge branch 'main' into import_assertions
bartlomieju Dec 11, 2021
d8eeb8f
Merge branch 'main' into import_assertions
bartlomieju Dec 12, 2021
4098ebd
use ModuleType
bartlomieju Dec 12, 2021
a1c5f54
check passed assertion value
bartlomieju Dec 12, 2021
1e6f134
validate import assertions
bartlomieju Dec 12, 2021
795dcce
example(core): add example for FS module loading
bartlomieju Dec 12, 2021
cf7c69d
fix cargo lock, add ModuleType::Json
bartlomieju Dec 12, 2021
ce0117f
fix
bartlomieju Dec 12, 2021
f06d9ba
Merge branch 'core_example_loading' into import_assertions
bartlomieju Dec 12, 2021
4b0cf46
update WPT expectations
bartlomieju Dec 12, 2021
694ae08
Merge branch 'main' into import_assertions
bartlomieju Dec 13, 2021
73f20db
JSON module evaluation
bartlomieju Dec 13, 2021
f881a94
fmt
bartlomieju Dec 14, 2021
54fa3e8
Merge branch 'main' into import_assertions
bartlomieju Dec 14, 2021
2cabd3c
parsing of assertions
bartlomieju Dec 15, 2021
e4ad657
add ModuleRequest struct
bartlomieju Dec 15, 2021
acc2ac0
import functions
bartlomieju Dec 15, 2021
b1ae3f2
wire up in the CLI
bartlomieju Dec 15, 2021
4535edb
fix validation of assertions
bartlomieju Dec 15, 2021
6a549ca
lint
bartlomieju Dec 15, 2021
1cb9bdf
add tests, set resolveJsonModule in tsc
bartlomieju Dec 15, 2021
37a464c
review comments
bartlomieju Dec 15, 2021
da0ba53
update TS config for LSP
bartlomieju Dec 15, 2021
6c8be58
add wildcard to test output
bartlomieju Dec 15, 2021
519de28
work around bug in deno_ast
kitsonk Dec 15, 2021
853982d
revert change to display
bartlomieju Dec 15, 2021
48590d8
ignore emit for json modules
kitsonk Dec 15, 2021
9627341
update output assertions
bartlomieju Dec 15, 2021
fb8295f
add test for type checking JSON module
bartlomieju Dec 15, 2021
98fdbf7
fmt
bartlomieju Dec 15, 2021
c533c65
use SyntaxError for invalid JSON
bartlomieju Dec 15, 2021
3fe6133
update WPT
bartlomieju Dec 15, 2021
50e9299
update WPT2
bartlomieju Dec 15, 2021
0428fa6
lint
bartlomieju Dec 15, 2021
265a408
pass another WPT test
bartlomieju Dec 15, 2021
fab5d86
review comments
bartlomieju Dec 15, 2021
a5dbc9c
fix tests
bartlomieju Dec 15, 2021
f0662ff
Merge branch 'main' into import_assertions
bartlomieju Dec 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
example(core): add example for FS module loading
  • Loading branch information
bartlomieju committed Dec 12, 2021
commit 795dcce6a2336651d350f5213c04cb86eed0e496
47 changes: 47 additions & 0 deletions core/examples/fs_module_loader.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

use deno_core::anyhow::Error;
use deno_core::FsModuleLoader;
use deno_core::JsRuntime;
use deno_core::RuntimeOptions;
use std::rc::Rc;

fn main() -> Result<(), Error> {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
println!("Usage: target/examples/debug/fs_module_loading <path_to_module>");
std::process::exit(1);
}
let main_url = args[1].clone();
println!("Run {}", main_url);

let mut js_runtime = JsRuntime::new(RuntimeOptions {
module_loader: Some(Rc::new(FsModuleLoader)),
..Default::default()
});

let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;

let main_module = deno_core::resolve_path(&main_url)?;

let future = async move {
let mod_id = js_runtime.load_main_module(&main_module, None).await?;

let mut receiver = js_runtime.mod_evaluate(mod_id);
tokio::select! {
maybe_result = &mut receiver => {
maybe_result.expect("Module evaluation result not provided.")
}

event_loop_result = js_runtime.run_event_loop(false) => {
event_loop_result?;
let maybe_result = receiver.await;
maybe_result.expect("Module evaluation result not provided.")
}
}
};
runtime.block_on(future)?;
Ok(())
}