@midwayjs/mock 3.11.6 → 3.11.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/creator.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import { IMidwayApplication, IMidwayFramework, MidwayFrameworkType } from '@midwayjs/core';
2
- import { ComponentModule, MockAppConfigurationOptions } from './interface';
1
+ import { IMidwayApplication, IMidwayFramework } from '@midwayjs/core';
2
+ import { ComponentModule, MockAppConfigurationOptions, IBootstrapAppStarter } from './interface';
3
3
  export declare function create<T extends IMidwayFramework<any, any, any, any, any>>(appDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
4
4
  new (...args: any[]): T;
5
5
  } | ComponentModule): Promise<T>;
6
6
  export declare function createApp<T extends IMidwayFramework<any, any, any, any, any>>(baseDir?: string, options?: MockAppConfigurationOptions, customFramework?: {
7
7
  new (...args: any[]): T;
8
8
  } | ComponentModule): Promise<ReturnType<T['getApplication']>>;
9
- export declare function close<T extends IMidwayApplication<any>>(app: T, options?: {
9
+ export declare function close(app: IMidwayApplication<any> | {
10
+ close: (...args: any[]) => void;
11
+ }, options?: {
10
12
  cleanLogsDir?: boolean;
11
13
  cleanTempDir?: boolean;
12
14
  sleep?: number;
@@ -14,18 +16,11 @@ export declare function close<T extends IMidwayApplication<any>>(app: T, options
14
16
  export declare function createFunctionApp<T extends IMidwayFramework<any, any, any, any, any>, Y = ReturnType<T['getApplication']>>(baseDir?: string | MockAppConfigurationOptions, options?: MockAppConfigurationOptions, customFrameworkModule?: {
15
17
  new (...args: any[]): T;
16
18
  } | ComponentModule): Promise<Y>;
17
- declare class BootstrapAppStarter {
18
- getApp(type: MidwayFrameworkType | string): IMidwayApplication<any>;
19
- close(options?: {
20
- sleep?: number;
21
- }): Promise<void>;
22
- }
23
19
  /**
24
20
  * Create a real project but not ready or a virtual project
25
21
  * @param baseDir
26
22
  * @param options
27
23
  */
28
24
  export declare function createLightApp(baseDir?: string, options?: MockAppConfigurationOptions): Promise<IMidwayApplication>;
29
- export declare function createBootstrap(entryFile: string): Promise<BootstrapAppStarter>;
30
- export {};
25
+ export declare function createBootstrap(entryFile: string, options?: MockAppConfigurationOptions): Promise<IBootstrapAppStarter>;
31
26
  //# sourceMappingURL=creator.d.ts.map
package/dist/creator.js CHANGED
@@ -155,24 +155,31 @@ exports.createApp = createApp;
155
155
  async function close(app, options) {
156
156
  if (!app)
157
157
  return;
158
- debug(`[mock]: Closing app, appDir=${app.getAppDir()}`);
159
- options = options || {};
160
- await (0, core_1.destroyGlobalApplicationContext)(app.getApplicationContext());
161
- if ((0, utils_1.isTestEnvironment)()) {
162
- // clean first
163
- if (options.cleanLogsDir && !(0, utils_1.isWin32)()) {
164
- await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'logs'));
165
- }
166
- if (core_1.MidwayFrameworkType.WEB === app.getFrameworkType()) {
167
- if (options.cleanTempDir && !(0, utils_1.isWin32)()) {
168
- await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'run'));
158
+ if (app instanceof BootstrapAppStarter ||
159
+ (typeof app['close'] === 'function' && !app['getConfig'])) {
160
+ await app['close'](options);
161
+ }
162
+ else {
163
+ app = app;
164
+ debug(`[mock]: Closing app, appDir=${app.getAppDir()}`);
165
+ options = options || {};
166
+ await (0, core_1.destroyGlobalApplicationContext)(app.getApplicationContext());
167
+ if ((0, utils_1.isTestEnvironment)()) {
168
+ // clean first
169
+ if (options.cleanLogsDir && !(0, utils_1.isWin32)()) {
170
+ await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'logs'));
171
+ }
172
+ if (core_1.MidwayFrameworkType.WEB === app.getFrameworkType()) {
173
+ if (options.cleanTempDir && !(0, utils_1.isWin32)()) {
174
+ await (0, utils_1.removeFile)((0, path_1.join)(app.getAppDir(), 'run'));
175
+ }
176
+ }
177
+ if (options.sleep > 0) {
178
+ await (0, core_1.sleep)(options.sleep);
179
+ }
180
+ else {
181
+ await (0, core_1.sleep)(50);
169
182
  }
170
- }
171
- if (options.sleep > 0) {
172
- await (0, core_1.sleep)(options.sleep);
173
- }
174
- else {
175
- await (0, core_1.sleep)(50);
176
183
  }
177
184
  }
178
185
  }
@@ -183,7 +190,13 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
183
190
  options = baseDir;
184
191
  baseDir = options.appDir || '';
185
192
  }
193
+ // v3 新的处理 bootstrap 过来的 faas 入口
194
+ if (options.entryFile) {
195
+ const exportModules = require((0, path_1.join)(baseDir, options.entryFile));
196
+ options.starter = exportModules.getStarter();
197
+ }
186
198
  let starterName;
199
+ // 老的 f.yml 逻辑
187
200
  if (!options.starter) {
188
201
  if (!baseDir) {
189
202
  baseDir = process.cwd();
@@ -422,11 +435,22 @@ async function createLightApp(baseDir = '', options = {}) {
422
435
  });
423
436
  }
424
437
  exports.createLightApp = createLightApp;
425
- async function createBootstrap(entryFile) {
426
- await create(undefined, {
427
- entryFile,
428
- });
429
- return new BootstrapAppStarter();
438
+ async function createBootstrap(entryFile, options = {}) {
439
+ if ((0, core_1.safeRequire)('@midwayjs/faas')) {
440
+ options.entryFile = entryFile;
441
+ const app = await createFunctionApp(process.cwd(), options);
442
+ return {
443
+ close: async () => {
444
+ return close(app);
445
+ },
446
+ };
447
+ }
448
+ else {
449
+ await create(undefined, {
450
+ entryFile,
451
+ });
452
+ return new BootstrapAppStarter();
453
+ }
430
454
  }
431
455
  exports.createBootstrap = createBootstrap;
432
456
  //# sourceMappingURL=creator.js.map
@@ -1,10 +1,17 @@
1
- import { IMidwayBootstrapOptions } from '@midwayjs/core';
1
+ import { IMidwayApplication, IMidwayBootstrapOptions, MidwayFrameworkType } from '@midwayjs/core';
2
2
  export interface MockAppConfigurationOptions extends IMidwayBootstrapOptions {
3
3
  cleanLogsDir?: boolean;
4
4
  cleanTempDir?: boolean;
5
5
  ssl?: boolean;
6
+ entryFile?: string;
6
7
  }
7
8
  export type ComponentModule = {
8
9
  Configuration: new () => any;
9
10
  };
11
+ export interface IBootstrapAppStarter {
12
+ getApp?(type: MidwayFrameworkType | string): IMidwayApplication<any>;
13
+ close(options?: {
14
+ sleep?: number;
15
+ }): Promise<void>;
16
+ }
10
17
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/mock",
3
- "version": "3.11.6",
3
+ "version": "3.11.10",
4
4
  "description": "create your test app from midway framework",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -49,5 +49,5 @@
49
49
  "type": "git",
50
50
  "url": "https://github.com/midwayjs/midway.git"
51
51
  },
52
- "gitHead": "d1ca8ca3ee5223c1c034ad3c97d335348931404b"
52
+ "gitHead": "521c42cc4af8850b77c5cf1f040b7430a74db041"
53
53
  }