summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs46
1 files changed, 28 insertions, 18 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 40d25aa74..975e01ee1 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -33,39 +33,49 @@ pub fn op_cache(
}
#[derive(Deserialize)]
-struct FetchSourceFileArgs {
- specifier: String,
+struct FetchSourceFilesArgs {
+ specifiers: Vec<String>,
referrer: String,
}
-pub fn op_fetch_source_file(
+pub fn op_fetch_source_files(
state: &ThreadSafeState,
args: Value,
_zero_copy: Option<PinnedBuf>,
) -> Result<JsonOp, ErrBox> {
- let args: FetchSourceFileArgs = serde_json::from_value(args)?;
+ let args: FetchSourceFilesArgs = serde_json::from_value(args)?;
// TODO(ry) Maybe a security hole. Only the compiler worker should have access
// to this. Need a test to demonstrate the hole.
let is_dyn_import = false;
- let resolved_specifier =
- state.resolve(&args.specifier, &args.referrer, false, is_dyn_import)?;
-
- let fut = state
- .file_fetcher
- .fetch_source_file_async(&resolved_specifier);
+ let mut futures = vec![];
+ for specifier in &args.specifiers {
+ let resolved_specifier =
+ state.resolve(specifier, &args.referrer, false, is_dyn_import)?;
+ let fut = state
+ .file_fetcher
+ .fetch_source_file_async(&resolved_specifier);
+ futures.push(fut);
+ }
// WARNING: Here we use tokio_util::block_on() which starts a new Tokio
- // runtime for executing the future. This is so we don't inadvernently run
+ // runtime for executing the future. This is so we don't inadvertently run
// out of threads in the main runtime.
- let out = tokio_util::block_on(fut)?;
- Ok(JsonOp::Sync(json!({
- "moduleName": out.url.to_string(),
- "filename": out.filename.to_str().unwrap(),
- "mediaType": out.media_type as i32,
- "sourceCode": String::from_utf8(out.source_code).unwrap(),
- })))
+ let files = tokio_util::block_on(futures::future::join_all(futures))?;
+ let res: Vec<serde_json::value::Value> = files
+ .into_iter()
+ .map(|file| {
+ json!({
+ "moduleName": file.url.to_string(),
+ "filename": file.filename.to_str().unwrap(),
+ "mediaType": file.media_type as i32,
+ "sourceCode": String::from_utf8(file.source_code).unwrap(),
+ })
+ })
+ .collect();
+
+ Ok(JsonOp::Sync(json!(res)))
}
#[derive(Deserialize)]