@nocobase/server 2.1.0-beta.43 → 2.1.0-beta.45

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.
@@ -13,7 +13,7 @@ import { IncomingMessage, ServerResponse } from 'http';
13
13
  import { AsyncEmitter } from '@nocobase/utils';
14
14
  import { EventEmitter } from 'events';
15
15
  import Application, { ApplicationOptions } from '../application';
16
- import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, EnvironmentInfo, GetAppOptions, ProcessCommand, AppDbCreator, AppOptionsFactory, AppDbCreatorOptions, AppCommandAdapter, AppModel, BootstrapLock } from './types';
16
+ import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, EnvironmentInfo, GetAppOptions, ProcessCommand, AppDbCreator, AppOptionsFactory, AppDbCreatorOptions, AppCommandAdapter, AppModel, BootstrapLock, AppCondition, GetAppsByConditionOptions } from './types';
17
17
  import { Predicate } from './condition-registry';
18
18
  import { PubSubManagerPublishOptions } from '../pub-sub-manager';
19
19
  import { Transaction, Transactionable } from '@nocobase/database';
@@ -48,6 +48,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
48
48
  private processAdapterName;
49
49
  private commandAdapterName;
50
50
  private appDbCreator;
51
+ private appConditions;
51
52
  appOptionsFactory: AppOptionsFactory;
52
53
  private environmentHeartbeatInterval;
53
54
  private environmentHeartbeatTimer;
@@ -107,11 +108,15 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
107
108
  getAppLastSeenAt(appName: string): Promise<number>;
108
109
  addAppModel(appModel: AppModel): Promise<void>;
109
110
  getAppModel(appName: string): Promise<AppModel>;
111
+ registerAppCondition(name: string, condition: AppCondition): void;
112
+ unregisterAppCondition(name: string): void;
113
+ getAppCondition(name: string): AppCondition;
114
+ getAppConditions(): [string, AppCondition][];
115
+ getAppsByCondition(conditionName: string, options?: GetAppsByConditionOptions): Promise<string[]>;
110
116
  removeAppModel(appName: string): Promise<void>;
111
117
  getAppNameByCName(cname: string): Promise<string>;
