{"id":27634900,"url":"https://github.com/aleclarson/ts-module-graph","last_synced_at":"2025-04-23T19:39:05.598Z","repository":{"id":276851125,"uuid":"930521623","full_name":"aleclarson/ts-module-graph","owner":"aleclarson","description":"Library for constructing a module graph from a set of TypeScript files","archived":false,"fork":false,"pushed_at":"2025-02-10T19:49:22.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-16T02:59:47.060Z","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/aleclarson.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":"2025-02-10T19:10:33.000Z","updated_at":"2025-02-14T23:00:09.000Z","dependencies_parsed_at":"2025-02-10T19:54:05.772Z","dependency_job_id":"39866b31-c853-4a67-a13a-0b45d01920f6","html_url":"https://github.com/aleclarson/ts-module-graph","commit_stats":null,"previous_names":["aleclarson/ts-module-graph"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fts-module-graph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fts-module-graph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fts-module-graph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aleclarson%2Fts-module-graph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aleclarson","download_url":"https://codeload.github.com/aleclarson/ts-module-graph/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250500903,"owners_count":21440909,"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":[],"created_at":"2025-04-23T19:39:05.028Z","updated_at":"2025-04-23T19:39:05.585Z","avatar_url":"https://github.com/aleclarson.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-module-graph\n\nA modest package for constructing a module graph from TypeScript source files.\n\n## Install\n\n```\npnpm add ts-module-graph\n```\n\n## Usage\n\n```ts\nimport { createModuleGraph } from 'ts-module-graph'\nimport path from 'node:path'\n\n// The entry points must be absolute paths.\nconst moduleGraph = await createModuleGraph([path.resolve('src/index.ts')])\n\n// The module graph is a Map of ts.SourceFile objects to ModuleGraphNode objects.\nconsole.log(moduleGraph)\n```\n\n### ModuleGraphNode\n\nEach source file has a `ModuleGraphNode` object associated with it. Each node has the following properties:\n\n- `imports`: An array of import objects, each containing information about an import statement.\n  - `id`: The module specifier text (e.g. 'lodash', './my-module')\n  - `importSpecifiers`: An array of `ImportSpecifier` objects, representing the individual elements being imported.\n  - `resolvedImports`: An array of `ResolvedImport` objects, providing semantic information about the resolved imports.\n  - `resolvedModule`: A `ts.ResolvedModuleFull` object, containing information about the resolved module, if available.\n- `dependencies`: A Set of `ts.SourceFile` objects, representing the direct dependencies of this module.\n\n### ResolvedImport\n\nEach import resolution has the following properties:\n\n- `kind`: The kind of import specifier (e.g. 'name', 'namespace', 'default').\n- `name`: The `ts.Identifier` representing the imported name.\n- `exportName`: The `ts.ModuleExportName` representing the original exported name, if different from the imported name.\n- `symbol`: The `ts.Symbol` associated with the imported entity.\n- `aliasedSymbol`: The original `ts.Symbol` if the imported symbol is an alias.\n- `declarations`: An array of `ts.Declaration` objects where the imported symbol is declared.\n\n### ImportSpecifier\n\nEach import specifier has the following properties:\n\n- `kind`: The kind of import specifier. Can be:\n  - `'name'`: A named import (e.g. `{ foo }`)\n    - `name`: The `ts.ModuleExportName` representing the imported name.\n    - `alias`: An optional `ts.Identifier` representing the alias used for the import (e.g. `{ foo as bar }`).\n  - `'namespace'`: A namespace import (e.g. `* as foo`)\n    - `name`: The `ts.Identifier` representing the namespace.\n  - `'default'`: A default import (e.g. `foo`)\n    - `name`: The `ts.Identifier` representing the default import.\n\n## Roadmap\n\nContribution is welcome to implement these features:\n\n- [ ] Namespace imports should have their usage tracked to determine which symbols are actually used.\n- [ ] Add a tree-shaking API that whittles down the module graph to only the necessary modules. It doesn't need to be fine-grained; i.e. just filter out modules not used by the entry points (directly or indirectly).\n\n## Command-line API\n\n```\nts-module-graph \u003c...entries\u003e\n```\n\nThe entry points are resolved relative to the current working directory. Globs are supported.\n\nThis command will print the flattened module graph to the console, using colorization to help with readability.\n\n## Thanks\n\nThis project wouldn't be possible without these amazing dependencies:\n\n- [tsc-extra](https://github.com/alien-rpc/alien-rpc/tree/master/packages/tsc-extra) - For providing a clean API to work with TypeScript's compiler API\n- [ts-expose-internals](https://github.com/nonara/ts-expose-internals) - For exposing TypeScript's internal types\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Fts-module-graph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faleclarson%2Fts-module-graph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faleclarson%2Fts-module-graph/lists"}