1.3.0 • Published 5 years ago
npx-esm v1.3.0
NPX ESM
Run ESM modules as node programs with npx in a three steps.
- Install
npx-esmpackage:npm install -D npx-esm - Create program
index.js:export default function() { console.log('Hello') } - Execute it:
npx esm index.js
API
CmdParams
{
argv: Array<string>,
argvHead: Array<string>,
cwd: string,
stdin: ReadableStream,
stdout: WritableStream,
stderr: WriteableStream,
}The main function receives a command params as the first argument. It contains minimal set of params to execute a command and interact with the user or pipeline.
argvis the list of command line arguments remained after removing executable adn script paths.argvHeadis the list of command line arguments cropped as executable and script paths.cwdis the current directory.stdin,stdoutandstderrare I/O streams.
Example
async function main({
argv, // -> ['--help']
argvHead, // -> ['node', 'script.js']
cwd, // '/dev/project/esm'
stdout, // writable stream
stderr, // writable stream
stdin, // readable stream
}) {
stdout.write('OK')
return 1
}License
MIT © Rumkin