@tego/core 1.3.52 → 1.3.53

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.
@@ -46,15 +46,15 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
46
46
  getApp(appName: string, options?: {
47
47
  withOutBootStrap?: boolean;
48
48
  [key: string]: any;
49
- }): Promise<Application<import("./application").DefaultState, import("./application").DefaultContext>>;
49
+ }): Promise<Application>;
50
50
  setAppBootstrapper(appBootstrapper: AppBootstrapper): void;
51
51
  getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus | null;
52
- bootMainApp(options: ApplicationOptions): Application<import("./application").DefaultState, import("./application").DefaultContext>;
52
+ bootMainApp(options: ApplicationOptions): Application;
53
53
  hasApp(appName: string): boolean;
54
- addApp(app: Application): Application<import("./application").DefaultState, import("./application").DefaultContext>;
54
+ addApp(app: Application): Application;
55
55
  getAppsNames(): Promise<string[]>;
56
56
  removeApp(appName: string): Promise<void>;
57
- subApps(): Application<import("./application").DefaultState, import("./application").DefaultContext>[];
57
+ subApps(): Application[];
58
58
  on(eventName: string | symbol, listener: (...args: any[]) => void): this;
59
59
  private bindAppEvents;
60
60
  }
@@ -1,5 +1,6 @@
1
1
  import { IncomingMessage, ServerResponse } from 'node:http';
2
2
  import { RecordableHistogram } from 'node:perf_hooks';
3
+ import { EventEmitter } from 'node:stream';
3
4
  import { AuthManager, AuthManagerOptions } from '@tachybase/auth';
4
5
  import { Cache, CacheManager, CacheManagerOptions } from '@tachybase/cache';
5
6
  import { DataSourceManager, SequelizeDataSource } from '@tachybase/data-source';
@@ -10,7 +11,8 @@ import { ResourceOptions, Resourcer } from '@tachybase/resourcer';
10
11
  import { AsyncEmitter, Constructable, ToposortOptions } from '@tachybase/utils';
11
12
  import { Command, CommandOptions, ParseOptions } from 'commander';
12
13
  import { i18n, InitOptions } from 'i18next';
13
- import Koa, { DefaultContext as KoaDefaultContext, DefaultState as KoaDefaultState } from 'koa';
14
+ import Koa from 'koa';
15
+ import winston from 'winston';
14
16
  import WebSocket from 'ws';
15
17
  import AesEncryptor from './aes-encryptor';
16
18
  import { AppCommand } from './app-command';
@@ -63,16 +65,22 @@ export interface ApplicationOptions {
63
65
  perfHooks?: boolean;
64
66
  tmpl?: any;
65
67
  }
