File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,19 @@ function attachCommand<C extends Command<boolean>>(
82
82
command : C ,
83
83
config : C extends DetachedCommand ? Config | undefined : Config ,
84
84
) : void {
85
+ // [email protected] will internally push commands into an array structure!
86
+ // Commands with duplicate names (e.g. from config) must be reduced before
87
+ // calling this function.
88
+ // https://unpkg.com/browse/[email protected] /lib/command.js#L1308
89
+ if ( program . commands . find ( ( cmd ) => cmd . name ( ) === command . name ) ) {
90
+ throw new Error (
91
+ 'Invariant Violation: Attempted to override an already registered ' +
92
+ `command: '${ command . name } '. This is not supported by the underlying ` +
93
+ 'library and will cause bugs. Ensure a command with this `name` is ' +
94
+ 'only registered once.' ,
95
+ ) ;
96
+ }
97
+
85
98
const cmd = program
86
99
. command ( command . name )
87
100
. option ( '--verbose' , 'Increase logging verbosity' )
@@ -165,7 +178,14 @@ async function setupAndRun() {
165
178
166
179
logger . enable ( ) ;
167
180
181
+ const commands : Record < string , Command > = { } ;
182
+
183
+ // Reduce overridden commands before registering
168
184
for ( const command of [ ...projectCommands , ...config . commands ] ) {
185
+ commands [ command . name ] = command ;
186
+ }
187
+
188
+ for ( const command of Object . values ( commands ) ) {
169
189
attachCommand ( command , config ) ;
170
190
}
171
191
} catch ( error ) {
You can’t perform that action at this time.
0 commit comments