Tomasz Golinski
Tomasz Golinski

Reputation: 728

npm command doesn't update json

This command works fine:

json -I -f ./src/environments/build.json -e 'this.patch++'

I'm trying to create a custom build NPM command in my package.json file that runs this command before the actual build, but first I just tried to run the json command, just to see if it's working, but it doesn't :/

package.json

{
  ...
  "scripts": {
    ...
    "svrge-build-dev": "json -I -f ./src/environments/build.json -e 'this.patch++'",
    ...
  }

then I get this output (which is exactly the same as when I run the JSON code by itself) which means that the command is definitely running

> [email protected] svrge-build-dev D:\repos\test\web-client
> json -I -f ./src/environments/build.json -e 'this.patch++

json: updated "./src/environments/build.json" in-place //<- this is exactly the same'

However, the build.json file is not being updated

No errors in the terminal

any idea how I can get it to work? I can't seem to find anything regarding that.

I would appreciate any help, been scratching my head for hours

Tom

Upvotes: 2

Views: 60

Answers (1)

axm__
axm__

Reputation: 2673

Re-stating what I said in the comment: try to replace the single quotes with double quotes:

{
    // ...
    "scripts": {
        // ...
        "svrge-build-dev": "json -I -f ./src/environments/build.json -e \"this.patch++\"",
        // ...
}

What triggered that thought was this line in the output:

> json -I -f ./src/environments/build.json -e 'this.patch++

After doing some digging, I think it depends on the OS and/or command line interpreter. It shows the command that was run, but not with the finishing single quote.

After some searching, it appears that is indeed a bug: see this issue and this issue. You might want to give the maintainers a heads up about it: the last issue I've linked to, makes it seem like it's a Windows issue.

Upvotes: 2

Related Questions