@midwayjs/core 3.12.0 → 3.12.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/setup.d.ts +3 -3
- package/dist/setup.js +7 -7
- package/dist/util/index.js +16 -4
- package/package.json +2 -2
package/dist/setup.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export declare function destroyGlobalApplicationContext(applicationContext: IMid
|
|
|
9
9
|
* prepare applicationContext
|
|
10
10
|
* @param globalOptions
|
|
11
11
|
*/
|
|
12
|
-
export declare function
|
|
12
|
+
export declare function prepareGlobalApplicationContextAsync(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer | MidwayContainer>;
|
|
13
13
|
/**
|
|
14
|
-
* prepare applicationContext, it use in egg framework
|
|
14
|
+
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
15
15
|
* @param globalOptions
|
|
16
16
|
*/
|
|
17
|
-
export declare function
|
|
17
|
+
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): IMidwayContainer | MidwayContainer;
|
|
18
18
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/setup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareGlobalApplicationContext = exports.prepareGlobalApplicationContextAsync = exports.destroyGlobalApplicationContext = exports.initializeGlobalApplicationContext = void 0;
|
|
4
4
|
const _1 = require("./");
|
|
5
5
|
const config_default_1 = require("./config/config.default");
|
|
6
6
|
const decorator_1 = require("./decorator");
|
|
@@ -17,7 +17,7 @@ function printStepDebugInfo(stepInfo) {
|
|
|
17
17
|
* @param globalOptions
|
|
18
18
|
*/
|
|
19
19
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
20
|
-
const applicationContext = await
|
|
20
|
+
const applicationContext = await prepareGlobalApplicationContextAsync(globalOptions);
|
|
21
21
|
printStepDebugInfo('Init logger');
|
|
22
22
|
// init logger
|
|
23
23
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService, [
|
|
@@ -71,7 +71,7 @@ exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
|
71
71
|
* prepare applicationContext
|
|
72
72
|
* @param globalOptions
|
|
73
73
|
*/
|
|
74
|
-
async function
|
|
74
|
+
async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
75
75
|
var _a, _b, _c, _d, _e;
|
|
76
76
|
printStepDebugInfo('Ready to create applicationContext');
|
|
77
77
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
@@ -174,12 +174,12 @@ async function prepareGlobalApplicationContext(globalOptions) {
|
|
|
174
174
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
175
175
|
return applicationContext;
|
|
176
176
|
}
|
|
177
|
-
exports.
|
|
177
|
+
exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAsync;
|
|
178
178
|
/**
|
|
179
|
-
* prepare applicationContext, it use in egg framework
|
|
179
|
+
* prepare applicationContext, it use in egg framework, hooks and serverless function generator
|
|
180
180
|
* @param globalOptions
|
|
181
181
|
*/
|
|
182
|
-
function
|
|
182
|
+
function prepareGlobalApplicationContext(globalOptions) {
|
|
183
183
|
var _a, _b, _c, _d;
|
|
184
184
|
printStepDebugInfo('Ready to create applicationContext');
|
|
185
185
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
@@ -269,5 +269,5 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
269
269
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
270
270
|
return applicationContext;
|
|
271
271
|
}
|
|
272
|
-
exports.
|
|
272
|
+
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
273
273
|
//# sourceMappingURL=setup.js.map
|
package/dist/util/index.js
CHANGED
|
@@ -12,6 +12,7 @@ const uuid_1 = require("./uuid");
|
|
|
12
12
|
const flatted_1 = require("./flatted");
|
|
13
13
|
const crypto = require("crypto");
|
|
14
14
|
const types_1 = require("./types");
|
|
15
|
+
const url_1 = require("url");
|
|
15
16
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
16
17
|
/**
|
|
17
18
|
* @since 2.0.0
|
|
@@ -54,6 +55,7 @@ const safeRequire = (p, enabledCache = true) => {
|
|
|
54
55
|
}
|
|
55
56
|
};
|
|
56
57
|
exports.safeRequire = safeRequire;
|
|
58
|
+
const innerLoadModuleCache = {};
|
|
57
59
|
/**
|
|
58
60
|
* load module, and it can be chosen commonjs or esm mode
|
|
59
61
|
* @param p
|
|
@@ -68,6 +70,7 @@ const loadModule = async (p, options = {}) => {
|
|
|
68
70
|
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
69
71
|
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
70
72
|
}
|
|
73
|
+
debug(`[core]: load module ${p}, cache: ${options.enableCache}, mode: ${options.loadMode}, safeLoad: ${options.safeLoad}`);
|
|
71
74
|
try {
|
|
72
75
|
if (options.enableCache) {
|
|
73
76
|
if (options.loadMode === 'commonjs') {
|
|
@@ -76,12 +79,21 @@ const loadModule = async (p, options = {}) => {
|
|
|
76
79
|
else {
|
|
77
80
|
// if json file, import need add options
|
|
78
81
|
if (p.endsWith('.json')) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
/**
|
|
83
|
+
* attention: import json not support under nodejs 16
|
|
84
|
+
* use readFileSync instead
|
|
85
|
+
*/
|
|
86
|
+
if (!innerLoadModuleCache[p]) {
|
|
87
|
+
// return (await import(p, { assert: { type: 'json' } })).default;
|
|
88
|
+
const content = (0, fs_1.readFileSync)(p, {
|
|
89
|
+
encoding: 'utf-8',
|
|
90
|
+
});
|
|
91
|
+
innerLoadModuleCache[p] = JSON.parse(content);
|
|
92
|
+
}
|
|
93
|
+
return innerLoadModuleCache[p];
|
|
82
94
|
}
|
|
83
95
|
else {
|
|
84
|
-
return await import(p);
|
|
96
|
+
return await import((0, url_1.pathToFileURL)(p).href);
|
|
85
97
|
}
|
|
86
98
|
}
|
|
87
99
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.2",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "2f385d135df1dcb65bfdfd25a0c97476773f8315"
|
|
46
46
|
}
|