@4399ywkf/core 5.1.1 → 5.1.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.
@@ -12,7 +12,9 @@ declare function findConfigFile(cwd: string): string | null;
12
12
  /**
13
13
  * 加载配置文件
14
14
  */
15
- declare function loadConfigFile(configPath: string): Promise<YwkfConfig>;
15
+ declare function loadConfigFile(configPath: string, opts?: {
16
+ fresh?: boolean;
17
+ }): Promise<YwkfConfig>;
16
18
  /**
17
19
  * 合并配置
18
20
  */
@@ -20,9 +22,12 @@ declare function mergeConfig(userConfig: YwkfConfig, baseConfig?: YwkfConfig): R
20
22
  /**
21
23
  * 解析并加载完整配置
22
24
  * @param cwd 工作目录
25
+ * @param opts.fresh 为 true 时对 .js/.mjs 配置破除 import 缓存(用于热重启)
23
26
  * @returns 合并后的完整配置
24
27
  */
25
- declare function resolveConfig(cwd: string): Promise<{
28
+ declare function resolveConfig(cwd: string, opts?: {
29
+ fresh?: boolean;
30
+ }): Promise<{
26
31
  config: Required<YwkfConfig>;
27
32
  configPath: string | null;
28
33
  }>;
@@ -2117,7 +2117,7 @@ var defaultConfig = {
2117
2117
  strictMode: true,
2118
2118
  dev: {
2119
2119
  port: 3e3,
2120
- host: "localhost",
2120
+ host: "127.0.0.1",
2121
2121
  proxy: {},
2122
2122
  https: false
2123
2123
  },
@@ -2181,32 +2181,39 @@ function findConfigFile(cwd) {
2181
2181
  }
2182
2182
  return null;
2183
2183
  }
2184
- async function loadTsConfig(configPath) {
2184
+ async function loadTsConfig(configPath, fresh = false) {
2185
2185
  const jiti = (await import("jiti")).default;
2186
2186
  const loader = jiti(configPath, {
2187
- interopDefault: true
2187
+ interopDefault: true,
2188
+ // fresh(热重启)时必须禁用缓存:jiti 的 moduleCache 默认与 Node 原生 require 缓存集成,
2189
+ // 即使新建 jiti 实例,loader(configPath) 仍会命中 Node 全局缓存读回旧配置;
2190
+ // fsCache 为转译产物缓存,一并关闭以确保读到最新源码。
2191
+ ...fresh ? { moduleCache: false, fsCache: false } : {}
2188
2192
  });
2189
2193
  const config = loader(configPath);
2190
2194
  return config.default || config;
2191
2195
  }
2192
- async function loadJsConfig(configPath) {
2193
- const fileUrl = pathToFileURL(configPath).href;
2196
+ async function loadJsConfig(configPath, fresh = false) {
2197
+ let fileUrl = pathToFileURL(configPath).href;
2198
+ if (fresh) {
2199
+ fileUrl += `?t=${Date.now()}`;
2200
+ }
2194
2201
  const module = await import(fileUrl);
2195
2202
  return module.default || module;
2196
2203
  }
2197
- async function loadConfigFile(configPath) {
2204
+ async function loadConfigFile(configPath, opts = {}) {
2198
2205
  const ext = extname(configPath);
2199
2206
  if (ext === ".ts" || ext === ".mts") {
2200
- return loadTsConfig(configPath);
2207
+ return loadTsConfig(configPath, opts.fresh);
2201
2208
  }
2202
- return loadJsConfig(configPath);
2209
+ return loadJsConfig(configPath, opts.fresh);
2203
2210
  }
2204
2211
  function mergeConfig(userConfig, baseConfig = defaultConfig) {
2205
2212
  return deepmerge(baseConfig, userConfig, {
2206
2213
  arrayMerge: (_, sourceArray) => sourceArray
2207
2214
  });
2208
2215
  }
2209
- async function resolveConfig(cwd) {
2216
+ async function resolveConfig(cwd, opts = {}) {
2210
2217
  const configPath = findConfigFile(cwd);
2211
2218
  if (!configPath) {
2212
2219
  console.warn("\u26A0\uFE0F \u672A\u627E\u5230\u914D\u7F6E\u6587\u4EF6 (ywkf.config.ts)\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u914D\u7F6E");
@@ -2216,7 +2223,7 @@ async function resolveConfig(cwd) {
2216
2223
  };
2217
2224
  }
2218
2225
  try {
2219
- const userConfig = await loadConfigFile(configPath);
2226
+ const userConfig = await loadConfigFile(configPath, opts);
2220
2227
  const normalized = normalizeConfig(userConfig);
2221
2228
  const config = mergeConfig(normalized);
2222
2229
  return { config, configPath };