Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class Workspace implements Disposable {
}
const wasmLoader = await this.#inner.create_loader();
const loader = new Loader(wasmLoader, this.#debug);
await loader.addRoots(options.entrypoints);
await loader.addEntrypoints(options.entrypoints);
return loader;
}
}
Expand Down Expand Up @@ -186,14 +186,14 @@ export class Loader implements Disposable {
this.#inner.free();
}

/** Adds additional roots to the loader.
/** Adds additional entrypoints to the loader after the fact.
*
* This may be useful for having a JSR specifier stored
* in the internal module graph on the fly, which will allow
* it to be resolved.
* This may be useful for having a JSR specifier asynchronously
* stored in the internal module graph on the fly, which will allow
* it to be synchronously resolved.
*/
addRoots(entrypoints: string[]): Promise<void> {
return this.#inner.add_roots(entrypoints);
addEntrypoints(entrypoints: string[]): Promise<void> {
return this.#inner.add_entrypoints(entrypoints);
}

/** Resolves a specifier using the given referrer and resolution mode. */
Expand Down
18 changes: 13 additions & 5 deletions src/rs_lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,19 +333,27 @@ impl DenoLoader {
self.graph.serialize(&serializer).unwrap()
}

pub async fn add_roots(&mut self, roots: Vec<String>) -> Result<(), JsValue> {
pub async fn add_entrypoints(
&mut self,
entrypoints: Vec<String>,
) -> Result<(), JsValue> {
// only allow one async task to modify the graph at a time
let task_queue = self.task_queue.clone();
task_queue
.run(async { self.add_roots_inner(roots).await.map_err(create_js_error) })
.run(async {
self
.add_entrypoints_internal(entrypoints)
.await
.map_err(create_js_error)
})
.await
}

async fn add_roots_inner(
async fn add_entrypoints_internal(
&mut self,
roots: Vec<String>,
entrypoints: Vec<String>,
) -> Result<(), anyhow::Error> {
let roots = roots
let roots = entrypoints
.into_iter()
.map(|e| self.resolve_entrypoint(e))
.collect::<Result<Vec<_>, _>>()?;
Expand Down