defense-of-dot-js
defense-of-dot-js copied to clipboard
package.json bin
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.
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.
@boopathi as @bmeck said, this is not a problem, the resolution process proposed here handles that case.
@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")
A note to clarify bin usage should be added to the proposal.