Skip to content

Commit

Permalink
fix: move the fig complete import to an optional require
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Dec 4, 2023
1 parent 9317680 commit 72b2a00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/stale-pillows-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'nest-commander': patch
---

Move the fig completion package to an optional import to get around jest
throwing an error about esm packages
12 changes: 9 additions & 3 deletions packages/nest-commander/src/completion.factory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { addCompletionSpecCommand } from '@fig/complete-commander';
import type { INestApplicationContext } from '@nestjs/common';
import { Command } from 'commander';
import type { CompletionFactoryOptions } from './completion.factory.interface';
Expand Down Expand Up @@ -50,7 +48,15 @@ export class CompletionFactory {
}

if (parsedOptions.fig) {
addCompletionSpecCommand(commander);
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { addCompletionSpecCommand } = require('@fig/complete-commander');
addCompletionSpecCommand(commander);
} catch {
throw new Error(
`There was a problem creating the fig completion. Did you make sure to install "@fig/complete-commander"?`,
);
}
}
}

Expand Down

0 comments on commit 72b2a00

Please sign in to comment.