Search code examples
javascriptnpmversionprettier

How to stop npm version patch from formatting my typescript code


Not sure why in my setup, every time I do

npm version patch

It will auto reformat all my typescript source code. This is very annoying as the style is totally not what I preferred. I have to manually revert the format. How can I avoid it from reformatting?

Here is the console output for the command, I can see the annoying "prettier" is triggered.

npm version patch

> [email protected] preversion /Users/jianwche/opensource/treedoc_ts
> npm run lint


> [email protected] lint /Users/jianwche/opensource/treedoc_ts
> tslint -p tsconfig.json

v0.2.1

> [email protected] version /Users/jianwche/opensource/treedoc_ts
> npm run format && git add -A src


> [email protected] format /Users/jianwche/opensource/treedoc_ts
> prettier --write "src/**/*.ts" "src/**/*.js"

Here are my package scripts:

{
  scripts: {
    "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
    "version": "npm run format && git add -A src",
  }
}

Solution

  • Seems it's my fault, the template I used to create the project seems automatically add the "format" command in the "version" script in the package.json. I solved this issue by removing it.

    Updated package.json:

    {
      scripts: {
        "version": "npm run format && git add -A src",
      }
    }