0.1.5 • Published 7 years ago

npm-extends v0.1.5

Weekly downloads
15
License
MIT
Repository
github
Last release
7 years ago

npm-extends 😈

What?

This abuses npm’s onload-script option, which can be set on a per-project basis, to poison the require.cache entry for npm’s run-script command with a cooler version that runs a custom CLI of your choosing if the specified script isn’t in package.json.

Should I use this?

No.

But how would I use it, in theory?

Install npm-extends in your project, then add an .npmrc file to your project with this line:

onload-script="${PWD}/node_modules/npm-extends"

(Yes, unfortunately this will not work when you run npm from directories below your package.json. You could probably make it work by installing npm-extends globally.)

Add an npm:extends script to scripts in your package.json file that runs the command you’d like to use instead of npm run when a script isn’t found. It will be passed the script name and arguments.

{
  "scripts": {
    "npm:extends": "your-cli",
    "boring-script": "echo This is boring!"
  }
}

Now you can run scripts that aren’t in there, but are supported by your tool!

$ npm run boring-script

> echo BooOoOOOriing

BooOoOOOriing

$ npm run cool-script

> your-cli "cool-script"

WaaAAaay cooler!
0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago