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
4 changes: 3 additions & 1 deletion src/mod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import {
} from "./mod.ts";
import { assert, assertEquals } from "@std/assert";

Deno.test("should resolve and load", async () => {
Deno.test("should resolve, load and get graph", async () => {
const workspace = new Workspace({
nodeConditions: undefined, // unsure doesn't error
});
const modFileUrl = import.meta.resolve("./mod.ts");
const loader = await workspace.createLoader({
entrypoints: [modFileUrl],
});
const graph = loader.getGraphUnstable();
assertEquals((graph as any).roots[0], modFileUrl);
const resolvedUrl = loader.resolve(
"./mod.test.ts",
modFileUrl,
Expand Down
9 changes: 9 additions & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ export class Loader implements Disposable {
}
return this.#inner.load(specifier, requestedModuleType);
}

/** Gets the module graph.
*
* WARNING: This function is very unstable and the output may change between
* patch releases.
*/
getGraphUnstable(): unknown {
return this.#inner.get_graph();
}
}

function requestedModuleTypeToString(moduleType: RequestedModuleType) {
Expand Down
6 changes: 6 additions & 0 deletions src/rs_lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ impl Drop for DenoLoader {

#[wasm_bindgen]
impl DenoLoader {
pub fn get_graph(&self) -> JsValue {
let serializer =
serde_wasm_bindgen::Serializer::new().serialize_maps_as_objects(true);
self.graph.serialize(&serializer).unwrap()
}

pub async fn add_roots(&mut self, roots: Vec<String>) -> Result<(), JsValue> {
// only allow one async task to modify the graph at a time
let task_queue = self.task_queue.clone();
Expand Down