npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kokojs/plugin-npm-duplicate

v4.0.27

Published

`@kokojs/plugin-npm-duplicate` 用于检测 npm 依赖包是否重复安装了多个版本。

Downloads

2,440

Readme

Npm Duplicate 插件

@kokojs/plugin-npm-duplicate 用于检测 npm 依赖包是否重复安装了多个版本。

如果白名单内的依赖被安装了多个版本,Npm Duplicate 插件会直接阻止代码编译,直到版本冲突被解决。

使用场景

这个插件的主要用处是避免某些包被重复安装,尤其是单实例的包、体积较大的包。

如果需要全量分析项目中的重复依赖,可以使用 Analyze 插件

安装

yarn add @kokojs/plugin-npm-duplicate --dev

安装完成后,在 koko.config.js 中添加如下配置:

module.exports = {
  plugins: {
    'npm-duplicate': {
      packages: ['@youzan/znb'],
    },
  },
};

配置项

packages

  • Type: string[]
  • Default: []

需要被检测的包列表,如 ['lodash', 'date-fns']

yarnLockPath

  • Type: string
  • Default: 'yarn.lock'

需要检测的 yarnLock 文件所在路径。

常见问题

如何优化重复依赖?

重复依赖有两种情况:

1. semver 可以匹配,但 yarn.lock 中存在多个版本

这种情况一般是在依赖升级过程中 yarn.lock 文件没有正确更新引起的。

直接使用 yarn-deduplicate 这个工具进行合并即可,它会自动将可匹配的版本进行合并。

# 消除所有依赖
npx yarn-deduplicate

# 消除特定重复依赖
npx yarn-deduplicate --packages @youzan/znb,@youzan/utils

2. semver 无法匹配

对于 semver 无法匹配的情况,需要手动修改版本号范围,使之能够匹配。

如果暂时无法修改版本号范围,也可以通过 yarn 提供的 resolutions 字段来指定一个版本号。

// package.json
{
  "resolutions": {
    "@youzan/utils": "^3.0.0"
  }
}

维护者

新春。