Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/package-utils/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
'use strict';

import { packageExists } from '../src';
jest.mock('@webpack-cli/package-utils')

import { packageExists, promptInstallation } from '@webpack-cli/package-utils';
import ExternalCommand from '../../webpack-cli/lib/commands/ExternalCommand';

describe('@webpack-cli/package-utils', () => {
it('should check existence of package', () => {
(packageExists as any).mockImplementation(() => true);
const exists = packageExists('@webpack-cli/info');

expect(exists).toBeTruthy();
});

it('should not throw if the user interrupts', async () => {
(promptInstallation as any).mockImplementation(() => { throw new Error() });
await expect(ExternalCommand.run('info')).resolves.not.toThrow();
});
});
8 changes: 6 additions & 2 deletions packages/webpack-cli/lib/commands/ExternalCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ class ExternalCommand {
const scopeName = packagePrefix + '/' + name;
let pkgLoc = packageExists(scopeName);
if (!pkgLoc) {
pkgLoc = await promptInstallation(`${scopeName}`, () => {
try {
pkgLoc = await promptInstallation(`${scopeName}`, () => {
logger.error(`The command moved into a separate package: ${chalk.keyword('orange')(scopeName)}\n`);
});
});
} catch (err) {
logger.error(`Action Interrupted, use ${chalk.cyan(`webpack-cli help`)} to see possible commands.`)
}
}
return pkgLoc ? require(scopeName).default(...args) : null;
}
Expand Down