update package.json version automatically

后端 未结 12 2091
长发绾君心
长发绾君心 2020-12-02 04:37

Before I do a small release and tag it, I\'d like to update the package.json to reflect the new version of the program.

Is there a way to edit the file package

12条回答
  •  执念已碎
    2020-12-02 04:58

    To give a more up-to-date approach.

    package.json

      "scripts": {
        "eslint": "eslint index.js",
        "pretest": "npm install",
        "test": "npm run eslint",
        "preversion": "npm run test",
        "version": "",
        "postversion": "git push && git push --tags && npm publish"
      }
    

    Then you run it:

    npm version minor --force -m "Some message to commit"
    

    Which will:

    1. ... run tests ...

    2. change your package.json to a next minor version (e.g: 1.8.1 to 1.9.0)

    3. push your changes

    4. create a new git tag release and

    5. publish your npm package.

    --force is to show who is the boss! Jokes aside see https://github.com/npm/npm/issues/8620

提交回复
热议问题