Skip to content

Commit

Permalink
Merge pull request #2502 from micalevisk/fix/issue-2458
Browse files Browse the repository at this point in the history
feat: check only the major slice on nestjs dep mismatch
  • Loading branch information
kamilmysliwiec authored Feb 7, 2024
2 parents 42b15e1 + be2f7e6 commit 195dc7b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 39 deletions.
51 changes: 26 additions & 25 deletions actions/info.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface NestDependencyWarnings {

export class InfoAction extends AbstractAction {
private manager!: AbstractPackageManager;
// Nest dependencies whitelist used to compare minor version
// Nest dependencies whitelist used to compare the major version
private warningMessageDependenciesWhiteList = [
'@nestjs/core',
'@nestjs/common',
Expand All @@ -55,7 +55,10 @@ export class InfoAction extends AbstractAction {

private async displaySystemInformation(): Promise<void> {
console.info(chalk.green('[System Information]'));
console.info('OS Version :', chalk.blue(osName(platform(), release()), release()));
console.info(
'OS Version :',
chalk.blue(osName(platform(), release()), release()),
);
console.info('NodeJS Version :', chalk.blue(process.version));
await this.displayPackageManagerVersion();
}
Expand Down Expand Up @@ -131,15 +134,15 @@ export class InfoAction extends AbstractAction {
displayWarningMessage(nestDependencies: NestDependency[]) {
try {
const warnings = this.buildNestVersionsWarningMessage(nestDependencies);
const minorVersions = Object.keys(warnings);
if (minorVersions.length > 0) {
const majorVersions = Object.keys(warnings);
if (majorVersions.length > 0) {
console.info('\r');
console.info(chalk.yellow('[Warnings]'));
console.info(
'The following packages are not in the same minor version',
'The following packages are not in the same major version',
);
console.info('This could lead to runtime errors');
minorVersions.forEach((version) => {
majorVersions.forEach((version) => {
console.info(chalk.bold(`* Under version ${version}`));
warnings[version].forEach(({ packageName, value }) => {
console.info(`- ${packageName} ${value}`);
Expand All @@ -161,25 +164,23 @@ export class InfoAction extends AbstractAction {
buildNestVersionsWarningMessage(
nestDependencies: NestDependency[],
): NestDependencyWarnings {
const unsortedWarnings: NestDependencyWarnings =
nestDependencies.reduce<NestDependencyWarnings>(
(acc, { name, packageName, value }) => {
if (!this.warningMessageDependenciesWhiteList.includes(packageName)) {
return acc;
}
const unsortedWarnings = nestDependencies.reduce(
(depWarningsGroup, { name, packageName, value }) => {
if (!this.warningMessageDependenciesWhiteList.includes(packageName)) {
return depWarningsGroup;
}

const cleanedValue = value.replace(/[^\d.]/g, '');
const [major, minor] = cleanedValue.split('.');
const minorVersion = `${major}.${minor}`;
acc[minorVersion] = [
...(acc[minorVersion] || []),
{ name, packageName, value },
];
const [major] = value.replace(/[^\d.]/g, '').split('.', 1);
const minimumVersion = major;
depWarningsGroup[minimumVersion] = [
...(depWarningsGroup[minimumVersion] || []),
{ name, packageName, value },
];

return acc;
},
{},
);
return depWarningsGroup;
},
Object.create(null) as NestDependencyWarnings,
);

const unsortedMinorVersions = Object.keys(unsortedWarnings);
if (unsortedMinorVersions.length <= 1) {
Expand All @@ -201,12 +202,12 @@ export class InfoAction extends AbstractAction {
},
);

return sortedMinorVersions.reduce<NestDependencyWarnings>(
return sortedMinorVersions.reduce(
(warnings, minorVersion) => {
warnings[minorVersion] = unsortedWarnings[minorVersion];
return warnings;
},
{},
Object.create(null) as NestDependencyWarnings,
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/compiler/defaults/swc-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const swcDefaultsFactory = (

return {
swcOptions: {
sourceMaps: tsOptions?.sourceMap || (tsOptions?.inlineSourceMap && 'inline'),
sourceMaps:
tsOptions?.sourceMap || (tsOptions?.inlineSourceMap && 'inline'),
module: {
type: 'commonjs',
},
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/os-info.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default function osName(platform: string, release: string): string {
case 'android':
return 'Android';
default:
return platform;
return platform;
}
}
}
20 changes: 9 additions & 11 deletions test/actions/info.action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('InfoAction', () => {
];
const result = infoAction.buildNestVersionsWarningMessage(dependencies);
const expected = {
'1.2': [
'1': [
{ packageName: '@nestjs/core', name: 'core', value: '1.2.3' },
{ packageName: '@nestjs/common', name: 'common', value: '1.2.4' },
{
Expand All @@ -93,7 +93,7 @@ describe('InfoAction', () => {
value: '1.2.4',
},
],
'2.1': [
'2': [
{
packageName: '@nestjs/platform-ws',
name: 'platform-ws',
Expand Down Expand Up @@ -131,21 +131,21 @@ describe('InfoAction', () => {
name: 'platform-socket.io',
value: '1.2$$.4',
},
{
name: 'platform-socket.io',
packageName: '@nestjs/platform-socket.io',
value: '2.0.1',
},
{
packageName: '@nestjs/websockets',
name: 'websockets',
value: '^2.*&1.0',
},
{
name: 'platform-socket.io',
packageName: '@nestjs/platform-socket.io',
value: '2.0.1',
},
];

const result = infoAction.buildNestVersionsWarningMessage(dependencies);
const expected = {
'2.1': [
'2': [
{
name: 'platform-fastify',
packageName: '@nestjs/platform-fastify',
Expand All @@ -156,15 +156,13 @@ describe('InfoAction', () => {
name: 'websockets',
value: '^2.*&1.0',
},
],
'2.0': [
{
name: 'platform-socket.io',
packageName: '@nestjs/platform-socket.io',
value: '2.0.1',
},
],
'1.2': [
'1': [
{
name: 'schematics',
packageName: '@nestjs/schematics',
Expand Down

0 comments on commit 195dc7b

Please sign in to comment.