112
- addAutoStartApps(environmentName: string, appNames: string[]): Promise<void>;
113
- getAutoStartApps(): Promise<string[]>;
114
- removeAutoStartApps(environmentName: string, appNames: string[]): Promise<void>;
118
+ addAppsToCondition(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
119
+ removeAppsFromCondition(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
115
120
  addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
116
121
  getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
117
122
  hasApp(appName: string): boolean;
@@ -134,6 +139,9 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
134
139
  upgradeApp(appName: string, context?: {
135
140
  requestId: string;
136
141
  }): Promise<void>;
142
+ dispatchAppEvent(appName: string, event: string, payload?: any, context?: {
143
+ requestId: string;
144
+ }): Promise<void>;
137
145
  /**
138
146
  * @deprecated
139
147
  * use {#getApps} instead
@@ -157,5 +165,5 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
157
165
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
158
166
  private bindAppEvents;
159
167
  }
160
- export type { AppDiscoveryAdapter, AppProcessAdapter, AppCommandAdapter, AppStatus, ProcessCommand, EnvironmentInfo, GetAppOptions, AppDbCreator, AppOptionsFactory, AppModel, AppModelOptions, BootstrapLock, } from './types';
168
+ export type { AppDiscoveryAdapter, AppProcessAdapter, AppCommandAdapter, AppStatus, ProcessCommand, EnvironmentInfo, GetAppOptions, AppDbCreator, AppOptionsFactory, AppModel, AppModelOptions, AppCondition, GetAppsByConditionOptions, BootstrapLock, } from './types';
161
169
  export { MainOnlyAdapter } from './main-only-adapter';
@@ -69,6 +69,7 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
69
69
  processAdapterName;
70
70
  commandAdapterName;
71
71
  appDbCreator = new import_condition_registry.ConditionalRegistry();
72
+ appConditions = /* @__PURE__ */ new Map();
72
73
  appOptionsFactory = import_app_options_factory.appOptionsFactory;
73
74
  environmentHeartbeatInterval = 2 * 60 * 1e3;
74
75
  environmentHeartbeatTimer = null;
@@ -420,6 +421,28 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
420
421
  async getAppModel(appName) {
421
422
  return this.discoveryAdapter.getAppModel(appName);
422
423
  }
424
+ registerAppCondition(name, condition) {
425
+ this.appConditions.set(name, condition);
426
+ }
427
+ unregisterAppCondition(name) {
428
+ this.appConditions.delete(name);
429
+ }
430
+ getAppCondition(name) {
431
+ return this.appConditions.get(name);
432
+ }
433
+ getAppConditions() {
434
+ return Array.from(this.appConditions.entries());
435
+ }
436
+ async getAppsByCondition(conditionName, options = {}) {
437
+ const condition = this.getAppCondition(conditionName);
438
+ if (!condition || typeof this.discoveryAdapter.getAppsByCondition !== "function") {
439
+ return [];
440
+ }
441
+ return this.discoveryAdapter.getAppsByCondition(conditionName, condition, {
442
+ ...options,
443
+ environmentName: options.allEnvironments ? options.environmentName : options.environmentName ?? this.environmentName
444
+ });
445
+ }
423
446
  async removeAppModel(appName) {
424
447
  if (typeof this.discoveryAdapter.removeAppModel !== "function") {
425
448
  return;
@@ -432,23 +455,17 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
432
455
  }
433
456
  return this.discoveryAdapter.getAppNameByCName(cname);
434
457
  }
435
- async addAutoStartApps(environmentName, appNames) {
436
- if (typeof this.discoveryAdapter.addAutoStartApps !== "function") {
458
+ async addAppsToCondition(conditionName, environmentName, appNames) {
459
+ if (typeof this.discoveryAdapter.addAppsToCondition !== "function") {
437
460
  return;
438
461
  }
439
- return this.discoveryAdapter.addAutoStartApps(environmentName, appNames);
440
- }
441
- async getAutoStartApps() {
442
- if (typeof this.discoveryAdapter.getAutoStartApps === "function") {
443
- return this.discoveryAdapter.getAutoStartApps(this.environmentName);
444
- }
445
- return [];
462
+ return this.discoveryAdapter.addAppsToCondition(conditionName, environmentName, appNames);
446
463
  }
447
- async removeAutoStartApps(environmentName, appNames) {
448
- if (typeof this.discoveryAdapter.addAutoStartApps !== "function") {
464
+ async removeAppsFromCondition(conditionName, environmentName, appNames) {
465
+ if (typeof this.discoveryAdapter.removeAppsFromCondition !== "function") {
449
466
  return;
450
467
  }
451
- return this.discoveryAdapter.removeAutoStartApps(environmentName, appNames);
468
+ return this.discoveryAdapter.removeAppsFromCondition(conditionName, environmentName, appNames);
452
469
  }
453
470
  addApp(app) {
454
471
  this.processAdapter.addApp(app);
@@ -477,6 +494,10 @@ const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
477
494
  async upgradeApp(appName, context) {
478
495
  await this.processAdapter.upgradeApp(appName, context);
479
496
  }
497
+ async dispatchAppEvent(appName, event, payload, context) {
498
+ var _a, _b;
499
+ return (_b = (_a = this.processAdapter).dispatchAppEvent) == null ? void 0 : _b.call(_a, appName, event, payload, context);
500
+ }
480
501
  /**
481
502
  * @deprecated
482
503
  * use {#getApps} instead
@@ -26,6 +26,9 @@ export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessA
26
26
  stopApp(appName: string): Promise<void>;
27
27
  removeApp(appName: string): Promise<void>;
28
28
  upgradeApp(appName: string): Promise<void>;
29
+ dispatchAppEvent(appName: string, event: string, payload?: any, _context?: {
30
+ requestId: string;
31
+ }): Promise<void>;
29
32
  removeAllApps(): Promise<void>;
30
33
  setAppStatus(appName: string, status: AppStatus, options?: {}): void;
31
34
  getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus;
@@ -124,6 +124,13 @@ const _MainOnlyAdapter = class _MainOnlyAdapter {
124
124
  }
125
125
  await this.apps[appName].runCommand("upgrade");
126
126
  }
127
+ async dispatchAppEvent(appName, event, payload, _context) {
128
+ const app = await this.getApp(appName, { withOutBootStrap: true });
129
+ if (!app) {
130
+ return;
131
+ }
132
+ await app.emitAsync(event, payload);
133
+ }
127
134
  async removeAllApps() {
128
135
  return this.removeApp("main");
129
136
  }
@@ -57,11 +57,23 @@ export type AppModelOptions = {
57
57
  };
58
58
  export type AppModel = {
59
59
  name: string;
60
+ title?: string;
61
+ icon?: string;
60
62
  cname?: string;
63
+ sort?: number;
64
+ pinned?: boolean;
61
65
  environment?: string;
62
66
  environments?: string[];
63
67
  options: AppModelOptions;
64
68
  };
69
+ export type AppCondition = {
70
+ filter?: Record<string, any>;
71
+ match?: (appModel: AppModel) => boolean;
72
+ };
73
+ export type GetAppsByConditionOptions = {
74
+ environmentName?: string;
75
+ allEnvironments?: boolean;
76
+ };
65
77
  export type ProcessCommand = {
66
78
  requestId: string;
67
79
  appName: string;
@@ -102,9 +114,9 @@ export interface AppDiscoveryAdapter {
102
114
  clearAppStatus?(appName: string): void | Promise<void>;
103
115
  loadAppModels?(mainApp: Application): Promise<void>;
104
116
  getAppsStatuses?(appNames?: string[]): Promise<AppStatusesResult> | AppStatusesResult;
105
- addAutoStartApps?(environmentName: string, appName: string[]): Promise<void>;
106
- getAutoStartApps?(environmentName: string): Promise<string[]>;
107
- removeAutoStartApps?(environmentName: string, appNames: string[]): Promise<void>;
117
+ getAppsByCondition?(conditionName: string, condition: AppCondition, options?: GetAppsByConditionOptions): Promise<string[]>;
118
+ addAppsToCondition?(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
119
+ removeAppsFromCondition?(conditionName: string, environmentName: string, appNames: string[]): Promise<void>;
108
120
  addAppModel?(appModel: AppModel): Promise<void>;
109
121
  getAppModel?(appName: string): Promise<AppModel>;
110
122
  removeAppModel?(appName: string): Promise<void>;
@@ -149,6 +161,9 @@ export interface AppProcessAdapter {
149
161
  upgradeApp?(appName: string, context?: {
150
162
  requestId: string;
151
163
  }): Promise<void>;
164
+ dispatchAppEvent?(appName: string, event: string, payload?: any, context?: {
165
+ requestId: string;
166
+ }): Promise<void>;
152
167
  removeAllApps?(): Promise<void>;
153
168
  setAppError?(appName: string, error: Error): void;
154
169
  hasAppError?(appName: string): boolean;
@@ -287,6 +287,7 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
287
287
  getV2RuntimeConfig() {
288
288
  return {
289
289
  __nocobase_public_path__: this.getV2PublicPath(),
290
+ __nocobase_modern_client_prefix__: (0, import_utils3.normalizeModernClientPrefix)(import_node_process.default.env.APP_MODERN_CLIENT_PREFIX),
290
291
  __webpack_public_path__: import_node_process.default.env.CDN_BASE_URL ? `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/` : "",
291
292
  __nocobase_api_base_url__: import_node_process.default.env.API_BASE_URL || import_node_process.default.env.API_BASE_PATH,
292
293
  __nocobase_api_client_storage_prefix__: import_node_process.default.env.API_CLIENT_STORAGE_PREFIX,
@@ -306,12 +307,12 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
306
307
  }
307
308
  getV2AssetPublicPath() {
308
309
  if (import_node_process.default.env.CDN_BASE_URL) {
309
- return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/v2/`;
310
+ return `${import_node_process.default.env.CDN_BASE_URL.replace(/\/+$/, "")}/${import_utils3.MODERN_CLIENT_DIST_DIR}/`;
310
311
  }
311
312
  return this.getV2PublicPath();
312
313
  }
313
314
  getV2IndexTemplate() {
314
- const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/v2/index.html`;
315
+ const file = `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client/${import_utils3.MODERN_CLIENT_DIST_DIR}/index.html`;
315
316
  if (!import_fs.default.existsSync(file)) {
316
317
  return null;
317
318
  }
@@ -371,6 +372,20 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
371
372
  directoryListing: false
372
373
  });
373
374
  }
375
+ if (pathname.startsWith(APP_PUBLIC_PATH + "dist/")) {
376
+ if (handleApp !== "main") {
377
+ const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
378
+ if (isProxy) {
379
+ return;
380
+ }
381
+ }
382
+ req.url = req.url.substring(APP_PUBLIC_PATH.length + "dist".length);
383
+ await compress(req, res);
384
+ return (0, import_serve_handler.default)(req, res, {
385
+ public: (0, import_utils.storagePathJoin)("dist-client"),
386
+ directoryListing: false
387
+ });
388
+ }
374
389
  if (pathname.startsWith(PLUGIN_STATICS_PATH) && !pathname.includes("/server/")) {
375
390
  if (handleApp !== "main") {
376
391
  const isProxy = await this.proxyRequestToSubApp(supervisor, handleApp, req, res);
@@ -409,6 +424,10 @@ const _Gateway = class _Gateway extends import_events.EventEmitter {
409
424
  }
410
425
  }
411
426
  req.url = req.url.substring(APP_PUBLIC_PATH.length - 1);
427
+ const modernPrefix = (0, import_utils3.normalizeModernClientPrefix)(import_node_process.default.env.APP_MODERN_CLIENT_PREFIX);
428
+ if (modernPrefix !== import_utils3.MODERN_CLIENT_DIST_DIR && req.url.startsWith(`/${modernPrefix}/`)) {
429
+ req.url = `/${import_utils3.MODERN_CLIENT_DIST_DIR}/${req.url.slice(modernPrefix.length + 2)}`;
430
+ }
412
431
  await compress(req, res);
413
432
  return (0, import_serve_handler.default)(req, res, {
414
433
  public: `${import_node_process.default.env.APP_PACKAGE_ROOT}/dist/client`
@@ -9,7 +9,9 @@
9
9
  /// <reference types="node" />
10
10
  import { IncomingMessage } from 'http';
11
11
  import { IncomingRequest } from '.';
12
+ export declare const MODERN_CLIENT_DIST_DIR = "v";
12
13
  export declare function resolvePublicPath(appPublicPath?: string): string;
14
+ export declare function normalizeModernClientPrefix(value?: string): string;
13
15
  export declare function resolveV2PublicPath(appPublicPath?: string): string;
14
16
  export declare function rewriteV2AssetPublicPath(html: string, assetPublicPath: string): string;
15
17
  export declare function injectRuntimeScript(html: string, runtimeScript: string): string;
@@ -27,23 +27,32 @@ var __copyProps = (to, from, except, desc) => {
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var utils_exports = {};
29
29
  __export(utils_exports, {
30
+ MODERN_CLIENT_DIST_DIR: () => MODERN_CLIENT_DIST_DIR,
30
31
  getHost: () => getHost,
31
32
  getHostname: () => getHostname,
32
33
  injectRuntimeScript: () => injectRuntimeScript,
34
+ normalizeModernClientPrefix: () => normalizeModernClientPrefix,
33
35
  resolvePublicPath: () => resolvePublicPath,
34
36
  resolveV2PublicPath: () => resolveV2PublicPath,
35
37
  rewriteV2AssetPublicPath: () => rewriteV2AssetPublicPath
36
38
  });
37
39
  module.exports = __toCommonJS(utils_exports);
40
+ const MODERN_CLIENT_DIST_DIR = "v";
38
41
  function resolvePublicPath(appPublicPath = "/") {
39
42
  const normalized = String(appPublicPath || "/").trim() || "/";
40
43
  const withLeadingSlash = normalized.startsWith("/") ? normalized : `/${normalized}`;
41
44
  return withLeadingSlash.endsWith("/") ? withLeadingSlash : `${withLeadingSlash}/`;
42
45
  }
43
46
  __name(resolvePublicPath, "resolvePublicPath");
47
+ function normalizeModernClientPrefix(value) {
48
+ const segment = String(value || "").trim().replace(/^\/+|\/+$/g, "");
49
+ return segment || MODERN_CLIENT_DIST_DIR;
50
+ }
51
+ __name(normalizeModernClientPrefix, "normalizeModernClientPrefix");
44
52
  function resolveV2PublicPath(appPublicPath = "/") {
45
53
  const publicPath = resolvePublicPath(appPublicPath);
46
- return `${publicPath.replace(/\/$/, "")}/v2/`;
54
+ const prefix = normalizeModernClientPrefix(process.env.APP_MODERN_CLIENT_PREFIX);
55
+ return `${publicPath.replace(/\/$/, "")}/${prefix}/`;
47
56
  }
48
57
  __name(resolveV2PublicPath, "resolveV2PublicPath");
49
58
  function ensureTrailingSlash(value) {
@@ -52,10 +61,12 @@ function ensureTrailingSlash(value) {
52
61
  __name(ensureTrailingSlash, "ensureTrailingSlash");
53
62
  function rewriteV2AssetPublicPath(html, assetPublicPath) {
54
63
  const normalizedAssetPublicPath = ensureTrailingSlash(assetPublicPath);
55
- if (normalizedAssetPublicPath === "/v2/") {
64
+ const sentinel = `/${MODERN_CLIENT_DIST_DIR}/`;
65
+ if (normalizedAssetPublicPath === sentinel) {
56
66
  return html;
57
67
  }
58
- return html.replace(/((?:src|href)=["'])\/v2\//g, `$1${normalizedAssetPublicPath}`);
68
+ const sentinelPattern = new RegExp(`((?:src|href)=["'])${sentinel.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "g");
69
+ return html.replace(sentinelPattern, `$1${normalizedAssetPublicPath}`);
59
70
  }
60
71
  __name(rewriteV2AssetPublicPath, "rewriteV2AssetPublicPath");
61
72
  function injectRuntimeScript(html, runtimeScript) {
@@ -106,9 +117,11 @@ function getHostname(req) {
106
117
  __name(getHostname, "getHostname");
107
118
  // Annotate the CommonJS export names for ESM import in node:
108
119
  0 && (module.exports = {
120
+ MODERN_CLIENT_DIST_DIR,
109
121
  getHost,
110
122
  getHostname,
111
123
  injectRuntimeScript,
124
+ normalizeModernClientPrefix,
112
125
  resolvePublicPath,
113
126
  resolveV2PublicPath,
114
127
  rewriteV2AssetPublicPath
@@ -38,7 +38,7 @@ module.exports = __toCommonJS(constants_exports);
38
38
  const APP_NAME = "nocobase";
39
39
  const DEFAULT_PLUGIN_STORAGE_PATH = "storage/plugins";
40
40
  const DEFAULT_PLUGIN_PATH = "packages/plugins/";
41
- const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(",");
41
+ const pluginPrefix = (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-").split(",");
42
42
  const requireRegex = /require\s*\(['"`](.*?)['"`]\)/g;
43
43
  const importRegex = /^import(?:['"\s]*([\w*${}\s,]+)from\s*)?['"\s]['"\s](.*[@\w_-]+)['"\s].*/gm;
44
44
  const EXTERNAL = [
@@ -6,11 +6,11 @@
6
6
  * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
- declare function trim(packageNames: string[]): Promise<any[]>;
10
- export declare function findPackageNames(): Promise<any[]>;
11
- export declare function findBuiltInPlugins(): Promise<any[]>;
12
- export declare function findLocalPlugins(): Promise<any[]>;
13
- export declare function findAllPlugins(): Promise<any[]>;
9
+ declare function trim(packageNames: string[]): Promise<string[]>;
10
+ export declare function findPackageNames(): Promise<string[]>;
11
+ export declare function findBuiltInPlugins(): Promise<string[]>;
12
+ export declare function findLocalPlugins(): Promise<string[]>;
13
+ export declare function findAllPlugins(): Promise<string[]>;
14
14
  export declare const packageNameTrim: typeof trim;
15
15
  export declare function appendToBuiltInPlugins(nameOrPkg: string): Promise<void>;
16
16
  export {};
@@ -45,25 +45,17 @@ __export(findPackageNames_exports, {
45
45
  packageNameTrim: () => packageNameTrim
46
46
  });
47
47
  module.exports = __toCommonJS(findPackageNames_exports);
48
- var import_fast_glob = __toESM(require("fast-glob"));
49
- var import_utils = require("@nocobase/utils");
50
- var import_fs_extra = __toESM(require("fs-extra"));
48
+ var import_plugin_package = require("../../../utils/plugin-package");
51
49
  var import_lodash = __toESM(require("lodash"));
52
- var import_path = __toESM(require("path"));
53
- var import__ = require("./");
54
- function splitNames(name) {
55
- return (name || "").split(",").filter(Boolean);
56
- }
57
- __name(splitNames, "splitNames");
58
50
  async function trim(packageNames) {
59
51
  const nameOrPkgs = import_lodash.default.uniq(packageNames).filter(Boolean);
60
52
  const names = [];
61
53
  for (const nameOrPkg of nameOrPkgs) {
62
- const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
63
- try {
64
- await import__.PluginManager.getPackageJson(packageName);
54
+ const { name, packageName } = await (0, import_plugin_package.parsePluginName)(nameOrPkg, {
55
+ nodeModulesPath: process.env.NODE_MODULES_PATH
56
+ });
57
+ if (await (0, import_plugin_package.resolvePluginPackagePath)(packageName)) {
65
58
  names.push(name);
66
- } catch (error) {
67
59
  }
68
60
  }
69
61
  return names;
@@ -82,76 +74,57 @@ const excludes = [
82
74
  "@nocobase/plugin-workflow-test"
83
75
  ];
84
76
  async function findPackageNames() {
85
- const pluginStoragePath = (0, import_utils.resolvePluginStoragePath)();
86
- const patterns = [
87
- "./packages/plugins/*/package.json",
88
- "./packages/plugins/*/*/package.json",
89
- "./packages/pro-plugins/*/*/package.json",
90
- import_path.default.join(pluginStoragePath, "*/package.json"),
91
- import_path.default.join(pluginStoragePath, "*/*/package.json")
92
- ];
93
77
  try {
94
- const packageJsonPaths = await (0, import_fast_glob.default)(patterns, {
95
- cwd: process.cwd(),
96
- absolute: true,
97
- ignore: ["**/external-db-data-source/**"]
78
+ const packages = await (0, import_plugin_package.discoverPluginPackages)({
79
+ nodeModulesPath: process.env.NODE_MODULES_PATH
98
80
  });
99
- const packageNames = await Promise.all(
100
- packageJsonPaths.map(async (packageJsonPath) => {
101
- const packageJson = await import_fs_extra.default.readJson(packageJsonPath);
102
- return packageJson.name;
103
- })
104
- );
105
- const nocobasePlugins = await findNocobasePlugins();
106
- const { APPEND_PRESET_BUILT_IN_PLUGINS = "", APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
107
- return trim(
108
- packageNames.filter((pkg) => pkg && !excludes.includes(pkg)).concat(nocobasePlugins).concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS))
109
- );
81
+ return trim(packages.filter((pkg) => !excludes.includes(pkg.packageName)).map((pkg) => pkg.packageName));
110
82
  } catch (error) {
111
83
  return [];
112
84
  }
113
85
  }
114
86
  __name(findPackageNames, "findPackageNames");
115
87
  async function getPackageJson() {
116
- const packageJson = await import_fs_extra.default.readJson(
117
- import_path.default.resolve(process.env.NODE_MODULES_PATH, "@nocobase/preset-nocobase/package.json")
118
- );
88
+ const packageJson = await (0, import_plugin_package.getPresetNocoBasePackageJson)({
89
+ nodeModulesPath: process.env.NODE_MODULES_PATH
90
+ });
91
+ if (!packageJson) {
92
+ throw new Error("Cannot find @nocobase/preset-nocobase package.json");
93
+ }
119
94
  return packageJson;
120
95
  }
121
96
  __name(getPackageJson, "getPackageJson");
122
- async function findNocobasePlugins() {
123
- try {
124
- const packageJson = await getPackageJson();
125
- const pluginNames = Object.keys(packageJson.dependencies).filter((name) => name.startsWith("@nocobase/plugin-"));
126
- return trim(pluginNames.filter((pkg) => pkg && !excludes.includes(pkg)));
127
- } catch (error) {
128
- return [];
129
- }
130
- }
131
- __name(findNocobasePlugins, "findNocobasePlugins");
132
97
  async function findBuiltInPlugins() {
133
98
  const { APPEND_PRESET_BUILT_IN_PLUGINS = "" } = process.env;
134
99
  try {
135
100
  const packageJson = await getPackageJson();
136
- return trim(packageJson.builtIn.concat(splitNames(APPEND_PRESET_BUILT_IN_PLUGINS)));
101
+ return trim((packageJson.builtIn || []).concat((0, import_plugin_package.splitPluginNames)(APPEND_PRESET_BUILT_IN_PLUGINS)));
137
102
  } catch (error) {
138
103
  return [];
139
104
  }
140
105
  }
141
106
  __name(findBuiltInPlugins, "findBuiltInPlugins");
142
107
  async function findLocalPlugins() {
143
- const { APPEND_PRESET_LOCAL_PLUGINS = "" } = process.env;
144
- const plugins1 = await findNocobasePlugins();
145
- const plugins2 = await findPackageNames();
146
- const builtInPlugins = await findBuiltInPlugins();
147
108
  const packageJson = await getPackageJson();
148
- const items = await trim(
109
+ const packages = await (0, import_plugin_package.discoverPluginPackages)({
110
+ nodeModulesPath: process.env.NODE_MODULES_PATH
111
+ });
112
+ const builtInPackageNames = await Promise.all(
113
+ (packageJson.builtIn || []).concat((0, import_plugin_package.splitPluginNames)(process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "")).map(
114
+ async (nameOrPkg) => (await (0, import_plugin_package.parsePluginName)(nameOrPkg, { nodeModulesPath: process.env.NODE_MODULES_PATH })).packageName
115
+ )
116
+ );
117
+ const deprecatedPackageNames = await Promise.all(
118
+ (packageJson.deprecated || []).map(
119
+ async (nameOrPkg) => (await (0, import_plugin_package.parsePluginName)(nameOrPkg, { nodeModulesPath: process.env.NODE_MODULES_PATH })).packageName
120
+ )
121
+ );
122
+ return trim(
149
123
  import_lodash.default.difference(
150
- plugins1.concat(plugins2).concat(splitNames(APPEND_PRESET_LOCAL_PLUGINS)),
151
- builtInPlugins.concat(await trim(packageJson.deprecated))
124
+ packages.filter((pkg) => !excludes.includes(pkg.packageName)).map((pkg) => pkg.packageName),
125
+ import_lodash.default.uniq(builtInPackageNames.concat(deprecatedPackageNames))
152
126
  )
153
127
  );
154
- return items;
155
128
  }
156
129
  __name(findLocalPlugins, "findLocalPlugins");
157
130
  async function findAllPlugins() {
@@ -163,8 +136,10 @@ __name(findAllPlugins, "findAllPlugins");
163
136
  const packageNameTrim = trim;
164
137
  async function appendToBuiltInPlugins(nameOrPkg) {
165
138
  const APPEND_PRESET_BUILT_IN_PLUGINS = process.env.APPEND_PRESET_BUILT_IN_PLUGINS || "";
166
- const keys = APPEND_PRESET_BUILT_IN_PLUGINS.split(",");
167
- const { name, packageName } = await import__.PluginManager.parseName(nameOrPkg);
139
+ const keys = (0, import_plugin_package.splitPluginNames)(APPEND_PRESET_BUILT_IN_PLUGINS);
140
+ const { name, packageName } = await (0, import_plugin_package.parsePluginName)(nameOrPkg, {
141
+ nodeModulesPath: process.env.NODE_MODULES_PATH
142
+ });
168
143
  if (keys.includes(packageName)) {
169
144
  return;
170
145
  }
@@ -57,6 +57,7 @@ var import_middleware = require("./middleware");
57
57
  var import_collection = __toESM(require("./options/collection"));
58
58
  var import_resource = __toESM(require("./options/resource"));
59
59
  var import_plugin_manager_repository = require("./plugin-manager-repository");
60
+ var import_plugin_package = require("../../../utils/plugin-package");
60
61
  var import_utils2 = require("./utils");
61
62
  const _PluginLoadError = class _PluginLoadError extends Error {
62
63
  constructor(pluginName) {
@@ -180,9 +181,7 @@ const _PluginManager = class _PluginManager {
180
181
  * @internal
181
182
  */
182
183
  static getPluginPkgPrefix() {
183
- return (process.env.PLUGIN_PACKAGE_PREFIX || "@nocobase/plugin-,@nocobase/preset-,@nocobase/plugin-pro-").split(
184
- ","
185
- );
184
+ return (0, import_plugin_package.getPluginPackagePrefixes)();
186
185
  }
187
186
  /**
188
187
  * @internal
@@ -237,32 +236,10 @@ const _PluginManager = class _PluginManager {
237
236
  if (this.parsedNames[nameOrPkg]) {
238
237
  return this.parsedNames[nameOrPkg];
239
238
  }
240
- if (nameOrPkg.startsWith("@nocobase/plugin-")) {
241
- this.parsedNames[nameOrPkg] = {
242
- packageName: nameOrPkg,
243
- name: nameOrPkg.replace("@nocobase/plugin-", "")
244
- };
245
- return this.parsedNames[nameOrPkg];
246
- }
247
- if (nameOrPkg.startsWith("@nocobase/preset-")) {
248
- this.parsedNames[nameOrPkg] = {
249
- packageName: nameOrPkg,
250
- name: nameOrPkg.replace("@nocobase/preset-", "")
251
- };
252
- return this.parsedNames[nameOrPkg];
253
- }
254
- const exists = /* @__PURE__ */ __name(async (name, isPreset = false) => {
255
- return import_fs_extra.default.exists(
256
- (0, import_path.resolve)(process.env.NODE_MODULES_PATH, `@nocobase/${isPreset ? "preset" : "plugin"}-${name}`, "package.json")
257
- );
258
- }, "exists");
259
- if (await exists(nameOrPkg)) {
260
- this.parsedNames[nameOrPkg] = { name: nameOrPkg, packageName: `@nocobase/plugin-${nameOrPkg}` };
261
- } else if (await exists(nameOrPkg, true)) {
262
- this.parsedNames[nameOrPkg] = { name: nameOrPkg, packageName: `@nocobase/preset-${nameOrPkg}` };
263
- } else {
264
- this.parsedNames[nameOrPkg] = { name: nameOrPkg, packageName: nameOrPkg };
265
- }
239
+ this.parsedNames[nameOrPkg] = await (0, import_plugin_package.parsePluginName)(nameOrPkg, {
240
+ nodeModulesPath: process.env.NODE_MODULES_PATH,
241
+ pluginPackagePrefixes: this.getPluginPkgPrefix()
242
+ });
266
243
  return this.parsedNames[nameOrPkg];
267
244
  }
268
245
  addPreset(plugin, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "2.1.0-beta.43",
3
+ "version": "2.1.0-beta.45",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -10,21 +10,21 @@
10
10
  "@koa/cors": "^5.0.0",
11
11
  "@koa/multer": "^3.1.0",
12
12
  "@koa/router": "^13.1.0",
13
- "@nocobase/acl": "2.1.0-beta.43",
14
- "@nocobase/actions": "2.1.0-beta.43",
15
- "@nocobase/ai": "2.1.0-beta.43",
16
- "@nocobase/auth": "2.1.0-beta.43",
17
- "@nocobase/cache": "2.1.0-beta.43",
18
- "@nocobase/data-source-manager": "2.1.0-beta.43",
19
- "@nocobase/database": "2.1.0-beta.43",
20
- "@nocobase/evaluators": "2.1.0-beta.43",
21
- "@nocobase/lock-manager": "2.1.0-beta.43",
22
- "@nocobase/logger": "2.1.0-beta.43",
23
- "@nocobase/resourcer": "2.1.0-beta.43",
24
- "@nocobase/sdk": "2.1.0-beta.43",
25
- "@nocobase/snowflake-id": "2.1.0-beta.43",
26
- "@nocobase/telemetry": "2.1.0-beta.43",
27
- "@nocobase/utils": "2.1.0-beta.43",
13
+ "@nocobase/acl": "2.1.0-beta.45",
14
+ "@nocobase/actions": "2.1.0-beta.45",
15
+ "@nocobase/ai": "2.1.0-beta.45",
16
+ "@nocobase/auth": "2.1.0-beta.45",
17
+ "@nocobase/cache": "2.1.0-beta.45",
18
+ "@nocobase/data-source-manager": "2.1.0-beta.45",
19
+ "@nocobase/database": "2.1.0-beta.45",
20
+ "@nocobase/evaluators": "2.1.0-beta.45",
21
+ "@nocobase/lock-manager": "2.1.0-beta.45",
22
+ "@nocobase/logger": "2.1.0-beta.45",
23
+ "@nocobase/resourcer": "2.1.0-beta.45",
24
+ "@nocobase/sdk": "2.1.0-beta.45",
25
+ "@nocobase/snowflake-id": "2.1.0-beta.45",
26
+ "@nocobase/telemetry": "2.1.0-beta.45",
27
+ "@nocobase/utils": "2.1.0-beta.45",
28
28
  "@types/decompress": "4.2.7",
29
29
  "@types/ini": "^1.3.31",
30
30
  "@types/koa-send": "^4.1.3",
@@ -61,5 +61,5 @@
61
61
  "@types/serve-handler": "^6.1.1",
62
62
  "@types/ws": "^8.5.5"
63
63
  },
64
- "gitHead": "6d7750e2373bf2451d246de88cc1f62491685e18"
64
+ "gitHead": "42587115fc34c3eb01ef2b2549f1c998e5708318"
65
65
  }