# @custom-elements-manifest/find-dependencies 中文文档

规范地址：https://npmcn.com/package/%40custom-elements-manifest/find-dependencies/

版本：0\.0\.7
npm 元数据更新时间：2025-11-04T10:35:34.894Z
中文译文更新时间：2026-11-11T05:14:18.445Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40custom-elements-manifest/find-dependencies
原文对照：https://npmcn.com/package/%40custom-elements-manifest/find-dependencies/?lang=original
项目主页：https://github.com/open-wc/custom-elements-manifest#readme
源码仓库：https://github.com/open-wc/custom-elements-manifest

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：12.6 kB，5 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- 运行依赖：2 个
- 首次发布：2021-10-18T09:34:10.728Z
- 最新版本发布：2025-11-04T10:35:34.699Z
- 近 30 天下载量：921566（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

考虑到一系列路径,扫描所有模块并返回所有不同的路径.

## 安装

```sh
npm install @custom-elements-manifest/find-dependencies
```

也可以使用：`pnpm add @custom-elements-manifest/find-dependencies`、`yarn add @custom-elements-manifest/find-dependencies`、`bun add @custom-elements-manifest/find-dependencies`

## README

# 查找相互依存关系

考虑到一系列路径,扫描所有模块并返回所有不同的路径.

打算用于建设后、前端面和基于无害环境管理的代码.

## 使用量

```js
import { findDependencies } from '@custom-elements-manifest/find-dependencies';

const inputPaths = ['my-package/index.js'];
const dependencies = await findDependencies(inputPaths);
```

何处 `my-package/index.js` 包含:

```js
import '@scoped/package';
import {b} from '@scoped/package/baz/index.js';
import c from 'export-map';
import d from 'nested';
import e from 'regular';
import g from './bla.js';
import('dynamic-import');
```

将输出 :

```js
[
  '/Users/blank/my-package/node_modules/@scoped/package/index.js',
  '/Users/blank/my-package/node_modules/@scoped/package/baz/index.js',
  '/Users/blank/my-package/node_modules/export-map/long/path/index.js',
  '/Users/blank/my-package/node_modules/nested/index.js',
  '/Users/blank/my-package/node_modules/regular/index.js',
  '/Users/blank/my-package/node_modules/dynamic-import/index.js',
  '/Users/blank/my-package/node_modules/nested/node_modules/regular/index.js'
]
```

## 配置

```ts
interface Options {
  /**
   * Module Resolution Options
   *
   * See [oxc-resolver](https://github.com/oxc-project/oxc-resolver) for more informations
   */
  resolutionOptions?: NapiResolveOptions,
  /** Defaults to `process.cwd()` */
  basePath?: string
}
```

```js
findDependencies(inputPaths, {
  basePath: 'foo/bar',
  resolutionOptions: {
    extensions: ['.js', '.ts', '.jsx', '.tsx', '.json', '.d.ts', ''],
    extensionAlias: {
      '.js': ['.ts', '.js'],
      '.jsx': ['.tsx', '.jsx']
    },
    mainFiles: ['index'],
    mainFields: ['module', 'browser', 'main'],
    conditionNames: ['import', 'require', 'node'],
    exportsFields: ['exports'],
    alias: {},
    symlinks: true,
    modules: ['node_modules']
  },
});
```

## 用户

```js
import { 
  splitPath, 
  getUniquePackages, 
  extractPackageNameFromSpecifier, 
  isBareModuleSpecifier, 
  isScopedPackage 
} from '@custom-elements-manifest/find-dependencies';
```

### `splitPath`

```js
splitPath('/blank/node_modules/foo/index.js');
// {packageRoot: '/blank/node_modules/foo', packageName: 'foo', specifier: 'foo/index.js', type: 'js' }

splitPath('/blank/node_modules/foo/data.json');
// {packageRoot: '/blank/node_modules/foo', packageName: 'foo', specifier: 'foo/data.json', type: 'json' }
```

### `extractPackageNameFromSpecifier`

```js
extractPackageNameFromSpecifier('foo/index.js') // foo
extractPackageNameFromSpecifier('foo/bar/baz/index.js') // foo
extractPackageNameFromSpecifier('@foo/bar/index.js') // @foo/bar
extractPackageNameFromSpecifier('@foo/bar/baz/asdgf/index.js') // @foo/bar
```

### `isBareModuleSpecifier`

```js
isBareModuleSpecifier('foo') // true
isBareModuleSpecifier('foo/bar.js') // true
isBareModuleSpecifier('./foo.js') // false
isBareModuleSpecifier('../foo.js') // false
```

### `isScopedPackage`

```js
isScopedPackage('foo') // false
isScopedPackage('@foo/bar') // true
```

### `getUniquePackages`

```js
getUniquePackages([
  'blank/node_modules/foo/index.js', 
  'blank/node_modules/bar/index.js',
  'blank/node_modules/bar/index2.js',
  'blank/node_modules/bar/index3.js'
])
// ['foo', 'bar',]

/** Or */
const dependencies = await findDependencies(inputPaths);
const unique = getUniquePackages(dependencies);
```

## 常见问题

### @custom-elements-manifest/find-dependencies 是什么？

考虑到一系列路径,扫描所有模块并返回所有不同的路径\.

### 如何安装 @custom-elements-manifest/find-dependencies？

在项目目录运行 npm install @custom-elements-manifest/find-dependencies，或使用 pnpm add / yarn add / bun add。

### @custom-elements-manifest/find-dependencies 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/custom-elements-manifest\_\_find-dependencies 是否存在。

### @custom-elements-manifest/find-dependencies 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @custom-elements-manifest/find-dependencies 可以商用吗？

@custom-elements-manifest/find-dependencies 使用 ISC 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @custom-elements-manifest/find-dependencies 的下载量有多少？

根据 npm 官方下载统计，@custom-elements-manifest/find-dependencies 在 2026/10/11 – 2026/11/09 这 30 天内被下载 921,566 次，日均约 30,719 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @custom-elements-manifest/find-dependencies 还在维护吗？

最新版本 0\.0\.7 发布于 2025/11/04（1 年前）；至今共发布 7 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/10/18。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

