简体   繁体   中英

Nodejs package.json defining scripts with the same name as a dependency

I've seen a lot of package.json files where there are scripts that doesn't do anything but call a dependency with the same name. For example :

{
    "scripts": {
        "lint": "npm run tslint \"src/**/*.ts\"",
        "tslint": "tslint"
    },
    "devDependencies": {
        "tslint": "~4.4.2",
        "tslint-loader": "^3.3.0"
    }
}

Here we have the script tslint that just calls the dependency tslint . I guess that is some kind of a way to make the lint script shorter but how would it look like if there was no script called tslint .

I don't believe NPM has this kind of functionality built in. Yarn (the third-party NPM client built by Facebook, Google, Exponent and Tilde) on the other hand, does - you can just use yarn run and it will pick up the executable from your dependencies, even if you don't have a script for it defined in your package.json :

yarn run tslint
yarn run tslint "src/**/*.ts"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM