Npm

GitbookKb2021-02-28


📑 🍷🐝 我的 npm package 信息

📑 🍷🐝 如何更新发布到 npm 的 package?

以@williamjiang scope 下面的 util 为例,当对 util 做了改动就需要更新到 npm。

  1. 进入到 util 目录, 对 index.js 做一些修改(做为要更新的内容)
  2. 然后再命令行执行npm version patch, 此命令会把package.json的 version 更新到 0.02
  3. 然后执行npm publish就可以更新到npm

Learning npm the Node Package Manager


🍷 package.json, package-lock.json


  • license: “ISC”
  • semantic (语义的) versioning: major, minor, patch: 4.16.3

    Caret^: All minor and patches OK: ^4 = 4.x.x

    Tilde~: All patches only: ~4.16.x

    "dependencies": {
    "my_dep": "^1.0.0",
    "another_dep": "~2.2.0"
    },
  • package-lock.json: control versioning, always include it to repo.
  • versioning check:

    $ npm outdated
    $ npm outdated -g
    
    $ npm install -g npm-check-updates
    $ ncu -u
    $ npm install

Notice: npm update not work well.

  • cache:

    $ npm cache verify
    $ npm cache clean --force
  • audit:

    $ npm audit
    $ npx audit fix

🍷 npmjs.com


$ npm publish
$ npm whoami
$ npm login