I need to write universal scripts for npm and yarn.
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "npm run build:clean; npm run test:clean"
}
}
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "yarn run build:clean; yarn run test:clean"
}
}
I usually use little hack: $_
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "$_ run build:clean; $_ run test:clean"
}
}
But sometime it does not work correctly.
Exists some legit way to do this?
I found solution I was looking for.
I think I found the optimal solution.
I searched in npm env and compared it with yarn env . I found the variable $npm_execpath that contains the path to used package manager. (For Windows %npm_execpath% )
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "$npm_execpath run build:clean; $npm_execpath run test:clean"
}
}
If add package cross-var , scripts works on Linux, Windows and Mac.
{
"scripts": {
"build:clean": "rim-raf dist",
"test:clean": "rim-raf coverage",
"clean": "cross-var $npm_execpath run build:clean; cross-var $npm_execpath run test:clean"
}
}
You could try this 3rd party module:
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.