diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-01-22 23:58:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-22 23:58:13 +0100 |
commit | 63293a90e1503aa9c18ce5f89ebc6d5c066f09bf (patch) | |
tree | cef7439565c558bede48bff6cf8cc527689808a9 /deno_typescript/ops.rs | |
parent | bd9561f4de8f940ce6ed8b5eedfa84161a749c54 (diff) |
refactor: snapshotting (#3753)
Diffstat (limited to 'deno_typescript/ops.rs')
-rw-r--r-- | deno_typescript/ops.rs | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/deno_typescript/ops.rs b/deno_typescript/ops.rs index 0680d07b3..f76662620 100644 --- a/deno_typescript/ops.rs +++ b/deno_typescript/ops.rs @@ -7,7 +7,7 @@ use serde::Deserialize; use serde_json::json; use serde_json::Value; -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct WrittenFile { pub url: String, pub module_name: String, @@ -41,14 +41,19 @@ struct ReadFile { should_create_new_source_file: bool, } -pub fn read_file(s: &mut TSState, v: Value) -> Result<Value, ErrBox> { +pub fn read_file(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> { let v: ReadFile = serde_json::from_value(v)?; let (module_name, source_code) = if v.file_name.starts_with("$asset$/") { let asset = v.file_name.replace("$asset$/", ""); - let source_code = match s.custom_assets.get(&asset) { - Some(asset_path) => std::fs::read_to_string(&asset_path)?, - None => crate::get_asset2(&asset)?.to_string(), + let source_code = match crate::get_asset(&asset) { + Some(code) => code.to_string(), + None => { + return Err( + std::io::Error::new(std::io::ErrorKind::NotFound, "Asset not found") + .into(), + ); + } }; (asset, source_code) @@ -117,27 +122,6 @@ 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(asset_path) = s.custom_assets.get(&args.name) { - let source_code = std::fs::read_to_string(&asset_path)?; - return Ok(json!(source_code)); - } - - 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, } |