diff --git a/packages/context/src/factory/applicationContext.ts b/packages/context/src/factory/applicationContext.ts index 291bfb5f5437..0930e94f3301 100644 --- a/packages/context/src/factory/applicationContext.ts +++ b/packages/context/src/factory/applicationContext.ts @@ -290,7 +290,6 @@ export class BaseApplicationContext extends EventEmitter implements IApplication try { return g.to_dot(); - // fs.writeSync(imagePath, g.to_dot()); } catch (err) { console.error('generate injection dependency tree fail, err = ', err.message); } diff --git a/packages/midway-core/src/loader.ts b/packages/midway-core/src/loader.ts index aaf3a93b5be7..f0987ba0f000 100644 --- a/packages/midway-core/src/loader.ts +++ b/packages/midway-core/src/loader.ts @@ -204,4 +204,14 @@ export class MidwayLoader extends EggLoader { // 插件加载完毕 this.pluginLoaded = true; } + + getAppInfo() { + if (!this.appInfo) { + const appInfo = super.getAppInfo(); + this.appInfo = Object.assign(appInfo, { + root: appInfo.env === 'local' || appInfo.env === 'unittest' ? this.appDir : appInfo.root + }); + } + return this.appInfo; + } } diff --git a/packages/midway-core/test/fixtures/base-app-function/src/config/plugin.ts b/packages/midway-core/test/fixtures/base-app-function/src/config/plugin.ts index e598173ff4ea..077c3c1a4790 100644 --- a/packages/midway-core/test/fixtures/base-app-function/src/config/plugin.ts +++ b/packages/midway-core/test/fixtures/base-app-function/src/config/plugin.ts @@ -1,4 +1,4 @@ -const path = require('path'); +import * as path from 'path'; module.exports = { // 默认开启的插件 @@ -10,4 +10,4 @@ module.exports = { enable: true, path: path.join(__dirname, '../plugins/plugin2'), } -}; \ No newline at end of file +}; diff --git a/packages/midway-core/test/loader.test.ts b/packages/midway-core/test/loader.test.ts index ee1c614989cf..a5adced6abde 100644 --- a/packages/midway-core/test/loader.test.ts +++ b/packages/midway-core/test/loader.test.ts @@ -1,7 +1,7 @@ const assert = require('assert'); const request = require('supertest'); const utils = require('./utils'); -const mm = require('mm'); +import * as path from 'path'; describe('/test/loader.test.ts', () => { @@ -16,6 +16,10 @@ describe('/test/loader.test.ts', () => { after(() => app.close()); + it('should get config merge', () => { + assert(app.config.rundir, path.join(__dirname, './fixtures/enhance/base-app/run')); + }); + it('should load ts directory', (done) => { request(app.callback()) .get('/api') @@ -190,7 +194,7 @@ describe('/test/loader.test.ts', () => { it('disable js app loader should be ok', async () => { try { const reqCtx = await app.applicationContext.getAsync('requestContext'); - reqCtx.updateContext({ logger: new Console }); + reqCtx.updateContext({ logger: console }); reqCtx.get('ctx'); reqCtx.getAsync('logger'); } catch (e) { diff --git a/packages/midway-web/test/enhance.test.ts b/packages/midway-web/test/enhance.test.ts index 0858baf7527f..c70bbfd97eb1 100644 --- a/packages/midway-web/test/enhance.test.ts +++ b/packages/midway-web/test/enhance.test.ts @@ -18,6 +18,10 @@ describe('/test/enhance.test.ts', () => { after(() => app.close()); + it('should get config merge', () => { + assert(app.config.rundir, path.join(__dirname, './fixtures/enhance/base-app/run')); + }); + it('should load ts directory', (done) => { request(app.callback()) .get('/api')