@nocobase/server 1.0.0-alpha.13 → 1.0.0-alpha.15

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.
@@ -11,7 +11,7 @@
11
11
  import { AuthManager, AuthManagerOptions } from '@nocobase/auth';
12
12
  import { Cache, CacheManager, CacheManagerOptions } from '@nocobase/cache';
13
13
  import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
14
- import { LoggerOptions, RequestLoggerOptions, SystemLogger, SystemLoggerOptions } from '@nocobase/logger';
14
+ import { Logger, LoggerOptions, RequestLoggerOptions, SystemLogger, SystemLoggerOptions } from '@nocobase/logger';
15
15
  import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
16
16
  import { Telemetry, TelemetryOptions } from '@nocobase/telemetry';
17
17
  import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
@@ -155,9 +155,15 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
155
155
  private _maintainingCommandStatus;
156
156
  private _maintainingStatusBeforeCommand;
157
157
  private _actionCommand;
158
- constructor(options: ApplicationOptions);
158
+ /**
159
+ * @internal
160
+ */
161
+ requestLogger: Logger;
162
+ private sqlLogger;
159
163
  protected _logger: SystemLogger;
164
+ constructor(options: ApplicationOptions);
160
165
  get logger(): SystemLogger;
166
+ get log(): SystemLogger;
161
167
  protected _loaded: boolean;
162
168
  /**
163
169
  * @internal
@@ -208,7 +214,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
208
214
  get telemetry(): Telemetry;
209
215
  protected _version: ApplicationVersion;
210
216
  get version(): ApplicationVersion;
211
- get log(): SystemLogger;
212
217
  get name(): string;
213
218
  protected _dataSourceManager: DataSourceManager;
214
219
  get dataSourceManager(): DataSourceManager;
@@ -329,8 +334,10 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
329
334
  * @internal
330
335
  */
331
336
  reInitEvents(): void;
332
- createLogger(options: LoggerOptions): import("winston").Logger;
337
+ createLogger(options: LoggerOptions): Logger;
333
338
  protected createCLI(): AppCommand;
339
+ protected initLogger(options: AppLoggerOptions): void;
340
+ protected closeLogger(): void;
334
341
  protected init(): void;
335
342
  protected createMainDataSource(options: ApplicationOptions): void;
336
343
  protected createDatabase(options: ApplicationOptions): Database;
@@ -70,6 +70,8 @@ var import_package = __toESM(require("../package.json"));
70
70
  var import_main_data_source = require("./main-data-source");
71
71
  var import_validate_filter_params = __toESM(require("./middlewares/validate-filter-params"));
72
72
  var import_path2 = __toESM(require("path"));
