Skip to content

Commit

Permalink
feat: add warning message for the info command
Browse files Browse the repository at this point in the history
  Added few changes after the review
  More details here: #1929
  • Loading branch information
GreGosPhaTos committed Nov 24, 2023
1 parent 305c3dd commit d29182f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
62 changes: 37 additions & 25 deletions actions/info.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ interface NestDependencyWarnings {

export class InfoAction extends AbstractAction {
private manager!: AbstractPackageManager;
// Nest dependencies whitelist used to compare minor version
private warningMessageDependenciesWhiteList = [
'@nestjs/core',
'@nestjs/common',
'@nestjs/schematics',
'@nestjs/platform-express',
'@nestjs/platform-fastify',
'@nestjs/platform-socket.io',
'@nestjs/platform-ws',
'@nestjs/websockets',
];

public async handle() {
this.manager = await PackageManagerFactory.find();
Expand Down Expand Up @@ -118,41 +129,42 @@ export class InfoAction extends AbstractAction {
}

displayWarningMessage(nestDependencies: NestDependency[]) {
const warnings = this.buildNestVersionsWarningMessage(nestDependencies);
const minorVersions = Object.keys(warnings);
if (minorVersions.length > 0) {
console.info('\r');

console.info(chalk.yellow('[Warnings]'));
console.info('The following packages are not in the same minor version');
console.info('This could lead to runtime errors');
minorVersions.forEach((version) => {
console.info(chalk.bold(`* Under version ${version}`));
warnings[version].forEach(({ packageName, value }) => {
console.info(`- ${packageName} ${value}`);
try {
const warnings = this.buildNestVersionsWarningMessage(nestDependencies);
const minorVersions = Object.keys(warnings);
if (minorVersions.length > 0) {
console.info('\r');
console.info(chalk.yellow('[Warnings]'));
console.info(
'The following packages are not in the same minor version',
);
console.info('This could lead to runtime errors');
minorVersions.forEach((version) => {
console.info(chalk.bold(`* Under version ${version}`));
warnings[version].forEach(({ packageName, value }) => {
console.info(`- ${packageName} ${value}`);
});
});
});
}
} catch {
console.info('\t');
console.error(
chalk.red(
MESSAGES.NEST_INFORMATION_PACKAGE_WARNING_FAILED(
this.warningMessageDependenciesWhiteList,
),
),
);
}
}

buildNestVersionsWarningMessage(
nestDependencies: NestDependency[],
): NestDependencyWarnings {
const dependenciesWhiteList = [
'@nestjs/core',
'@nestjs/common',
'@nestjs/schematics',
'@nestjs/platform-express',
'@nestjs/platform-fastify',
'@nestjs/platform-socket.io',
'@nestjs/platform-ws',
'@nestjs/websockets',
];

const unsortedWarnings: NestDependencyWarnings =
nestDependencies.reduce<NestDependencyWarnings>(
(acc, { name, packageName, value }) => {
if (!dependenciesWhiteList.includes(packageName)) {
if (!this.warningMessageDependenciesWhiteList.includes(packageName)) {
return acc;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/ui/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ export const MESSAGES = {
`${EMOJIS.SCREAM} Packages installation failed!\nIn case you don't see any errors above, consider manually running the failed command ${commandToRunManually} to see more details on why it errored out.`,
// tslint:disable-next-line:max-line-length
NEST_INFORMATION_PACKAGE_MANAGER_FAILED: `${EMOJIS.SMIRK} cannot read your project package.json file, are you inside your project directory?`,
NEST_INFORMATION_PACKAGE_WARNING_FAILED: (nestDependencies: string[]) =>
`${
EMOJIS.SMIRK
} failed to compare dependencies versions, please check that following packages are in the same minor version : \n ${nestDependencies.join(
'\n',
)}`,

LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE: (name: string) =>
`Unable to install library ${name} because package did not install. Please check package name.`,
LIBRARY_INSTALLATION_FAILED_NO_LIBRARY: 'No library found.',
Expand Down

0 comments on commit d29182f

Please sign in to comment.