@nocobase/resourcer 0.17.0-alpha.7 → 0.18.0-alpha.3

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.
@@ -123,6 +123,7 @@ export interface ImportOptions {
123
123
  extensions?: string[];
124
124
  }
125
125
  export declare class Resourcer {
126
+ readonly options: ResourcerOptions;
126
127
  protected resources: Map<string, Resource>;
127
128
  /**
128
129
  * 全局定义的 action handlers
@@ -131,7 +132,6 @@ export declare class Resourcer {
131
132
  protected actionHandlers: Map<ActionName, any>;
132
133
  protected middlewareHandlers: Map<string, any>;
133
134
  protected middlewares: Toposort<any>;
134
- readonly options: ResourcerOptions;
135
135
  constructor(options?: ResourcerOptions);
136
136
  /**
137
137
  * 载入指定目录下的 resource 配置(配置的文件驱动)
@@ -142,7 +142,7 @@ export declare class Resourcer {
142
142
  * @param {string} [options.directory] 指定配置所在路径
143
143
  * @param {array} [options.extensions = ['js', 'ts', 'json']] 文件后缀
144
144
  */
145
- import(options: ImportOptions): Map<string, Resource>;
145
+ import(options: ImportOptions): Promise<Map<string, Resource>>;
146
146
  /**
147
147
  * resource 配置
148
148
  *
package/lib/resourcer.js CHANGED
@@ -40,6 +40,7 @@ var import_path_to_regexp = require("path-to-regexp");
40
40
  var import_resource = __toESM(require("./resource"));
41
41
  var import_utils2 = require("./utils");
42
42
  const _Resourcer = class _Resourcer {
43
+ options;
43
44
  resources = /* @__PURE__ */ new Map();
44
45
  /**
45
46
  * 全局定义的 action handlers
@@ -48,7 +49,6 @@ const _Resourcer = class _Resourcer {
48
49
  actionHandlers = /* @__PURE__ */ new Map();
49
50
  middlewareHandlers = /* @__PURE__ */ new Map();
50
51
  middlewares;
51
- options;
52
52
  constructor(options = {}) {
53
53
  this.options = options;
54
54
  this.middlewares = new import_utils.Toposort();
@@ -62,18 +62,18 @@ const _Resourcer = class _Resourcer {
62
62
  * @param {string} [options.directory] 指定配置所在路径
63
63
  * @param {array} [options.extensions = ['js', 'ts', 'json']] 文件后缀
64
64
  */
65
- import(options) {
65
+ async import(options) {
66
66
  const { extensions = ["js", "ts", "json"], directory } = options;
67
67
  const patten = `${directory}/*.{${extensions.join(",")}}`;
68
68
  const files = import_glob.default.sync(patten, {
69
69
  ignore: ["**/*.d.ts"]
70
70
  });
71
71
  const resources = /* @__PURE__ */ new Map();
72
- files.forEach((file) => {
73
- const options2 = (0, import_utils.requireModule)(file);
72
+ for (const file of files) {
73
+ const options2 = await (0, import_utils.importModule)(file);
74
74
  const table = this.define(typeof options2 === "function" ? options2(this) : options2);
75
75
  resources.set(table.getName(), table);
76
- });
76
+ }
77
77
  return resources;
78
78
  }
79
79
  /**
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nocobase/resourcer",
3
- "version": "0.17.0-alpha.7",
3
+ "version": "0.18.0-alpha.3",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
- "@nocobase/utils": "0.17.0-alpha.7",
9
+ "@nocobase/utils": "0.18.0-alpha.3",
10
10
  "deepmerge": "^4.2.2",
11
11
  "koa-compose": "^4.1.0",
12
12
  "lodash": "^4.17.21",
@@ -18,5 +18,5 @@
18
18
  "url": "git+https://github.com/nocobase/nocobase.git",
19
19
  "directory": "packages/resourcer"
20
20
  },
21
- "gitHead": "91377a3abd1124f79fb3819f2d0e80905e091a32"
21
+ "gitHead": "3d34bcd0e3aca0f485e4a2425b87bc971526634d"
22
22
  }