isaacs/npm — Issue #1772: Single file package support
Author: jrburke
Created: 2011-11-23 20:36:43+00:00
State: open

This is about supporting a single JS file as an installable unit by npm.

## Motivation

There are many modules that are useful just as single files, and it would ease distribution complexity if the complete state of the module could be encapsulated in one file, particularly if this module is also usable in the browser, which is accustomed to single JS file distributions and installation.

## Approach

Support a comment in a .js file that has a comment with the package.json contents in it. So, something like:

/*package.json
{
}
*/

npm would install the file as `packagename.js` in `node_modules` without a directory named `packagename`, and since the module does not need a "main" property parsed out of a package.json during runtime, the package.json contents only need to be processed during npm install/uninstall actions.

IIRC, npm will install dependencies for the modules in a `node_modules` directory inside the `packagename` directory in an effort to avoid versioning conflicts with other modules. For this case, perhaps there could be support for a `packagename_modules` directory that is a sibling to the `packagename.js` file, but that probably affects node's module lookup algorithm? Maybe then creating a `packagename` directory and placing the dependencies in there or in a nested `node_modules` directory is enough?

I am willing to do the work for this feature, but I want to check first if it is something that would be considered and any design issues with it that need to be solved. In particular, I am not sure if the dependency installation/directory is a larger issue that affects node's runtime behavior for module lookup.

I apologize if this has come up before, doing a quick search of issues did not surface a similar ticket.