From 7b9ffe9e270f01b1769c5c50cf64075564ce8c7d Mon Sep 17 00:00:00 2001 From: Elias Rhouzlane Date: Tue, 29 Jul 2025 15:41:52 +0200 Subject: [PATCH 1/6] feat: added graph retrieval and assertion Added a test to verify that the module graph is correctly resolved and loaded. The test asserts that the root of the graph is the expected module URL. --- deno.json | 3 ++- deno.lock | 47 ++++++++++++++++++++++++++++++++++++++++++++--- src/mod.test.ts | 4 +++- src/mod.ts | 10 ++++++++++ src/rs_lib/lib.rs | 6 ++++++ 5 files changed, 65 insertions(+), 5 deletions(-) diff --git a/deno.json b/deno.json index 3a39ba8..b8096bf 100644 --- a/deno.json +++ b/deno.json @@ -24,6 +24,7 @@ "imports": { "@david/dax": "jsr:@david/dax@^0.43.2", "@std/assert": "jsr:@std/assert@^1.0.13", - "@std/toml": "jsr:@std/toml@^1.0.7" + "@std/toml": "jsr:@std/toml@^1.0.7", + "@deno/graph/types": "jsr:@deno/graph@^0.97.1/types" } } diff --git a/deno.lock b/deno.lock index ad73952..329493c 100644 --- a/deno.lock +++ b/deno.lock @@ -4,16 +4,24 @@ "jsr:@david/console-static-text@0.3": "0.3.0", "jsr:@david/dax@~0.43.2": "0.43.2", "jsr:@david/path@0.2": "0.2.0", + "jsr:@david/temp@~0.1.1": "0.1.1", "jsr:@david/which@~0.4.1": "0.4.1", + "jsr:@deno/wasmbuild@0.19.2": "0.19.2", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/bytes@^1.0.5": "1.0.6", + "jsr:@std/cli@^1.0.11": "1.0.21", "jsr:@std/collections@^1.1.1": "1.1.1", + "jsr:@std/encoding@^1.0.6": "1.0.10", "jsr:@std/fmt@1": "1.0.8", + "jsr:@std/fmt@^1.0.4": "1.0.8", "jsr:@std/fs@1": "1.0.18", + "jsr:@std/fs@^1.0.10": "1.0.18", "jsr:@std/internal@^1.0.6": "1.0.8", "jsr:@std/io@0.225": "0.225.2", "jsr:@std/path@1": "1.1.0", "jsr:@std/path@^1.1.0": "1.1.0", + "jsr:@std/streams@^1.0.9": "1.0.10", + "jsr:@std/tar@~0.1.4": "0.1.6", "jsr:@std/toml@^1.0.7": "1.0.7", "npm:@types/jscodeshift@*": "17.3.0", "npm:@types/node@*": "22.15.15", @@ -29,8 +37,8 @@ "jsr:@david/console-static-text", "jsr:@david/path", "jsr:@david/which", - "jsr:@std/fmt", - "jsr:@std/fs", + "jsr:@std/fmt@1", + "jsr:@std/fs@1", "jsr:@std/io", "jsr:@std/path@1" ] @@ -38,13 +46,31 @@ "@david/path@0.2.0": { "integrity": "f2d7aa7f02ce5a55e27c09f9f1381794acb09d328f8d3c8a2e3ab3ffc294dccd", "dependencies": [ - "jsr:@std/fs", + "jsr:@std/fs@1", "jsr:@std/path@1" ] }, + "@david/temp@0.1.1": { + "integrity": "3974e3aa76536bd831294b72f5b70bfb67af3f4119ae334360e321f6ded18840", + "dependencies": [ + "jsr:@david/path" + ] + }, "@david/which@0.4.1": { "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" }, + "@deno/wasmbuild@0.19.2": { + "integrity": "f4a92beae788e2fd68189aefb6a6d8c3be79519c3ef8429a10519296379c33d1", + "dependencies": [ + "jsr:@david/path", + "jsr:@david/temp", + "jsr:@std/cli", + "jsr:@std/encoding", + "jsr:@std/fmt@^1.0.4", + "jsr:@std/fs@^1.0.10", + "jsr:@std/tar" + ] + }, "@std/assert@1.0.13": { "integrity": "ae0d31e41919b12c656c742b22522c32fb26ed0cba32975cb0de2a273cb68b29", "dependencies": [ @@ -54,9 +80,15 @@ "@std/bytes@1.0.6": { "integrity": "f6ac6adbd8ccd99314045f5703e23af0a68d7f7e58364b47d2c7f408aeb5820a" }, + "@std/cli@1.0.21": { + "integrity": "cd25b050bdf6282e321854e3822bee624f07aca7636a3a76d95f77a3a919ca2a" + }, "@std/collections@1.1.1": { "integrity": "eff6443fbd9d5a6697018fb39c5d13d5f662f0045f21392d640693d0008ab2af" }, + "@std/encoding@1.0.10": { + "integrity": "8783c6384a2d13abd5e9e87a7ae0520a30e9f56aeeaa3bdf910a3eaaf5c811a1" + }, "@std/fmt@1.0.8": { "integrity": "71e1fc498787e4434d213647a6e43e794af4fd393ef8f52062246e06f7e372b7" }, @@ -78,6 +110,15 @@ "@std/path@1.1.0": { "integrity": "ddc94f8e3c275627281cbc23341df6b8bcc874d70374f75fec2533521e3d6886" }, + "@std/streams@1.0.10": { + "integrity": "75c0b1431873cd0d8b3d679015220204d36d3c7420d93b60acfc379eb0dc30af" + }, + "@std/tar@0.1.6": { + "integrity": "7f06a5359518262207e1c28ea965fd552dff3ba2047d2e9225339af287b1f3a4", + "dependencies": [ + "jsr:@std/streams" + ] + }, "@std/toml@1.0.7": { "integrity": "3c86f8bbde31578da33d2fbe410b80e3cb672b66e008e06cf41afc4d7409921c", "dependencies": [ diff --git a/src/mod.test.ts b/src/mod.test.ts index dd06568..d6bd165 100644 --- a/src/mod.test.ts +++ b/src/mod.test.ts @@ -6,7 +6,7 @@ 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 }); @@ -14,6 +14,8 @@ Deno.test("should resolve and load", async () => { const loader = await workspace.createLoader({ entrypoints: [modFileUrl], }); + const graph = loader.getGraph(); + assertEquals(graph.roots[0], modFileUrl); const resolvedUrl = loader.resolve( "./mod.test.ts", modFileUrl, diff --git a/src/mod.ts b/src/mod.ts index 112d7df..62837ae 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -37,6 +37,9 @@ import { DenoLoader as WasmLoader, DenoWorkspace as WasmWorkspace, } from "./lib/rs_lib.js"; +import type { ModuleGraphJson } from "@deno/graph/types"; + +export type { ModuleGraphJson }; /** Options for creating a workspace. */ export interface WorkspaceOptions { @@ -219,6 +222,13 @@ export class Loader implements Disposable { } return this.#inner.load(specifier, requestedModuleType); } + + getGraph(): ModuleGraphJson { + if (this.#debug) { + console.error("Getting the module graph"); + } + return this.#inner.get_graph(); + } } function requestedModuleTypeToString(moduleType: RequestedModuleType) { diff --git a/src/rs_lib/lib.rs b/src/rs_lib/lib.rs index fae6872..81d026a 100644 --- a/src/rs_lib/lib.rs +++ b/src/rs_lib/lib.rs @@ -327,6 +327,12 @@ impl Drop for DenoLoader { #[wasm_bindgen] impl DenoLoader { + pub fn get_graph(&self) -> Result { + let serializer = serde_wasm_bindgen::Serializer::new() + .serialize_maps_as_objects(true); + Ok(self.graph.serialize(&serializer).unwrap()) + } + pub async fn add_roots(&mut self, roots: Vec) -> Result<(), JsValue> { // only allow one async task to modify the graph at a time let task_queue = self.task_queue.clone(); From 2314ed3059eaefb3f7df87cf74ccd9a38f359dfd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 12:40:55 -0400 Subject: [PATCH 2/6] limit this --- deno.json | 3 +-- deno.lock | 5 +++++ src/mod.test.ts | 2 +- src/mod.ts | 13 ++++++------- src/rs_lib/lib.rs | 8 ++++---- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/deno.json b/deno.json index 8d7ad86..6874de9 100644 --- a/deno.json +++ b/deno.json @@ -29,7 +29,6 @@ "imports": { "@david/dax": "jsr:@david/dax@^0.43.2", "@std/assert": "jsr:@std/assert@^1.0.13", - "@std/toml": "jsr:@std/toml@^1.0.7", - "@deno/graph/types": "jsr:@deno/graph@^0.97.1/types" + "@std/toml": "jsr:@std/toml@^1.0.7" } } diff --git a/deno.lock b/deno.lock index 329493c..91c4610 100644 --- a/deno.lock +++ b/deno.lock @@ -6,6 +6,7 @@ "jsr:@david/path@0.2": "0.2.0", "jsr:@david/temp@~0.1.1": "0.1.1", "jsr:@david/which@~0.4.1": "0.4.1", + "jsr:@deno/graph@~0.97.1": "0.97.1", "jsr:@deno/wasmbuild@0.19.2": "0.19.2", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/bytes@^1.0.5": "1.0.6", @@ -59,6 +60,9 @@ "@david/which@0.4.1": { "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" }, + "@deno/graph@0.97.1": { + "integrity": "e35e2586406c1402e4026ebf328714f85ade84f114355e9014e6c92cadd2b654" + }, "@deno/wasmbuild@0.19.2": { "integrity": "f4a92beae788e2fd68189aefb6a6d8c3be79519c3ef8429a10519296379c33d1", "dependencies": [ @@ -856,6 +860,7 @@ "workspace": { "dependencies": [ "jsr:@david/dax@~0.43.2", + "jsr:@deno/graph@~0.97.1", "jsr:@std/assert@^1.0.13", "jsr:@std/toml@^1.0.7" ] diff --git a/src/mod.test.ts b/src/mod.test.ts index d6bd165..52a167d 100644 --- a/src/mod.test.ts +++ b/src/mod.test.ts @@ -14,7 +14,7 @@ Deno.test("should resolve, load and get graph", async () => { const loader = await workspace.createLoader({ entrypoints: [modFileUrl], }); - const graph = loader.getGraph(); + const graph = loader.getGraphUnstable(); assertEquals(graph.roots[0], modFileUrl); const resolvedUrl = loader.resolve( "./mod.test.ts", diff --git a/src/mod.ts b/src/mod.ts index 62837ae..47f7645 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -37,9 +37,6 @@ import { DenoLoader as WasmLoader, DenoWorkspace as WasmWorkspace, } from "./lib/rs_lib.js"; -import type { ModuleGraphJson } from "@deno/graph/types"; - -export type { ModuleGraphJson }; /** Options for creating a workspace. */ export interface WorkspaceOptions { @@ -223,10 +220,12 @@ export class Loader implements Disposable { return this.#inner.load(specifier, requestedModuleType); } - getGraph(): ModuleGraphJson { - if (this.#debug) { - console.error("Getting the module graph"); - } + /** Gets the module graph. + * + * WARNING: This function is very unstable and the + * output may change in patch releases. + */ + getGraphUnstable(): unknown { return this.#inner.get_graph(); } } diff --git a/src/rs_lib/lib.rs b/src/rs_lib/lib.rs index 81d026a..27277bf 100644 --- a/src/rs_lib/lib.rs +++ b/src/rs_lib/lib.rs @@ -327,10 +327,10 @@ impl Drop for DenoLoader { #[wasm_bindgen] impl DenoLoader { - pub fn get_graph(&self) -> Result { - let serializer = serde_wasm_bindgen::Serializer::new() - .serialize_maps_as_objects(true); - Ok(self.graph.serialize(&serializer).unwrap()) + 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) -> Result<(), JsValue> { From 5d8915d70fa0c1fe2fdb08c7b54eaca2751b8067 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 12:41:13 -0400 Subject: [PATCH 3/6] fix --- src/mod.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod.test.ts b/src/mod.test.ts index 52a167d..823faf5 100644 --- a/src/mod.test.ts +++ b/src/mod.test.ts @@ -15,7 +15,7 @@ Deno.test("should resolve, load and get graph", async () => { entrypoints: [modFileUrl], }); const graph = loader.getGraphUnstable(); - assertEquals(graph.roots[0], modFileUrl); + assertEquals((graph as any).roots[0], modFileUrl); const resolvedUrl = loader.resolve( "./mod.test.ts", modFileUrl, From 38e1d10661937cc37f9afb520c0173a3401030e7 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 12:42:09 -0400 Subject: [PATCH 4/6] update --- deno.lock | 5 ----- 1 file changed, 5 deletions(-) diff --git a/deno.lock b/deno.lock index 91c4610..329493c 100644 --- a/deno.lock +++ b/deno.lock @@ -6,7 +6,6 @@ "jsr:@david/path@0.2": "0.2.0", "jsr:@david/temp@~0.1.1": "0.1.1", "jsr:@david/which@~0.4.1": "0.4.1", - "jsr:@deno/graph@~0.97.1": "0.97.1", "jsr:@deno/wasmbuild@0.19.2": "0.19.2", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/bytes@^1.0.5": "1.0.6", @@ -60,9 +59,6 @@ "@david/which@0.4.1": { "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" }, - "@deno/graph@0.97.1": { - "integrity": "e35e2586406c1402e4026ebf328714f85ade84f114355e9014e6c92cadd2b654" - }, "@deno/wasmbuild@0.19.2": { "integrity": "f4a92beae788e2fd68189aefb6a6d8c3be79519c3ef8429a10519296379c33d1", "dependencies": [ @@ -860,7 +856,6 @@ "workspace": { "dependencies": [ "jsr:@david/dax@~0.43.2", - "jsr:@deno/graph@~0.97.1", "jsr:@std/assert@^1.0.13", "jsr:@std/toml@^1.0.7" ] From 76084e521207a5a1657223496eb53250e13c66a0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 12:42:47 -0400 Subject: [PATCH 5/6] revert --- deno.lock | 47 +++-------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/deno.lock b/deno.lock index 329493c..ad73952 100644 --- a/deno.lock +++ b/deno.lock @@ -4,24 +4,16 @@ "jsr:@david/console-static-text@0.3": "0.3.0", "jsr:@david/dax@~0.43.2": "0.43.2", "jsr:@david/path@0.2": "0.2.0", - "jsr:@david/temp@~0.1.1": "0.1.1", "jsr:@david/which@~0.4.1": "0.4.1", - "jsr:@deno/wasmbuild@0.19.2": "0.19.2", "jsr:@std/assert@^1.0.13": "1.0.13", "jsr:@std/bytes@^1.0.5": "1.0.6", - "jsr:@std/cli@^1.0.11": "1.0.21", "jsr:@std/collections@^1.1.1": "1.1.1", - "jsr:@std/encoding@^1.0.6": "1.0.10", "jsr:@std/fmt@1": "1.0.8", - "jsr:@std/fmt@^1.0.4": "1.0.8", "jsr:@std/fs@1": "1.0.18", - "jsr:@std/fs@^1.0.10": "1.0.18", "jsr:@std/internal@^1.0.6": "1.0.8", "jsr:@std/io@0.225": "0.225.2", "jsr:@std/path@1": "1.1.0", "jsr:@std/path@^1.1.0": "1.1.0", - "jsr:@std/streams@^1.0.9": "1.0.10", - "jsr:@std/tar@~0.1.4": "0.1.6", "jsr:@std/toml@^1.0.7": "1.0.7", "npm:@types/jscodeshift@*": "17.3.0", "npm:@types/node@*": "22.15.15", @@ -37,8 +29,8 @@ "jsr:@david/console-static-text", "jsr:@david/path", "jsr:@david/which", - "jsr:@std/fmt@1", - "jsr:@std/fs@1", + "jsr:@std/fmt", + "jsr:@std/fs", "jsr:@std/io", "jsr:@std/path@1" ] @@ -46,31 +38,13 @@ "@david/path@0.2.0": { "integrity": "f2d7aa7f02ce5a55e27c09f9f1381794acb09d328f8d3c8a2e3ab3ffc294dccd", "dependencies": [ - "jsr:@std/fs@1", + "jsr:@std/fs", "jsr:@std/path@1" ] }, - "@david/temp@0.1.1": { - "integrity": "3974e3aa76536bd831294b72f5b70bfb67af3f4119ae334360e321f6ded18840", - "dependencies": [ - "jsr:@david/path" - ] - }, "@david/which@0.4.1": { "integrity": "896a682b111f92ab866cc70c5b4afab2f5899d2f9bde31ed00203b9c250f225e" }, - "@deno/wasmbuild@0.19.2": { - "integrity": "f4a92beae788e2fd68189aefb6a6d8c3be79519c3ef8429a10519296379c33d1", - "dependencies": [ - "jsr:@david/path", - "jsr:@david/temp", - "jsr:@std/cli", - "jsr:@std/encoding", - "jsr:@std/fmt@^1.0.4", - "jsr:@std/fs@^1.0.10", - "jsr:@std/tar" - ] - }, "@std/assert@1.0.13": { "integrity": "ae0d31e41919b12c656c742b22522c32fb26ed0cba32975cb0de2a273cb68b29", "dependencies": [ @@ -80,15 +54,9 @@ "@std/bytes@1.0.6": { "integrity": "f6ac6adbd8ccd99314045f5703e23af0a68d7f7e58364b47d2c7f408aeb5820a" }, - "@std/cli@1.0.21": { - "integrity": "cd25b050bdf6282e321854e3822bee624f07aca7636a3a76d95f77a3a919ca2a" - }, "@std/collections@1.1.1": { "integrity": "eff6443fbd9d5a6697018fb39c5d13d5f662f0045f21392d640693d0008ab2af" }, - "@std/encoding@1.0.10": { - "integrity": "8783c6384a2d13abd5e9e87a7ae0520a30e9f56aeeaa3bdf910a3eaaf5c811a1" - }, "@std/fmt@1.0.8": { "integrity": "71e1fc498787e4434d213647a6e43e794af4fd393ef8f52062246e06f7e372b7" }, @@ -110,15 +78,6 @@ "@std/path@1.1.0": { "integrity": "ddc94f8e3c275627281cbc23341df6b8bcc874d70374f75fec2533521e3d6886" }, - "@std/streams@1.0.10": { - "integrity": "75c0b1431873cd0d8b3d679015220204d36d3c7420d93b60acfc379eb0dc30af" - }, - "@std/tar@0.1.6": { - "integrity": "7f06a5359518262207e1c28ea965fd552dff3ba2047d2e9225339af287b1f3a4", - "dependencies": [ - "jsr:@std/streams" - ] - }, "@std/toml@1.0.7": { "integrity": "3c86f8bbde31578da33d2fbe410b80e3cb672b66e008e06cf41afc4d7409921c", "dependencies": [ From 8c8a628481835b5378a0f0d9ca84fbb706337e29 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 30 Jul 2025 12:43:15 -0400 Subject: [PATCH 6/6] update comment --- src/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod.ts b/src/mod.ts index 47f7645..3445426 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -222,8 +222,8 @@ export class Loader implements Disposable { /** Gets the module graph. * - * WARNING: This function is very unstable and the - * output may change in patch releases. + * WARNING: This function is very unstable and the output may change between + * patch releases. */ getGraphUnstable(): unknown { return this.#inner.get_graph();