@midwayjs/core 3.11.12-beta.3 → 3.11.15
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/LICENSE +21 -0
- package/dist/common/fileDetector.d.ts +5 -15
- package/dist/common/fileDetector.js +12 -32
- package/dist/context/container.d.ts +4 -3
- package/dist/context/container.js +29 -31
- package/dist/context/requestContainer.d.ts +1 -1
- package/dist/context/requestContainer.js +1 -1
- package/dist/decorator/common/configuration.d.ts +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/interface.d.ts +4 -7
- package/dist/service/slsFunctionService.js +1 -1
- package/dist/setup.d.ts +1 -6
- package/dist/setup.js +17 -117
- package/dist/util/httpclient.js +2 -2
- package/dist/util/index.d.ts +0 -11
- package/dist/util/index.js +1 -42
- package/package.json +3 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
|
@@ -2,14 +2,11 @@ import { IFileDetector, IMidwayContainer } from '../interface';
|
|
|
2
2
|
export declare abstract class AbstractFileDetector<T> implements IFileDetector {
|
|
3
3
|
options: T;
|
|
4
4
|
extraDetectorOptions: T;
|
|
5
|
-
constructor(options
|
|
6
|
-
abstract run(container: IMidwayContainer):
|
|
5
|
+
constructor(options: any);
|
|
6
|
+
abstract run(container: IMidwayContainer): any;
|
|
7
7
|
setExtraDetectorOptions(detectorOptions: T): void;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
* CommonJS module loader
|
|
11
|
-
*/
|
|
12
|
-
export declare class CommonJSFileDetector extends AbstractFileDetector<{
|
|
9
|
+
export declare class DirectoryFileDetector extends AbstractFileDetector<{
|
|
13
10
|
loadDir?: string | string[];
|
|
14
11
|
pattern?: string | string[];
|
|
15
12
|
ignore?: string | string[];
|
|
@@ -17,19 +14,12 @@ export declare class CommonJSFileDetector extends AbstractFileDetector<{
|
|
|
17
14
|
conflictCheck?: boolean;
|
|
18
15
|
}> {
|
|
19
16
|
private duplicateModuleCheckSet;
|
|
20
|
-
run(container: any):
|
|
21
|
-
getType(): 'commonjs' | 'module';
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* ES module loader
|
|
25
|
-
*/
|
|
26
|
-
export declare class ESModuleFileDetector extends CommonJSFileDetector {
|
|
27
|
-
getType(): 'commonjs' | 'module';
|
|
17
|
+
run(container: any): void;
|
|
28
18
|
}
|
|
29
19
|
export declare class CustomModuleDetector extends AbstractFileDetector<{
|
|
30
20
|
modules?: any[];
|
|
31
21
|
namespace?: string;
|
|
32
22
|
}> {
|
|
33
|
-
run(container: any):
|
|
23
|
+
run(container: any): void;
|
|
34
24
|
}
|
|
35
25
|
//# sourceMappingURL=fileDetector.d.ts.map
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomModuleDetector = exports.
|
|
3
|
+
exports.CustomModuleDetector = exports.DirectoryFileDetector = exports.AbstractFileDetector = void 0;
|
|
4
4
|
const types_1 = require("../util/types");
|
|
5
5
|
const glob_1 = require("@midwayjs/glob");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
7
|
const constants_1 = require("../constants");
|
|
8
8
|
const decorator_1 = require("../decorator");
|
|
9
|
-
async function requireModule(modulePath, type) {
|
|
10
|
-
if (type === 'commonjs') {
|
|
11
|
-
return require(modulePath);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
return await import(modulePath);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
9
|
class AbstractFileDetector {
|
|
18
10
|
constructor(options) {
|
|
19
11
|
this.options = options;
|
|
@@ -29,23 +21,23 @@ const DEFAULT_IGNORE_PATTERN = [
|
|
|
29
21
|
'**/logs/**',
|
|
30
22
|
'**/run/**',
|
|
31
23
|
'**/public/**',
|
|
24
|
+
'**/app/view/**',
|
|
25
|
+
'**/app/views/**',
|
|
26
|
+
'**/app/extend/**',
|
|
32
27
|
'**/node_modules/**',
|
|
33
28
|
'**/**.test.ts',
|
|
34
29
|
'**/**.test.js',
|
|
35
30
|
'**/__test__/**',
|
|
36
31
|
].concat(constants_1.IGNORE_PATTERN);
|
|
37
|
-
|
|
38
|
-
* CommonJS module loader
|
|
39
|
-
*/
|
|
40
|
-
class CommonJSFileDetector extends AbstractFileDetector {
|
|
32
|
+
class DirectoryFileDetector extends AbstractFileDetector {
|
|
41
33
|
constructor() {
|
|
42
34
|
super(...arguments);
|
|
43
35
|
this.duplicateModuleCheckSet = new Map();
|
|
44
36
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
run(container) {
|
|
38
|
+
const loadDirs = []
|
|
39
|
+
.concat(this.options.loadDir || [])
|
|
40
|
+
.concat(this.extraDetectorOptions.loadDir || []);
|
|
49
41
|
for (const dir of loadDirs) {
|
|
50
42
|
const fileResults = (0, glob_1.run)(DEFAULT_GLOB_PATTERN.concat(this.options.pattern || []).concat(this.extraDetectorOptions.pattern || []), {
|
|
51
43
|
cwd: dir,
|
|
@@ -68,7 +60,7 @@ class CommonJSFileDetector extends AbstractFileDetector {
|
|
|
68
60
|
}
|
|
69
61
|
};
|
|
70
62
|
for (const file of fileResults) {
|
|
71
|
-
const exports =
|
|
63
|
+
const exports = require(file);
|
|
72
64
|
// add module to set
|
|
73
65
|
container.bindClass(exports, {
|
|
74
66
|
namespace: this.options.namespace,
|
|
@@ -81,22 +73,10 @@ class CommonJSFileDetector extends AbstractFileDetector {
|
|
|
81
73
|
// check end
|
|
82
74
|
this.duplicateModuleCheckSet.clear();
|
|
83
75
|
}
|
|
84
|
-
getType() {
|
|
85
|
-
return 'commonjs';
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.CommonJSFileDetector = CommonJSFileDetector;
|
|
89
|
-
/**
|
|
90
|
-
* ES module loader
|
|
91
|
-
*/
|
|
92
|
-
class ESModuleFileDetector extends CommonJSFileDetector {
|
|
93
|
-
getType() {
|
|
94
|
-
return 'module';
|
|
95
|
-
}
|
|
96
76
|
}
|
|
97
|
-
exports.
|
|
77
|
+
exports.DirectoryFileDetector = DirectoryFileDetector;
|
|
98
78
|
class CustomModuleDetector extends AbstractFileDetector {
|
|
99
|
-
|
|
79
|
+
run(container) {
|
|
100
80
|
for (const module of this.options.modules) {
|
|
101
81
|
container.bindClass(module, {
|
|
102
82
|
namespace: this.options.namespace,
|
|
@@ -13,6 +13,7 @@ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
|
|
|
13
13
|
private fileDetector;
|
|
14
14
|
private attrMap;
|
|
15
15
|
private _namespaceSet;
|
|
16
|
+
private isLoad;
|
|
16
17
|
constructor(parent?: IMidwayContainer);
|
|
17
18
|
protected init(): void;
|
|
18
19
|
get objectCreateEventTarget(): EventEmitter;
|
|
@@ -21,8 +22,8 @@ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
|
|
|
21
22
|
get managedResolverFactory(): ManagedResolverFactory;
|
|
22
23
|
get identifierMapping(): IIdentifierRelationShip;
|
|
23
24
|
get namespaceSet(): Set<string>;
|
|
24
|
-
load(module
|
|
25
|
-
protected loadDefinitions(): void
|
|
25
|
+
load(module?: any): void;
|
|
26
|
+
protected loadDefinitions(): void;
|
|
26
27
|
bindClass(exports: any, options?: Partial<IObjectDefinition>): void;
|
|
27
28
|
bind<T>(target: T, options?: Partial<IObjectDefinition>): void;
|
|
28
29
|
bind<T>(identifier: ObjectIdentifier, target: T, options?: Partial<IObjectDefinition>): void;
|
|
@@ -34,7 +35,7 @@ export declare class MidwayContainer implements IMidwayContainer, IModuleStore {
|
|
|
34
35
|
protected getIdentifier(target: any): string;
|
|
35
36
|
protected getManagedResolverFactory(): ManagedResolverFactory;
|
|
36
37
|
stop(): Promise<void>;
|
|
37
|
-
ready(): void
|
|
38
|
+
ready(): void;
|
|
38
39
|
get<T>(identifier: {
|
|
39
40
|
new (...args: any[]): T;
|
|
40
41
|
}, args?: any[], objectContext?: ObjectContext): T;
|
|
@@ -14,6 +14,7 @@ const environmentService_1 = require("../service/environmentService");
|
|
|
14
14
|
const configService_1 = require("../service/configService");
|
|
15
15
|
const EventEmitter = require("events");
|
|
16
16
|
const error_1 = require("../error");
|
|
17
|
+
const extend_1 = require("../util/extend");
|
|
17
18
|
const types_1 = require("../util/types");
|
|
18
19
|
const util_1 = require("../util");
|
|
19
20
|
const debug = util.debuglog('midway:debug');
|
|
@@ -24,7 +25,7 @@ class ContainerConfiguration {
|
|
|
24
25
|
this.container = container;
|
|
25
26
|
this.loadedMap = new WeakMap();
|
|
26
27
|
this.namespaceList = [];
|
|
27
|
-
this.
|
|
28
|
+
this.detectorOptionsList = [];
|
|
28
29
|
}
|
|
29
30
|
load(module) {
|
|
30
31
|
let namespace = decorator_1.MAIN_MODULE_KEY;
|
|
@@ -55,7 +56,10 @@ class ContainerConfiguration {
|
|
|
55
56
|
namespace = configurationOptions.namespace;
|
|
56
57
|
this.namespaceList.push(namespace);
|
|
57
58
|
}
|
|
58
|
-
this.
|
|
59
|
+
this.detectorOptionsList.push({
|
|
60
|
+
conflictCheck: configurationOptions.conflictCheck,
|
|
61
|
+
...configurationOptions.detectorOptions,
|
|
62
|
+
});
|
|
59
63
|
debug(`[core]: load configuration in namespace="${namespace}"`);
|
|
60
64
|
this.addImports(configurationOptions.imports);
|
|
61
65
|
this.addImportObjects(configurationOptions.importObjects);
|
|
@@ -175,8 +179,8 @@ class ContainerConfiguration {
|
|
|
175
179
|
getNamespaceList() {
|
|
176
180
|
return this.namespaceList;
|
|
177
181
|
}
|
|
178
|
-
|
|
179
|
-
return this.
|
|
182
|
+
getDetectorOptionsList() {
|
|
183
|
+
return this.detectorOptionsList;
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
class MidwayContainer {
|
|
@@ -190,6 +194,7 @@ class MidwayContainer {
|
|
|
190
194
|
this.ctx = {};
|
|
191
195
|
this.attrMap = new Map();
|
|
192
196
|
this._namespaceSet = null;
|
|
197
|
+
this.isLoad = false;
|
|
193
198
|
this.parent = parent;
|
|
194
199
|
this.init();
|
|
195
200
|
}
|
|
@@ -232,37 +237,30 @@ class MidwayContainer {
|
|
|
232
237
|
return this._namespaceSet;
|
|
233
238
|
}
|
|
234
239
|
load(module) {
|
|
235
|
-
var _a
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
configuration.load(mod);
|
|
240
|
+
var _a;
|
|
241
|
+
if (module) {
|
|
242
|
+
// load configuration
|
|
243
|
+
const configuration = new ContainerConfiguration(this);
|
|
244
|
+
configuration.load(module);
|
|
245
|
+
for (const ns of configuration.getNamespaceList()) {
|
|
246
|
+
this.namespaceSet.add(ns);
|
|
247
|
+
debug(`[core]: load configuration in namespace="${ns}" complete`);
|
|
244
248
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// find user code configuration it's without namespace
|
|
252
|
-
const userCodeConfiguration = (_b = configurationOptionsList.find(options => !options.namespace)) !== null && _b !== void 0 ? _b : {};
|
|
253
|
-
this.fileDetector = (_c = userCodeConfiguration.detector) !== null && _c !== void 0 ? _c : this.fileDetector;
|
|
254
|
-
if (this.fileDetector) {
|
|
255
|
-
this.fileDetector.setExtraDetectorOptions({
|
|
256
|
-
conflictCheck: userCodeConfiguration.conflictCheck,
|
|
257
|
-
...userCodeConfiguration.detectorOptions,
|
|
258
|
-
});
|
|
249
|
+
const detectorOptionsMerged = {};
|
|
250
|
+
for (const detectorOptions of configuration.getDetectorOptionsList()) {
|
|
251
|
+
(0, extend_1.extend)(true, detectorOptionsMerged, detectorOptions);
|
|
252
|
+
}
|
|
253
|
+
(_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.setExtraDetectorOptions(detectorOptionsMerged);
|
|
254
|
+
this.isLoad = true;
|
|
259
255
|
}
|
|
260
256
|
}
|
|
261
257
|
loadDefinitions() {
|
|
262
|
-
|
|
263
|
-
if (this.
|
|
264
|
-
|
|
258
|
+
var _a;
|
|
259
|
+
if (!this.isLoad) {
|
|
260
|
+
this.load();
|
|
265
261
|
}
|
|
262
|
+
// load project file
|
|
263
|
+
(_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.run(this);
|
|
266
264
|
}
|
|
267
265
|
bindClass(exports, options) {
|
|
268
266
|
if (types_1.Types.isClass(exports) || types_1.Types.isFunction(exports)) {
|
|
@@ -413,7 +411,7 @@ class MidwayContainer {
|
|
|
413
411
|
this.registry.clearAll();
|
|
414
412
|
}
|
|
415
413
|
ready() {
|
|
416
|
-
|
|
414
|
+
this.loadDefinitions();
|
|
417
415
|
}
|
|
418
416
|
get(identifier, args, objectContext) {
|
|
419
417
|
var _a;
|
|
@@ -6,7 +6,7 @@ export declare class MidwayRequestContainer extends MidwayContainer {
|
|
|
6
6
|
init(): void;
|
|
7
7
|
get<T = any>(identifier: any, args?: any): T;
|
|
8
8
|
getAsync<T = any>(identifier: any, args?: any): Promise<T>;
|
|
9
|
-
ready():
|
|
9
|
+
ready(): void;
|
|
10
10
|
getContext(): {};
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=requestContainer.d.ts.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { IFileDetector } from '../../interface';
|
|
2
1
|
export interface IComponentInfo {
|
|
3
2
|
component: any;
|
|
4
3
|
enabledEnvironment?: string[];
|
|
@@ -18,7 +17,6 @@ export interface InjectionConfigurationOptions {
|
|
|
18
17
|
}> | Record<string, any>;
|
|
19
18
|
importConfigFilter?: (config: Record<string, any>) => Record<string, any>;
|
|
20
19
|
namespace?: string;
|
|
21
|
-
detector?: IFileDetector | false;
|
|
22
20
|
detectorOptions?: Record<string, any>;
|
|
23
21
|
conflictCheck?: boolean;
|
|
24
22
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export { AsyncContextManager, ASYNC_ROOT_CONTEXT, AsyncContext, } from './common
|
|
|
33
33
|
export * from './decorator';
|
|
34
34
|
export * from './decorator/decoratorManager';
|
|
35
35
|
export * from './decorator/constant';
|
|
36
|
-
export { safelyGet, safeRequire,
|
|
36
|
+
export { safelyGet, safeRequire, delegateTargetPrototypeMethod, delegateTargetMethod, delegateTargetProperties, delegateTargetAllPrototypeMethod, deprecatedOutput, transformRequestObjectByType, pathMatching, wrapMiddleware, wrapAsync, } from './util/';
|
|
37
37
|
export { extend } from './util/extend';
|
|
38
38
|
export * from './util/webRouterParam';
|
|
39
39
|
export * from './util/contextUtil';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FORMAT = exports.FileUtils = exports.PathFileUtil = exports.Types = exports.Utils = exports.sleep = exports.retryWith = exports.retryWithAsync = exports.extend = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.
|
|
17
|
+
exports.FORMAT = exports.FileUtils = exports.PathFileUtil = exports.Types = exports.Utils = exports.sleep = exports.retryWith = exports.retryWithAsync = exports.extend = exports.wrapAsync = exports.wrapMiddleware = exports.pathMatching = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.safeRequire = exports.safelyGet = exports.ASYNC_ROOT_CONTEXT = exports.DataSourceManager = exports.WebRouterCollector = exports.MidwayServerlessFunctionService = exports.MidwayWebRouterService = exports.MidwayMockService = exports.MidwayDecoratorService = exports.MidwayMiddlewareService = exports.MidwayLifeCycleService = exports.MidwayAspectService = exports.MidwayFrameworkService = exports.MidwayLoggerService = exports.MidwayInformationService = exports.MidwayEnvironmentService = exports.MidwayConfigService = exports.FunctionalConfiguration = exports.createConfiguration = exports.BaseFramework = exports.MidwayRequestContainer = void 0;
|
|
18
18
|
__exportStar(require("./interface"), exports);
|
|
19
19
|
__exportStar(require("./context/container"), exports);
|
|
20
20
|
var requestContainer_1 = require("./context/requestContainer");
|
|
@@ -74,7 +74,6 @@ __exportStar(require("./decorator/constant"), exports);
|
|
|
74
74
|
var util_1 = require("./util/");
|
|
75
75
|
Object.defineProperty(exports, "safelyGet", { enumerable: true, get: function () { return util_1.safelyGet; } });
|
|
76
76
|
Object.defineProperty(exports, "safeRequire", { enumerable: true, get: function () { return util_1.safeRequire; } });
|
|
77
|
-
Object.defineProperty(exports, "loadModule", { enumerable: true, get: function () { return util_1.loadModule; } });
|
|
78
77
|
Object.defineProperty(exports, "delegateTargetPrototypeMethod", { enumerable: true, get: function () { return util_1.delegateTargetPrototypeMethod; } });
|
|
79
78
|
Object.defineProperty(exports, "delegateTargetMethod", { enumerable: true, get: function () { return util_1.delegateTargetMethod; } });
|
|
80
79
|
Object.defineProperty(exports, "delegateTargetProperties", { enumerable: true, get: function () { return util_1.delegateTargetProperties; } });
|
package/dist/interface.d.ts
CHANGED
|
@@ -569,10 +569,10 @@ export interface IMidwayContainer extends IObjectFactory, WithFn<IObjectLifeCycl
|
|
|
569
569
|
parent: IMidwayContainer;
|
|
570
570
|
identifierMapping: IIdentifierRelationShip;
|
|
571
571
|
objectCreateEventTarget: EventEmitter;
|
|
572
|
-
ready():
|
|
572
|
+
ready(): any;
|
|
573
573
|
stop(): Promise<void>;
|
|
574
574
|
registerObject(identifier: ObjectIdentifier, target: any): any;
|
|
575
|
-
load(module
|
|
575
|
+
load(module?: any): any;
|
|
576
576
|
hasNamespace(namespace: string): boolean;
|
|
577
577
|
getNamespaceList(): string[];
|
|
578
578
|
hasDefinition(identifier: ObjectIdentifier): any;
|
|
@@ -599,7 +599,7 @@ export interface IMidwayContainer extends IObjectFactory, WithFn<IObjectLifeCycl
|
|
|
599
599
|
*/
|
|
600
600
|
export type IApplicationContext = IMidwayContainer;
|
|
601
601
|
export interface IFileDetector {
|
|
602
|
-
run(container: IMidwayContainer, fileDetectorOptions?: Record<string, any>):
|
|
602
|
+
run(container: IMidwayContainer, fileDetectorOptions?: Record<string, any>): any;
|
|
603
603
|
setExtraDetectorOptions(detectorOptions: Record<string, any>): any;
|
|
604
604
|
}
|
|
605
605
|
export interface IConfigService {
|
|
@@ -810,11 +810,8 @@ export interface IMidwayBootstrapOptions {
|
|
|
810
810
|
*/
|
|
811
811
|
configurationModule?: any | any[];
|
|
812
812
|
imports?: any | any[];
|
|
813
|
-
moduleDetector?: IFileDetector | false;
|
|
813
|
+
moduleDetector?: 'file' | IFileDetector | false;
|
|
814
814
|
logger?: boolean | ILogger;
|
|
815
|
-
/**
|
|
816
|
-
* @deprecated please set it from '@Configuration' decorator
|
|
817
|
-
*/
|
|
818
815
|
ignore?: string[];
|
|
819
816
|
globalConfig?: Array<{
|
|
820
817
|
[environmentName: string]: Record<string, any>;
|
|
@@ -203,7 +203,7 @@ class WebRouterCollector {
|
|
|
203
203
|
if (this.baseDir) {
|
|
204
204
|
const container = new container_1.MidwayContainer();
|
|
205
205
|
(0, decorator_1.bindContainer)(container);
|
|
206
|
-
container.setFileDetector(new fileDetector_1.
|
|
206
|
+
container.setFileDetector(new fileDetector_1.DirectoryFileDetector({
|
|
207
207
|
loadDir: this.baseDir,
|
|
208
208
|
}));
|
|
209
209
|
await container.ready();
|
package/dist/setup.d.ts
CHANGED
|
@@ -5,14 +5,9 @@ import { MidwayContainer, IMidwayBootstrapOptions, IMidwayContainer } from './';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer>;
|
|
7
7
|
export declare function destroyGlobalApplicationContext(applicationContext: IMidwayContainer): Promise<void>;
|
|
8
|
-
/**
|
|
9
|
-
* prepare applicationContext
|
|
10
|
-
* @param globalOptions
|
|
11
|
-
*/
|
|
12
|
-
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer | MidwayContainer>;
|
|
13
8
|
/**
|
|
14
9
|
* prepare applicationContext, it use in egg framework.
|
|
15
10
|
* @param globalOptions
|
|
16
11
|
*/
|
|
17
|
-
export declare function
|
|
12
|
+
export declare function prepareGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): IMidwayContainer | MidwayContainer;
|
|
18
13
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/setup.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareGlobalApplicationContext = 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");
|
|
7
7
|
const util = require("util");
|
|
8
|
-
const slsFunctionService_1 = require("./service/slsFunctionService");
|
|
9
8
|
const path_1 = require("path");
|
|
9
|
+
const slsFunctionService_1 = require("./service/slsFunctionService");
|
|
10
10
|
const debug = util.debuglog('midway:debug');
|
|
11
11
|
let stepIdx = 1;
|
|
12
12
|
function printStepDebugInfo(stepInfo) {
|
|
@@ -17,7 +17,7 @@ function printStepDebugInfo(stepInfo) {
|
|
|
17
17
|
* @param globalOptions
|
|
18
18
|
*/
|
|
19
19
|
async function initializeGlobalApplicationContext(globalOptions) {
|
|
20
|
-
const applicationContext =
|
|
20
|
+
const applicationContext = prepareGlobalApplicationContext(globalOptions);
|
|
21
21
|
printStepDebugInfo('Init logger');
|
|
22
22
|
// init logger
|
|
23
23
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService, [
|
|
@@ -67,120 +67,11 @@ async function destroyGlobalApplicationContext(applicationContext) {
|
|
|
67
67
|
global['MIDWAY_MAIN_FRAMEWORK'] = undefined;
|
|
68
68
|
}
|
|
69
69
|
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
70
|
-
/**
|
|
71
|
-
* prepare applicationContext
|
|
72
|
-
* @param globalOptions
|
|
73
|
-
*/
|
|
74
|
-
async function prepareGlobalApplicationContext(globalOptions) {
|
|
75
|
-
var _a, _b, _c, _d, _e;
|
|
76
|
-
printStepDebugInfo('Ready to create applicationContext');
|
|
77
|
-
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
78
|
-
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
79
|
-
const appDir = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
|
|
80
|
-
const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
|
|
81
|
-
// new container
|
|
82
|
-
const applicationContext = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
|
|
83
|
-
// bind container to decoratorManager
|
|
84
|
-
debug('[core]: delegate module map from decoratorManager');
|
|
85
|
-
(0, decorator_1.bindContainer)(applicationContext);
|
|
86
|
-
global['MIDWAY_APPLICATION_CONTEXT'] = applicationContext;
|
|
87
|
-
// register baseDir and appDir
|
|
88
|
-
applicationContext.registerObject('baseDir', baseDir);
|
|
89
|
-
applicationContext.registerObject('appDir', appDir);
|
|
90
|
-
debug('[core]: set default file detector');
|
|
91
|
-
// set module detector
|
|
92
|
-
if (globalOptions.moduleDetector !== false) {
|
|
93
|
-
const pkgJSON = await (0, _1.loadModule)((0, path_1.join)(appDir, 'package.json'), {
|
|
94
|
-
safeLoad: true,
|
|
95
|
-
enableCache: false,
|
|
96
|
-
});
|
|
97
|
-
const loadMode = (pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.type) === 'module' ? 'esm' : 'commonjs';
|
|
98
|
-
debug('[core]: module load mode = %s', loadMode);
|
|
99
|
-
// set default entry file
|
|
100
|
-
if (!globalOptions.imports) {
|
|
101
|
-
globalOptions.imports = [
|
|
102
|
-
await (0, _1.loadModule)((0, path_1.join)(baseDir, 'configuration'), {
|
|
103
|
-
loadMode,
|
|
104
|
-
safeLoad: true,
|
|
105
|
-
}),
|
|
106
|
-
];
|
|
107
|
-
}
|
|
108
|
-
if (globalOptions.moduleDetector === undefined) {
|
|
109
|
-
if (loadMode === 'esm') {
|
|
110
|
-
applicationContext.setFileDetector(new _1.ESModuleFileDetector({
|
|
111
|
-
loadDir: baseDir,
|
|
112
|
-
ignore: (_d = globalOptions.ignore) !== null && _d !== void 0 ? _d : [],
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
applicationContext.setFileDetector(new _1.CommonJSFileDetector({
|
|
117
|
-
loadDir: baseDir,
|
|
118
|
-
ignore: (_e = globalOptions.ignore) !== null && _e !== void 0 ? _e : [],
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
printStepDebugInfo('Binding inner service');
|
|
124
|
-
// bind inner service
|
|
125
|
-
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
126
|
-
applicationContext.bindClass(_1.MidwayInformationService);
|
|
127
|
-
applicationContext.bindClass(_1.MidwayAspectService);
|
|
128
|
-
applicationContext.bindClass(_1.MidwayDecoratorService);
|
|
129
|
-
applicationContext.bindClass(_1.MidwayConfigService);
|
|
130
|
-
applicationContext.bindClass(_1.MidwayLoggerService);
|
|
131
|
-
applicationContext.bindClass(_1.MidwayApplicationManager);
|
|
132
|
-
applicationContext.bindClass(_1.MidwayFrameworkService);
|
|
133
|
-
applicationContext.bindClass(_1.MidwayMiddlewareService);
|
|
134
|
-
applicationContext.bindClass(_1.MidwayLifeCycleService);
|
|
135
|
-
applicationContext.bindClass(_1.MidwayMockService);
|
|
136
|
-
applicationContext.bindClass(_1.MidwayWebRouterService);
|
|
137
|
-
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
138
|
-
printStepDebugInfo('Binding preload module');
|
|
139
|
-
// bind preload module
|
|
140
|
-
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
141
|
-
for (const preloadModule of globalOptions.preloadModules) {
|
|
142
|
-
applicationContext.bindClass(preloadModule);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
printStepDebugInfo('Init MidwayConfigService, MidwayAspectService and MidwayDecoratorService');
|
|
146
|
-
// init default config
|
|
147
|
-
const configService = applicationContext.get(_1.MidwayConfigService);
|
|
148
|
-
configService.add([
|
|
149
|
-
{
|
|
150
|
-
default: config_default_1.default,
|
|
151
|
-
},
|
|
152
|
-
]);
|
|
153
|
-
// init aop support
|
|
154
|
-
applicationContext.get(_1.MidwayAspectService, [applicationContext]);
|
|
155
|
-
// init decorator service
|
|
156
|
-
applicationContext.get(_1.MidwayDecoratorService, [applicationContext]);
|
|
157
|
-
printStepDebugInfo('Load imports(component) and user code configuration module');
|
|
158
|
-
applicationContext.load([].concat(globalOptions.imports).concat(globalOptions.configurationModule));
|
|
159
|
-
printStepDebugInfo('Run applicationContext ready method');
|
|
160
|
-
// bind user code module
|
|
161
|
-
await applicationContext.ready();
|
|
162
|
-
if (globalOptions.globalConfig) {
|
|
163
|
-
if (Array.isArray(globalOptions.globalConfig)) {
|
|
164
|
-
configService.add(globalOptions.globalConfig);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
configService.addObject(globalOptions.globalConfig);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
printStepDebugInfo('Load config file');
|
|
171
|
-
// merge config
|
|
172
|
-
configService.load();
|
|
173
|
-
debug('[core]: Current config = %j', configService.getConfiguration());
|
|
174
|
-
// middleware support
|
|
175
|
-
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
176
|
-
return applicationContext;
|
|
177
|
-
}
|
|
178
|
-
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
179
70
|
/**
|
|
180
71
|
* prepare applicationContext, it use in egg framework.
|
|
181
72
|
* @param globalOptions
|
|
182
73
|
*/
|
|
183
|
-
function
|
|
74
|
+
function prepareGlobalApplicationContext(globalOptions) {
|
|
184
75
|
var _a, _b, _c, _d;
|
|
185
76
|
printStepDebugInfo('Ready to create applicationContext');
|
|
186
77
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
@@ -198,8 +89,10 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
198
89
|
applicationContext.registerObject('appDir', appDir);
|
|
199
90
|
printStepDebugInfo('Ready module detector');
|
|
200
91
|
if (globalOptions.moduleDetector !== false) {
|
|
201
|
-
if (globalOptions.moduleDetector === undefined
|
|
202
|
-
|
|
92
|
+
if (globalOptions.moduleDetector === undefined ||
|
|
93
|
+
globalOptions.moduleDetector === 'file') {
|
|
94
|
+
applicationContext.setFileDetector(new _1.DirectoryFileDetector({
|
|
95
|
+
loadDir: baseDir,
|
|
203
96
|
ignore: (_d = globalOptions.ignore) !== null && _d !== void 0 ? _d : [],
|
|
204
97
|
}));
|
|
205
98
|
}
|
|
@@ -247,7 +140,14 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
247
140
|
(0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
|
|
248
141
|
];
|
|
249
142
|
}
|
|
250
|
-
|
|
143
|
+
for (const configurationModule of []
|
|
144
|
+
.concat(globalOptions.imports)
|
|
145
|
+
.concat(globalOptions.configurationModule)) {
|
|
146
|
+
// load configuration and component
|
|
147
|
+
if (configurationModule) {
|
|
148
|
+
applicationContext.load(configurationModule);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
251
151
|
printStepDebugInfo('Run applicationContext ready method');
|
|
252
152
|
// bind user code module
|
|
253
153
|
applicationContext.ready();
|
|
@@ -267,5 +167,5 @@ function prepareGlobalApplicationContextSync(globalOptions) {
|
|
|
267
167
|
applicationContext.get(_1.MidwayMiddlewareService, [applicationContext]);
|
|
268
168
|
return applicationContext;
|
|
269
169
|
}
|
|
270
|
-
exports.
|
|
170
|
+
exports.prepareGlobalApplicationContext = prepareGlobalApplicationContext;
|
|
271
171
|
//# sourceMappingURL=setup.js.map
|
package/dist/util/httpclient.js
CHANGED
|
@@ -23,10 +23,10 @@ async function makeHttpRequest(url, options = {}) {
|
|
|
23
23
|
const whatwgUrl = new URL(url);
|
|
24
24
|
const client = whatwgUrl.protocol === 'https:' ? https : http;
|
|
25
25
|
options.method = (options.method || 'GET').toUpperCase();
|
|
26
|
-
const { contentType, dataType, method, timeout = 5000, ...otherOptions } = options;
|
|
26
|
+
const { contentType, dataType, method, timeout = 5000, headers: customHeaders, ...otherOptions } = options;
|
|
27
27
|
const headers = {
|
|
28
28
|
Accept: mimeMap[dataType] || mimeMap.octet,
|
|
29
|
-
...
|
|
29
|
+
...customHeaders,
|
|
30
30
|
};
|
|
31
31
|
let data;
|
|
32
32
|
if (method === 'GET' && options.data) {
|
package/dist/util/index.d.ts
CHANGED
|
@@ -17,17 +17,6 @@ export declare const getCurrentEnvironment: () => string;
|
|
|
17
17
|
* @since 2.0.0
|
|
18
18
|
*/
|
|
19
19
|
export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
|
|
20
|
-
/**
|
|
21
|
-
* load module, and it can be chosen commonjs or esm mode
|
|
22
|
-
* @param p
|
|
23
|
-
* @param options
|
|
24
|
-
* @since 3.12.0
|
|
25
|
-
*/
|
|
26
|
-
export declare const loadModule: (p: string, options?: {
|
|
27
|
-
enableCache?: boolean;
|
|
28
|
-
loadMode?: 'commonjs' | 'esm';
|
|
29
|
-
safeLoad?: boolean;
|
|
30
|
-
}) => Promise<any>;
|
|
31
20
|
/**
|
|
32
21
|
* @example
|
|
33
22
|
* safelyGet(['a','b'],{a: {b: 2}}) // => 2
|
package/dist/util/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Utils = exports.toAsyncFunction = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.wrapAsync = exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.
|
|
3
|
+
exports.Utils = exports.toAsyncFunction = exports.merge = exports.generateRandomId = exports.getParamNames = exports.sleep = exports.wrapAsync = exports.isIncludeProperty = exports.wrapMiddleware = exports.pathMatching = exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetAllPrototypeMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const util_1 = require("util");
|
|
@@ -54,47 +54,6 @@ const safeRequire = (p, enabledCache = true) => {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
exports.safeRequire = safeRequire;
|
|
57
|
-
/**
|
|
58
|
-
* load module, and it can be chosen commonjs or esm mode
|
|
59
|
-
* @param p
|
|
60
|
-
* @param options
|
|
61
|
-
* @since 3.12.0
|
|
62
|
-
*/
|
|
63
|
-
const loadModule = async (p, options = {}) => {
|
|
64
|
-
var _a, _b, _c;
|
|
65
|
-
options.enableCache = (_a = options.enableCache) !== null && _a !== void 0 ? _a : true;
|
|
66
|
-
options.safeLoad = (_b = options.safeLoad) !== null && _b !== void 0 ? _b : false;
|
|
67
|
-
options.loadMode = (_c = options.loadMode) !== null && _c !== void 0 ? _c : 'commonjs';
|
|
68
|
-
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
69
|
-
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
70
|
-
}
|
|
71
|
-
try {
|
|
72
|
-
if (options.enableCache) {
|
|
73
|
-
if (options.loadMode === 'commonjs') {
|
|
74
|
-
return require(p);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
return await import(p);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
const content = (0, fs_1.readFileSync)(p, {
|
|
82
|
-
encoding: 'utf-8',
|
|
83
|
-
});
|
|
84
|
-
return JSON.parse(content);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
catch (err) {
|
|
88
|
-
if (!options.safeLoad) {
|
|
89
|
-
throw err;
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
debug(`[core]: SafeLoadModule Warning\n\n${err.message}\n`);
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
exports.loadModule = loadModule;
|
|
98
57
|
/**
|
|
99
58
|
* @example
|
|
100
59
|
* safelyGet(['a','b'],{a: {b: 2}}) // => 2
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.15",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"koa": "2.14.1",
|
|
26
26
|
"mm": "3.3.0",
|
|
27
27
|
"raw-body": "2.5.2",
|
|
28
|
-
"sinon": "15.
|
|
28
|
+
"sinon": "15.2.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@midwayjs/glob": "^1.0.2",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=12"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "a4054247f3b9f4fc8ba51684c002606d849e0bd3"
|
|
46
46
|
}
|