@midwayjs/mock 3.11.12 → 3.12.0-beta.2
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.js +65 -21
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +5 -2
- package/package.json +4 -4
- package/LICENSE +0 -21
package/dist/creator.js
CHANGED
|
@@ -42,13 +42,6 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
42
42
|
}
|
|
43
43
|
(0, logger_1.clearAllLoggers)();
|
|
44
44
|
options = options || {};
|
|
45
|
-
if (options.baseDir) {
|
|
46
|
-
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
47
|
-
}
|
|
48
|
-
else if (appDir) {
|
|
49
|
-
options.baseDir = `${appDir}/src`;
|
|
50
|
-
(0, core_1.safeRequire)((0, path_1.join)(`${options.baseDir}`, 'interface'));
|
|
51
|
-
}
|
|
52
45
|
if (options.entryFile) {
|
|
53
46
|
// start from entry file, like bootstrap.js
|
|
54
47
|
options.entryFile = formatPath(appDir, options.entryFile);
|
|
@@ -73,8 +66,28 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
73
66
|
});
|
|
74
67
|
return;
|
|
75
68
|
}
|
|
69
|
+
if (!options.moduleLoadType) {
|
|
70
|
+
const pkgJSON = await (0, core_1.loadModule)((0, path_1.join)(appDir, 'package.json'), {
|
|
71
|
+
safeLoad: true,
|
|
72
|
+
enableCache: false,
|
|
73
|
+
});
|
|
74
|
+
options.fileLoadMode = (pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.type) === 'module' ? 'esm' : 'commonjs';
|
|
75
|
+
}
|
|
76
|
+
if (options.baseDir) {
|
|
77
|
+
await (0, core_1.loadModule)((0, path_1.join)(`${options.baseDir}`, 'interface.ts'), {
|
|
78
|
+
safeLoad: true,
|
|
79
|
+
loadMode: options.fileLoadMode,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (appDir) {
|
|
83
|
+
options.baseDir = `${appDir}/src`;
|
|
84
|
+
await (0, core_1.loadModule)((0, path_1.join)(`${options.baseDir}`, 'interface.ts'), {
|
|
85
|
+
safeLoad: true,
|
|
86
|
+
loadMode: options.fileLoadMode,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
76
89
|
if (!options.imports && customFramework) {
|
|
77
|
-
options.imports = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
90
|
+
options.imports = await (0, utils_1.transformFrameworkToConfiguration)(customFramework, options.moduleLoadType);
|
|
78
91
|
}
|
|
79
92
|
if (customFramework === null || customFramework === void 0 ? void 0 : customFramework['Configuration']) {
|
|
80
93
|
options.imports = customFramework;
|
|
@@ -125,10 +138,11 @@ async function create(appDir, options = {}, customFramework) {
|
|
|
125
138
|
...options,
|
|
126
139
|
appDir,
|
|
127
140
|
asyncContextManager: (0, async_hooks_context_manager_1.createContextManager)(),
|
|
128
|
-
imports: []
|
|
129
|
-
.
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
imports: [].concat(options.imports).concat(options.baseDir
|
|
142
|
+
? await (0, core_1.loadModule)((0, path_1.join)(options.baseDir, 'configuration.ts'), {
|
|
143
|
+
safeLoad: true,
|
|
144
|
+
loadMode: options.fileLoadMode,
|
|
145
|
+
})
|
|
132
146
|
: []),
|
|
133
147
|
});
|
|
134
148
|
if (customFramework) {
|
|
@@ -213,7 +227,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
213
227
|
const doc = yaml.load((0, fs_1.readFileSync)((0, path_1.join)(baseDir, 'f.yml'), 'utf8'));
|
|
214
228
|
starterName = (_a = doc === null || doc === void 0 ? void 0 : doc['provider']) === null || _a === void 0 ? void 0 : _a['starter'];
|
|
215
229
|
if (starterName) {
|
|
216
|
-
const m = (0, core_1.
|
|
230
|
+
const m = await (0, core_1.loadModule)(starterName);
|
|
217
231
|
if (m && m['BootstrapStarter']) {
|
|
218
232
|
options.starter = new m['BootstrapStarter']();
|
|
219
233
|
}
|
|
@@ -238,13 +252,24 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
238
252
|
}
|
|
239
253
|
}
|
|
240
254
|
(0, logger_1.clearAllLoggers)();
|
|
255
|
+
const pkgJSON = await (0, core_1.loadModule)((0, path_1.join)(options.appDir, 'package.json'), {
|
|
256
|
+
safeLoad: true,
|
|
257
|
+
enableCache: false,
|
|
258
|
+
});
|
|
259
|
+
options.fileLoadMode = (pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.type) === 'module' ? 'esm' : 'commonjs';
|
|
241
260
|
options = options || {};
|
|
242
261
|
if (options.baseDir) {
|
|
243
|
-
(0, core_1.
|
|
262
|
+
await (0, core_1.loadModule)((0, path_1.join)(`${options.baseDir}`, 'interface.ts'), {
|
|
263
|
+
safeLoad: true,
|
|
264
|
+
loadMode: options.fileLoadMode,
|
|
265
|
+
});
|
|
244
266
|
}
|
|
245
267
|
else if (options.appDir) {
|
|
246
268
|
options.baseDir = `${options.appDir}/src`;
|
|
247
|
-
(0, core_1.
|
|
269
|
+
await (0, core_1.loadModule)((0, path_1.join)(`${options.baseDir}`, 'interface.ts'), {
|
|
270
|
+
safeLoad: true,
|
|
271
|
+
loadMode: options.fileLoadMode,
|
|
272
|
+
});
|
|
248
273
|
}
|
|
249
274
|
// new mode
|
|
250
275
|
const exports = options.starter.start(options);
|
|
@@ -364,7 +389,7 @@ async function createFunctionApp(baseDir, options = {}, customFrameworkModule) {
|
|
|
364
389
|
'@ali/serverless-app',
|
|
365
390
|
'@midwayjs/serverless-app',
|
|
366
391
|
]);
|
|
367
|
-
const serverlessModule = (0, utils_1.transformFrameworkToConfiguration)(customFramework);
|
|
392
|
+
const serverlessModule = await (0, utils_1.transformFrameworkToConfiguration)(customFramework, options.moduleLoadType);
|
|
368
393
|
if (serverlessModule) {
|
|
369
394
|
if (options && options.imports) {
|
|
370
395
|
options.imports.unshift(serverlessModule);
|
|
@@ -401,6 +426,9 @@ class LightFramework extends core_1.BaseFramework {
|
|
|
401
426
|
}
|
|
402
427
|
}
|
|
403
428
|
class BootstrapAppStarter {
|
|
429
|
+
constructor(options) {
|
|
430
|
+
this.options = options;
|
|
431
|
+
}
|
|
404
432
|
getApp(type) {
|
|
405
433
|
const applicationContext = (0, core_1.getCurrentApplicationContext)();
|
|
406
434
|
const applicationManager = applicationContext.get(core_1.MidwayApplicationManager);
|
|
@@ -408,7 +436,10 @@ class BootstrapAppStarter {
|
|
|
408
436
|
}
|
|
409
437
|
async close(options = {}) {
|
|
410
438
|
// eslint-disable-next-line node/no-extraneous-require
|
|
411
|
-
const BootstrapModule = (0, core_1.
|
|
439
|
+
const BootstrapModule = await (0, core_1.loadModule)('@midwayjs/bootstrap', {
|
|
440
|
+
loadMode: this.options.fileLoadMode,
|
|
441
|
+
safeLoad: true,
|
|
442
|
+
});
|
|
412
443
|
if (BootstrapModule === null || BootstrapModule === void 0 ? void 0 : BootstrapModule.Bootstrap) {
|
|
413
444
|
await BootstrapModule.Bootstrap.stop();
|
|
414
445
|
}
|
|
@@ -436,19 +467,32 @@ async function createLightApp(baseDir = '', options = {}) {
|
|
|
436
467
|
},
|
|
437
468
|
},
|
|
438
469
|
}, (_a = options.globalConfig) !== null && _a !== void 0 ? _a : {});
|
|
470
|
+
if (!options.moduleLoadType) {
|
|
471
|
+
const cwd = process.cwd();
|
|
472
|
+
const pkgJSON = await (0, core_1.loadModule)((0, path_1.join)(cwd, 'package.json'), {
|
|
473
|
+
safeLoad: true,
|
|
474
|
+
enableCache: false,
|
|
475
|
+
});
|
|
476
|
+
options.fileLoadMode = (pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.type) === 'module' ? 'esm' : 'commonjs';
|
|
477
|
+
}
|
|
439
478
|
return createApp(baseDir, {
|
|
440
479
|
...options,
|
|
441
|
-
imports: [
|
|
480
|
+
imports: [
|
|
481
|
+
await (0, utils_1.transformFrameworkToConfiguration)(LightFramework, options.moduleLoadType),
|
|
482
|
+
].concat(options === null || options === void 0 ? void 0 : options.imports),
|
|
442
483
|
});
|
|
443
484
|
}
|
|
444
485
|
exports.createLightApp = createLightApp;
|
|
445
486
|
async function createBootstrap(entryFile, options = {}) {
|
|
487
|
+
const cwd = process.cwd();
|
|
446
488
|
if (!options.bootstrapMode) {
|
|
447
|
-
options.bootstrapMode = (0,
|
|
489
|
+
options.bootstrapMode = (0, fs_1.existsSync)((0, path_1.join)(cwd, 'node_modules/@midwayjs/faas'))
|
|
490
|
+
? 'faas'
|
|
491
|
+
: 'app';
|
|
448
492
|
}
|
|
449
493
|
if (options.bootstrapMode === 'faas') {
|
|
450
494
|
options.entryFile = entryFile;
|
|
451
|
-
const app = await createFunctionApp(
|
|
495
|
+
const app = await createFunctionApp(cwd, options);
|
|
452
496
|
return {
|
|
453
497
|
close: async () => {
|
|
454
498
|
return close(app);
|
|
@@ -459,7 +503,7 @@ async function createBootstrap(entryFile, options = {}) {
|
|
|
459
503
|
await create(undefined, {
|
|
460
504
|
entryFile,
|
|
461
505
|
});
|
|
462
|
-
return new BootstrapAppStarter();
|
|
506
|
+
return new BootstrapAppStarter(options);
|
|
463
507
|
}
|
|
464
508
|
}
|
|
465
509
|
exports.createBootstrap = createBootstrap;
|
package/dist/utils.d.ts
CHANGED
|
@@ -7,10 +7,10 @@ export declare function findFirstExistModule(moduleList: any): ComponentModule;
|
|
|
7
7
|
* transform a framework component or framework module to configuration class
|
|
8
8
|
* @param Framework
|
|
9
9
|
*/
|
|
10
|
-
export declare function transformFrameworkToConfiguration<T extends IMidwayFramework<any, any, any>>(Framework: any): {
|
|
10
|
+
export declare function transformFrameworkToConfiguration<T extends IMidwayFramework<any, any, any>>(Framework: any, loadMode: 'commonjs' | 'esm'): Promise<{
|
|
11
11
|
[key: string]: any;
|
|
12
12
|
Configuration: any;
|
|
13
|
-
}
|
|
13
|
+
}>;
|
|
14
14
|
export declare function removeFile(file: string): Promise<void>;
|
|
15
15
|
export declare function mergeGlobalConfig(globalConfig: any, newConfigObject: Record<string, any>): any;
|
|
16
16
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.js
CHANGED
|
@@ -39,12 +39,15 @@ exports.findFirstExistModule = findFirstExistModule;
|
|
|
39
39
|
* transform a framework component or framework module to configuration class
|
|
40
40
|
* @param Framework
|
|
41
41
|
*/
|
|
42
|
-
function transformFrameworkToConfiguration(Framework) {
|
|
42
|
+
async function transformFrameworkToConfiguration(Framework, loadMode) {
|
|
43
43
|
if (!Framework)
|
|
44
44
|
return null;
|
|
45
45
|
let CustomFramework = Framework;
|
|
46
46
|
if (typeof Framework === 'string') {
|
|
47
|
-
Framework = (0, core_1.
|
|
47
|
+
Framework = await (0, core_1.loadModule)(Framework, {
|
|
48
|
+
loadMode,
|
|
49
|
+
safeLoad: true,
|
|
50
|
+
});
|
|
48
51
|
}
|
|
49
52
|
if (Framework.Configuration) {
|
|
50
53
|
return Framework;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mock",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.12.0-beta.2",
|
|
4
4
|
"description": "create your test app from midway framework",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/core": "^3.11.
|
|
30
|
+
"@midwayjs/core": "^3.11.15",
|
|
31
31
|
"@midwayjs/logger": "^2.15.0",
|
|
32
32
|
"@types/amqplib": "0.10.1",
|
|
33
33
|
"amqplib": "0.10.3",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"ws": "8.13.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@midwayjs/async-hooks-context-manager": "^3.11.
|
|
40
|
+
"@midwayjs/async-hooks-context-manager": "^3.11.15",
|
|
41
41
|
"@types/superagent": "4.1.14",
|
|
42
42
|
"@types/supertest": "2.0.12",
|
|
43
43
|
"js-yaml": "4.1.0",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"type": "git",
|
|
50
50
|
"url": "https://github.com/midwayjs/midway.git"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "a603d2348d6141f8f723901498f03a162a037708"
|
|
53
53
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2013 - Now midwayjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|