@nocobase/server 1.4.0-alpha.9 → 1.4.0-beta.10

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.
@@ -69,6 +69,9 @@ var pm_default = /* @__PURE__ */ __name((app) => {
69
69
  try {
70
70
  await app.pm.enable(plugins);
71
71
  } catch (error) {
72
+ await app.tryReloadOrRestart({
73
+ recover: true
74
+ });
72
75
  throw new import_plugin_command_error.PluginCommandError(`Failed to enable plugin`, { cause: error });
73
76
  }
74
77
  });
@@ -119,7 +119,8 @@ var resource_default = {
119
119
  if (!filterByTk) {
120
120
  ctx.throw(400, "plugin name invalid");
121
121
  }
122
- app.runAsCLI(["pm", "enable", filterByTk], { from: "user" });
122
+ const keys = Array.isArray(filterByTk) ? filterByTk : [filterByTk];
123
+ app.runAsCLI(["pm", "enable", ...keys], { from: "user" });
123
124
  ctx.body = filterByTk;
124
125
  await next();
125
126
  },
@@ -32,6 +32,7 @@ export declare class PluginManagerRepository extends Repository {
32
32
  * @deprecated
33
33
  */
34
34
  disable(name: string | string[]): Promise<string[]>;
35
- getItems(): Promise<any>;
35
+ sort(names: string[]): Promise<string[]>;
36
+ getItems(): Promise<any[]>;
36
37
  init(): Promise<void>;
37
38
  }
@@ -40,6 +40,7 @@ __export(plugin_manager_repository_exports, {
40
40
  PluginManagerRepository: () => PluginManagerRepository
41
41
  });
42
42
  module.exports = __toCommonJS(plugin_manager_repository_exports);
43
+ var import_topo = __toESM(require("@hapi/topo"));
43
44
  var import_database = require("@nocobase/database");
44
45
  var import_lodash = __toESM(require("lodash"));
45
46
  var import_plugin_manager = require("./plugin-manager");
@@ -140,17 +141,49 @@ const _PluginManagerRepository = class _PluginManagerRepository extends import_d
140
141
  });
141
142
  return pluginNames;
142
143
  }
144
+ async sort(names) {
145
+ const pluginNames = import_lodash.default.castArray(names);
146
+ if (pluginNames.length === 1) {
147
+ return pluginNames;
148
+ }
149
+ const sorter = new import_topo.default.Sorter();
150
+ for (const pluginName of pluginNames) {
151
+ let packageJson = {};
152
+ try {
153
+ packageJson = await import_plugin_manager.PluginManager.getPackageJson(pluginName);
154
+ } catch (error) {
155
+ packageJson = {};
156
+ }
157
+ const peerDependencies = Object.keys((packageJson == null ? void 0 : packageJson.peerDependencies) || {});
158
+ sorter.add(pluginName, { after: peerDependencies, group: (packageJson == null ? void 0 : packageJson.packageName) || pluginName });
159
+ }
160
+ return sorter.nodes;
161
+ }
143
162
  async getItems() {
144
163
  const exists = await this.collection.existsInDb();
145
164
  if (!exists) {
146
165
  return [];
147
166
  }
148
- return await this.find({
167
+ const items = await this.find({
149
168
  sort: "id",
150
169
  filter: {
151
170
  enabled: true
152
171
  }
153
172
  });
173
+ const sortedItems = [];
174
+ const map = {};
175
+ for (const item of items) {
176
+ if (item.packageName) {
177
+ map[item.packageName] = item;
178
+ } else {
179
+ sortedItems.push(item);
180
+ }
181
+ }
182
+ const names = await this.sort(Object.keys(map));
183
+ for (const name of names) {
184
+ sortedItems.push(map[name]);
185
+ }
186
+ return sortedItems;
154
187
  }
155
188
  async init() {
156
189
  const items = await this.getItems();
@@ -129,9 +129,11 @@ const _PluginManager = class _PluginManager {
129
129
  */
130
130
  static async getPackageJson(nameOrPkg) {
131
131
  const { packageName } = await this.parseName(nameOrPkg);
132
- const file = await import_fs_extra.default.realpath((0, import_path.resolve)(process.env.NODE_MODULES_PATH, packageName, "package.json"));
133
- const data = await import_fs_extra.default.readFile(file, { encoding: "utf-8" });
134
- return JSON.parse(data);
132
+ const packageFile = (0, import_path.resolve)(process.env.NODE_MODULES_PATH, packageName, "package.json");
133
+ if (!await import_fs_extra.default.exists(packageFile)) {
134
+ throw new Error(`Cannot find plugin '${nameOrPkg}'`);
135
+ }
136
+ return import_fs_extra.default.readJSON(packageFile);
135
137
  }
136
138
  /**
137
139
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.4.0-alpha.9",
3
+ "version": "1.4.0-beta.10",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -10,18 +10,18 @@
10
10
  "@koa/cors": "^3.1.0",
11
11
  "@koa/multer": "^3.0.2",
12
12
  "@koa/router": "^9.4.0",
13
- "@nocobase/acl": "1.4.0-alpha.9",
14
- "@nocobase/actions": "1.4.0-alpha.9",
15
- "@nocobase/auth": "1.4.0-alpha.9",
16
- "@nocobase/cache": "1.4.0-alpha.9",
17
- "@nocobase/data-source-manager": "1.4.0-alpha.9",
18
- "@nocobase/database": "1.4.0-alpha.9",
19
- "@nocobase/evaluators": "1.4.0-alpha.9",
20
- "@nocobase/logger": "1.4.0-alpha.9",
21
- "@nocobase/resourcer": "1.4.0-alpha.9",
22
- "@nocobase/sdk": "1.4.0-alpha.9",
23
- "@nocobase/telemetry": "1.4.0-alpha.9",
24
- "@nocobase/utils": "1.4.0-alpha.9",
13
+ "@nocobase/acl": "1.4.0-beta.10",
14
+ "@nocobase/actions": "1.4.0-beta.10",
15
+ "@nocobase/auth": "1.4.0-beta.10",
16
+ "@nocobase/cache": "1.4.0-beta.10",
17
+ "@nocobase/data-source-manager": "1.4.0-beta.10",
18
+ "@nocobase/database": "1.4.0-beta.10",
19
+ "@nocobase/evaluators": "1.4.0-beta.10",
20
+ "@nocobase/logger": "1.4.0-beta.10",
21
+ "@nocobase/resourcer": "1.4.0-beta.10",
22
+ "@nocobase/sdk": "1.4.0-beta.10",
23
+ "@nocobase/telemetry": "1.4.0-beta.10",
24
+ "@nocobase/utils": "1.4.0-beta.10",
25
25
  "@types/decompress": "4.2.7",
26
26
  "@types/ini": "^1.3.31",
27
27
  "@types/koa-send": "^4.1.3",
@@ -54,5 +54,5 @@
54
54
  "@types/serve-handler": "^6.1.1",
55
55
  "@types/ws": "^8.5.5"
56
56
  },
57
- "gitHead": "af26b630a5b590f986e21231f0db289c65dd7f70"
57
+ "gitHead": "4e3bbdab89b6eea6011a7b86fdefd66e0d0080d4"
58
58
  }