Skip to content

Commit

Permalink
fix: implement optional dep for amqplib in mock package (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Oct 1, 2020
1 parent abae8f2 commit 3319872
Show file tree
Hide file tree
Showing 21 changed files with 173 additions and 132 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/gh-pages.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ jobs:
- run: npm run cov
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1

#
# build-windows:
# runs-on: windows-latest
#
# strategy:
# matrix:
# node-version: [12.x, 14.x]
#
# steps:
# - uses: actions/checkout@v2
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v1
# with:
# node-version: ${{ matrix.node-version }}
# - run: npm install
# - run: npm run bootstrap
# - run: npm run build --if-present
# - run: npm run cov
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
}
},
"npmClient": "npm",
"version": "2.3.4"
"version": "2.3.5"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"url": "http://github.com/midwayjs/midway.git"
},
"engines": {
"node": ">= 8.0.0"
"node": ">= 12.0.0"
},
"license": "MIT",
"collective": {
Expand Down
2 changes: 1 addition & 1 deletion packages/bootstrap/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Bootstrap {
.then(() => {
console.log('[midway] current app started');
})
.catch((err) => {
.catch(err => {
console.error(err);
process.exit(1);
});
Expand Down
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,8 @@
"type": "git",
"url": "http://github.com/midwayjs/midway.git"
},
"engines": {
"node": ">= 12.0.0"
},
"gitHead": "44c0803552baf265debed8a11a860988b7e07a85"
}
2 changes: 1 addition & 1 deletion packages/core/src/context/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { generateProvideId } from '../common/util';
import { isAsyncFunction, isClass, isFunction } from '../util';
import * as util from 'util';

const globalDebugLogger = util.debuglog(`midway:container`);
const globalDebugLogger = util.debuglog('midway:container');

export class Container extends BaseApplicationContext implements IContainer {
id = Math.random().toString(10).slice(-5);
Expand Down
24 changes: 13 additions & 11 deletions packages/core/src/context/midwayContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
ScopeEnum,
} from '@midwayjs/decorator';
import { ContainerConfiguration } from './configuration';
import { FUNCTION_INJECT_KEY, generateProvideId, PRIVATE_META_DATA_KEY } from '..';
import {
FUNCTION_INJECT_KEY,
generateProvideId,
PRIVATE_META_DATA_KEY,
} from '..';
import {
IApplicationContext,
IConfigService,
Expand Down Expand Up @@ -239,10 +243,7 @@ export class MidwayContainer extends Container implements IMidwayContainer {
return this.environmentService.getCurrentEnvironment();
}

public async addAspect(
aspectIns: IMethodAspect,
aspectData: AspectMetadata
) {
public async addAspect(aspectIns: IMethodAspect, aspectData: AspectMetadata) {
const module = aspectData.aspectTarget;
const names = Object.getOwnPropertyNames(module.prototype);
const isMatch = aspectData.match ? pm(aspectData.match) : () => true;
Expand All @@ -260,7 +261,9 @@ export class MidwayContainer extends Container implements IMidwayContainer {
}
let originMethod = descriptor.value;
if (isAsyncFunction(originMethod)) {
this.debugLogger(`aspect [#${module.name}:${name}], isAsync=true, aspect class=[${aspectIns.constructor.name}]`);
this.debugLogger(
`aspect [#${module.name}:${name}], isAsync=true, aspect class=[${aspectIns.constructor.name}]`
);
descriptor.value = async function (...args) {
let error, result;
originMethod = originMethod.bind(this);
Expand All @@ -278,10 +281,7 @@ export class MidwayContainer extends Container implements IMidwayContainer {
result = await originMethod(...joinPoint.args);
}
joinPoint.proceed = undefined;
const resultTemp = await aspectIns.afterReturn?.(
joinPoint,
result
);
const resultTemp = await aspectIns.afterReturn?.(joinPoint, result);
result = typeof resultTemp === 'undefined' ? result : resultTemp;
return result;
} catch (err) {
Expand All @@ -297,7 +297,9 @@ export class MidwayContainer extends Container implements IMidwayContainer {
}
};
} else {
this.debugLogger(`aspect [#${module.name}:${name}], isAsync=false, aspect class=[${aspectIns.constructor.name}]`);
this.debugLogger(
`aspect [#${module.name}:${name}], isAsync=false, aspect class=[${aspectIns.constructor.name}]`
);
descriptor.value = function (...args) {
let error, result;
originMethod = originMethod.bind(this);
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/util/isClass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const ToString = Function.prototype.toString;

function fnBody(fn) {
return ToString.call(fn).replace(/^[^{]*{\s*/, '').replace(/\s*}[^}]*$/, '');
return ToString.call(fn)
.replace(/^[^{]*{\s*/, '')
.replace(/\s*}[^}]*$/, '');
}

export function isClass(fn) {
Expand All @@ -15,5 +17,8 @@ export function isClass(fn) {

// babel.js classCallCheck() & inlined
const body = fnBody(fn);
return (/classCallCheck\(/.test(body) || /TypeError\("Cannot call a class as a function"\)/.test(body));
return (
/classCallCheck\(/.test(body) ||
/TypeError\("Cannot call a class as a function"\)/.test(body)
);
}
1 change: 0 additions & 1 deletion packages/decorator/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const WEB_RESPONSE_HEADER = 'web:response_header';
export const WEB_RESPONSE_CONTENT_TYPE = 'web:response_content_type';
export const WEB_RESPONSE_RENDER = 'web:response_render';


// ws
export const WS_CONTROLLER_KEY = 'ws:controller';
export const WS_EVENT_KEY = 'ws:event';
Expand Down
7 changes: 6 additions & 1 deletion packages/decorator/src/framework/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ALL, attachClassMetadata, attachConstructorDataOnClass, CONFIG_KEY, } from '../';
import {
ALL,
attachClassMetadata,
attachConstructorDataOnClass,
CONFIG_KEY,
} from '../';

export function Config(identifier?: string) {
return function (target: any, targetKey: string, index?: number): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/decorator/src/microservice/rabbitmqConsumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface RabbitMQListenerOptions {
durable?: boolean;
maxPriority?: number;
prefetch?: number;
keys?: {[keyName: string]: string};
keys?: { [keyName: string]: string };
routingKey?: string;
consumeOptions?: {
consumerTag?: string;
Expand All @@ -17,7 +17,7 @@ export interface RabbitMQListenerOptions {
exclusive?: boolean;
priority?: number;
arguments?: any;
}
};
}

export function RabbitMQListener(
Expand Down
6 changes: 5 additions & 1 deletion packages/decorator/src/web/paramMapping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { attachPropertyDataToClass, getParamNames, WEB_ROUTER_PARAM_KEY } from '../';
import {
attachPropertyDataToClass,
getParamNames,
WEB_ROUTER_PARAM_KEY,
} from '../';

export interface GetFileStreamOptions {
requireFile?: boolean; // required file submit, default is true
Expand Down
9 changes: 6 additions & 3 deletions packages/decorator/src/web/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
WEB_RESPONSE_HEADER,
WEB_RESPONSE_KEY,
WEB_RESPONSE_CONTENT_TYPE,
WEB_RESPONSE_RENDER
WEB_RESPONSE_RENDER,
} from '..';

export function Redirect(url: string, code = 302) {
Expand Down Expand Up @@ -82,7 +82,10 @@ export function ContentType(contentType: string) {
};
}

export function createRender(RenderEngine: { render: () => string; renderString: () => string }) {
export function createRender(RenderEngine: {
render: () => string;
renderString: () => string;
}) {
return (templateName: string) => {
return (target, key, descriptor: PropertyDescriptor) => {
attachPropertyMetadata(
Expand All @@ -97,5 +100,5 @@ export function createRender(RenderEngine: { render: () => string; renderString:

return descriptor;
};
}
};
}
5 changes: 1 addition & 4 deletions packages/faas/src/framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ export class MidwayFaaSFramework extends BaseFramework<
});

this.containerLoader.registerHook(LOGGER_KEY, (key, target) => {
return (
target[REQUEST_OBJ_CTX_KEY]?.['logger'] ||
this.app.getLogger()
);
return target[REQUEST_OBJ_CTX_KEY]?.['logger'] || this.app.getLogger();
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mock/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@midwayjs/mock",
"version": "2.3.4",
"version": "2.3.5",
"description": "create your test app from midway framework",
"main": "dist/index",
"typings": "dist/index.d.ts",
Expand Down
Loading

0 comments on commit 3319872

Please sign in to comment.