From 2b0f44c6d4c91154fb8a7779b6789acbb2635b1b Mon Sep 17 00:00:00 2001 From: Kurten Date: Tue, 7 Apr 2020 15:21:27 +0800 Subject: [PATCH] fix: 2.x fix conflicts (#458) * fix dfs circular depth bug * remove lodash * add isProvide --- package.json | 18 +++++++++--------- .../midway-core/src/context/midwayContainer.ts | 5 +++-- packages/midway-decorator/src/common/utils.ts | 7 +++++++ .../test/annotation/provide.test.ts | 4 +++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 6e0775056a41..61690b2d15d3 100644 --- a/package.json +++ b/package.json @@ -3,26 +3,26 @@ "description": "a web framework for complex Node.js application", "version": "1.0.0", "devDependencies": { - "@types/chai": "^4.1.7", - "@types/lodash": "^4.14.119", - "@types/mocha": "^5.2.5", - "@types/node": "^10.12.18", + "@types/chai": "^4.2.11", + "@types/lodash": "^4.14.149", + "@types/mocha": "^5.2.7", + "@types/node": "^10.17.18", "autocannon": "^2.4.1", "chalk": "^3.0.0", "debug": "^4.1.1", "eslint": "^6.1.0", "gh-pages": "^2.2.0", "git-hooks": "^1.1.10", - "lerna": "^3.14.1", + "lerna": "^3.20.2", "lerna-relinker": "^1.4.0", "node-ab": "0.0.6", "opencollective": "^1.0.3", "opencollective-postinstall": "^2.0.2", - "rimraf": "^3.0.0", - "tree-kill": "^1.2.0", - "tslint": "^5.17.0", + "rimraf": "^3.0.2", + "tree-kill": "^1.2.2", + "tslint": "^5.20.1", "tslint-no-unused-expression-chai": "^0.1.4", - "typescript": "^3.5.1", + "typescript": "^3.8.3", "vuepress": "^0.14.11" }, "scripts": { diff --git a/packages/midway-core/src/context/midwayContainer.ts b/packages/midway-core/src/context/midwayContainer.ts index 4fdfc38f49e5..5645c3e885ad 100644 --- a/packages/midway-core/src/context/midwayContainer.ts +++ b/packages/midway-core/src/context/midwayContainer.ts @@ -12,7 +12,8 @@ import { ScopeEnum, PIPELINE_IDENTIFIER, listModule, - CONFIGURATION_KEY + CONFIGURATION_KEY, + isProvide } from '@midwayjs/decorator'; import * as is from 'is-type-of'; import { join } from 'path'; @@ -155,7 +156,7 @@ export class MidwayContainer extends Container implements IMidwayContainer { } protected bindModule(module, namespace = '', filePath?: string) { - if (is.class(module)) { + if (is.class(module) && isProvide(module)) { const providerId = getProviderId(module); if (providerId) { this.bind( diff --git a/packages/midway-decorator/src/common/utils.ts b/packages/midway-decorator/src/common/utils.ts index 5c751d6e911b..8e8bb421ca8a 100644 --- a/packages/midway-decorator/src/common/utils.ts +++ b/packages/midway-decorator/src/common/utils.ts @@ -171,3 +171,10 @@ export function saveProviderId(identifier: ObjectIdentifier, target: any, overri return target; } +/** + * 是否使用了 saveProviderId + * @param target class + */ +export function isProvide(target: any): boolean { + return Reflect.hasOwnMetadata(TAGGED_CLS, target); +} diff --git a/packages/midway-decorator/test/annotation/provide.test.ts b/packages/midway-decorator/test/annotation/provide.test.ts index 567326ec488c..6734e426a8a6 100644 --- a/packages/midway-decorator/test/annotation/provide.test.ts +++ b/packages/midway-decorator/test/annotation/provide.test.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; -import { Provide, getProviderId } from '../../src'; +import { Provide, getProviderId, isProvide } from '../../src'; @Provide('jjj') class Test {} @@ -9,5 +9,7 @@ describe('/test/annotation/provide.test.ts', () => { it('provide decorator should be ok', () => { const id = getProviderId(Test); expect(id).eq('jjj'); + + expect(isProvide(Test)).true; }); });