What is colon : in npm script names?

后端 未结 3 1551
滥情空心
滥情空心 2020-12-15 17:26

Trying to figure out what putting : in an npm script name does. For example:

package.json

\"test:ci\": \"rest of script\"


        
相关标签:
3条回答
  • 2020-12-15 17:51

    I solved this by running - "npm run <scriptName>"

    Within my package.json file, I had two "start scripts"

    start: nodemon server.js

    start:elasticsearch: docker run elasticsearch..

    Solved with npm run start:elasticsearch

    0 讨论(0)
  • 2020-12-15 17:58

    I believe it's just a naming convention to group a set of related tasks. For example you might have

    "test:ci": ...
    "test:units": ....
    "test:integration"...
    

    In this case it is grouping a related set of test tasks.

    It would be down to the package author to specify. You can split tasks out like described in the answer above and then have a 'global' test command which combines each of them e.g. test:ci && test:unit && test:integration enabling you to run them all at once or when individually when needed.

    You can use npm-run-all (link) and use the command npm-run-all test:*, which would then find all scripts starting with the test: group.

    0 讨论(0)
  • 2020-12-15 18:02

    If using Yarn package manager, you can use a colon in the name to call the script from any workspace.

    According to the yarn docs on How to share scripts between workspaces?:

    Little-known Yarn feature: any script with a colon in its name (build:foo) can be called from any workspace.

    Also, according to yarn docs on CLI > run:

    Otherwise, if the specified name contains a colon character and if one of the workspaces in the project contains exactly one script with a matching name, then this script will get executed.

    0 讨论(0)
提交回复
热议问题