xojs/create-xo

question: how about using npm lifecycle scripts?

joakimbeng opened this issue · 15 comments

I myself prefer having the ability to run the linting on a project as a separate task without running the tests, e.g. npm run lint. And then automatically running the linting before the tests using the pretest lifecycle script in package.json.

So what do you think about adding xo to its own script and also add a pretest script, for instance like this:

{
  "scripts": {
    "lint": "xo",
    "pretest": "npm run -s lint"
  }
}

Instead of adding it to the test script like now. What's your opinion on this?

I usually never run linting without tests as I already have linting in my editor. If I were to do it though, I would just use the globally installed XO: $ xo.

Thoughts?

I see. I like to not have to install many libraries globally, which makes it easier for new developers as well.
This is no big deal though...
But what would you think about adding this feature behind an optional flag? (I could make a PR if you're interested)

@joakimbeng Re flag. I'll think about it. Keeping this open for now.

I kinda got this idea. What if npm could run local binaries. npm run xo would run the local xo binary if no run script exists by that name. Would be sweet. I don't always want to have to proxy binaries through a run script. Do you think that would be a good feature request for npm?

That would be great IMO!
Have you seen the npm-exec discussion? It looks like there's plenty more wanting this feature...
I personally have added node_modules/.bin/ to my path so I seldom run the global executables ;) But I would prefer something like npm run xo or npm exec xo.

@joakimbeng Yes, but totally forgot about it. You should 👍 here: npm/npm#6053 (comment).

+1 but I would put it in posttest
Also `-s' means silent? Why silent it?

{
  "scripts": {
    "lint": "xo",
    "posttest": "npm run lint"
  }
}

Without the silent flag you'll get two npm error sections, which is ugly in my opinion:

npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "run" "lint"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.3
npm ERR! code ELIFECYCLE
npm ERR! my-package@0.1.0 lint: `xo`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-package@0.1.0 lint script 'xo'.
npm ERR! This is most likely a problem with the my-package package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     xo
npm ERR! You can get their info via:
npm ERR!     npm owner ls my-package
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/joakimbeng/my-package/npm-debug.log

npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "run" "test"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.3
npm ERR! code ELIFECYCLE
npm ERR! my-package@0.1.0 pretest: `npm run lint`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-package@0.1.0 pretest script 'npm run lint'.
npm ERR! This is most likely a problem with the my-package package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run lint
npm ERR! You can get their info via:
npm ERR!     npm owner ls my-package
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/joakimbeng/my-package/npm-debug.log

With -s it just becomes:

npm ERR! Darwin 14.0.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "run" "test"
npm ERR! node v4.0.0
npm ERR! npm  v2.14.3
npm ERR! code ELIFECYCLE
npm ERR! my-package@0.1.0 pretest: `npm run -s lint`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my-package@0.1.0 pretest script 'npm run -s lint'.
npm ERR! This is most likely a problem with the my-package package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     npm run -s lint
npm ERR! You can get their info via:
npm ERR!     npm owner ls my-package
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/joakimbeng/my-package/npm-debug.log

Oh OK, but I don't wanna silent the output from xo.

The silent flag only affects npm's own output and not XO's

yup, cool :)

Putting it in posttest is ok with me, although in bigger packages/applications I think it's better the other way around. Because then the time to run the tests will probably exceed the linting time, and IMO it's a better experience to fail fast.

The reason I want to put it in posttest is the same why I made this PR #6 unless npm-exec can land

JaKXz commented

TIL $(npm bin) will give you the path to your installed executables...

e.g. $(npm bin)/rimraf *.* :trollface:

Decided to pass on this: #8 (comment)