befly 3.4.1 → 3.4.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.
@@ -18,7 +18,7 @@ import { Logger } from '../lib/logger.js';
18
18
  import { Database } from '../lib/database.js';
19
19
  import { join } from 'pathe';
20
20
  import { existsSync } from 'node:fs';
21
- import { coreDIr, projectDir } from '../paths.js';
21
+ import { coreDir, projectDir } from '../paths.js';
22
22
 
23
23
  interface SyncMenuOptions {
24
24
  plan?: boolean;
@@ -296,7 +296,7 @@ export async function syncMenuCommand(options: SyncMenuOptions = {}) {
296
296
  // 1. 读取两个配置文件
297
297
  Logger.info('=== 步骤 1: 读取菜单配置文件 ===');
298
298
  const projectMenuPath = join(projectDir, 'menu.json');
299
- const coreMenuPath = join(coreDIr, 'menu.json');
299
+ const coreMenuPath = join(coreDir, 'menu.json');
300
300
 
301
301
  Logger.info(` 项目路径: ${projectMenuPath}`);
302
302
  Logger.info(` core 路径: ${coreMenuPath}`);
@@ -4,6 +4,7 @@
4
4
  */
5
5
 
6
6
  import { relative, basename } from 'pathe';
7
+ import { existsSync } from 'node:fs';
7
8
  import { isPlainObject } from 'es-toolkit/compat';
8
9
  import { Logger } from '../lib/logger.js';
9
10
  import { calcPerfTime } from '../util.js';
@@ -260,41 +261,45 @@ export class Loader {
260
261
  }
261
262
 
262
263
  // 扫描用户插件目录
263
- const userPluginsScanStart = Bun.nanoseconds();
264
- for await (const file of glob.scan({
265
- cwd: projectPluginDir,
266
- onlyFiles: true,
267
- absolute: true
268
- })) {
269
- const fileName = basename(file).replace(/\.ts$/, '');
270
- if (fileName.startsWith('_')) continue;
271
-
272
- // 检查是否已经加载了同名的核心插件
273
- if (loadedPluginNames.has(fileName)) {
274
- Logger.info(`跳过用户插件 ${fileName},因为同名的核心插件已存在`);
275
- continue;
276
- }
277
-
278
- try {
279
- const importStart = Bun.nanoseconds();
280
- Logger.debug(`准备导入用户插件: ${fileName}`);
281
- const plugin = await importWithTimeout(file);
282
- const importTime = calcPerfTime(importStart);
283
- Logger.debug(`用户插件 ${fileName} 导入成功,耗时: ${importTime}`);
284
-
285
- const pluginInstance = plugin.default;
286
- pluginInstance.pluginName = fileName;
287
- userPlugins.push(pluginInstance);
264
+ if (!existsSync(projectPluginDir)) {
265
+ Logger.info(`项目插件目录不存在,跳过加载: ${projectPluginDir}`);
266
+ } else {
267
+ const userPluginsScanStart = Bun.nanoseconds();
268
+ for await (const file of glob.scan({
269
+ cwd: projectPluginDir,
270
+ onlyFiles: true,
271
+ absolute: true
272
+ })) {
273
+ const fileName = basename(file).replace(/\.ts$/, '');
274
+ if (fileName.startsWith('_')) continue;
275
+
276
+ // 检查是否已经加载了同名的核心插件
277
+ if (loadedPluginNames.has(fileName)) {
278
+ Logger.info(`跳过用户插件 ${fileName},因为同名的核心插件已存在`);
279
+ continue;
280
+ }
288
281
 
289
- Logger.info(`用户插件 ${fileName} 导入耗时: ${importTime}`);
290
- } catch (err: any) {
291
- hadUserPluginError = true;
292
- Logger.error(`用户插件 ${fileName} 导入失败`, error);
293
- process.exit(1);
282
+ try {
283
+ const importStart = Bun.nanoseconds();
284
+ Logger.debug(`准备导入用户插件: ${fileName}`);
285
+ const plugin = await importWithTimeout(file);
286
+ const importTime = calcPerfTime(importStart);
287
+ Logger.debug(`用户插件 ${fileName} 导入成功,耗时: ${importTime}`);
288
+
289
+ const pluginInstance = plugin.default;
290
+ pluginInstance.pluginName = fileName;
291
+ userPlugins.push(pluginInstance);
292
+
293
+ Logger.info(`用户插件 ${fileName} 导入耗时: ${importTime}`);
294
+ } catch (err: any) {
295
+ hadUserPluginError = true;
296
+ Logger.error(`用户插件 ${fileName} 导入失败`, error);
297
+ process.exit(1);
298
+ }
294
299
  }
300
+ const userPluginsScanTime = calcPerfTime(userPluginsScanStart);
301
+ Logger.info(`用户插件扫描完成,耗时: ${userPluginsScanTime},共找到 ${userPlugins.length} 个插件`);
295
302
  }
296
- const userPluginsScanTime = calcPerfTime(userPluginsScanStart);
297
- Logger.info(`用户插件扫描完成,耗时: ${userPluginsScanTime},共找到 ${userPlugins.length} 个插件`);
298
303
 
299
304
  const sortedUserPlugins = sortPlugins(userPlugins);
300
305
  if (sortedUserPlugins === false) {
@@ -400,6 +405,12 @@ export class Loader {
400
405
  apiDir = projectApiDir;
401
406
  }
402
407
 
408
+ // 检查目录是否存在
409
+ if (!existsSync(apiDir)) {
410
+ Logger.info(`${dirDisplayName}接口目录不存在,跳过加载: ${apiDir}`);
411
+ return;
412
+ }
413
+
403
414
  let totalApis = 0;
404
415
  let loadedApis = 0;
405
416
  let failedApis = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.4.1",
3
+ "version": "3.4.3",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -81,5 +81,5 @@
81
81
  "ora": "^9.0.0",
82
82
  "pathe": "^2.0.3"
83
83
  },
84
- "gitHead": "3131d53e72d22577a42c02620249f39c8930e621"
84
+ "gitHead": "baf1c6cd89fce539a76eb7035119b1090a53e7da"
85
85
  }