Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
breaking: Fix ability to override commands via config
Browse files Browse the repository at this point in the history
huntie committed Jul 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5d8a847 commit 889f00f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -82,6 +82,19 @@ function attachCommand<C extends Command<boolean>>(
command: C,
config: C extends DetachedCommand ? Config | undefined : Config,
): void {
// [email protected] will internally push commands into an array structure!
// Commands with duplicate names (e.g. from config) must be reduced before
// calling this function.
// https://unpkg.com/browse/[email protected]/lib/command.js#L1308
// @ts-ignore
if (program._findCommand(command.name)) {
throw new Error(
'Invariant Violation: Attempted to override an already registered ' +
'command. This is not supported by the underlying library and will ' +
'cause bugs. Ensure a command with this `name` is only registered once.',
);
}

const cmd = program
.command(command.name)
.option('--verbose', 'Increase logging verbosity')
@@ -165,7 +178,14 @@ async function setupAndRun() {

logger.enable();

const commands: Record<string, Command> = {};

// Reduce overridden commands before registering
for (const command of [...projectCommands, ...config.commands]) {
commands[command.name] = command;
}

for (const command of Object.values(commands)) {
attachCommand(command, config);
}
} catch (error) {

0 comments on commit 889f00f

Please sign in to comment.