@nocobase/server 0.21.0-alpha.7 → 0.21.0-alpha.9

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.
@@ -55,6 +55,13 @@ var pm_default = /* @__PURE__ */ __name((app) => {
55
55
  throw new import_plugin_command_error.PluginCommandError(`Failed to update plugin`, { cause: error });
56
56
  }
57
57
  });
58
+ pm.command("enable-all").ipc().preload().action(async () => {
59
+ try {
60
+ await app.pm.enable("*");
61
+ } catch (error) {
62
+ throw new import_plugin_command_error.PluginCommandError(`Failed to enable plugin`, { cause: error });
63
+ }
64
+ });
58
65
  pm.command("enable").ipc().preload().arguments("<plugins...>").action(async (plugins) => {
59
66
  try {
60
67
  await app.pm.enable(plugins);
@@ -86,7 +86,7 @@ const _Locale = class _Locale {
86
86
  getResources(lang) {
87
87
  var _a;
88
88
  const resources = {};
89
- const names = this.app.pm.getAliases();
89
+ const names = this.app.pm.getPlugins().keys();
90
90
  for (const name of names) {
91
91
  try {
92
92
  const p = this.app.pm.get(name);
@@ -93,6 +93,7 @@ export declare class PluginManager {
93
93
  loadCommands(): Promise<void>;
94
94
  load(options?: any): Promise<void>;
95
95
  install(options?: InstallOptions): Promise<void>;
96
+ private sort;
96
97
  enable(name: string | string[]): Promise<void>;
97
98
  disable(name: string | string[]): Promise<void>;
98
99
  remove(name: string | string[], options?: {
@@ -34,6 +34,7 @@ __export(plugin_manager_exports, {
34
34
  sleep: () => sleep
35
35
  });
36
36
  module.exports = __toCommonJS(plugin_manager_exports);
37
+ var import_topo = __toESM(require("@hapi/topo"));
37
38
  var import_utils = require("@nocobase/utils");
38
39
  var import_plugin_symlink = require("@nocobase/utils/plugin-symlink");
39
40
  var import_execa = __toESM(require("execa"));
@@ -312,6 +313,9 @@ const _PluginManager = class _PluginManager {
312
313
  if (options.name) {
313
314
  this.pluginAliases.set(options.name, instance);
314
315
  }
316
+ if (options.packageName) {
317
+ this.pluginAliases.set(options.packageName, instance);
318
+ }
315
319
  if (insert && options.name) {
316
320
  await this.repository.updateOrCreate({
317
321
  values: {
@@ -443,8 +447,27 @@ const _PluginManager = class _PluginManager {
443
447
  }
444
448
  });
445
449
  }
450
+ sort(names) {
451
+ var _a, _b, _c;
452
+ const pluginNames = import_lodash.default.castArray(names);
453
+ if (pluginNames.length === 1) {
454
+ return pluginNames;
455
+ }
456
+ const sorter = new import_topo.default.Sorter();
457
+ for (const pluginName of pluginNames) {
458
+ const plugin = this.get(pluginName);
459
+ const peerDependencies = Object.keys(((_b = (_a = plugin.options) == null ? void 0 : _a.packageJson) == null ? void 0 : _b.peerDependencies) || {});
460
+ sorter.add(pluginName, { after: peerDependencies, group: ((_c = plugin.options) == null ? void 0 : _c.packageName) || pluginName });
461
+ }
462
+ return sorter.nodes;
463
+ }
446
464
  async enable(name) {
447
- const pluginNames = import_lodash.default.castArray(name);
465
+ let pluginNames = name;
466
+ if (name === "*") {
467
+ const items = await this.repository.find();
468
+ pluginNames = items.map((item) => item.name);
469
+ }
470
+ pluginNames = this.sort(pluginNames);
448
471
  this.app.log.debug(`enabling plugin ${pluginNames.join(",")}`);
449
472
  this.app.setMaintainingMessage(`enabling plugin ${pluginNames.join(",")}`);
450
473
  const toBeUpdated = [];
@@ -457,9 +480,17 @@ const _PluginManager = class _PluginManager {
457
480
  continue;
458
481
  }
459
482
  await this.app.emitAsync("beforeEnablePlugin", pluginName);
460
- await plugin.beforeEnable();
461
- plugin.enabled = true;
462
- toBeUpdated.push(pluginName);
483
+ try {
484
+ await plugin.beforeEnable();
485
+ plugin.enabled = true;
486
+ toBeUpdated.push(pluginName);
487
+ } catch (error) {
488
+ if (name === "*") {
489
+ this.app.log.error(error.message);
490
+ } else {
491
+ throw error;
492
+ }
493
+ }
463
494
  }
464
495
  if (toBeUpdated.length === 0) {
465
496
  return;
@@ -474,10 +505,10 @@ const _PluginManager = class _PluginManager {
474
505
  });
475
506
  try {
476
507
  await this.app.reload();
477
- this.app.log.debug(`syncing database in enable plugin ${pluginNames.join(",")}...`);
478
- this.app.setMaintainingMessage(`syncing database in enable plugin ${pluginNames.join(",")}...`);
508
+ this.app.log.debug(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
509
+ this.app.setMaintainingMessage(`syncing database in enable plugin ${toBeUpdated.join(",")}...`);
479
510
  await this.app.db.sync();
480
- for (const pluginName of pluginNames) {
511
+ for (const pluginName of toBeUpdated) {
481
512
  const plugin = this.get(pluginName);
482
513
  if (!plugin.installed) {
483
514
  this.app.log.debug(`installing plugin ${pluginName}...`);
@@ -494,7 +525,7 @@ const _PluginManager = class _PluginManager {
494
525
  installed: true
495
526
  }
496
527
  });
497
- for (const pluginName of pluginNames) {
528
+ for (const pluginName of toBeUpdated) {
498
529
  const plugin = this.get(pluginName);
499
530
  this.app.log.debug(`emit afterEnablePlugin event...`);
500
531
  await plugin.afterEnable();
@@ -823,7 +854,7 @@ const _PluginManager = class _PluginManager {
823
854
  async list(options = {}) {
824
855
  const { locale = "en-US", isPreset = false } = options;
825
856
  return Promise.all(
826
- [...this.getAliases()].map((name) => {
857
+ [...this.getPlugins().keys()].map((name) => {
827
858
  const plugin = this.get(name);
828
859
  if (!isPreset && plugin.options.isPreset) {
829
860
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.21.0-alpha.7",
3
+ "version": "0.21.0-alpha.9",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.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": "0.21.0-alpha.7",
14
- "@nocobase/actions": "0.21.0-alpha.7",
15
- "@nocobase/auth": "0.21.0-alpha.7",
16
- "@nocobase/cache": "0.21.0-alpha.7",
17
- "@nocobase/data-source-manager": "0.21.0-alpha.7",
18
- "@nocobase/database": "0.21.0-alpha.7",
19
- "@nocobase/evaluators": "0.21.0-alpha.7",
20
- "@nocobase/logger": "0.21.0-alpha.7",
21
- "@nocobase/resourcer": "0.21.0-alpha.7",
22
- "@nocobase/sdk": "0.21.0-alpha.7",
23
- "@nocobase/telemetry": "0.21.0-alpha.7",
24
- "@nocobase/utils": "0.21.0-alpha.7",
13
+ "@nocobase/acl": "0.21.0-alpha.9",
14
+ "@nocobase/actions": "0.21.0-alpha.9",
15
+ "@nocobase/auth": "0.21.0-alpha.9",
16
+ "@nocobase/cache": "0.21.0-alpha.9",
17
+ "@nocobase/data-source-manager": "0.21.0-alpha.9",
18
+ "@nocobase/database": "0.21.0-alpha.9",
19
+ "@nocobase/evaluators": "0.21.0-alpha.9",
20
+ "@nocobase/logger": "0.21.0-alpha.9",
21
+ "@nocobase/resourcer": "0.21.0-alpha.9",
22
+ "@nocobase/sdk": "0.21.0-alpha.9",
23
+ "@nocobase/telemetry": "0.21.0-alpha.9",
24
+ "@nocobase/utils": "0.21.0-alpha.9",
25
25
  "@types/decompress": "4.2.4",
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": "b1be3993f8aa81173d01bc390aa8e4c5adcc0e2d"
57
+ "gitHead": "a6fe6c4ee532c04e5a50ec777bf76436ca624cbd"
58
58
  }