Kousha
Kousha

Reputation: 36299

npm run "script" doesn't do anything

This is really weird, I have the following scripts in my package.json:

"scripts": {
   "lint": "./node_modules/tslint/bin/tslint src/js/**/*",
   "lint:fix": "./node_modules/tslint/bin/tslint src/js/**/* --fix"
},

When I run npm run lint I don't get any errors and running echo $? immediately after shows 0.

However, if I run tslint src/js/**/* I do get linting errors.

How come?

Upvotes: 2

Views: 289

Answers (3)

zetavolt
zetavolt

Reputation: 3227

There are a host of well-known issues in npm arising from the use of globbing. Many of them exclusively impact Windows, while others are "merely" shell-specific.

Try the following.

"scripts": {
   "lint": "./node_modules/tslint/bin/tslint \"src/**/*.ts\"",
},

If this didn't immediately persuade you that computers have been a disaster for the human race, you can learn more about why these issues occur in the fantastic The Linux Programming Interface, which covers a surprising number non-Linux portability issues such as this one.

Upvotes: 1

Bulkan
Bulkan

Reputation: 2592

With npm-run-scripts you can omit the ./node_modules/.bin as npm will first look in there.

Upvotes: 0

ArcQ
ArcQ

Reputation: 31

using npm run lint defaults to the tslint in the node_modules of your local project directory, while using tslint src/js/**/* defaults to the the one in your global, you should check if there is a version mismatch which could cause differences in rules

Upvotes: 0

Related Questions