{"id":19176981,"url":"https://github.com/joomcode/get-modules-graph","last_synced_at":"2026-02-17T18:31:50.559Z","repository":{"id":192738965,"uuid":"687367880","full_name":"joomcode/get-modules-graph","owner":"joomcode","description":"Get and traverse graph of ECMAScript/TypeScript modules","archived":false,"fork":false,"pushed_at":"2025-03-02T11:00:25.000Z","size":168,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-28T23:30:13.448Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/joomcode.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}},"created_at":"2023-09-05T08:05:41.000Z","updated_at":"2025-04-25T19:51:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"cc479a86-546a-459d-9e98-5e9f0c08c55f","html_url":"https://github.com/joomcode/get-modules-graph","commit_stats":null,"previous_names":["joomcode/get-modules-graph"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/joomcode/get-modules-graph","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fget-modules-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fget-modules-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fget-modules-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fget-modules-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joomcode","download_url":"https://codeload.github.com/joomcode/get-modules-graph/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomcode%2Fget-modules-graph/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29552795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T18:16:07.221Z","status":"ssl_error","status_checked_at":"2026-02-17T18:16:04.782Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-09T10:31:27.890Z","updated_at":"2026-02-17T18:31:45.551Z","avatar_url":"https://github.com/joomcode.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# get-modules-graph\n\n[![NPM version][npm-image]][npm-url]\n[![minzipped size][size-image]][size-url]\n[![code style: prettier][prettier-image]][prettier-url]\n[![Conventional Commits][conventional-commits-image]][conventional-commits-url]\n[![License MIT][license-image]][license-url]\n\nGet and traverse graph of ECMAScript/TypeScript modules.\n\n## Basic example\n\n```ts\nimport {dirname, join, sep} from 'node:path';\n\nimport {getModulesGraph} from 'get-modules-graph';\n\nconst modulesGraph = await getModulesGraph\u003cnumber\u003e({\n  /**\n   * Chooses an index module in a directory by the resolved path and directory path.\n   * Throws an error if a directory and not a file is selected.\n   */\n  chooseIndexModule: (resolvedPath, directoryPath, directoryContent) =\u003e {\n    if ('index.ts' in directoryContent) {\n      return 'index.ts';\n    }\n\n    throw new Error(\n      `Cannot choose index module in directory \\`${directoryPath}\\` for \\`${resolvedPath}\\``,\n    );\n  },\n  /**\n   * Chooses a module (or directory) in a directory by the resolved path\n   * to a module in that directory.\n   * If a directory is chosen, the choosing process will continue in a `chooseIndexModule` call\n   * already for the contents of that chosen directory.\n   */\n  chooseModule: (resolvedPath, parsedPath, directoryContent) =\u003e {\n    const fileName = `${parsedPath.base}.ts`;\n\n    if (fileName in directoryContent) {\n      return fileName;\n    }\n\n    throw new Error(`Cannot choose module for \\`${resolvedPath}\\``);\n  },\n  /**\n   * List of relative paths to directories for recursive traversal in depth\n   * and by their dependencies.\n   */\n  directories: [],\n  /**\n   * If `true`, then `import(...)` expression with static strings will be taken into account\n   * (as importing the namespace of the entire module).\n   */\n  includeDynamicImports: true,\n  /**\n   * If `true`, then `require(...)` expression with static strings will be taken into account\n   * (as importing the namespace of the entire module).\n   */\n  includeRequires: true,\n  /**\n   * List of relative paths to modules for recursive traversal by their dependencies.\n   */\n  modules: ['./index.ts'],\n  /**\n   * The callback on completing (adding) dependencies to a module.\n   * Called when all module dependencies have been recursively completed.\n   * Always called before the `onAddModule` callback.\n   * Should return the data obtained from the dependencies of the module,\n   * which will be stored in the `dependenciesData` module field.\n   */\n  onAddDependencies: () =\u003e {},\n  /**\n   * The callback on adding a module. Called as soon as the module has been parsed\n   * and added to the module graph (without its own dependencies).\n   * Should return the data obtained from the source code of the module,\n   * which will be stored in the `sourceData` module field.\n   */\n  onAddModule: (_module, source) =\u003e source.length,\n  /**\n   * Resolves raw path to dependency module (after the `from` keyword) to relative path\n   * from current working directory or to bare path to the package.\n   * The returned relative path to the module must begin with a dot,\n   * otherwise it will be considered the path to the package.\n   * The returned path must use `path.sep` as path segment separator.\n   * If returns `undefined`, dependency module is skipped.\n   */\n  resolvePath: (modulePath, rawPath) =\u003e {\n    if (rawPath[0] === '.') {\n      return `.${sep}${join(dirname(modulePath), rawPath)}`;\n    }\n\n    return rawPath;\n  },\n  /**\n   * If `true`, then we respect string literals when parsing, that is,\n   * we ignore the expressions inside them (but parsing will be a little slower).\n   */\n  respectStringLiterals: true,\n  /**\n   * If returns `true`, directory is skipped in recursive directories traversal.\n   */\n  skipDirectory: () =\u003e false,\n  /**\n   * If returns `true`, module is skipped in recursive directories traversal.\n   */\n  skipModule: () =\u003e false,\n  /**\n   * Transforms source of module.\n   */\n  transformSource: (_path, source) =\u003e source,\n});\n\nconsole.log(modulesGraph.circularDependencies);\nconsole.log(modulesGraph.errors);\nconsole.log(modulesGraph.modules);\nconsole.log(modulesGraph.packages);\n```\n\n## Install\n\nRequires [node](https://nodejs.org/en/) version 20 or higher:\n\n```sh\nnpm install get-modules-graph\n```\n\n## License\n\n[MIT][license-url]\n\n[conventional-commits-image]: https://img.shields.io/badge/Conventional_Commits-1.0.0-yellow.svg 'The Conventional Commits specification'\n[conventional-commits-url]: https://www.conventionalcommits.org/en/v1.0.0/\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg 'The MIT License'\n[license-url]: LICENSE\n[npm-image]: https://img.shields.io/npm/v/get-modules-graph.svg 'get-modules-graph'\n[npm-url]: https://www.npmjs.com/package/get-modules-graph\n[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg 'Prettier code formatter'\n[prettier-url]: https://prettier.io/\n[size-image]: https://img.shields.io/bundlephobia/minzip/get-modules-graph 'get-modules-graph'\n[size-url]: https://bundlephobia.com/package/get-modules-graph\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomcode%2Fget-modules-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoomcode%2Fget-modules-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomcode%2Fget-modules-graph/lists"}