Saturday 16 December 2017

Best Practice for Recursively Invoking the Package Manager While Running Scripts?

Inside my package.json I'm trying to call the lint script I have inside my test script before I run Jasmine. I personally use Yarn but in the unlikely event of someone else doing dev work on this package I didn't want to hardcode yarn run lint && jasmine in case that's not installed on their system. Since I was curious I figured I'd make a script that when invoked simply echoed out the contents of process.env to see if I could use anything from there. I ended up with two candidates for usage npm_execpath: '/usr/local/lib/node_modules/yarn/bin/yarn.js' and _: '/usr/local/bin/yarn'. I'm leaning toward using the later to invoke my script (e.g. $_ run lint && jasmine). But I was curious if that env var is not guaranteed to always be the package manager binary, there could be cross-platform compatibility issues, or if there was simply a better way of accomplishing this task.

Submitted December 17, 2017 at 01:24AM by jbenner

No comments:

Post a Comment