@custom-elements-manifest/find-dependencies

中文文档
0.0.7发布于 2025/11/04ISCES Module近 30 天下载 92.2万

Given an array of paths, scans all modules and returns all depending paths.

原始使用文档
文档目录8 节
  1. Usage
  2. Configuration
  3. Utils
  4. splitPath
  5. extractPackageNameFromSpecifier
  6. isBareModuleSpecifier
  7. isScopedPackage
  8. getUniquePackages

find-dependencies

Given an array of paths, scans all modules and returns all depending paths.

Intended to be used on post-build, frontend facing, ESM based code.

Usage

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

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

Where my-package/index.js contains:

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');

Will output:

[
  '/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'
]

Configuration

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
}
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']
  },
});

Utils

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

splitPath

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

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

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

isScopedPackage

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

getUniquePackages

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 共发布 7 个版本,首次发布于 2021/10/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.7latest2025/11/041 年前
0.0.62025/09/171.1 年前
0.0.52022/05/254 年前
0.0.42021/10/215 年前
0.0.32021/10/215 年前
0.0.22021/10/205 年前

关于 @custom-elements-manifest/find-dependencies 的常见问题

@custom-elements-manifest/find-dependencies 是什么?

Given an array of paths, scans all modules and returns all depending paths.

如何安装 @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 和提交记录判断。