Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty framework ready #882

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/core/src/util/emptyFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { BaseFramework } from '../baseFramework';
import { IMidwayApplication, IMidwayBootstrapOptions } from '../interface';
import { MidwayFrameworkType } from '@midwayjs/decorator';

/**
* 一个不 ready 的空框架
*/
export class EmptyFramework extends BaseFramework<any, any, any> {
getApplication(): any {
return this.app;
Expand All @@ -20,4 +23,31 @@ export class EmptyFramework extends BaseFramework<any, any, any> {
getDefaultContextLoggerClass() {
return super.getDefaultContextLoggerClass();
}

async containerReady() {}

async afterContainerReady() {}
}

/**
* 一个全量的空框架
*/
export class LightFramework extends BaseFramework<any, any, any> {
getApplication(): any {
return this.app;
}

getFrameworkType(): MidwayFrameworkType {
return MidwayFrameworkType.CUSTOM;
}

async run(): Promise<void> {}

async applicationInitialize(options: IMidwayBootstrapOptions) {
this.app = {} as IMidwayApplication;
}

getDefaultContextLoggerClass() {
return super.getDefaultContextLoggerClass();
}
}
4 changes: 2 additions & 2 deletions packages/core/src/util/webRouterCollector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EmptyFramework } from './emptyFramework';
import { LightFramework } from './emptyFramework';
import {
CONTROLLER_KEY,
ControllerOption,
Expand Down Expand Up @@ -90,7 +90,7 @@ export class WebRouterCollector {

protected async analyze() {
if (!MidwayContainer.parentDefinitionMetadata) {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: this.baseDir,
});
Expand Down
62 changes: 31 additions & 31 deletions packages/core/test/baseFramework.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import * as mm from 'mm';
import sinon = require('sinon');
import { LifeCycleTest, LifeCycleTest1, TestBinding } from "./fixtures/lifecycle";
import { EmptyFramework } from '../src/util/emptyFramework';
import { LightFramework } from '../src/util/emptyFramework';

@Provide()
class TestModule {
Expand All @@ -32,7 +32,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it.skip('should load js directory and auto disable', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(__dirname, './fixtures/js-app-loader'),
isTsMode: false,
Expand All @@ -47,7 +47,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should load preload module', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(__dirname, './fixtures/base-app/src'),
preloadModules: [TestModule],
Expand All @@ -59,7 +59,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should load configuration', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -82,7 +82,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should load config.*.ts by default env', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -98,7 +98,7 @@ describe('/test/baseFramework.test.ts', () => {

it('should load config.*.ts by process.env', async () => {
mm(process.env, 'NODE_ENV', 'local');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -118,7 +118,7 @@ describe('/test/baseFramework.test.ts', () => {
callback(m);
});

const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -137,7 +137,7 @@ describe('/test/baseFramework.test.ts', () => {

it('should load with no package.json', async () => {
mm(process.env, 'MIDWAY_SERVER_ENV', 'local');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -160,7 +160,7 @@ describe('/test/baseFramework.test.ts', () => {

it('should load configuration with namespace', async () => {
mm(process.env, 'MIDWAY_SERVER_ENV', 'local');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('/test/baseFramework.test.ts', () => {

it('should load configuration with object', async () => {
mm(process.env, 'MIDWAY_SERVER_ENV', 'local');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('/test/baseFramework.test.ts', () => {
// });

it('should load conflict without error', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -268,7 +268,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load default env', async () => {
mm(process.env, 'NODE_ENV', '');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -285,7 +285,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load prod env', async () => {
mm(process.env, 'NODE_ENV', 'prod');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -302,7 +302,7 @@ describe('/test/baseFramework.test.ts', () => {

it('load daily env', async () => {
mm(process.env, 'NODE_ENV', 'daily');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -320,7 +320,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load pre env', async () => {
mm(process.env, 'NODE_ENV', 'pre');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -339,7 +339,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load local env', async () => {
mm(process.env, 'NODE_ENV', 'local');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -362,7 +362,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load default env', async () => {
mm(process.env, 'NODE_ENV', '');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -388,7 +388,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load prod env', async () => {
mm(process.env, 'NODE_ENV', 'prod');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -407,7 +407,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load daily env', async () => {
mm(process.env, 'NODE_ENV', 'daily');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -426,7 +426,7 @@ describe('/test/baseFramework.test.ts', () => {
it('load pre env', async () => {
mm(process.env, 'NODE_ENV', 'pre');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -445,7 +445,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should test aspect decorator', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -469,7 +469,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should inject global value in component', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -484,7 +484,7 @@ describe('/test/baseFramework.test.ts', () => {
it('should load component in different type and different env', async () => {
mm(process.env, 'NODE_ENV', '');
mm(process.env, 'MIDWAY_SERVER_ENV', '');
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -500,7 +500,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('lifecycle should be ok', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand Down Expand Up @@ -544,7 +544,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should get service in a component write with app', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand Down Expand Up @@ -572,7 +572,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should create logger and match property between framework and app', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
framework.configure({});
await framework.initialize({
baseDir: path.join(
Expand Down Expand Up @@ -612,7 +612,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should support functional configuration and hook load', async () => {
const framework = new EmptyFramework();
const framework = new LightFramework();
await framework.initialize({
baseDir: path.join(
__dirname,
Expand All @@ -626,7 +626,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should run multi framework in one process and use cache', async () => {
const framework1 = new EmptyFramework();
const framework1 = new LightFramework();
framework1.configure({});
await framework1.initialize({
baseDir: path.join(
Expand All @@ -635,7 +635,7 @@ describe('/test/baseFramework.test.ts', () => {
),
});

class CustomTwoFramework extends EmptyFramework {
class CustomTwoFramework extends LightFramework {
async applicationInitialize(options: IMidwayBootstrapOptions) {
this.app = {} as IMidwayApplication;
}
Expand Down Expand Up @@ -667,7 +667,7 @@ describe('/test/baseFramework.test.ts', () => {
});

it('should run multi framework in one process and container independent', async () => {
const framework1 = new EmptyFramework();
const framework1 = new LightFramework();
framework1.configure({});
await framework1.initialize({
baseDir: path.join(
Expand All @@ -676,7 +676,7 @@ describe('/test/baseFramework.test.ts', () => {
),
});

class CustomTwoFramework extends EmptyFramework {
class CustomTwoFramework extends LightFramework {
async applicationInitialize(options: IMidwayBootstrapOptions) {
this.app = {} as IMidwayApplication;
}
Expand Down