befly 3.4.2 → 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.
- package/lifecycle/loader.ts +43 -32
- package/package.json +2 -2
package/lifecycle/loader.ts
CHANGED
|
@@ -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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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.
|
|
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": "
|
|
84
|
+
"gitHead": "baf1c6cd89fce539a76eb7035119b1090a53e7da"
|
|
85
85
|
}
|