Skip to content

Commit

Permalink
fix(discovery): support NestJS 11 (#945)
Browse files Browse the repository at this point in the history
* fix(deps): update nest monorepo to v11

* fix(discovery): support NestJS 11

From NestJS 11, InstanceWrapper.metatype can be null. Mapping it from `null` to `undefined` for
`DiscoveredClass.injectType` to avoid a breaking change.

#944

* fix(discovery): discoveredClass.injectType can be null

Support both undefined and null while supporting NestJS 10 and 11.

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
xballoy and renovate[bot] authored Jan 22, 2025
1 parent 7893882 commit 7617ac1
Show file tree
Hide file tree
Showing 9 changed files with 273 additions and 168 deletions.
2 changes: 1 addition & 1 deletion integration/rabbitmq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"@golevelup/nestjs-rabbitmq": "workspace:^",
"@golevelup/ts-jest": "workspace:^",
"@nestjs/testing": "^10.4.4",
"@nestjs/testing": "^11.0.0",
"@types/express": "5.0.0",
"@types/jest": "^27.0.3",
"@types/node": "^22.0.0",
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"private": true,
"license": "MIT",
"dependencies": {
"@nestjs/common": "^10.4.4",
"@nestjs/core": "^10.4.4",
"@nestjs/platform-express": "^10.4.4",
"@nestjs/common": "^11.0.0",
"@nestjs/core": "^11.0.0",
"@nestjs/platform-express": "^11.0.0",
"lodash": "^4.17.21",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
Expand All @@ -16,7 +16,7 @@
"@commitlint/prompt": "^19.7.0",
"@eslint/eslintrc": "^3.2.0",
"@eslint/js": "^9.18.0",
"@nestjs/testing": "^10.4.4",
"@nestjs/testing": "^11.0.0",
"@types/express": "5.0.0",
"@types/jest": "^27.0.3",
"@types/lodash": "^4.17.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lodash": "^4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^10.x"
"@nestjs/common": "^10.x || ^11.0.0"
},
"jest": {
"moduleFileExtensions": [
Expand Down
4 changes: 2 additions & 2 deletions packages/discovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"lodash": "^4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^10.x",
"@nestjs/core": "^10.x"
"@nestjs/common": "^10.x || ^11.0.0",
"@nestjs/core": "^10.x || ^11.0.0"
},
"bugs": {
"url": "https://github.com/golevelup/nestjs/issues"
Expand Down
3 changes: 2 additions & 1 deletion packages/discovery/src/discovery.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Type } from '@nestjs/common';
export interface DiscoveredModule<T = object> {
name: string;
instance: T;
// TODO: remove undefined from injectType when dropping NestJS 10 support
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
injectType?: Function | Type<any>;
injectType: Function | Type<any> | undefined | null;
dependencyType: Type<T>;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/discovery/src/discovery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ export class DiscoveryService {
return {
name: wrapper.name as string,
instance: instanceHost.instance,
injectType: wrapper.metatype,
// TODO: remove nullish coalescing operator to return undefined when dropping NestJS 10 support
injectType: wrapper.metatype ?? undefined,
dependencyType: get(instanceHost, 'instance.constructor'),
parentModule: {
name: nestModule.metatype.name,
Expand Down
2 changes: 1 addition & 1 deletion packages/modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"lodash": "^4.17.21"
},
"peerDependencies": {
"@nestjs/common": "^10.x",
"@nestjs/common": "^10.x || ^11.0.0",
"rxjs": "^7.x"
},
"jest": {
Expand Down
4 changes: 2 additions & 2 deletions packages/rabbitmq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"@types/amqplib": "^0.10.6"
},
"peerDependencies": {
"@nestjs/common": "^10.x",
"@nestjs/core": "^10.x",
"@nestjs/common": "^10.x || ^11.0.0",
"@nestjs/core": "^10.x || ^11.0.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.x"
},
Expand Down
Loading

0 comments on commit 7617ac1

Please sign in to comment.