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"
}
}
{
"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 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"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With