shama / napa

:wine_glass: A helper for installing stuff without a package.json with npm.
MIT License
412 stars 34 forks source link

User-specified `package.json` #18

Open namuol opened 10 years ago

namuol commented 10 years ago

Since napa is meant to be used with libraries that don't supply package.json, it could be useful to allow the user to specify their own custom file to integrate more naturally with node.js.

My use case is simple: I don't want to have to require the absolute path to the "index" file of a library.

In other words, this is what I'm doing now:

var lib = require('lib/bin/index.js');

...when I'd much rather just be able to do this:

var lib = require('lib');

So my suggestion is to allow the user to specify a package.json body along with any URL.

Example:

package.json:

{
  ...
  "napa": {
    "lib": {
      "url": "user/lib",
      "package.json": {
        "main": "bin/index.js"
      }
    }
  }
}

Another use-case might be a package that needs to be built ahead-of-time:

package.json:

{
  ...
  "napa": {
    "lib": {
      "url": "user/lib",
      "package.json": {
        "main": "bin/index.js",
        "scripts": {
          "install": "make"
        }
      }
    }
  }
}

I realize all of this could technically be achieved through scripts, but this would offer a more localized configuration.

Thoughts?

shama commented 10 years ago

That is a really cool idea. I am +1 for that.

Also, I created this package some time ago metamorph which will transform one meta file into another (but is in serious need of an update). It might be cool to detect other common meta files and create a package.json from one of those, if a specific user overridden package.json key is not supplied.

giggio commented 9 years ago

+1 to the idea. This would be really useful. I don't know if you need a a full package.json. It would be enough for me to enable to specify the default main.