Last active
September 26, 2024 04:50
-
-
Save coryhouse/b26f49bead69066844d9 to your computer and use it in GitHub Desktop.
Example of calling one script from another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "npm-scripts-example", | |
"version": "1.0.0", | |
"description": "npm scripts example", | |
"scripts": { | |
"clean": "rimraf ./dist && mkdir dist", | |
"prebuild": "npm run clean", | |
"build": "cross-env NODE_ENV=production webpack" | |
} | |
} |
I should note if you are using corepack, you should use corepack enable
, not npm -g install ...
. See the docs
If you are happy to force everyone to use a specific setup
Joke aside: it's not bad practice to write your package.json
(or any source for that matter) as it'll be used by your CI and stop there.
Anyone wants anything fancier/newer/better/more-comfy they may do it on their machine but it's up to them.
Joke back on: not my fault if (close to) all CIs are on unix ¯\_(ツ)_/¯
&&
assumes a POSIX sh environment. This likely breaks on various and sundry Windows environments, it may break the default (Free)BSD csh. It may break fish, Plan 9's rc, ion, and more.
A Gruntfile or makefile are more portable than NPM's awful built-in task runner.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are happy to force everyone to use a specific setup, its probably easier to force everyone to use a specific package manager: npm (it is already installed), or your package manager of choice (it is only a
npm -g i
away).I think the best option is: if you are the primary developer/maintainer, just hard-code your package manager of choice rather than using
$npm_execpath
. And set thepackageManager
field inpackage.json
to support usage with corepack, which is now included in Node.If your team/organization really can't decide on a package manager, I think its worth using
yarpm
/ni
/dum
/npm-run-all
rather than forcing everyone to use a Posix shell. Most npm packages are targeting NodeJS or the browser, which are cross-platform environments, so it does not make much sense to rely on OS-specific features.