From 7e498565e3b0e4e41046c0f7f8b2327599987783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caleb=20=E3=83=84=20Everett?= Date: Sat, 18 Jun 2022 10:01:36 -0700 Subject: [PATCH 1/3] Export InvalidOptionArgumentError in esm I upgraded a typescript project to native es modules and imported `InvalidOptionArgumentError` was undefined at runtime, tho typescript defined it as an alias to InvalidArgumentError. ``` import { InvalidOptionArgumentError } from 'commander' // ^ No type error here, typescript thinks InvalidOptionArgumentError should exist assert(InvalidOptionArgumentError != null); // But it doesn't, this will throw an error ``` A quick test showed that there was a difference between the commonjs and ecmascript module. The issue wasn't limited to typescript. ``` const { InvalidOptionArgumentError } = require('commander') assert(InvalidOptionArgumentError != null); ``` ``` import { InvalidOptionArgumentError } from 'commander' assert(InvalidOptionArgumentError != null); // This will throw an error ``` This commit fixes the issue by exporting InvalidOptionArgumentError from the esm entry point. Alternatively we could remove InvalidOptionArgumentError from typings, I'm happy as long as build and runtime match. --- esm.mjs | 1 + tests/esm-imports-test.mjs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/esm.mjs b/esm.mjs index dc6bd11c9..201e86098 100644 --- a/esm.mjs +++ b/esm.mjs @@ -8,6 +8,7 @@ export const { createOption, CommanderError, InvalidArgumentError, + InvalidArgumentError: InvalidOptionArgumentError, Command, Argument, Option, diff --git a/tests/esm-imports-test.mjs b/tests/esm-imports-test.mjs index 1ad478ac6..10ac8c722 100644 --- a/tests/esm-imports-test.mjs +++ b/tests/esm-imports-test.mjs @@ -1,4 +1,4 @@ -import { program, Command, Option, Argument, CommanderError, InvalidArgumentError, Help, createCommand, createArgument, createOption } from '../esm.mjs'; +import { program, Command, Option, Argument, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Help, createCommand, createArgument, createOption } from '../esm.mjs'; // Do some simple checks that expected imports are available at runtime. // Run using `npm run test-esm`. @@ -25,6 +25,7 @@ checkClass(new Command(), 'Command'); checkClass(new Option('-e, --example'), 'Option'); checkClass(new CommanderError(1, 'code', 'failed'), 'CommanderError'); checkClass(new InvalidArgumentError('failed'), 'InvalidArgumentError'); +checkClass(new InvalidOptionArgumentError('failed'), 'InvalidArgumentError'); checkClass(new Help(), 'Help'); checkClass(new Argument(''), 'Argument'); From f4c1cb3a433a2df3938484571e522bfaf3e15632 Mon Sep 17 00:00:00 2001 From: Caleb Everett Date: Sat, 18 Jun 2022 21:58:43 -0700 Subject: [PATCH 2/3] Update esm.mjs Co-authored-by: John Gee --- esm.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esm.mjs b/esm.mjs index 201e86098..bf100edfa 100644 --- a/esm.mjs +++ b/esm.mjs @@ -8,7 +8,7 @@ export const { createOption, CommanderError, InvalidArgumentError, - InvalidArgumentError: InvalidOptionArgumentError, +InvalidOptionArgumentError, // deprecated old name Command, Argument, Option, From 487a6d51a05bb84adaa112b569d6d1451241e7b4 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 19 Jun 2022 18:36:23 +1200 Subject: [PATCH 3/3] Fix indentation --- esm.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esm.mjs b/esm.mjs index bf100edfa..e7190a1b8 100644 --- a/esm.mjs +++ b/esm.mjs @@ -8,7 +8,7 @@ export const { createOption, CommanderError, InvalidArgumentError, -InvalidOptionArgumentError, // deprecated old name + InvalidOptionArgumentError, // deprecated old name Command, Argument, Option,