73
+ var import_middlewares = require("./middlewares");
74
+ var import_data_template = require("./middlewares/data-template");
73
75
  const _Application = class _Application extends import_koa.default {
74
76
  constructor(options) {
75
77
  super();
@@ -111,10 +113,18 @@ const _Application = class _Application extends import_koa.default {
111
113
  _maintainingCommandStatus;
112
114
  _maintainingStatusBeforeCommand;
113
115
  _actionCommand;
116
+ /**
117
+ * @internal
118
+ */
119
+ requestLogger;
120
+ sqlLogger;
114
121
  _logger;
115
122
  get logger() {
116
123
  return this._logger;
117
124
  }
125
+ get log() {
126
+ return this._logger;
127
+ }
118
128
  _loaded;
119
129
  /**
120
130
  * @internal
@@ -207,9 +217,6 @@ const _Application = class _Application extends import_koa.default {
207
217
  get version() {
208
218
  return this._version;
209
219
  }
210
- get log() {
211
- return this._logger;
212
- }
213
220
  get name() {
214
221
  return this.options.name || "main";
215
222
  }
@@ -323,6 +330,7 @@ const _Application = class _Application extends import_koa.default {
323
330
  if (this.telemetry.started) {
324
331
  await this.telemetry.shutdown();
325
332
  }
333
+ this.closeLogger();
326
334
  const oldDb = this.db;
327
335
  this.init();
328
336
  if (!oldDb.closed()) {
@@ -351,8 +359,10 @@ const _Application = class _Application extends import_koa.default {
351
359
  }
352
360
  }
353
361
  this._cacheManager = await (0, import_cache2.createCacheManager)(this, this.options.cacheManager);
362
+ this.log.debug("init plugins");
354
363
  this.setMaintainingMessage("init plugins");
355
364
  await this.pm.initPlugins();
365
+ this.log.debug("loading app...");
356
366
  this.setMaintainingMessage("start load");
357
367
  this.setMaintainingMessage("emit beforeLoad");
358
368
  if ((options == null ? void 0 : options.hooks) !== false) {
@@ -532,6 +542,7 @@ const _Application = class _Application extends import_koa.default {
532
542
  `Application ${this.name} is not installed, Please run 'yarn nocobase install' command first`
533
543
  );
534
544
  }
545
+ this.log.debug(`starting app...`);
535
546
  this.setMaintainingMessage("starting app...");
536
547
  if (this.db.closed()) {
537
548
  await this.db.reconnect();
@@ -621,6 +632,7 @@ const _Application = class _Application extends import_koa.default {
621
632
  this.log.debug("emit afterDestroy", { method: "destory" });
622
633
  await this.emitAsync("afterDestroy", this, options);
623
634
  this.log.debug("finish destroy app", { method: "destory" });
635
+ this.closeLogger();
624
636
  }
625
637
  async isInstalled() {
626
638
  return await this.db.collectionExistsInDb("applicationVersion") || await this.db.collectionExistsInDb("collections");
@@ -737,19 +749,38 @@ const _Application = class _Application extends import_koa.default {
737
749
  });
738
750
  return command;
739
751
  }
740
- init() {
741
- var _a;
742
- const options = this.options;
752
+ initLogger(options) {
743
753
  this._logger = (0, import_logger.createSystemLogger)({
744
754
  dirname: (0, import_logger.getLoggerFilePath)(this.name),
745
755
  filename: "system",
746
756
  seperateError: true,
747
- ...((_a = options.logger) == null ? void 0 : _a.system) || {}
757
+ ...(options == null ? void 0 : options.system) || {}
748
758
  }).child({
749
759
  reqId: this.context.reqId,
750
760
  app: this.name,
751
761
  module: "application"
762
+ // Due to the use of custom log levels,
763
+ // we have to use any type here until Winston updates the type definitions.
752
764
  });
765
+ this.requestLogger = (0, import_logger.createLogger)({
766
+ dirname: (0, import_logger.getLoggerFilePath)(this.name),
767
+ filename: "request",
768
+ ...(options == null ? void 0 : options.request) || {}
769
+ });
770
+ this.sqlLogger = this.createLogger({
771
+ filename: "sql",
772
+ level: "debug"
773
+ });
774
+ }
775
+ closeLogger() {
776
+ var _a, _b, _c;
777
+ (_a = this.log) == null ? void 0 : _a.close();
778
+ (_b = this.requestLogger) == null ? void 0 : _b.close();
779
+ (_c = this.sqlLogger) == null ? void 0 : _c.close();
780
+ }
781
+ init() {
782
+ const options = this.options;
783
+ this.initLogger(options.logger);
753
784
  this.reInitEvents();
754
785
  this.middleware = new import_utils.Toposort();
755
786
  this.plugins = /* @__PURE__ */ new Map();
@@ -786,6 +817,11 @@ const _Application = class _Application extends import_koa.default {
786
817
  });
787
818
  this._dataSourceManager.use(this._authManager.middleware(), { tag: "auth" });
788
819
  this._dataSourceManager.use(import_validate_filter_params.default, { tag: "validate-filter-params", before: ["auth"] });
820
+ this._dataSourceManager.use(import_middlewares.parseVariables, {
821
+ group: "parseVariables",
822
+ after: "acl"
823
+ });
824
+ this._dataSourceManager.use(import_data_template.dataTemplate, { group: "dataTemplate", after: "acl" });
789
825
  this._locales = new import_locale.Locale((0, import_helper.createAppProxy)(this));
790
826
  if (options.perfHooks) {
791
827
  (0, import_helper.enablePerfHooks)(this);
@@ -809,10 +845,6 @@ const _Application = class _Application extends import_koa.default {
809
845
  this.dataSourceManager.dataSources.set("main", mainDataSourceInstance);
810
846
  }
811
847
  createDatabase(options) {
812
- const sqlLogger = this.createLogger({
813
- filename: "sql",
814
- level: "debug"
815
- });
816
848
  const logging = /* @__PURE__ */ __name((msg) => {
817
849
  if (typeof msg === "string") {
818
850
  msg = msg.replace(/[\r\n]/gm, "").replace(/\s+/g, " ");
@@ -820,7 +852,7 @@ const _Application = class _Application extends import_koa.default {
820
852
  if (msg.includes("INSERT INTO")) {
821
853
  msg = msg.substring(0, 2e3) + "...";
822
854
  }
823
- sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
855
+ this.sqlLogger.debug({ message: msg, app: this.name, reqId: this.context.reqId });
824
856
  }, "logging");
825
857
  const dbOptions = options.database instanceof import_database.default ? options.database.options : options.database;
826
858
  const db = new import_database.default({
@@ -52,7 +52,10 @@ var start_default = /* @__PURE__ */ __name((app) => {
52
52
  const upgrading = await (0, import_utils.fsExists)(file);
53
53
  if (upgrading) {
54
54
  await app.upgrade();
55
- await import_fs.default.promises.rm(file);
55
+ try {
56
+ await import_fs.default.promises.rm(file);
57
+ } catch (error) {
58
+ }
56
59
  } else if (options.quickstart) {
57
60
  if (await app.isInstalled()) {
58
61
  await app.upgrade();
@@ -52,7 +52,7 @@ export declare class Gateway extends EventEmitter {
52
52
  destroy(): void;
53
53
  reset(): void;
54
54
  addAppSelectorMiddleware(middleware: AppSelectorMiddleware, options?: ToposortOptions): void;
55
- getLogger(appName: string, res: ServerResponse): import("winston").Logger;
55
+ getLogger(appName: string, res: ServerResponse): import("@nocobase/logger/lib/logger").Logger;
56
56
  responseError(res: ServerResponse, error: {
57
57
  status: number;
58
58
  maintaining: boolean;
package/lib/helper.js CHANGED
@@ -80,7 +80,7 @@ function registerMiddlewares(app, options) {
80
80
  app.context.reqId = (0, import_crypto.randomUUID)();
81
81
  await next();
82
82
  });
83
- app.use((0, import_logger.requestLogger)(app.name, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
83
+ app.use((0, import_logger.requestLogger)(app.name, app.requestLogger, (_a = options.logger) == null ? void 0 : _a.request), { tag: "logger" });
84
84
  app.use(
85
85
  (0, import_cors.default)({
86
86
  exposeHeaders: ["content-disposition"],
@@ -43,7 +43,7 @@ const _Locale = class _Locale {
43
43
  constructor(app) {
44
44
  this.app = app;
45
45
  this.app.on("afterLoad", async () => {
46
- this.app.log.debug("load locale resource", { submodule: "locale", method: "onAfterLoad" });
46
+ this.app.log.debug("loading locale resource...", { submodule: "locale", method: "onAfterLoad" });
47
47
  this.app.setMaintainingMessage("load locale resource");
48
48
  await this.load();
49
49
  this.app.log.debug("locale resource loaded", { submodule: "locale", method: "onAfterLoad" });
@@ -31,8 +31,6 @@ __export(main_data_source_exports, {
31
31
  });
32
32
  module.exports = __toCommonJS(main_data_source_exports);
33
33
  var import_data_source_manager = require("@nocobase/data-source-manager");
34
- var import_middlewares = require("./middlewares");
35
- var import_data_template = require("./middlewares/data-template");
36
34
  const _MainDataSource = class _MainDataSource extends import_data_source_manager.SequelizeDataSource {
37
35
  init(options = {}) {
38
36
  const { acl, resourceManager, database } = options;
@@ -49,11 +47,6 @@ const _MainDataSource = class _MainDataSource extends import_data_source_manager
49
47
  if (options.useACL !== false) {
50
48
  this.resourceManager.use(this.acl.middleware(), { group: "acl", after: "auth" });
51
49
  }
52
- this.resourceManager.use(import_middlewares.parseVariables, {
53
- group: "parseVariables",
54
- after: "acl"
55
- });
56
- this.resourceManager.use(import_data_template.dateTemplate, { group: "dateTemplate", after: "acl" });
57
50
  }
58
51
  };
59
52
  __name(_MainDataSource, "MainDataSource");
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { Context } from '@nocobase/actions';
10
- export declare const dateTemplate: (ctx: Context, next: any) => Promise<void>;
10
+ export declare const dataTemplate: (ctx: Context, next: any) => Promise<void>;
@@ -27,10 +27,10 @@ var __copyProps = (to, from, except, desc) => {
27
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
28
  var data_template_exports = {};
29
29
  __export(data_template_exports, {
30
- dateTemplate: () => dateTemplate
30
+ dataTemplate: () => dataTemplate
31
31
  });
32
32
  module.exports = __toCommonJS(data_template_exports);
33
- const dateTemplate = /* @__PURE__ */ __name(async (ctx, next) => {
33
+ const dataTemplate = /* @__PURE__ */ __name(async (ctx, next) => {
34
34
  const { resourceName, actionName } = ctx.action;
35
35
  const { isTemplate, fields } = ctx.action.params;
36
36
  await next();
@@ -40,7 +40,7 @@ const dateTemplate = /* @__PURE__ */ __name(async (ctx, next) => {
40
40
  include: fields
41
41
  });
42
42
  }
43
- }, "dateTemplate");
43
+ }, "dataTemplate");
44
44
  const traverseHasMany = /* @__PURE__ */ __name((arr, { collection, exclude = [], include = [] }) => {
45
45
  if (!arr) {
46
46
  return arr;
@@ -142,5 +142,5 @@ const traverseJSON = /* @__PURE__ */ __name((data, options) => {
142
142
  }, "traverseJSON");
143
143
  // Annotate the CommonJS export names for ESM import in node:
144
144
  0 && (module.exports = {
145
- dateTemplate
145
+ dataTemplate
146
146
  });
@@ -338,7 +338,7 @@ const _PluginManager = class _PluginManager {
338
338
  } catch (error) {
339
339
  console.error(error);
340
340
  }
341
- this.app.log.debug(`add plugin [${options.name}]`, {
341
+ this.app.log.trace(`add plugin [${options.name}]`, {
342
342
  method: "add",
343
343
  submodule: "plugin-manager",
344
344
  name: options.name
@@ -379,7 +379,7 @@ const _PluginManager = class _PluginManager {
379
379
  * @internal
380
380
  */
381
381
  async loadCommands() {
382
- this.app.log.debug("load commands");
382
+ this.app.log.info("load commands");
383
383
  const items = await this.repository.find({
384
384
  filter: {
385
385
  enabled: true
@@ -388,21 +388,15 @@ const _PluginManager = class _PluginManager {
388
388
  const packageNames = items.map((item) => item.packageName);
389
389
  const source = [];
390
390
  for (const packageName of packageNames) {
391
- const file = require.resolve(packageName);
392
- const sourceDir = (0, import_path.basename)((0, import_path.dirname)(file)) === "src" ? "src" : "dist";
393
- const directory = (0, import_path.join)(
394
- packageName,
395
- sourceDir,
396
- "server/commands/*." + ((0, import_path.basename)((0, import_path.dirname)(file)) === "src" ? "ts" : "js")
397
- );
391
+ const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
392
+ const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "ts" : "js"));
398
393
  source.push(directory.replaceAll(import_path.sep, "/"));
399
394
  }
400
395
  for (const plugin of this.options.plugins || []) {
401
396
  if (typeof plugin === "string") {
402
- const packageName = await _PluginManager.getPackageName(plugin);
403
- const file = require.resolve(packageName);
404
- const sourceDir = (0, import_path.basename)((0, import_path.dirname)(file)) === "src" ? "src" : "lib";
405
- const directory = (0, import_path.join)(packageName, sourceDir, "server/commands/*." + (sourceDir === "src" ? "ts" : "js"));
397
+ const { packageName } = await _PluginManager.parseName(plugin);
398
+ const dirname = await (0, import_utils2.getPluginBasePath)(packageName);
399
+ const directory = (0, import_path.join)(dirname, "server/commands/*." + ((0, import_path.basename)(dirname) === "src" ? "ts" : "js"));
406
400
  source.push(directory.replaceAll(import_path.sep, "/"));
407
401
  }
408
402
  }
@@ -416,6 +410,7 @@ const _PluginManager = class _PluginManager {
416
410
  }
417
411
  }
418
412
  async load(options = {}) {
413
+ this.app.log.debug("loading plugins...");
419
414
  this.app.setMaintainingMessage("loading plugins...");
420
415
  const total = this.pluginInstances.size;
421
416
  let current = 0;
@@ -429,7 +424,7 @@ const _PluginManager = class _PluginManager {
429
424
  if (!plugin.enabled) {
430
425
  continue;
431
426
  }
432
- this.app.logger.debug(`before load plugin [${name}]`, { submodule: "plugin-manager", method: "load", name });
427
+ this.app.logger.trace(`before load plugin [${name}]`, { submodule: "plugin-manager", method: "load", name });
433
428
  await plugin.beforeLoad();
434
429
  }
435
430
  current = 0;
@@ -444,13 +439,14 @@ const _PluginManager = class _PluginManager {
444
439
  continue;
445
440
  }
446
441
  await this.app.emitAsync("beforeLoadPlugin", plugin, options);
447
- this.app.logger.debug(`load plugin [${name}] `, { submodule: "plugin-manager", method: "load", name });
442
+ this.app.logger.trace(`load plugin [${name}] `, { submodule: "plugin-manager", method: "load", name });
448
443
  await plugin.loadCollections();
449
444
  await plugin.load();
450
445
  plugin.state.loaded = true;
451
446
  await this.app.emitAsync("afterLoadPlugin", plugin, options);
452
447
  }
453
- this.app.setMaintainingMessage("loaded plugins");
448
+ this.app.log.debug("plugins loaded");
449
+ this.app.setMaintainingMessage("plugins loaded");
454
450
  }
455
451
  async install(options = {}) {
456
452
  this.app.setMaintainingMessage("install plugins...");
@@ -111,4 +111,5 @@ export declare function checkAndGetCompatible(packageName: string): Promise<{
111
111
  isCompatible: boolean;
112
112
  depsCompatible: DepCompatible[];
113
113
  }>;
114
+ export declare function getPluginBasePath(packageName: string): Promise<string>;
114
115
  export {};
@@ -57,6 +57,7 @@ __export(utils_exports, {
57
57
  getPackageJsonByLocalPath: () => getPackageJsonByLocalPath,
58
58
  getPackageNameFromString: () => getPackageNameFromString,
59
59
  getPackagesFromFiles: () => getPackagesFromFiles,
60
+ getPluginBasePath: () => getPluginBasePath,
60
61
  getPluginInfoByNpm: () => getPluginInfoByNpm,
61
62
  getPluginStoragePath: () => getPluginStoragePath,
62
63
  getServerPackages: () => getServerPackages,
@@ -512,6 +513,21 @@ async function checkAndGetCompatible(packageName) {
512
513
  };
513
514
  }
514
515
  __name(checkAndGetCompatible, "checkAndGetCompatible");
516
+ async function getPluginBasePath(packageName) {
517
+ if (!packageName) {
518
+ return;
519
+ }
520
+ const file = await import_fs_extra.default.realpath(await (0, import_utils.requireResolve)(packageName));
521
+ try {
522
+ const basePath = await import_fs_extra.default.realpath(import_path.default.resolve(process.env.NODE_MODULES_PATH, packageName, "src"));
523
+ if (file.startsWith(basePath)) {
524
+ return basePath;
525
+ }
526
+ } catch (error) {
527
+ }
528
+ return import_path.default.dirname(import_path.default.dirname(file));
529
+ }
530
+ __name(getPluginBasePath, "getPluginBasePath");
515
531
  // Annotate the CommonJS export names for ESM import in node:
516
532
  0 && (module.exports = {
517
533
  checkAndGetCompatible,
@@ -534,6 +550,7 @@ __name(checkAndGetCompatible, "checkAndGetCompatible");
534
550
  getPackageJsonByLocalPath,
535
551
  getPackageNameFromString,
536
552
  getPackagesFromFiles,
553
+ getPluginBasePath,
537
554
  getPluginInfoByNpm,
538
555
  getPluginStoragePath,
539
556
  getServerPackages,
package/lib/plugin.d.ts CHANGED
@@ -43,7 +43,7 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
43
43
  */
44
44
  private _sourceDir;
45
45
  constructor(app: Application, options?: any);
46
- get log(): import("winston").Logger;
46
+ get log(): import("@nocobase/logger/lib/logger").Logger;
47
47
  get name(): string;
48
48
  get pm(): import("./plugin-manager").PluginManager;
49
49
  get db(): import("@nocobase/database").default;
@@ -53,7 +53,7 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
53
53
  set installed(value: any);
54
54
  get isPreset(): any;
55
55
  getName(): any;
56
- createLogger(options: LoggerOptions): import("winston").Logger;
56
+ createLogger(options: LoggerOptions): import("@nocobase/logger/lib/logger").Logger;
57
57
  afterAdd(): void;
58
58
  beforeLoad(): void;
59
59
  load(): Promise<void>;
@@ -73,10 +73,6 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
73
73
  * @internal
74
74
  */
75
75
  setOptions(options: any): void;
76
- /**
77
- * @internal
78
- */
79
- loadCommands(): Promise<void>;
80
76
  /**
81
77
  * @internal
82
78
  */
@@ -85,6 +81,7 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
85
81
  afterSync: any[];
86
82
  afterLoad: any[];
87
83
  }>;
84
+ private getPluginBasePath;
88
85
  /**
89
86
  * @internal
90
87
  */
@@ -98,13 +95,5 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
98
95
  * @experimental
99
96
  */
100
97
  toJSON(options?: any): Promise<any>;
101
- /**
102
- * @internal
103
- */
104
- protected getSourceDir(): Promise<string>;
105
- /**
106
- * @internal
107
- */
108
- protected isDev(): Promise<boolean>;
109
98
  }
110
99
  export default Plugin;
package/lib/plugin.js CHANGED
@@ -43,7 +43,6 @@ __export(plugin_exports, {
43
43
  module.exports = __toCommonJS(plugin_exports);
44
44
  var import_utils = require("@nocobase/utils");
45
45
  var import_fs = __toESM(require("fs"));
46
- var import_glob = __toESM(require("glob"));
47
46
  var import_path = require("path");
48
47
  var import_plugin_manager = require("./plugin-manager");
49
48
  var import_utils2 = require("./plugin-manager/utils");
@@ -136,45 +135,16 @@ const _Plugin = class _Plugin {
136
135
  setOptions(options) {
137
136
  this.options = options || {};
138
137
  }
139
- /**
140
- * @internal
141
- */
142
- async loadCommands() {
143
- const extensions = ["js", "ts"];
144
- const directory = (0, import_path.resolve)(
145
- process.env.NODE_MODULES_PATH,
146
- this.options.packageName,
147
- await this.getSourceDir(),
148
- "server/commands"
149
- );
150
- const patten = `${directory}/*.{${extensions.join(",")}}`;
151
- const files = import_glob.default.sync(patten, {
152
- ignore: ["**/*.d.ts"]
153
- });
154
- for (const file of files) {
155
- let filename = (0, import_path.basename)(file);
156
- filename = filename.substring(0, filename.lastIndexOf(".")) || filename;
157
- const callback = await (0, import_utils.importModule)(file);
158
- callback(this.app);
159
- }
160
- if (files.length) {
161
- this.app.log.debug(`load commands [${this.name}]`);
162
- }
163
- }
164
138
  /**
165
139
  * @internal
166
140
  */
167
141
  async loadMigrations() {
168
142
  this.app.log.debug(`load plugin migrations [${this.name}]`);
169
- if (!this.options.packageName) {
143
+ const basePath = await this.getPluginBasePath();
144
+ if (!basePath) {
170
145
  return { beforeLoad: [], afterSync: [], afterLoad: [] };
171
146
  }
172
- const directory = (0, import_path.resolve)(
173
- process.env.NODE_MODULES_PATH,
174
- this.options.packageName,
175
- await this.getSourceDir(),
176
- "server/migrations"
177
- );
147
+ const directory = (0, import_path.resolve)(basePath, "server/migrations");
178
148
  return await this.app.loadMigrations({
179
149
  directory,
180
150
  namespace: this.options.packageName,
@@ -183,19 +153,21 @@ const _Plugin = class _Plugin {
183
153
  }
184
154
  });
185
155
  }
156
+ async getPluginBasePath() {
157
+ if (!this.options.packageName) {
158
+ return;
159
+ }
160
+ return (0, import_utils2.getPluginBasePath)(this.options.packageName);
161
+ }
186
162
  /**
187
163
  * @internal
188
164
  */
189
165
  async loadCollections() {
190
- if (!this.options.packageName) {
166
+ const basePath = await this.getPluginBasePath();
167
+ if (!basePath) {
191
168
  return;
192
169
  }
193
- const directory = (0, import_path.resolve)(
194
- process.env.NODE_MODULES_PATH,
195
- this.options.packageName,
196
- await this.getSourceDir(),
197
- "server/collections"
198
- );
170
+ const directory = (0, import_path.resolve)(basePath, "server/collections");
199
171
  if (await (0, import_utils.fsExists)(directory)) {
200
172
  await this.db.import({
201
173
  directory,
@@ -246,36 +218,6 @@ const _Plugin = class _Plugin {
246
218
  }
247
219
  return results;
248
220
  }
249
- /**
250
- * @internal
251
- */
252
- async getSourceDir() {
253
- if (this._sourceDir) {
254
- return this._sourceDir;
255
- }
256
- if (await this.isDev()) {
257
- return this._sourceDir = "src";
258
- }
259
- if ((0, import_path.basename)(__dirname) === "src") {
260
- return this._sourceDir = "src";
261
- }
262
- return this._sourceDir = this.isPreset ? "lib" : "dist";
263
- }
264
- /**
265
- * @internal
266
- */
267
- async isDev() {
268
- if (!this.options.packageName) {
269
- return false;
270
- }
271
- const file = await import_fs.default.promises.realpath(
272
- (0, import_path.resolve)(process.env.NODE_MODULES_PATH || (0, import_path.resolve)(process.cwd(), "node_modules"), this.options.packageName)
273
- );
274
- if (file.startsWith((0, import_path.resolve)(process.cwd(), "packages"))) {
275
- return !!process.env.IS_DEV_CMD;
276
- }
277
- return false;
278
- }
279
221
  };
280
222
  __name(_Plugin, "Plugin");
281
223
  let Plugin = _Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.15",
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.0.0-alpha.13",
14
- "@nocobase/actions": "1.0.0-alpha.13",
15
- "@nocobase/auth": "1.0.0-alpha.13",
16
- "@nocobase/cache": "1.0.0-alpha.13",
17
- "@nocobase/data-source-manager": "1.0.0-alpha.13",
18
- "@nocobase/database": "1.0.0-alpha.13",
19
- "@nocobase/evaluators": "1.0.0-alpha.13",
20
- "@nocobase/logger": "1.0.0-alpha.13",
21
- "@nocobase/resourcer": "1.0.0-alpha.13",
22
- "@nocobase/sdk": "1.0.0-alpha.13",
23
- "@nocobase/telemetry": "1.0.0-alpha.13",
24
- "@nocobase/utils": "1.0.0-alpha.13",
13
+ "@nocobase/acl": "1.0.0-alpha.15",
14
+ "@nocobase/actions": "1.0.0-alpha.15",
15
+ "@nocobase/auth": "1.0.0-alpha.15",
16
+ "@nocobase/cache": "1.0.0-alpha.15",
17
+ "@nocobase/data-source-manager": "1.0.0-alpha.15",
18
+ "@nocobase/database": "1.0.0-alpha.15",
19
+ "@nocobase/evaluators": "1.0.0-alpha.15",
20
+ "@nocobase/logger": "1.0.0-alpha.15",
21
+ "@nocobase/resourcer": "1.0.0-alpha.15",
22
+ "@nocobase/sdk": "1.0.0-alpha.15",
23
+ "@nocobase/telemetry": "1.0.0-alpha.15",
24
+ "@nocobase/utils": "1.0.0-alpha.15",
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": "bd97adef70762a6691b5b58ca6572672a8cdf838"
57
+ "gitHead": "2793d371368e094ea2bba04cfbe9b9b73c44edba"
58
58
  }