befly 3.13.6 → 3.13.7

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.
@@ -72,17 +72,18 @@ const defaultOptions = {
72
72
  addons: {}
73
73
  };
74
74
  export async function loadBeflyConfig(nodeEnv) {
75
- const normalizedNodeEnv = normalizeNodeEnv(nodeEnv);
76
- const envSuffix = normalizedNodeEnv === "production" ? "production" : "development";
75
+ if (nodeEnv !== "development" && nodeEnv !== "production") {
76
+ throw new Error(`配置错误:NODE_ENV 只能是 'development' 'production',当前值=${String(nodeEnv)}`);
77
+ }
77
78
  // 使用 importDefault 加载 configs 目录下的配置文件。
78
79
  // 合并顺序:defaultOptions ← befly.common.json ← befly.development/production.json
79
80
  const configsDir = join(process.cwd(), "configs");
80
81
  const commonConfig = await importDefault(join(configsDir, "befly.common.json"), {});
81
- const envConfig = await importDefault(join(configsDir, `befly.${envSuffix}.json`), {});
82
+ const envConfig = await importDefault(join(configsDir, `befly.${nodeEnv}.json`), {});
82
83
  const config = mergeAndConcat(defaultOptions, commonConfig, envConfig);
83
84
  // 重要:nodeEnv 的来源只从 Befly.start(env) 的入参 env.NODE_ENV 传入,避免 process.env 在 bundle 阶段被常量折叠。
84
85
  // 同时确保运行时行为(例如 Bun.serve development 标记)与实际选择的配置文件一致。
85
- config.nodeEnv = normalizedNodeEnv;
86
+ config.nodeEnv = nodeEnv;
86
87
  // 配置校验:redis.prefix 作为 key 前缀,由 RedisHelper 统一拼接 ":"。
87
88
  // 因此 prefix 本身不允许包含 ":",否则会导致 key 结构出现空段或多段分隔(例如 "prefix::key"),
88
89
  // 在 RedisInsight 等工具里可能显示 [NO NAME] 空分组,且容易造成 key 管理混乱。
@@ -95,9 +96,3 @@ export async function loadBeflyConfig(nodeEnv) {
95
96
  }
96
97
  return config;
97
98
  }
98
- function normalizeNodeEnv(nodeEnv) {
99
- if (typeof nodeEnv === "string" && nodeEnv.trim()) {
100
- return nodeEnv.trim();
101
- }
102
- return "development";
103
- }
package/dist/befly.js CHANGED
@@ -7609,13 +7609,14 @@ var defaultOptions = {
7609
7609
  addons: {}
7610
7610
  };
7611
7611
  async function loadBeflyConfig(nodeEnv) {
7612
- const normalizedNodeEnv = normalizeNodeEnv(nodeEnv);
7613
- const envSuffix = normalizedNodeEnv === "production" ? "production" : "development";
7612
+ if (nodeEnv !== "development" && nodeEnv !== "production") {
7613
+ throw new Error(`\u914D\u7F6E\u9519\u8BEF\uFF1ANODE_ENV \u53EA\u80FD\u662F 'development' \u6216 'production'\uFF0C\u5F53\u524D\u503C=${String(nodeEnv)}`);
7614
+ }
7614
7615
  const configsDir = join(process.cwd(), "configs");
7615
7616
  const commonConfig = await importDefault(join(configsDir, "befly.common.json"), {});
7616
- const envConfig = await importDefault(join(configsDir, `befly.${envSuffix}.json`), {});
7617
+ const envConfig = await importDefault(join(configsDir, `befly.${nodeEnv}.json`), {});
7617
7618
  const config2 = mergeAndConcat(defaultOptions, commonConfig, envConfig);
7618
- config2.nodeEnv = normalizedNodeEnv;
7619
+ config2.nodeEnv = nodeEnv;
7619
7620
  const redisPrefix = config2?.redis?.prefix;
7620
7621
  if (typeof redisPrefix === "string") {
7621
7622
  const trimmedPrefix = redisPrefix.trim();
@@ -7625,12 +7626,6 @@ async function loadBeflyConfig(nodeEnv) {
7625
7626
  }
7626
7627
  return config2;
7627
7628
  }
7628
- function normalizeNodeEnv(nodeEnv) {
7629
- if (typeof nodeEnv === "string" && nodeEnv.trim()) {
7630
- return nodeEnv.trim();
7631
- }
7632
- return "development";
7633
- }
7634
7629
 
7635
7630
  // checks/checkApi.ts
7636
7631
  init_logger();