befly 3.12.3 → 3.12.4
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/dist/befly.js +88 -27
- package/dist/befly.min.js +12 -12
- package/dist/checks/checkHook.js +46 -12
- package/dist/checks/checkPlugin.js +46 -12
- package/dist/hooks/cors.js +1 -1
- package/dist/lib/logger.js +8 -0
- package/dist/utils/scanCoreBuiltins.js +4 -1
- package/dist/utils/scanFiles.d.ts +2 -0
- package/dist/utils/scanFiles.js +5 -2
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -825,6 +825,12 @@ function createSinkLogger(options) {
|
|
|
825
825
|
if (options.consoleSink) {
|
|
826
826
|
options.consoleSink.enqueue(level, line);
|
|
827
827
|
}
|
|
828
|
+
if (LOG_LEVEL_NUM[level] >= LOG_LEVEL_NUM.warn) {
|
|
829
|
+
options.fileSink.flushNow();
|
|
830
|
+
if (options.consoleSink) {
|
|
831
|
+
options.consoleSink.flushNow();
|
|
832
|
+
}
|
|
833
|
+
}
|
|
828
834
|
};
|
|
829
835
|
return {
|
|
830
836
|
info(...args) {
|
|
@@ -8014,6 +8020,7 @@ async function checkApi(apis) {
|
|
|
8014
8020
|
|
|
8015
8021
|
// checks/checkHook.ts
|
|
8016
8022
|
init_logger();
|
|
8023
|
+
var exportKeys = ["name", "enable", "deps", "handler"];
|
|
8017
8024
|
async function checkHook(hooks) {
|
|
8018
8025
|
let hasError = false;
|
|
8019
8026
|
const coreBuiltinNameRegexp = /^[a-z]+(?:_[a-z]+)*$/;
|
|
@@ -8029,16 +8036,34 @@ async function checkHook(hooks) {
|
|
|
8029
8036
|
hasError = true;
|
|
8030
8037
|
continue;
|
|
8031
8038
|
}
|
|
8032
|
-
|
|
8033
|
-
|
|
8039
|
+
const customKeys = hook.customKeys;
|
|
8040
|
+
if (!Array.isArray(customKeys)) {
|
|
8041
|
+
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09");
|
|
8042
|
+
hasError = true;
|
|
8043
|
+
continue;
|
|
8044
|
+
}
|
|
8045
|
+
if (customKeys.some((k) => typeof k !== "string")) {
|
|
8046
|
+
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09");
|
|
8034
8047
|
hasError = true;
|
|
8035
8048
|
continue;
|
|
8036
8049
|
}
|
|
8037
|
-
|
|
8038
|
-
|
|
8050
|
+
const unknownCustomKeys = customKeys.filter((k) => !exportKeys.includes(k));
|
|
8051
|
+
if (unknownCustomKeys.length > 0) {
|
|
8052
|
+
Logger.warn(omit(hook, ["handler"]), `\u94A9\u5B50\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${unknownCustomKeys.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${exportKeys.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${customKeys.join(", ")}`);
|
|
8039
8053
|
hasError = true;
|
|
8040
8054
|
continue;
|
|
8041
8055
|
}
|
|
8056
|
+
const hasCustomEnable = customKeys.includes("enable");
|
|
8057
|
+
const hasCustomDeps = customKeys.includes("deps");
|
|
8058
|
+
if (hasCustomEnable) {
|
|
8059
|
+
if (typeof hook.enable !== "boolean") {
|
|
8060
|
+
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B");
|
|
8061
|
+
hasError = true;
|
|
8062
|
+
continue;
|
|
8063
|
+
}
|
|
8064
|
+
} else {
|
|
8065
|
+
hook.enable = true;
|
|
8066
|
+
}
|
|
8042
8067
|
if (hook.source === "core") {
|
|
8043
8068
|
const name = typeof hook.name === "string" ? hook.name : "";
|
|
8044
8069
|
if (name === "") {
|
|
@@ -8067,14 +8092,21 @@ async function checkHook(hooks) {
|
|
|
8067
8092
|
continue;
|
|
8068
8093
|
}
|
|
8069
8094
|
}
|
|
8070
|
-
if (
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8095
|
+
if (hasCustomDeps) {
|
|
8096
|
+
if (!Array.isArray(hook.deps)) {
|
|
8097
|
+
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");
|
|
8098
|
+
hasError = true;
|
|
8099
|
+
continue;
|
|
8100
|
+
}
|
|
8101
|
+
if (hook.deps.some((depItem) => typeof depItem !== "string")) {
|
|
8102
|
+
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");
|
|
8103
|
+
hasError = true;
|
|
8104
|
+
continue;
|
|
8105
|
+
}
|
|
8106
|
+
} else {
|
|
8107
|
+
if (!Array.isArray(hook.deps)) {
|
|
8108
|
+
hook.deps = [];
|
|
8109
|
+
}
|
|
8078
8110
|
}
|
|
8079
8111
|
if (typeof hook.handler !== "function") {
|
|
8080
8112
|
Logger.warn(omit(hook, ["handler"]), "\u94A9\u5B50\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570");
|
|
@@ -8227,6 +8259,7 @@ var checkMenu = async (addons, options = {}) => {
|
|
|
8227
8259
|
|
|
8228
8260
|
// checks/checkPlugin.ts
|
|
8229
8261
|
init_logger();
|
|
8262
|
+
var exportKeys2 = ["name", "enable", "deps", "handler"];
|
|
8230
8263
|
async function checkPlugin(plugins) {
|
|
8231
8264
|
let hasError = false;
|
|
8232
8265
|
const coreBuiltinNameRegexp = /^[a-z]+(?:_[a-z]+)*$/;
|
|
@@ -8242,16 +8275,34 @@ async function checkPlugin(plugins) {
|
|
|
8242
8275
|
hasError = true;
|
|
8243
8276
|
continue;
|
|
8244
8277
|
}
|
|
8245
|
-
|
|
8246
|
-
|
|
8278
|
+
const customKeys = plugin.customKeys;
|
|
8279
|
+
if (!Array.isArray(customKeys)) {
|
|
8280
|
+
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09");
|
|
8281
|
+
hasError = true;
|
|
8282
|
+
continue;
|
|
8283
|
+
}
|
|
8284
|
+
if (customKeys.some((k) => typeof k !== "string")) {
|
|
8285
|
+
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09");
|
|
8247
8286
|
hasError = true;
|
|
8248
8287
|
continue;
|
|
8249
8288
|
}
|
|
8250
|
-
|
|
8251
|
-
|
|
8289
|
+
const unknownCustomKeys = customKeys.filter((k) => !exportKeys2.includes(k));
|
|
8290
|
+
if (unknownCustomKeys.length > 0) {
|
|
8291
|
+
Logger.warn(omit(plugin, ["handler"]), `\u63D2\u4EF6\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${unknownCustomKeys.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${exportKeys2.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${customKeys.join(", ")}`);
|
|
8252
8292
|
hasError = true;
|
|
8253
8293
|
continue;
|
|
8254
8294
|
}
|
|
8295
|
+
const hasCustomEnable = customKeys.includes("enable");
|
|
8296
|
+
const hasCustomDeps = customKeys.includes("deps");
|
|
8297
|
+
if (hasCustomEnable) {
|
|
8298
|
+
if (typeof plugin.enable !== "boolean") {
|
|
8299
|
+
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B");
|
|
8300
|
+
hasError = true;
|
|
8301
|
+
continue;
|
|
8302
|
+
}
|
|
8303
|
+
} else {
|
|
8304
|
+
plugin.enable = true;
|
|
8305
|
+
}
|
|
8255
8306
|
if (plugin.source === "core") {
|
|
8256
8307
|
const name = typeof plugin.name === "string" ? plugin.name : "";
|
|
8257
8308
|
if (name === "") {
|
|
@@ -8280,14 +8331,21 @@ async function checkPlugin(plugins) {
|
|
|
8280
8331
|
continue;
|
|
8281
8332
|
}
|
|
8282
8333
|
}
|
|
8283
|
-
if (
|
|
8284
|
-
|
|
8285
|
-
|
|
8286
|
-
|
|
8287
|
-
|
|
8288
|
-
|
|
8289
|
-
|
|
8290
|
-
|
|
8334
|
+
if (hasCustomDeps) {
|
|
8335
|
+
if (!Array.isArray(plugin.deps)) {
|
|
8336
|
+
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");
|
|
8337
|
+
hasError = true;
|
|
8338
|
+
continue;
|
|
8339
|
+
}
|
|
8340
|
+
if (plugin.deps.some((depItem) => typeof depItem !== "string")) {
|
|
8341
|
+
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4");
|
|
8342
|
+
hasError = true;
|
|
8343
|
+
continue;
|
|
8344
|
+
}
|
|
8345
|
+
} else {
|
|
8346
|
+
if (!Array.isArray(plugin.deps)) {
|
|
8347
|
+
plugin.deps = [];
|
|
8348
|
+
}
|
|
8291
8349
|
}
|
|
8292
8350
|
if (typeof plugin.handler !== "function") {
|
|
8293
8351
|
Logger.warn(omit(plugin, ["handler"]), "\u63D2\u4EF6\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570");
|
|
@@ -10876,7 +10934,7 @@ var cors_default = {
|
|
|
10876
10934
|
const req = ctx.req;
|
|
10877
10935
|
const defaultConfig = {
|
|
10878
10936
|
origin: "*",
|
|
10879
|
-
methods: "GET, POST,
|
|
10937
|
+
methods: "GET, POST, OPTIONS",
|
|
10880
10938
|
allowedHeaders: "Content-Type, Authorization, authorization, token",
|
|
10881
10939
|
exposedHeaders: "Content-Range, X-Content-Range, Authorization, authorization, token",
|
|
10882
10940
|
maxAge: 86400,
|
|
@@ -15260,6 +15318,7 @@ var tool_default = {
|
|
|
15260
15318
|
// utils/scanCoreBuiltins.ts
|
|
15261
15319
|
function toCoreBuiltinScanFileResult(type, item) {
|
|
15262
15320
|
const name = item.name;
|
|
15321
|
+
const customKeys = isPlainObject(item) ? Object.keys(item) : [];
|
|
15263
15322
|
return {
|
|
15264
15323
|
source: "core",
|
|
15265
15324
|
type,
|
|
@@ -15274,7 +15333,8 @@ function toCoreBuiltinScanFileResult(type, item) {
|
|
|
15274
15333
|
name,
|
|
15275
15334
|
enable: item ? item.enable : undefined,
|
|
15276
15335
|
deps: Array.isArray(item && item.deps) ? item.deps : [],
|
|
15277
|
-
handler: item ? item.handler : null
|
|
15336
|
+
handler: item ? item.handler : null,
|
|
15337
|
+
customKeys
|
|
15278
15338
|
};
|
|
15279
15339
|
}
|
|
15280
15340
|
function scanCoreBuiltinPlugins() {
|
|
@@ -15402,7 +15462,8 @@ async function scanFiles(dir, source, type, pattern) {
|
|
|
15402
15462
|
moduleName,
|
|
15403
15463
|
addonName,
|
|
15404
15464
|
fileBaseName: parse(normalizedFile).base,
|
|
15405
|
-
fileDir: dir
|
|
15465
|
+
fileDir: dir,
|
|
15466
|
+
customKeys: isPlainObject(content) ? Object.keys(content) : []
|
|
15406
15467
|
};
|
|
15407
15468
|
if (type === "table") {
|
|
15408
15469
|
base.content = content;
|