defense-of-dot-js icon indicating copy to clipboard operation
defense-of-dot-js copied to clipboard

package.json bin

Open boopathi opened this issue 9 years ago • 4 comments

If the package has a CLI that uses ES6 imports, how should we declare that the CLI is ES6 module ?

"bin.module": {} or "module.bin": {}

or, should the "modules.root" take care of that internally, how should that work?

Update:

Also, for node --module cli.js, one can simply specify - #!/usr/bin/env node --module and execute that as ./cli.js.

But if you run node cli.js it would be script mode instead of module mode and would throw.

boopathi avatar Apr 27 '16 09:04 boopathi

bins are symlinked, the module system still eventually resolves it to an absolute path. From there you can find the package.json. A bin to support both CJS and ES entry would most likely look like:

// bin/app.js
require('../');

and in the case of this proposal the package.json would route to the proper place.

bmeck avatar Apr 27 '16 14:04 bmeck

@boopathi as @bmeck said, this is not a problem, the resolution process proposed here handles that case.

caridy avatar Apr 27 '16 14:04 caridy

@caridy @bmeck not all bins are symlinked directly to a .js file; it's not that uncommon to create bins that just use the shebang line and require the destination file (for example bower: https://github.com/bower/bower/blob/master/bin/bower).

We could simply disallow bins that aren't symlinked that are standard modules, and this seems necessary for the file extension approach. In the package.json approach, we could use the same rules for bins as we use for other modules ("if there is only module, treat bins as standard modules, otherwise use modules.root or modules")

wycats avatar Apr 27 '16 14:04 wycats

A note to clarify bin usage should be added to the proposal.

jdalton avatar Jun 08 '16 21:06 jdalton