3 ms·
"yarn/npm install" has an artifact in the project directory, so here's one point for "make" instead of "just": start: node_modules yarn run start te
by Izkata 2y ago
"yarn/npm install" has an artifact in the project directory, so here's one point for "make" instead of "just":
start: node_modules
yarn run start
test: node_modules
yarn run test
node_modules: package.json yarn.lock
yarn install
touch $@
You can clone the repo and "make test", and it'll include "yarn install" automatically - then on subsequent "make test", it'll skip it because "node_modules" is already up-to-date. And then include it again later if someone updated the packages. The "touch" is so the last-modified timestamp on "node_modules" is updated even if "yarn install" doesn't add/remove anything, so make knows it succeeded.
"yarn install" is usually pretty fast when it has nothing to do, so I can see why people may not bother and just have it run every time, but patterns like this can be used for quite a bit. This way heavier commands don't need to be run repeatedly and devs don't need to know all the individual commands to run in sequence.
- soulofmischief 2y agoThe touch trick is nice. There's definitely merit to such an approach, since it provides a simple cross-platform way to check if node_modules exists. Though things begin to get more complicated if say, the project use plug-n-play resolution. `yarn` handles both cases. Another benefit of `"test": "yarn && <test command>"` is that you also make sure the project is in a buildable state when testing.