{"id":26257087,"url":"https://github.com/sunny-117/esfinder","last_synced_at":"2025-07-05T04:33:58.902Z","repository":{"id":278672594,"uuid":"932695562","full_name":"Sunny-117/esfinder","owner":"Sunny-117","description":"esfinder 是一个基于Babel 和 SWC 的用于分析和解析 JavaScript 和 TypeScript 项目中文件的导入及其相关依赖的工具。它能够高效地追踪与导入路径相关的文件，支持静态和动态导入。","archived":false,"fork":false,"pushed_at":"2025-02-24T07:11:29.000Z","size":245,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-28T22:43:10.598Z","etag":null,"topics":["babel","export","exporter","finder","import","importer","swc"],"latest_commit_sha":null,"homepage":"","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/Sunny-117.png","metadata":{"files":{"readme":"README-zh.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2025-02-14T10:54:08.000Z","updated_at":"2025-03-16T12:53:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"e0cd5814-4246-41b4-b351-99e87e1c30dd","html_url":"https://github.com/Sunny-117/esfinder","commit_stats":null,"previous_names":["sunny-117/esfinder"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Sunny-117/esfinder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sunny-117%2Fesfinder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sunny-117%2Fesfinder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sunny-117%2Fesfinder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sunny-117%2Fesfinder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sunny-117","download_url":"https://codeload.github.com/Sunny-117/esfinder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sunny-117%2Fesfinder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263305224,"owners_count":23445855,"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":["babel","export","exporter","finder","import","importer","swc"],"created_at":"2025-03-13T20:28:15.380Z","updated_at":"2025-07-05T04:33:58.897Z","avatar_url":"https://github.com/Sunny-117.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# esfinder\n\n[![npm version][npm-version-src]][npm-version-href]\n[![npm downloads][npm-downloads-src]][npm-downloads-href]\n[![bundle][bundle-src]][bundle-href]\n[![JSDocs][jsdocs-src]][jsdocs-href]\n[![License][license-src]][license-href]\n\n简体中文 | \u003ca href=\"./README.md\"\u003eEnglish\u003c/a\u003e\n\n`esfinder` 是一个基于Babel 和 SWC 的用于分析和解析 JavaScript 和 TypeScript 项目中文件的导入及其相关依赖的工具。它能够高效地追踪与导入路径相关的文件，支持静态和动态导入。\n\n## 安装\n\n```bash\nnpm install esfinder\n```\n\n## API 文档\n\n### `parseExports(filePath: string): Promise\u003cSet\u003cstring\u003e\u003e`\n\n#### 参数:\n- **`filePath`** (string): 要解析的文件的绝对或相对路径。\n\n#### 返回:\n- **`Promise\u003cSet\u003cstring\u003e\u003e`**: 返回一个 `Promise`，解析为该文件中的所有导出名称的 `Set`。\n\n#### 描述:\n此函数解析文件的导出，返回一个包含所有具名和默认导出的 `Set`。它会缓存结果，以便在多次调用相同文件时提高性能。\n\n### `getRelatedFiles(files: string[], importsDir: string, extensions: string[] = DEFAULT_EXTENSIONS): Promise\u003cstring[]\u003e`\n\n#### 参数:\n- **`files`** (string[]): 需要检查与之相关的文件的路径列表。\n- **`importsDir`** (string): 包含待检查导入文件的目录。\n- **`extensions`** (string[]): 可选的文件扩展名数组。默认为 `['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs']`。\n\n#### 返回:\n- **`Promise\u003cstring[]\u003e`**: 返回一个 `Promise`，解析为与给定文件相关的文件路径数组。\n\n#### 描述:\n此函数检查 `importsDir` 中的所有文件的 `import` 语句，并将其与给定的文件进行比较。它利用缓存的导出数据，并尝试根据提供的扩展名解析路径。\n\n## 使用示例\n\n```ts\nimport path from 'node:path'\nimport { getRelatedFiles, parseExports } from 'esfinder' // by babel\nimport { getRelatedFiles, parseExports } from 'esfinder/swc' // by swc\n\nconst files = ['./src/a.js', './src/c.js']\nconst importsDir = './src/__tests__'\n\n// 预缓存目标文件的导出内容\nPromise.all(files.map(f =\u003e parseExports(path.resolve(f))))\n  .then(() =\u003e getRelatedFiles(files, importsDir))\n  .then(console.log)\n  .catch(console.error)\n```\n\n在这个示例中：\n1. 预缓存了 `a.js` 和 `c.js` 的导出内容。\n2. `getRelatedFiles` 函数根据导入关系找到 `__tests__` 中与给定文件相关的所有文件。\n\n## 许可证\n\n此项目根据 MIT 许可证开源 - 请参阅 [LICENSE](LICENSE) 文件了解详情。\n\n## 贡献\n\n我们欢迎对 `esfinder` 的贡献。请克隆此仓库，创建一个新的分支，然后提交一个拉取请求。\n\n### 准则：\n- 请遵守 [Code of Conduct](CODE_OF_CONDUCT.md)。\n- 确保为任何新功能或修复的 bug 添加测试。\n- 根据需要更新文档。\n\n\u003c!-- Badges --\u003e\n\n[npm-version-src]: https://img.shields.io/npm/v/esfinder?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-version-href]: https://npmjs.com/package/esfinder\n[npm-downloads-src]: https://img.shields.io/npm/dm/esfinder?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[npm-downloads-href]: https://npmjs.com/package/esfinder\n[bundle-src]: https://img.shields.io/bundlephobia/minzip/esfinder?style=flat\u0026colorA=080f12\u0026colorB=1fa669\u0026label=minzip\n[bundle-href]: https://bundlephobia.com/result?p=esfinder\n[license-src]: https://img.shields.io/github/license/Sunny-117/esfinder.svg?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[license-href]: https://github.com/Sunny-117/esfinder/blob/main/LICENSE\n[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat\u0026colorA=080f12\u0026colorB=1fa669\n[jsdocs-href]: https://www.jsdocs.io/package/esfinder\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunny-117%2Fesfinder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsunny-117%2Fesfinder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsunny-117%2Fesfinder/lists"}