@midwayjs/core 3.0.9 → 3.0.13

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.
@@ -1,8 +1,10 @@
1
1
  import { IFileDetector, IMidwayContainer } from '../interface';
2
2
  export declare abstract class AbstractFileDetector<T> implements IFileDetector {
3
3
  options: T;
4
+ extraDetectorOptions: T;
4
5
  constructor(options: any);
5
6
  abstract run(container: IMidwayContainer): any;
7
+ setExtraDetectorOptions(detectorOptions: T): void;
6
8
  }
7
9
  export declare class DirectoryFileDetector extends AbstractFileDetector<{
8
10
  loadDir: string | string[];
@@ -6,6 +6,10 @@ const glob_1 = require("@midwayjs/glob");
6
6
  class AbstractFileDetector {
7
7
  constructor(options) {
8
8
  this.options = options;
9
+ this.extraDetectorOptions = {};
10
+ }
11
+ setExtraDetectorOptions(detectorOptions) {
12
+ this.extraDetectorOptions = detectorOptions;
9
13
  }
10
14
  }
11
15
  exports.AbstractFileDetector = AbstractFileDetector;
@@ -29,11 +33,13 @@ class DirectoryFileDetector extends AbstractFileDetector {
29
33
  this.directoryFilterArray = [];
30
34
  }
31
35
  run(container) {
32
- const loadDirs = [].concat(this.options.loadDir || []);
36
+ const loadDirs = []
37
+ .concat(this.options.loadDir || [])
38
+ .concat(this.extraDetectorOptions.loadDir || []);
33
39
  for (const dir of loadDirs) {
34
- const fileResults = (0, glob_1.run)(DEFAULT_PATTERN.concat(this.options.pattern || []), {
40
+ const fileResults = (0, glob_1.run)(DEFAULT_PATTERN.concat(this.options.pattern || []).concat(this.extraDetectorOptions.pattern || []), {
35
41
  cwd: dir,
36
- ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []),
42
+ ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []).concat(this.extraDetectorOptions.ignore || []),
37
43
  });
38
44
  for (const file of fileResults) {
39
45
  if (this.directoryFilterArray.length) {
@@ -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 debug = util.debuglog('midway:debug');
18
19
  const debugBind = util.debuglog('midway:bind');
19
20
  class ContainerConfiguration {
@@ -21,6 +22,7 @@ class ContainerConfiguration {
21
22
  this.container = container;
22
23
  this.loadedMap = new WeakMap();
23
24
  this.namespaceList = [];
25
+ this.detectorOptionsList = [];
24
26
  }
25
27
  load(module) {
26
28
  let namespace = decorator_1.MAIN_MODULE_KEY;
@@ -51,6 +53,9 @@ class ContainerConfiguration {
51
53
  namespace = configurationOptions.namespace;
52
54
  this.namespaceList.push(namespace);
53
55
  }
56
+ if (configurationOptions.detectorOptions) {
57
+ this.detectorOptionsList.push(configurationOptions.detectorOptions);
58
+ }
54
59
  debug(`[core]: load configuration in namespace="${namespace}"`);
55
60
  this.addImports(configurationOptions.imports);
56
61
  this.addImportObjects(configurationOptions.importObjects);
@@ -164,6 +169,9 @@ class ContainerConfiguration {
164
169
  getNamespaceList() {
165
170
  return this.namespaceList;
166
171
  }
172
+ getDetectorOptionsList() {
173
+ return this.detectorOptionsList;
174
+ }
167
175
  }
168
176
  class MidwayContainer {
169
177
  constructor(parent) {
@@ -219,6 +227,7 @@ class MidwayContainer {
219
227
  return this._namespaceSet;
220
228
  }
221
229
  load(module) {
230
+ var _a;
222
231
  this.isLoad = true;
223
232
  if (module) {
224
233
  // load configuration
@@ -228,6 +237,11 @@ class MidwayContainer {
228
237
  this.namespaceSet.add(ns);
229
238
  debug(`[core]: load configuration in namespace="${ns}" complete`);
230
239
  }
240
+ const detectorOptionsMerged = {};
241
+ for (const detectorOptions of configuration.getDetectorOptionsList()) {
242
+ (0, extend_1.extend)(true, detectorOptionsMerged, detectorOptions);
243
+ }
244
+ (_a = this.fileDetector) === null || _a === void 0 ? void 0 : _a.setExtraDetectorOptions(detectorOptionsMerged);
231
245
  }
232
246
  }
233
247
  loadDefinitions() {
@@ -243,7 +243,8 @@ export interface IMidwayContainer extends IObjectFactory, IObjectLifeCycle {
243
243
  */
244
244
  export declare type IApplicationContext = IMidwayContainer;
245
245
  export interface IFileDetector {
246
- run(container: IMidwayContainer): any;
246
+ run(container: IMidwayContainer, fileDetectorOptions?: Record<string, any>): any;
247
+ setExtraDetectorOptions(detectorOptions: Record<string, any>): any;
247
248
  }
248
249
  export interface IConfigService {
249
250
  add(configFilePaths: any[]): any;
@@ -21,7 +21,7 @@ const levelTransform = level => {
21
21
  switch (level) {
22
22
  case 'NONE':
23
23
  case Infinity: // egg logger 的 none 是这个等级
24
- return null;
24
+ return 'none';
25
25
  case 0:
26
26
  case 'DEBUG':
27
27
  case 'debug':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/core",
3
- "version": "3.0.9",
3
+ "version": "3.0.13",
4
4
  "description": "midway core",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -21,11 +21,11 @@
21
21
  ],
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@midwayjs/decorator": "^3.0.7",
24
+ "@midwayjs/decorator": "^3.0.10",
25
25
  "koa": "2.13.4",
26
26
  "midway-test-component": "*",
27
27
  "mm": "3.2.0",
28
- "raw-body": "2.4.3",
28
+ "raw-body": "2.5.1",
29
29
  "sinon": "13.0.1"
30
30
  },
31
31
  "peerDependencies": {
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=12"
47
47
  },
48
- "gitHead": "6fbf54fb8840844c229d2cf11b30128c67cbeaf1"
48
+ "gitHead": "8c8338f4488ec65765c342dd5238ed3e61872b37"
49
49
  }