pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 10 forks source link

automatic argv does not work as intended from es6 #18

Closed shadowspawn closed 2 years ago

shadowspawn commented 2 years ago

https://github.com/pkgjs/parseargs/blob/886e99c1d5dc1b37a004d31a8b201a186c564354/index.js#L4

I assume this line is intended to emulate the proposed process.mainArgs and get the slice right when called from the node REPL and/or with --eval.

However, when the script being executed is es6 (.mjs) then require.main is undefined and it slices incorrectly. Tested using node v16.13.0.

(I can refrain from posting bug reports if inappropriate for "early WIP"!)

shadowspawn commented 2 years ago
// es6.mjs
import { parseArgs } from '@pkgjs/parseargs';

const result = parseArgs();

console.log(result);
$ node es6.mjs
{
  args: {},
  values: {},
  positionals: [
    '/Users/john/Documents/Sandpits/pkgjs/parseargs-issues/play/es6.mjs'
  ]
}
bcoe commented 2 years ago

@shadowspawn this seems good to fix 👍 commented on your PR.

shadowspawn commented 2 years ago

Fixed by #20