summaryrefslogtreecommitdiff
path: root/deno_typescript
diff options
context:
space:
mode:
authorKitson Kelly <me@kitsonkelly.com>2020-01-12 22:20:33 +1100
committerBartek IwaƄczuk <biwanczuk@gmail.com>2020-01-12 12:20:33 +0100
commit737ab94ea1bdf65eeef323ea37e84bcf430fb92c (patch)
treeb6a239195a960557a5d32f1762886f77a71a9104 /deno_typescript
parent8fac8ab130b3cb8a93d7e0e37fa1ea6ea4cc2e4a (diff)
Create an old program to be used in snapshot. (#3644)
Diffstat (limited to 'deno_typescript')
-rw-r--r--deno_typescript/lib.rs8
-rw-r--r--deno_typescript/ops.rs15
2 files changed, 23 insertions, 0 deletions
diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs
index c86ed645b..a9083b86d 100644
--- a/deno_typescript/lib.rs
+++ b/deno_typescript/lib.rs
@@ -204,6 +204,10 @@ pub fn mksnapshot_bundle_ts(
state: Arc<Mutex<TSState>>,
) -> Result<(), ErrBox> {
let runtime_isolate = &mut Isolate::new(StartupData::None, true);
+ runtime_isolate.register_op(
+ "fetch_asset",
+ compiler_op(state.clone(), ops::json_op(ops::fetch_asset)),
+ );
let source_code_vec = std::fs::read(bundle)?;
let source_code = std::str::from_utf8(&source_code_vec)?;
@@ -257,6 +261,10 @@ pub fn get_asset(name: &str) -> Option<&'static str> {
match name {
"bundle_loader.js" => Some(include_str!("bundle_loader.js")),
"lib.deno_core.d.ts" => Some(include_str!("lib.deno_core.d.ts")),
+ "lib.deno_runtime.d.ts" => {
+ Some(include_str!("../cli/js/lib.deno_runtime.d.ts"))
+ }
+ "bootstrap.ts" => Some("console.log(\"hello deno\");"),
"typescript.d.ts" => inc!("typescript.d.ts"),
"lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
"lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
diff --git a/deno_typescript/ops.rs b/deno_typescript/ops.rs
index e45349591..d557b9b8c 100644
--- a/deno_typescript/ops.rs
+++ b/deno_typescript/ops.rs
@@ -112,6 +112,21 @@ pub fn resolve_module_names(
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
+struct FetchAssetArgs {
+ name: String,
+}
+
+pub fn fetch_asset(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let args: FetchAssetArgs = serde_json::from_value(v)?;
+ if let Some(source_code) = crate::get_asset(&args.name) {
+ Ok(json!(source_code))
+ } else {
+ panic!("op_fetch_asset bad asset {}", args.name)
+ }
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
struct Exit {
code: i32,
}