{"id":13688523,"url":"https://github.com/denoland/deno_graph","last_synced_at":"2025-05-15T10:00:50.282Z","repository":{"id":37228810,"uuid":"391780302","full_name":"denoland/deno_graph","owner":"denoland","description":"The module graph logic for Deno CLI","archived":false,"fork":false,"pushed_at":"2025-05-13T17:27:30.000Z","size":103724,"stargazers_count":127,"open_issues_count":37,"forks_count":45,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-05-13T18:37:56.658Z","etag":null,"topics":["deno","rust","typescript","webassembly"],"latest_commit_sha":null,"homepage":"https://docs.rs/deno_graph","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/denoland.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-08-02T01:12:09.000Z","updated_at":"2025-05-13T17:27:33.000Z","dependencies_parsed_at":"2023-11-29T16:29:49.832Z","dependency_job_id":"e90797fe-3310-4c13-9780-54404bc6dd0f","html_url":"https://github.com/denoland/deno_graph","commit_stats":{"total_commits":571,"total_committers":27,"mean_commits":21.14814814814815,"dds":0.532399299474606,"last_synced_commit":"e4c1162a548752921b4502796acc0029650da965"},"previous_names":[],"tags_count":256,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fdeno_graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fdeno_graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fdeno_graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denoland%2Fdeno_graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denoland","download_url":"https://codeload.github.com/denoland/deno_graph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254005662,"owners_count":21998295,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","rust","typescript","webassembly"],"created_at":"2024-08-02T15:01:15.875Z","updated_at":"2025-05-15T10:00:44.630Z","avatar_url":"https://github.com/denoland.png","language":"Rust","funding_links":[],"categories":["Rust","deno"],"sub_categories":[],"readme":"# deno_graph\n\n[![JSR](https://jsr.io/badges/@deno/graph)](https://jsr.io/@deno/graph)\n[![Build Status - Cirrus][]][Build status] [![Twitter handle][]][Twitter badge]\n[![Discord Chat](https://img.shields.io/discord/684898665143206084?logo=discord\u0026style=social)](https://discord.gg/deno)\n\nThe module graph/dependency logic for the Deno CLI.\n\nThis repository is a Rust crate which provides the foundational code to be able\nto build a module graph, following the Deno CLI's module resolution logic. It\nalso provides a web assembly interface to the built code, making it possible to\nleverage the logic outside of the Deno CLI from JavaScript/TypeScript.\n\n## Rust usage\n\n### `ModuleGraph::new(...)`\n\n`ModuleGraph::new(GraphKind::All)` creates a new module graph. From there, you\ncan use the `.build(...).await` method to add roots. The `build` method requires\nthe root module specifiers/URLs for the graph and an implementation of the\n`source::Loader` trait. It also optionally takes implementation of the\n`source::Resolver` trait. It will load and parse the root module and recursively\nall of its dependencies, returning asynchronously a resulting `ModuleGraph`.\n\n### `source::Loader` trait\n\nImplementing this trait requires the `load()` method and optionally the\n`get_cache_into()` method. The `load()` method returns a future with the\nrequested module specifier and the resulting load response. This allows the\nmodule graph to deal with redirections, error conditions, and local and remote\ncontent.\n\nThe `get_cache_info()` is the API for exposing additional meta data about a\nmodule specifier as it resides in the cache so it can be part of a module graphs\ninformation. When the graph is built, the method will be called with each\nresolved module in the graph to see if the additional information is available.\n\n### `source::Resolver` trait\n\nThis trait \"replaces\" the default resolution logic of the module graph. It is\nintended to allow concepts like import maps and alternative resolution logic to\n\"plug\" into the module graph.\n\nIt has two methods, `resolve` and `resolve_types`, which both have default\nimplementations. `resolve` takes the string specifier from the source and the\nreferring specifier and is expected to return a result with the resolved\nspecifier.\n\n`resolve_types` takes a specifier and is expected to return a result with an\noptional module specifier and optional source range of the types that should be\nused. For example, if you are trying represent the `\"typings\"` field from a\n`package.json` file, when you receive the request on `resolve_types` for the\nmain module of the package, you would respond with the absolute specifier to the\ntypes along with a range that indicates the file URL to the `package.json` and\nthe range where it was specified. Including the range is useful to allow errors\nproduced from the graph to indicate \"where\" the dependency came from.\n\n### `source::MemoryLoader` struct\n\n`MemoryLoader` is a structure that implements the `source::Loader` trait and is\ndesigned so that a cache of modules can be stored in memory to be parsed and\nretrieved when building a module graph. This is useful for testing purposes or\nin situations where the module contents is already available and _dynamically_\nloading them is not practical or desirable.\n\nA minimal example would look like this:\n\n```rust\nuse deno_graph::ModuleSpecifier;\nuse deno_graph::ModuleGraph;\nuse deno_graph::GraphKind;\nuse deno_graph::source::MemoryLoader;\nuse deno_graph::source::Source;\nuse futures::executor::block_on;\n\nfn main() {\n  let mut loader = MemoryLoader::new(\n    vec![\n      (\n        \"file:///test.ts\",\n        Source::Module {\n          specifier: \"file:///test.ts\",\n          maybe_headers: None,\n          content: \"import * as a from \\\"./a.ts\\\";\"\n        }\n      ),\n      (\n        \"file:///a.ts\",\n        Source::Module {\n          specifier: \"file:///a.ts\",\n          maybe_headers: None,\n          content: \"export const a = \\\"a\\\";\",\n        }\n      ),\n    ],\n    Vec::new(),\n  );\n  let roots = vec![ModuleSpecifier::parse(\"file:///test.ts\").unwrap()];\n  let future = async move {\n    let mut graph = ModuleGraph::new(GraphKind::All);\n    graph.build(roots, \u0026loader, Default::default()).await;\n    println!(\"{:#?}\", graph);\n  };\n  block_on(future)\n}\n```\n\n## Usage from Deno CLI or Deploy\n\nSee [js/README.md](js/README.md).\n\n## Building Web Assembly\n\nThe build script (`_build.ts`) requires the Deno CLI to be installed and\navailable in the path. If it is, the following command should _just work_:\n\n```\n\u003e deno task build\n```\n\n## Versioning Strategy\n\nThis crate does not follow semver so make sure to pin it to a patch version.\nInstead a versioning strategy that optimizes for more efficient maintenance is\nused:\n\n- Does [deno_doc](https://github.com/denoland/deno_doc) and\n  [eszip](https://github.com/denoland/eszip) still compile in the\n  [Deno](https://github.com/denoland/deno) repo?\n  - If yes, is this a change that would break something at runtime?\n    - If yes, it's a minor release.\n    - If no, it's a patch release.\n  - If no, it's a minor release.\n\n### Contributing\n\nWe appreciate your help!\n\nTo contribute, please read our\n[contributing instructions](https://deno.land/manual/contributing).\n\nThis repository includes `.devcontainer` metadata which will allow a development\ncontainer to be built which has all the development pre-requisites available to\nmake contribution easier.\n\n[Build Status - Cirrus]: https://github.com/denoland/deno_graph/workflows/ci/badge.svg?branch=main\u0026event=push\n[Build status]: https://github.com/denoland/deno_graph/actions\n[Twitter badge]: https://twitter.com/intent/follow?screen_name=deno_land\n[Twitter handle]: https://img.shields.io/twitter/follow/deno_land.svg?style=social\u0026label=Follow\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenoland%2Fdeno_graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenoland%2Fdeno_graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenoland%2Fdeno_graph/lists"}