66
- export interface DefaultState extends KoaDefaultState {
67
- currentUser?: any;
68
- [key: string]: any;
68
+ declare module 'koa' {
69
+ interface DefaultState {
70
+ currentUser?: any;
71
+ }
69
72
  }
70
- export interface DefaultContext extends KoaDefaultContext {
71
- db: Database;
72
- cache: Cache;
73
- resourcer: Resourcer;
74
- i18n: any;
75
- [key: string]: any;
73
+ declare module 'koa' {
74
+ interface ExtendableContext {
75
+ tego: Application;
76
+ db: Database;
77
+ cache: Cache;
78
+ resourcer: Resourcer;
79
+ i18n: any;
80
+ reqId: string;
81
+ logger: winston.Logger;
82
+ [key: string]: any;
83
+ }
76
84
  }
77
85
  interface ActionsOptions {
78
86
  resourceName?: string;
@@ -94,12 +102,8 @@ export type MaintainingCommandStatus = {
94
102
  status: MaintainingStatus;
95
103
  error?: Error;
96
104
  };
97
- export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
105
+ export declare class Application extends EventEmitter implements AsyncEmitter {
98
106
  options: ApplicationOptions;
99
- /**
100
- * @internal
101
- */
102
- middleware: any;
103
107
  /**
104
108
  * @internal
105
109
  */
@@ -142,14 +146,20 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
142
146
  private _maintainingStatusBeforeCommand;
143
147
  private _actionCommand;
144
148
  private _noticeManager;
149
+ private _koa;
145
150
  static KEY_CORE_APP_PREFIX: string;
146
151
  private currentId;
147
152
  container: ContainerInstance;
148
153
  modules: Record<string, any>;
154
+ private _middleware;
149
155
  middlewareSourceMap: WeakMap<Function, string>;
150
156
  private wsEventHandlers;
151
157
  constructor(options: ApplicationOptions);
152
158
  get noticeManager(): NoticeManager;
159
+ /**
160
+ * @deprecated
161
+ */
162
+ get context(): Koa.BaseContext & Koa.DefaultContext;
153
163
  protected _loaded: boolean;
154
164
  /**
155
165
  * @internal
@@ -197,11 +207,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
197
207
  get localeManager(): Locale;
198
208
  protected _version: ApplicationVersion;
199
209
  get version(): ApplicationVersion;
200
- /**
201
- * Use {@link logger}
202
- * @deprecated
203
- */
204
- get log(): SystemLogger;
205
210
  get name(): string;
206
211
  protected _dataSourceManager: DataSourceManager;
207
212
  get dataSourceManager(): DataSourceManager;
@@ -223,11 +228,11 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
223
228
  * @deprecated
224
229
  */
225
230
  getVersion(): string;
226
- use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: ToposortOptions): this;
231
+ use(middleware: Koa.Middleware, options?: ToposortOptions): this;
227
232
  /**
228
233
  * @internal
229
234
  */
230
- callback(): (req: IncomingMessage, res: ServerResponse) => any;
235
+ callback(): (req: IncomingMessage | import("http2").Http2ServerRequest, res: ServerResponse | import("http2").Http2ServerResponse) => Promise<void>;
231
236
  /**
232
237
  * This method is deprecated and should not be used.
233
238
  * Use {@link #this.db.collection()} instead.
@@ -327,7 +332,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
327
332
  * @internal
328
333
  */
329
334
  reInitEvents(): void;
330
- createLogger(options: LoggerOptions): import("winston").Logger;
335
+ createLogger(options: LoggerOptions): winston.Logger;
331
336
  protected init(): void;
332
337
  protected createMainDataSource(options: ApplicationOptions): void;
333
338
  protected createDatabase(options: ApplicationOptions): Database;
@@ -349,6 +354,5 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
349
354
  * @param handler 事件处理函数
350
355
  */
351
356
  removeWSEventHandler(eventType: WSEventType, handler: WSEventHandler): this;
352
- [key: string]: any;
353
357
  }
354
358
  export default Application;
@@ -29,12 +29,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var application_exports = {};
30
30
  __export(application_exports, {
31
31
  Application: () => Application,
32
- Logger: () => import_winston.Logger,
32
+ Logger: () => import_winston2.Logger,
33
33
  default: () => application_default
34
34
  });
35
35
  module.exports = __toCommonJS(application_exports);
36
36
  var import_node_crypto = require("node:crypto");
37
37
  var import_node_path = require("node:path");
38
+ var import_node_stream = require("node:stream");
38
39
  var import_actions = require("@tachybase/actions");
39
40
  var import_auth = require("@tachybase/auth");
40
41
  var import_data_source = require("@tachybase/data-source");
@@ -44,7 +45,6 @@ var import_utils = require("@tachybase/utils");
44
45
  var import_commander = require("commander");
45
46
  var import_glob = require("glob");
46
47
  var import_koa = __toESM(require("koa"));
47
- var import_koa_compose = __toESM(require("koa-compose"));
48
48
  var import_lodash = __toESM(require("lodash"));
49
49
  var import_nanoid = require("nanoid");
50
50
  var import_semver = __toESM(require("semver"));
@@ -69,8 +69,8 @@ var import_notice = require("./notice");
69
69
  var import_plugin_manager = require("./plugin-manager");
70
70
  var import_pub_sub_manager = require("./pub-sub-manager");
71
71
  var import_sync_message_manager = require("./sync-message-manager");
72
- var import_winston = require("winston");
73
- const _Application = class _Application extends import_koa.default {
72
+ var import_winston2 = require("winston");
73
+ const _Application = class _Application extends import_node_stream.EventEmitter {
74
74
  constructor(options) {
75
75
  super();
76
76
  this.options = options;
@@ -98,8 +98,10 @@ const _Application = class _Application extends import_koa.default {
98
98
  this._appSupervisor = import_app_supervisor.AppSupervisor.getInstance();
99
99
  this._authenticated = false;
100
100
  this._maintaining = false;
101
+ this._koa = new import_koa.default();
101
102
  this.currentId = (0, import_nanoid.nanoid)();
102
103
  this.modules = {};
104
+ this._middleware = new import_utils.Toposort();
103
105
  this.middlewareSourceMap = /* @__PURE__ */ new WeakMap();
104
106
  // WebSocket 事件处理器集合
105
107
  this.wsEventHandlers = {
@@ -119,6 +121,12 @@ const _Application = class _Application extends import_koa.default {
119
121
  get noticeManager() {
120
122
  return this._noticeManager;
121
123
  }
124
+ /**
125
+ * @deprecated
126
+ */
127
+ get context() {
128
+ return this._koa.context;
129
+ }
122
130
  /**
123
131
  * @internal
124
132
  */
@@ -197,13 +205,6 @@ const _Application = class _Application extends import_koa.default {
197
205
  get version() {
198
206
  return this._version;
199
207
  }
200
- /**
201
- * Use {@link logger}
202
- * @deprecated
203
- */
204
- get log() {
205
- return this._logger;
206
- }
207
208
  get name() {
208
209
  return this.options.name || "main";
209
210
  }
@@ -246,22 +247,17 @@ const _Application = class _Application extends import_koa.default {
246
247
  getVersion() {
247
248
  return import_package.default.version;
248
249
  }
249
- // @ts-ignore
250
250
  use(middleware, options) {
251
251
  this.middlewareSourceMap.set(middleware, (0, import_utils.getCurrentStacks)());
252
- this.middleware.add(middleware, options);
252
+ this._middleware.add(middleware, options);
253
+ this._koa.middleware = this._middleware.nodes;
253
254
  return this;
254
255
  }
255
256
  /**
256
257
  * @internal
257
258
  */
258
259
  callback() {
259
- const fn = (0, import_koa_compose.default)(this.middleware.nodes);
260
- if (!this.listenerCount("error")) this.on("error", this.onerror);
261
- return (req, res) => {
262
- const ctx = this.createContext(req, res);
263
- return this.handleRequest(ctx, fn);
264
- };
260
+ return this._koa.callback();
265
261
  }
266
262
  /**
267
263
  * This method is deprecated and should not be used.
@@ -740,7 +736,6 @@ const _Application = class _Application extends import_koa.default {
740
736
  module: "application"
741
737
  });
742
738
  this.reInitEvents();
743
- this.middleware = new import_utils.Toposort();
744
739
  this.plugins = /* @__PURE__ */ new Map();
745
740
  if (this.db) {
746
741
  this.db.removeAllListeners();
@@ -766,7 +761,7 @@ const _Application = class _Application extends import_koa.default {
766
761
  default: "basic",
767
762
  ...this.options.authManager
768
763
  });
769
- this.resource({
764
+ this.resourcer.define({
770
765
  name: "auth",
771
766
  actions: import_auth.actions
772
767
  });
@@ -60,6 +60,8 @@ var import_ipc_socket_server = require("./ipc-socket-server");
60
60
  var import_ws_server = require("./ws-server");
61
61
  var _port, _host;
62
62
  const compress = (0, import_node_util.promisify)((0, import_compression.default)());
63
+ const DEFAULT_PORT = 3e3;
64
+ const DEFAULT_HOST = "0.0.0.0";
63
65
  const _Gateway = class _Gateway extends import_node_events.EventEmitter {
64
66
  constructor() {
65
67
  super();
@@ -69,7 +71,7 @@ const _Gateway = class _Gateway extends import_node_events.EventEmitter {
69
71
  this.selectorMiddlewares = new import_utils.Toposort();
70
72
  this.server = null;
71
73
  this.ipcSocketServer = null;
72
- __privateAdd(this, _port, process.env.APP_PORT ? parseInt(process.env.APP_PORT) : null);
74
+ __privateAdd(this, _port, process.env.APP_PORT ? parseInt(process.env.APP_PORT) : DEFAULT_PORT);
73
75
  __privateAdd(this, _host, "0.0.0.0");
74
76
  this.socketPath = (0, import_node_path.resolve)(process.env.TEGO_RUNTIME_HOME, "storage", "gateway.sock");
75
77
  this.handlers = /* @__PURE__ */ new Map();
@@ -262,8 +264,8 @@ const _Gateway = class _Gateway extends import_node_events.EventEmitter {
262
264
  if (isStart) {
263
265
  await this.watch();
264
266
  const startOptions = this.getStartOptions();
265
- const port = startOptions.port || process.env.APP_PORT || 3e3;
266
- const host = startOptions.host || process.env.APP_HOST || "0.0.0.0";
267
+ const port = startOptions.port || process.env.APP_PORT || DEFAULT_PORT;
268
+ const host = startOptions.host || process.env.APP_HOST || DEFAULT_HOST;
267
269
  this.start({
268
270
  port,
269
271
  host
@@ -1,6 +1,6 @@
1
1
  import { IncomingMessage } from 'node:http';
2
2
  import { Logger } from '@tachybase/logger';
3
- import WebSocket from 'ws';
3
+ import WebSocket, { Server } from 'ws';
4
4
  declare class WebSocketWithId extends WebSocket {
5
5
  id: string;
6
6
  }
@@ -14,7 +14,7 @@ interface WebSocketClient {
14
14
  type WSEventType = 'close' | 'error' | 'message' | 'connection';
15
15
  type WSEventHandler = (ws: WebSocketWithId, ...args: any[]) => Promise<void> | void;
16
16
  export declare class WSServer {
17
- wss: WebSocket.Server;
17
+ wss: Server;
18
18
  webSocketClients: Map<string, WebSocketClient>;
19
19
  static KEY_CORE_MESSAGE: string;
20
20
  private currentId;
package/lib/helper.d.ts CHANGED
@@ -5,7 +5,8 @@ import Application, { ApplicationOptions } from './application';
5
5
  export declare function createI18n(options: ApplicationOptions): TypeI18n;
6
6
  export declare function createResourcer(options: ApplicationOptions): Resourcer;
7
7
  export declare function registerMiddlewares(app: Application, options: ApplicationOptions): void;
8
- export declare const createAppProxy: (app: Application) => Application<import("./application").DefaultState, import("./application").DefaultContext>;
8
+ export declare const createAppProxy: (app: Application) => Application;
9
9
  export declare const getCommandFullName: (command: Command) => string;
10
10
  export declare const tsxRerunning: () => Promise<void>;
11
11
  export declare const enablePerfHooks: (app: Application) => void;
12
+ export declare const resolveRequest: (request: string) => string;
package/lib/helper.js CHANGED
@@ -34,6 +34,7 @@ __export(helper_exports, {
34
34
  enablePerfHooks: () => enablePerfHooks,
35
35
  getCommandFullName: () => getCommandFullName,
36
36
  registerMiddlewares: () => registerMiddlewares,
37
+ resolveRequest: () => resolveRequest,
37
38
  tsxRerunning: () => tsxRerunning
38
39
  });
39
40
  module.exports = __toCommonJS(helper_exports);
@@ -41,6 +42,8 @@ var import_node_crypto = require("node:crypto");
41
42
  var import_node_fs = __toESM(require("node:fs"));
42
43
  var import_node_path = require("node:path");
43
44
  var import_node_perf_hooks = require("node:perf_hooks");
45
+ var import_globals = __toESM(require("@tachybase/globals"));
46
+ var import_loader = require("@tachybase/loader");
44
47
  var import_logger = require("@tachybase/logger");
45
48
  var import_resourcer = require("@tachybase/resourcer");
46
49
  var import_utils = require("@tachybase/utils");
@@ -71,7 +74,8 @@ function registerMiddlewares(app, options) {
71
74
  var _a;
72
75
  app.use(
73
76
  async (ctx, next) => {
74
- app.context.reqId = (0, import_node_crypto.randomUUID)();
77
+ ctx.reqId = (0, import_node_crypto.randomUUID)();
78
+ ctx.tego = app;
75
79
  await next();
76
80
  },
77
81
  { tag: "UUID" }
@@ -164,7 +168,7 @@ const enablePerfHooks = /* @__PURE__ */ __name((app) => {
164
168
  actions: {
165
169
  view: /* @__PURE__ */ __name(async (ctx, next) => {
166
170
  const result = {};
167
- const histograms = ctx.app.perfHistograms;
171
+ const histograms = ctx.tego.perfHistograms;
168
172
  const sortedHistograms = [...histograms.entries()].sort(([i, a], [j, b]) => b.mean - a.mean);
169
173
  sortedHistograms.forEach(([name, histogram]) => {
170
174
  result[name] = histogram;
@@ -173,7 +177,7 @@ const enablePerfHooks = /* @__PURE__ */ __name((app) => {
173
177
  await next();
174
178
  }, "view"),
175
179
  reset: /* @__PURE__ */ __name(async (ctx, next) => {
176
- const histograms = ctx.app.perfHistograms;
180
+ const histograms = ctx.tego.perfHistograms;
177
181
  histograms.forEach((histogram) => histogram.reset());
178
182
  await next();
179
183
  }, "reset")
@@ -181,6 +185,10 @@ const enablePerfHooks = /* @__PURE__ */ __name((app) => {
181
185
  });
182
186
  app.acl.allow("perf", "*", "public");
183
187
  }, "enablePerfHooks");
188
+ const globals = import_globals.default.getInstance();
189
+ const lookingPaths = globals.get("WORKER_PATHS");
190
+ const whitelists = new Set(globals.get("WORKER_MODULES"));
191
+ const resolveRequest = (0, import_loader.defineResolver)(whitelists, require.resolve, lookingPaths);
184
192
  // Annotate the CommonJS export names for ESM import in node:
185
193
  0 && (module.exports = {
186
194
  createAppProxy,
@@ -189,5 +197,6 @@ const enablePerfHooks = /* @__PURE__ */ __name((app) => {
189
197
  enablePerfHooks,
190
198
  getCommandFullName,
191
199
  registerMiddlewares,
200
+ resolveRequest,
192
201
  tsxRerunning
193
202
  });
@@ -1,6 +1,3 @@
1
- import Database from '@tachybase/database';
2
- import { ResourcerContext } from '@tachybase/resourcer';
3
- export declare function db2resource(ctx: ResourcerContext & {
4
- db: Database;
5
- }, next: () => Promise<any>): Promise<any>;
1
+ import { Context } from '@tachybase/actions';
2
+ export declare function db2resource(ctx: Context, next: () => Promise<any>): Promise<any>;
6
3
  export default db2resource;
@@ -23,11 +23,11 @@ __export(i18n_exports, {
23
23
  module.exports = __toCommonJS(i18n_exports);
24
24
  async function i18n(ctx, next) {
25
25
  ctx.getCurrentLocale = () => {
26
- const lng2 = ctx.get("X-Locale") || ctx.request.query.locale || ctx.app.i18n.language || ctx.acceptsLanguages().shift() || "en-US";
26
+ const lng2 = ctx.get("X-Locale") || ctx.request.query.locale || ctx.tego.i18n.language || ctx.acceptsLanguages().shift() || "en-US";
27
27
  return lng2;
28
28
  };
29
29
  const lng = ctx.getCurrentLocale();
30
- const localeManager = ctx.app.localeManager;
30
+ const localeManager = ctx.tego.localeManager;
31
31
  const i18n2 = await localeManager.getI18nInstance(lng);
32
32
  ctx.i18n = i18n2;
33
33
  ctx.t = i18n2.t.bind(i18n2);
@@ -43,7 +43,7 @@ const deps = {
43
43
  "react-router-dom": "6.x",
44
44
  antd: "5.x",
45
45
  "antd-style": "3.x",
46
- "@ant-design/icons": "5.x",
46
+ "@ant-design/icons": "6.x",
47
47
  "@ant-design/cssinjs": "1.x",
48
48
  i18next: "23.x",
49
49
  "react-i18next": "15.x",
@@ -38,7 +38,7 @@ var resource_default = {
38
38
  name: "pm",
39
39
  actions: {
40
40
  async add(ctx, next) {
41
- const app = ctx.app;
41
+ const app = ctx.tego;
42
42
  const { values = {} } = ctx.action.params;
43
43
  if (values == null ? void 0 : values.packageName) {
44
44
  const args = [];
@@ -72,7 +72,7 @@ var resource_default = {
72
72
  await next();
73
73
  },
74
74
  async update(ctx, next) {
75
- const app = ctx.app;
75
+ const app = ctx.tego;
76
76
  const values = ctx.action.params.values || {};
77
77
  const args = [];
78
78
  if (values.registry) {
@@ -111,13 +111,13 @@ var resource_default = {
111
111
  if (!filterByTk) {
112
112
  ctx.throw(400, "plugin name invalid");
113
113
  }
114
- const pm = ctx.app.pm;
114
+ const pm = ctx.tego.pm;
115
115
  ctx.body = await pm.getNpmVersionList(filterByTk);
116
116
  await next();
117
117
  },
118
118
  async enable(ctx, next) {
119
119
  const { filterByTk } = ctx.action.params;
120
- const app = ctx.app;
120
+ const app = ctx.tego;
121
121
  if (!filterByTk) {
122
122
  ctx.throw(400, "plugin name invalid");
123
123
  }
@@ -130,7 +130,7 @@ var resource_default = {
130
130
  if (!filterByTk) {
131
131
  ctx.throw(400, "plugin name invalid");
132
132
  }
133
- const app = ctx.app;
133
+ const app = ctx.tego;
134
134
  app.runAsCLI(["pm", "disable", filterByTk], { from: "user" });
135
135
  ctx.body = filterByTk;
136
136
  await next();
@@ -140,15 +140,15 @@ var resource_default = {
140
140
  if (!filterByTk) {
141
141
  ctx.throw(400, "plugin name invalid");
142
142
  }
143
- const app = ctx.app;
143
+ const app = ctx.tego;
144
144
  app.runAsCLI(["pm", "remove", filterByTk], { from: "user" });
145
145
  ctx.body = filterByTk;
146
146
  await next();
147
147
  },
148
148
  async list(ctx, next) {
149
149
  const locale = ctx.getCurrentLocale();
150
- const pm = ctx.app.pm;
151
- if (ctx.app.name === "main") {
150
+ const pm = ctx.tego.pm;
151
+ if (ctx.tego.name === "main") {
152
152
  ctx.body = await pm.list({ locale, isPreset: false });
153
153
  } else {
154
154
  ctx.body = await pm.list({ locale, isPreset: false, subView: true });
@@ -181,7 +181,7 @@ var resource_default = {
181
181
  },
182
182
  async get(ctx, next) {
183
183
  const locale = ctx.getCurrentLocale();
184
- const pm = ctx.app.pm;
184
+ const pm = ctx.tego.pm;
185
185
  const { filterByTk } = ctx.action.params;
186
186
  if (!filterByTk) {
187
187
  ctx.throw(400, "plugin name invalid");
@@ -1012,8 +1012,8 @@ const _PluginManager = class _PluginManager {
1012
1012
  if (this["_initRuntimePlugins"]) {
1013
1013
  return;
1014
1014
  }
1015
- if (process.env.RUNTIME_PLUGINS) {
1016
- const runtimePlugins = process.env.RUNTIME_PLUGINS.split(",");
1015
+ if (import_globals.default.settings.presets.runtimePlugins) {
1016
+ const runtimePlugins = import_globals.default.settings.presets.runtimePlugins;
1017
1017
  for (const plugin of runtimePlugins) {
1018
1018
  await this.add(plugin, { enabled: true });
1019
1019
  }
@@ -430,15 +430,22 @@ async function getExternalVersionFromSource(packageName) {
430
430
  __name(getExternalVersionFromSource, "getExternalVersionFromSource");
431
431
  async function getCompatible(packageName) {
432
432
  let externalVersion;
433
- if (!process.env.IS_DEV_CMD) {
433
+ const hasSrc = import_fs_extra.default.existsSync(import_node_path.default.join((0, import_clientStaticUtils.getPackageDir)(packageName), "src"));
434
+ let hasError = false;
435
+ if (hasSrc) {
436
+ try {
437
+ externalVersion = await getExternalVersionFromSource(packageName);
438
+ } catch {
439
+ hasError = true;
440
+ }
441
+ }
442
+ if (hasError || !hasSrc) {
434
443
  const res = await getExternalVersionFromDistFile(packageName);
435
444
  if (!res) {
436
445
  return false;
437
446
  } else {
438
447
  externalVersion = res;
439
448
  }
440
- } else {
441
- externalVersion = await getExternalVersionFromSource(packageName);
442
449
  }
443
450
  return Object.keys(externalVersion).reduce((result, packageName2) => {
444
451
  const packageVersion = externalVersion[packageName2];
package/lib/plugin.d.ts CHANGED
@@ -73,15 +73,10 @@ export declare abstract class Plugin implements PluginInterface {
73
73
  * @internal
74
74
  */
75
75
  setOptions(options: any): void;
76
- /**
77
- * @internal
78
- */
79
- protected getSourceDir(): Promise<string>;
80
76
  /**
81
77
  * @internal
82
78
  */
83
79
  loadCommands(): Promise<void>;
84
- loadCommandFromPath(basePath: string): Promise<void>;
85
80
  /**
86
81
  * @internal
87
82
  */
@@ -90,26 +85,15 @@ export declare abstract class Plugin implements PluginInterface {
90
85
  afterSync: any[];
91
86
  afterLoad: any[];
92
87
  }>;
93
- loadMigrationsFromPath(basePath: string): Promise<{
94
- beforeLoad: any[];
95
- afterSync: any[];
96
- afterLoad: any[];
97
- }>;
98
88
  /**
99
89
  * @internal
100
90
  */
101
91
  loadCollections(): Promise<void>;
102
- loadCollectionsFromPath(basePath: string): Promise<void>;
103
92
  /**
104
93
  * @deprecated
105
94
  */
106
95
  requiredPlugins(): any[];
107
96
  t(text: ParseKeys | ParseKeys[], options?: TOptions): string;
108
- /**
109
- * @internal
110
- * TODO 换一种判断,这类替换 NODE_MODULES_PATH 有点奇怪
111
- */
112
- protected isDev(): Promise<boolean>;
113
97
  /**
114
98
  * @experimental
115
99
  */
package/lib/plugin.js CHANGED
@@ -35,11 +35,11 @@ __export(plugin_exports, {
35
35
  module.exports = __toCommonJS(plugin_exports);
36
36
  var import_node_fs = __toESM(require("node:fs"));
37
37
  var import_node_path = require("node:path");
38
- var import_node_worker_threads = require("node:worker_threads");
39
38
  var import_di = require("@tachybase/di");
40
39
  var import_globals = __toESM(require("@tachybase/globals"));
41
40
  var import_utils = require("@tachybase/utils");
42
41
  var import_glob = require("glob");
42
+ var import_helper = require("./helper");
43
43
  var import_plugin_manager = require("./plugin-manager");
44
44
  var import_utils2 = require("./plugin-manager/utils");
45
45
  const _Plugin = class _Plugin {
@@ -141,36 +141,15 @@ const _Plugin = class _Plugin {
141
141
  setOptions(options) {
142
142
  this.options = options || {};
143
143
  }
144
- /**
145
- * @internal
146
- */
147
- async getSourceDir() {
148
- if (this._sourceDir) {
149
- return this._sourceDir;
150
- }
151
- if (await this.isDev()) {
152
- return this._sourceDir = "src";
153
- }
154
- if ((0, import_node_path.basename)(__dirname) === "src") {
155
- return this._sourceDir = "src";
156
- }
157
- if (!import_node_worker_threads.isMainThread) {
158
- return "dist";
159
- }
160
- return this._sourceDir = this.isPreset ? "lib" : "dist";
161
- }
162
144
  /**
163
145
  * @internal
164
146
  */
165
147
  async loadCommands() {
166
- const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
167
- for (const basePath of pluginPaths) {
168
- await this.loadCommandFromPath(basePath);
148
+ if (!this.options.packageName) {
149
+ return;
169
150
  }
170
- }
171
- async loadCommandFromPath(basePath) {
172
151
  const extensions = ["js", "ts"];
173
- const directory = (0, import_node_path.resolve)(basePath, this.options.packageName, await this.getSourceDir(), "server/commands");
152
+ const directory = (0, import_node_path.resolve)((0, import_helper.resolveRequest)(this.options.packageName), "../../server/commands");
174
153
  const patten = `${directory}/*.{${extensions.join(",")}}`;
175
154
  const files = (0, import_glob.globSync)(patten, {
176
155
  ignore: ["**/*.d.ts"]
@@ -189,27 +168,10 @@ const _Plugin = class _Plugin {
189
168
  * @internal
190
169
  */
191
170
  async loadMigrations() {
192
- const result = { beforeLoad: [], afterSync: [], afterLoad: [] };
193
- const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
194
- for (const basePath of pluginPaths) {
195
- const { beforeLoad, afterSync, afterLoad } = await this.loadMigrationsFromPath(basePath);
196
- result.beforeLoad.push(...beforeLoad);
197
- result.afterSync.push(...afterSync);
198
- result.afterLoad.push(...afterLoad);
199
- }
200
- return result;
201
- }
202
- async loadMigrationsFromPath(basePath) {
203
- this.app.logger.debug(`load plugin migrations [${this.name}]`);
204
171
  if (!this.options.packageName) {
205
172
  return { beforeLoad: [], afterSync: [], afterLoad: [] };
206
173
  }
207
- const directory = (0, import_node_path.resolve)(
208
- basePath,
209
- this.options.packageName,
210
- await this.getSourceDir(),
211
- "server/migrations"
212
- ).replace(/\\/g, "/");
174
+ const directory = (0, import_node_path.resolve)((0, import_helper.resolveRequest)(this.options.packageName), "../../server/migrations").replace(/\\/g, "/");
213
175
  return await this.app.loadMigrations({
214
176
  directory,
215
177
  namespace: this.options.packageName,
@@ -222,16 +184,10 @@ const _Plugin = class _Plugin {
222
184
  * @internal
223
185
  */
224
186
  async loadCollections() {
225
- const pluginPaths = import_globals.default.getInstance().get("PLUGIN_PATHS");
226
- for (const basePath of pluginPaths) {
227
- await this.loadCollectionsFromPath(basePath);
228
- }
229
- }
230
- async loadCollectionsFromPath(basePath) {
231
187
  if (!this.options.packageName) {
232
188
  return;
233
189
  }
234
- const directory = (0, import_node_path.resolve)(basePath, this.options.packageName, await this.getSourceDir(), "server/collections");
190
+ const directory = (0, import_node_path.resolve)((0, import_helper.resolveRequest)(this.options.packageName), "../../server/collections");
235
191
  if (await (0, import_utils.fsExists)(directory)) {
236
192
  await this.db.import({
237
193
  directory,
@@ -248,31 +204,6 @@ const _Plugin = class _Plugin {
248
204
  t(text, options = {}) {
249
205
  return this.app.i18n.t(text, { ns: this.options["packageName"], ...options });
250
206
  }
251
- /**
252
- * @internal
253
- * TODO 换一种判断,这类替换 NODE_MODULES_PATH 有点奇怪
254
- */
255
- async isDev() {
256
- if (!this.options.packageName) {
257
- return false;
258
- }
259
- const pluginPaths = [
260
- ...import_globals.default.getInstance().get("PLUGIN_PATHS"),
261
- (0, import_node_path.resolve)(process.cwd(), "node_modules")
262
- ];
263
- let path;
264
- for (const basePath of pluginPaths) {
265
- if (await (0, import_utils.fsExists)((0, import_node_path.resolve)(basePath, this.options.packageName))) {
266
- path = (0, import_node_path.resolve)(basePath, this.options.packageName);
267
- break;
268
- }
269
- }
270
- const file = await import_node_fs.default.promises.realpath(path);
271
- if (file.startsWith((0, import_node_path.resolve)(process.cwd(), "packages"))) {
272
- return !!process.env.IS_DEV_CMD;
273
- }
274
- return false;
275
- }
276
207
  /**
277
208
  * @experimental
278
209
  */
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "@tego/core",
3
- "version": "1.3.52",
3
+ "version": "1.3.53",
4
4
  "license": "Apache-2.0",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "dependencies": {
8
8
  "@koa/cors": "^5.0.0",
9
9
  "@types/decompress": "4.2.7",
10
- "@types/ini": "^1.3.34",
10
+ "@types/ini": "^4.1.1",
11
11
  "async-mutex": "^0.5.0",
12
12
  "axios": "0.29.0",
13
13
  "commander": "^9.5.0",
14
- "compression": "^1.7.5",
14
+ "compression": "^1.8.1",
15
15
  "dayjs": "1.11.13",
16
16
  "decompress": "4.2.1",
17
17
  "execa": "^5.1.1",
18
- "fast-glob": "^3.3.2",
19
- "fs-extra": "^11.3.0",
18
+ "fast-glob": "^3.3.3",
19
+ "fs-extra": "^11.3.2",
20
20
  "glob": "11.0.0",
21
21
  "i18next": "23.16.8",
22
- "ini": "^4.1.3",
23
- "koa": "^2.15.3",
22
+ "ini": "^5.0.0",
23
+ "koa": "^2.16.2",
24
24
  "koa-bodyparser": "^4.4.1",
25
25
  "koa-compose": "^4.1.0",
26
26
  "lodash": "^4.17.21",
@@ -29,19 +29,20 @@
29
29
  "semver": "7.7.2",
30
30
  "serve-handler": "^6.1.6",
31
31
  "winston": "^3.17.0",
32
- "ws": "^8.18.0",
32
+ "ws": "^8.18.3",
33
33
  "xpipe": "^1.0.8",
34
- "@tachybase/acl": "1.3.52",
35
- "@tachybase/actions": "1.3.52",
36
- "@tachybase/auth": "1.3.52",
37
- "@tachybase/cache": "1.3.52",
38
- "@tachybase/data-source": "1.3.52",
39
- "@tachybase/database": "1.3.52",
40
- "@tachybase/di": "1.3.52",
41
- "@tachybase/logger": "1.3.52",
42
- "@tachybase/globals": "1.3.52",
43
- "@tachybase/resourcer": "1.3.52",
44
- "@tachybase/utils": "1.3.52"
34
+ "@tachybase/acl": "1.3.53",
35
+ "@tachybase/actions": "1.3.53",
36
+ "@tachybase/auth": "1.3.53",
37
+ "@tachybase/cache": "1.3.53",
38
+ "@tachybase/data-source": "1.3.53",
39
+ "@tachybase/database": "1.3.53",
40
+ "@tachybase/di": "1.3.53",
41
+ "@tachybase/loader": "1.3.53",
42
+ "@tachybase/globals": "1.3.53",
43
+ "@tachybase/logger": "1.3.53",
44
+ "@tachybase/resourcer": "1.3.53",
45
+ "@tachybase/utils": "1.3.53"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@types/fs-extra": "11.0.4",
@@ -51,8 +52,9 @@
51
52
  "@types/koa-compose": "3.2.8",
52
53
  "@types/lodash": "4.17.20",
53
54
  "@types/qs": "^6.14.0",
54
- "@types/semver": "^7.5.8",
55
+ "@types/semver": "^7.7.1",
55
56
  "@types/serve-handler": "^6.1.4",
56
- "@types/ws": "^8.5.13"
57
+ "@types/ws": "^8.18.1",
58
+ "supertest": "^7.1.4"
57
59
  }
58
60
  }