@midwayjs/core 3.3.1 → 3.3.5

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.
@@ -15,6 +15,7 @@ export declare const FrameworkErrorEnum: {
15
15
  readonly MISSING_IMPORTS: "MIDWAY_10011";
16
16
  readonly UTIL_HTTP_TIMEOUT: "MIDWAY_10012";
17
17
  readonly INCONSISTENT_VERSION: "MIDWAY_10013";
18
+ readonly INVALID_CONFIG: "MIDWAY_10014";
18
19
  };
19
20
  export declare class MidwayCommonError extends MidwayError {
20
21
  constructor(message: string);
@@ -37,6 +38,9 @@ export declare class MidwayFeatureNotImplementedError extends MidwayError {
37
38
  export declare class MidwayConfigMissingError extends MidwayError {
38
39
  constructor(configKey: string);
39
40
  }
41
+ export declare class MidwayInvalidConfigError extends MidwayError {
42
+ constructor(message?: string);
43
+ }
40
44
  export declare class MidwayResolverMissingError extends MidwayError {
41
45
  constructor(type: string);
42
46
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
3
+ exports.MidwayInconsistentVersionError = exports.MidwayUtilHttpClientTimeoutError = exports.MidwayMissingImportComponentError = exports.MidwaySingletonInjectRequestError = exports.MidwayUseWrongMethodError = exports.MidwayDuplicateRouteError = exports.MidwayResolverMissingError = exports.MidwayInvalidConfigError = exports.MidwayConfigMissingError = exports.MidwayFeatureNotImplementedError = exports.MidwayFeatureNoLongerSupportedError = exports.MidwayDefinitionNotFoundError = exports.MidwayParameterError = exports.MidwayCommonError = exports.FrameworkErrorEnum = void 0;
4
4
  const base_1 = require("./base");
5
5
  exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
6
6
  UNKNOWN: 10000,
@@ -17,6 +17,7 @@ exports.FrameworkErrorEnum = (0, base_1.registerErrorCode)('midway', {
17
17
  MISSING_IMPORTS: 10011,
18
18
  UTIL_HTTP_TIMEOUT: 10012,
19
19
  INCONSISTENT_VERSION: 10013,
20
+ INVALID_CONFIG: 10014,
20
21
  });
21
22
  class MidwayCommonError extends base_1.MidwayError {
22
23
  constructor(message) {
@@ -67,6 +68,12 @@ class MidwayConfigMissingError extends base_1.MidwayError {
67
68
  }
68
69
  }
69
70
  exports.MidwayConfigMissingError = MidwayConfigMissingError;
71
+ class MidwayInvalidConfigError extends base_1.MidwayError {
72
+ constructor(message) {
73
+ super('Invalid config file \n' + message, exports.FrameworkErrorEnum.INVALID_CONFIG);
74
+ }
75
+ }
76
+ exports.MidwayInvalidConfigError = MidwayInvalidConfigError;
70
77
  class MidwayResolverMissingError extends base_1.MidwayError {
71
78
  constructor(type) {
72
79
  super(`${type} resolver is not exists!`, exports.FrameworkErrorEnum.MISSING_RESOLVER);
@@ -18,6 +18,7 @@ const util = require("util");
18
18
  const environmentService_1 = require("./environmentService");
19
19
  const informationService_1 = require("./informationService");
20
20
  const extend_1 = require("../util/extend");
21
+ const error_1 = require("../error");
21
22
  const debug = util.debuglog('midway:debug');
22
23
  let MidwayConfigService = class MidwayConfigService {
23
24
  constructor() {
@@ -174,8 +175,11 @@ let MidwayConfigService = class MidwayConfigService {
174
175
  let exports = typeof configFilename === 'string'
175
176
  ? require(configFilename)
176
177
  : configFilename;
177
- if (exports && exports['default'] && Object.keys(exports).length === 1) {
178
- exports = exports['default'];
178
+ if (exports && exports.default) {
179
+ if (Object.keys(exports).length > 1) {
180
+ throw new error_1.MidwayInvalidConfigError(`${configFilename} should not have both a default export and named export`);
181
+ }
182
+ exports = exports.default;
179
183
  }
180
184
  return exports;
181
185
  }
@@ -29,7 +29,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
29
29
  this.globalFrameworkList = [];
30
30
  }
31
31
  async init() {
32
- var _a;
32
+ var _a, _b;
33
33
  // register base config hook
34
34
  this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
35
35
  var _a;
@@ -49,6 +49,22 @@ let MidwayFrameworkService = class MidwayFrameworkService {
49
49
  var _a, _b;
50
50
  return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[interface_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
51
51
  });
52
+ // register @App decorator handler
53
+ this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
54
+ if (mete.type) {
55
+ const framework = this.applicationManager.getApplication(mete.type);
56
+ if (!framework) {
57
+ throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
58
+ }
59
+ return framework;
60
+ }
61
+ else {
62
+ return this.getMainApp();
63
+ }
64
+ });
65
+ this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
66
+ return this.getMainApp()[key];
67
+ });
52
68
  let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
53
69
  // filter proto
54
70
  frameworks = filterProtoFramework(frameworks);
@@ -77,24 +93,13 @@ let MidwayFrameworkService = class MidwayFrameworkService {
77
93
  this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
78
94
  this.globalFrameworkList.push(frameworkInstance);
79
95
  }
80
- // register @App decorator handler
81
- this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, mete) => {
82
- if (mete.type) {
83
- const framework = this.applicationManager.getApplication(mete.type);
84
- if (!framework) {
85
- throw new error_1.MidwayCommonError(`Framework ${mete.type} not Found`);
86
- }
87
- return framework;
88
- }
89
- else {
90
- return this.getMainApp();
91
- }
92
- });
93
- this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (key, target) => {
94
- return this.getMainApp()[key];
95
- });
96
+ const nsSet = this.applicationContext['namespaceSet'];
97
+ let mainNs;
98
+ if (nsSet.size > 0) {
99
+ [mainNs] = nsSet;
100
+ }
96
101
  global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
97
- this.globalFrameworkList[0];
102
+ (_b = this.applicationManager.getFramework(mainNs)) !== null && _b !== void 0 ? _b : this.globalFrameworkList[0];
98
103
  }
99
104
  // init aspect module
100
105
  await this.aspectService.loadAspect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.3.1",
3
+ "version": "3.3.5",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,12 +21,12 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.1.6",
24
+ "@midwayjs/decorator": "^3.3.4",
25
25
  "koa": "2.13.4",
26
26
  "midway-test-component": "*",
27
27
  "mm": "3.2.0",
28
28
  "raw-body": "2.5.1",
29
- "sinon": "13.0.1"
29
+ "sinon": "13.0.2"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@midwayjs/decorator": "*"
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "f603b622b205ec126de628eeab59f90045a75dd2"
48
+ "gitHead": "5a835008aaa26e1b3c7d99c525f4a9fdaa3e41d1"
49
49
  }