@tego/core 1.6.3-alpha.3 → 1.6.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.
@@ -273,6 +273,12 @@ export declare class Application extends EventEmitter implements AsyncEmitter {
273
273
  * @deprecated
274
274
  */
275
275
  getPlugin<P extends Plugin>(name: string | Constructable<P>): P;
276
+ /**
277
+ * Register a plugin class for testing purposes.
278
+ * This stores the plugin in the internal plugins map to be loaded later.
279
+ * @param pluginClass - The plugin class to register
280
+ */
281
+ plugin<P extends Plugin>(pluginClass: new (app: Application, options: any) => P): void;
276
282
  /**
277
283
  * This method is deprecated and should not be used.
278
284
  * Use {@link this.runAsCLI()} instead.
@@ -336,6 +336,14 @@ const _Application = class _Application extends import_node_stream.EventEmitter
336
336
  await this.emitAsync("beforeLoad", this, options);
337
337
  }
338
338
  await this.pm.load(options);
339
+ for (const [name, instance] of this.plugins) {
340
+ if (instance.beforeLoad) {
341
+ await instance.beforeLoad();
342
+ }
343
+ if (instance.load) {
344
+ await instance.load();
345
+ }
346
+ }
339
347
  if (options == null ? void 0 : options.sync) {
340
348
  await this.db.sync();
341
349
  }
@@ -366,6 +374,16 @@ const _Application = class _Application extends import_node_stream.EventEmitter
366
374
  getPlugin(name) {
367
375
  return this.pm.get(name);
368
376
  }
377
+ /**
378
+ * Register a plugin class for testing purposes.
379
+ * This stores the plugin in the internal plugins map to be loaded later.
380
+ * @param pluginClass - The plugin class to register
381
+ */
382
+ plugin(pluginClass) {
383
+ const name = pluginClass.name || `test-plugin-${this.plugins.size}`;
384
+ const instance = new pluginClass(this, {});
385
+ this.plugins.set(name, instance);
386
+ }
369
387
  /**
370
388
  * This method is deprecated and should not be used.
371
389
  * Use {@link this.runAsCLI()} instead.
@@ -22,8 +22,18 @@ __export(i18n_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(i18n_exports);
24
24
  async function i18n(ctx, next) {
25
+ var _a;
26
+ if (!ctx.tego || !ctx.tego.localeManager) {
27
+ if ((_a = ctx.tego) == null ? void 0 : _a.i18n) {
28
+ ctx.t = ctx.tego.i18n.t.bind(ctx.tego.i18n);
29
+ ctx.i18n = ctx.tego.i18n;
30
+ }
31
+ await next();
32
+ return;
33
+ }
25
34
  ctx.getCurrentLocale = () => {
26
- const lng2 = ctx.get("X-Locale") || ctx.request.query.locale || ctx.tego.i18n.language || ctx.acceptsLanguages().shift() || "en-US";
35
+ var _a2;
36
+ const lng2 = ctx.get("X-Locale") || ctx.request.query.locale || ((_a2 = ctx.tego.i18n) == null ? void 0 : _a2.language) || ctx.acceptsLanguages().shift() || "en-US";
27
37
  return lng2;
28
38
  };
29
39
  const lng = ctx.getCurrentLocale();
@@ -116,6 +116,9 @@ const _PluginManager = class _PluginManager {
116
116
  */
117
117
  static async getPackageName(name) {
118
118
  const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
119
+ if (!pluginPaths) {
120
+ throw new Error(`${name} plugin does not exist (PLUGIN_PATHS not initialized)`);
121
+ }
119
122
  const prefixes = this.getPluginPkgPrefix();
120
123
  for (const prefix of prefixes) {
121
124
  for (const basePath of pluginPaths) {
@@ -291,8 +294,15 @@ const _PluginManager = class _PluginManager {
291
294
  });
292
295
  let P;
293
296
  try {
294
- if (options.isPreset) {
295
- P = import_globals.default.getInstance().get("PRESETS")[options.name];
297
+ if (typeof plugin === "function") {
298
+ P = plugin;
299
+ } else if (options.isPreset) {
300
+ const presets = import_globals.default.getInstance().get("PRESETS");
301
+ P = presets == null ? void 0 : presets[options.name];
302
+ if (!P) {
303
+ this.app.logger.warn(`preset plugin [${options.name}] not found in PRESETS`);
304
+ return;
305
+ }
296
306
  } else {
297
307
  P = await _PluginManager.resolvePlugin(options.packageName || plugin, isUpgrade, !!options.packageName);
298
308
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tego/core",
3
- "version": "1.6.3-alpha.3",
3
+ "version": "1.6.3",
4
4
  "license": "Apache-2.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -31,18 +31,18 @@
31
31
  "winston": "^3.17.0",
32
32
  "ws": "^8.18.3",
33
33
  "xpipe": "^1.0.8",
34
- "@tachybase/acl": "1.6.3-alpha.3",
35
- "@tachybase/actions": "1.6.3-alpha.3",
36
- "@tachybase/cache": "1.6.3-alpha.3",
37
- "@tachybase/auth": "1.6.3-alpha.3",
38
- "@tachybase/database": "1.6.3-alpha.3",
39
- "@tachybase/di": "1.6.3-alpha.3",
40
- "@tachybase/data-source": "1.6.3-alpha.3",
41
- "@tachybase/globals": "1.6.3-alpha.3",
42
- "@tachybase/logger": "1.6.3-alpha.3",
43
- "@tachybase/loader": "1.6.3-alpha.3",
44
- "@tachybase/utils": "1.6.3-alpha.3",
45
- "@tachybase/resourcer": "1.6.3-alpha.3"
34
+ "@tachybase/actions": "1.6.3",
35
+ "@tachybase/auth": "1.6.3",
36
+ "@tachybase/acl": "1.6.3",
37
+ "@tachybase/cache": "1.6.3",
38
+ "@tachybase/data-source": "1.6.3",
39
+ "@tachybase/database": "1.6.3",
40
+ "@tachybase/di": "1.6.3",
41
+ "@tachybase/globals": "1.6.3",
42
+ "@tachybase/loader": "1.6.3",
43
+ "@tachybase/logger": "1.6.3",
44
+ "@tachybase/resourcer": "1.6.3",
45
+ "@tachybase/utils": "1.6.3"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/fs-extra": "11.0.4",