diff --git a/.changeset/stale-pillows-talk.md b/.changeset/stale-pillows-talk.md new file mode 100644 index 00000000..1048cb8b --- /dev/null +++ b/.changeset/stale-pillows-talk.md @@ -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 diff --git a/packages/nest-commander/src/completion.factory.ts b/packages/nest-commander/src/completion.factory.ts index 9c26a5e9..a166f7b3 100644 --- a/packages/nest-commander/src/completion.factory.ts +++ b/packages/nest-commander/src/completion.factory.ts @@ -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'; @@ -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"?`, + ); + } } }