@4399ywkf/core 5.3.1 → 5.4.1

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.
@@ -7,40 +7,40 @@ type RouterInstance = ReturnType<typeof createBrowserRouter>;
7
7
  * 应用配置
8
8
  */
9
9
  interface AppConfig {
10
+ /** Ant Design 配置 */
11
+ antd?: AntdConfig;
10
12
  /** 应用名称 */
11
13
  appName?: string;
12
- /** 路由实例(手动配置时使用) */
13
- router?: RouterInstance;
14
14
  /** 路由 basename */
15
15
  basename?: string;
16
+ /** 异步 chunk 加载失败恢复配置 */
17
+ chunkRecovery?: boolean | ChunkRecoveryConfig;
16
18
  /**
17
19
  * 使用约定式路由
18
20
  * 设为 true 时,框架自动从 @ywkf/routes 加载生成的路由
19
21
  * 无需手动配置 router
20
22
  */
21
23
  conventionalRoutes?: boolean;
24
+ /** 生命周期钩子 */
25
+ lifecycle?: LifecycleHooks;
26
+ /** 自定义 Providers */
27
+ providers?: ProviderConfig[];
22
28
  /** 根元素 ID */
23
29
  rootId?: string;
30
+ /** 路由实例(手动配置时使用) */
31
+ router?: RouterInstance;
24
32
  /** 是否启用严格模式 */
25
33
  strictMode?: boolean;
26
- /** Ant Design 配置 */
27
- antd?: AntdConfig;
28
- /** 自定义 Providers */
29
- providers?: ProviderConfig[];
30
- /** 生命周期钩子 */
31
- lifecycle?: LifecycleHooks;
32
- /** 异步 chunk 加载失败恢复配置 */
33
- chunkRecovery?: boolean | ChunkRecoveryConfig;
34
34
  }
35
35
  /**
36
36
  * 异步 chunk 加载失败恢复配置
37
37
  */
38
38
  interface ChunkRecoveryConfig {
39
39
  /**
40
- * 是否启用自动恢复
41
- * 默认仅在 production 环境启用
40
+ * 是否允许在微前端子应用中刷新整个页面
41
+ * 默认 false,避免子应用刷新宿主应用
42
42
  */
43
- enabled?: boolean;
43
+ allowInMicroApp?: boolean;
44
44
  /**
45
45
  * 当前构建的稳定标识(可选覆盖;ywkf 构建默认自动注入)
46
46
  * 同一 build 在一个标签页内最多自动刷新一次
@@ -49,10 +49,10 @@ interface ChunkRecoveryConfig {
49
49
  /** 自动刷新冷却时间(毫秒),默认 30000 */
50
50
  cooldownMs?: number;
51
51
  /**
52
- * 是否允许在微前端子应用中刷新整个页面
53
- * 默认 false,避免子应用刷新宿主应用
52
+ * 是否启用自动恢复
53
+ * 默认仅在 production 环境启用
54
54
  */
55
- allowInMicroApp?: boolean;
55
+ enabled?: boolean;
56
56
  /**
57
57
  * 是否注册 unhandledrejection / vite:preloadError 全局监听
58
58
  * 默认 false;已有应用级监听时无需开启
@@ -60,36 +60,36 @@ interface ChunkRecoveryConfig {
60
60
  globalHandlers?: boolean;
61
61
  }
62
62
  /** chunk 加载失败的来源 */
63
- type ChunkRecoverySource = "error-boundary" | "route-error-boundary" | "unhandled-rejection" | "vite-preload-error";
63
+ type ChunkRecoverySource = 'error-boundary' | 'route-error-boundary' | 'unhandled-rejection' | 'vite-preload-error';
64
64
  /** chunk 恢复处理结果 */
65
- type ChunkRecoveryOutcome = "reload-scheduled" | "reload-skipped-already-attempted" | "reload-skipped-disabled" | "reload-skipped-micro-app" | "reload-skipped-storage-unavailable" | "reload-skipped-cooldown";
65
+ type ChunkRecoveryOutcome = 'reload-scheduled' | 'reload-skipped-already-attempted' | 'reload-skipped-disabled' | 'reload-skipped-micro-app' | 'reload-skipped-storage-unavailable' | 'reload-skipped-cooldown';
66
66
  /** chunk 恢复事件,可用于接入业务侧监控 */
67
67
  interface ChunkRecoveryEvent {
68
+ /** 当前使用的刷新冷却时间 */
69
+ cooldownMs: number;
68
70
  /** 原始错误(非 Error 类型会被标准化) */
69
71
  error: Error;
70
- /** 错误来源 */
71
- source: ChunkRecoverySource;
72
72
  /** 本次处理结果 */
73
73
  outcome: ChunkRecoveryOutcome;
74
- /** 事件发生时间 */
75
- timestamp: number;
76
- /** 当前使用的刷新冷却时间 */
77
- cooldownMs: number;
78
74
  /** 用于防止同一构建重复刷新的匿名恢复标识 */
79
75
  recoveryId: string;
76
+ /** 错误来源 */
77
+ source: ChunkRecoverySource;
78
+ /** 事件发生时间 */
79
+ timestamp: number;
80
80
  }
81
81
  /**
82
82
  * Ant Design 配置
83
83
  */
84
84
  interface AntdConfig {
85
+ /** ConfigProvider props */
86
+ configProvider?: Record<string, unknown>;
85
87
  /** 是否启用 */
86
88
  enabled?: boolean;
87
- /** 主题配置 */
88
- theme?: Record<string, unknown>;
89
89
  /** 语言包 */
90
90
  locale?: object;
91
- /** ConfigProvider props */
92
- configProvider?: Record<string, unknown>;
91
+ /** 主题配置 */
92
+ theme?: Record<string, unknown>;
93
93
  }
94
94
  /**
95
95
  * Provider 配置
@@ -99,10 +99,10 @@ interface ProviderConfig {
99
99
  component: React.ComponentType<{
100
100
  children: ReactNode;
101
101
  }>;
102
- /** Provider props */
103
- props?: Record<string, unknown>;
104
102
  /** 排序权重(越小越外层) */
105
103
  order?: number;
104
+ /** Provider props */
105
+ props?: Record<string, unknown>;
106
106
  }
107
107
  /**
108
108
  * 生命周期钩子
@@ -110,14 +110,14 @@ interface ProviderConfig {
110
110
  interface LifecycleHooks {
111
111
  /** 应用挂载前 */
112
112
  onBeforeMount?: () => void | Promise<void>;
113
- /** 应用挂载后 */
114
- onMounted?: () => void;
115
- /** 应用卸载时 */
116
- onUnmount?: () => void;
117
113
  /** 全局错误处理 */
118
114
  onError?: (error: Error, errorInfo?: React.ErrorInfo) => void;
115
+ /** 应用挂载后 */
116
+ onMounted?: () => void;
119
117
  /** chunk 加载恢复事件 */
120
118
  onRecoveryEvent?: (event: ChunkRecoveryEvent) => void;
119
+ /** 应用卸载时 */
120
+ onUnmount?: () => void;
121
121
  }
122
122
  /**
123
123
  * 应用上下文数据
@@ -127,19 +127,19 @@ interface AppContextValue {
127
127
  appName: string;
128
128
  /** 路由 basename */
129
129
  basename: string;
130
- /** 是否开发环境 */
131
- isDev: boolean;
132
130
  /** 环境变量 */
133
131
  env: Record<string, string | undefined>;
132
+ /** 是否开发环境 */
133
+ isDev: boolean;
134
134
  }
135
135
  /**
136
136
  * 微前端相关配置
137
137
  */
138
138
  interface MicroAppConfig {
139
+ /** 微前端框架类型 */
140
+ framework?: 'qiankun' | 'garfish';
139
141
  /** 是否作为子应用运行 */
140
142
  isMicroApp?: boolean;
141
- /** 微前端框架类型 */
142
- framework?: "qiankun" | "garfish";
143
143
  /** 主应用传递的 props */
144
144
  masterProps?: Record<string, unknown>;
145
145
  }
@@ -155,10 +155,10 @@ interface MicroAppConfig {
155
155
  interface Result<T = unknown> {
156
156
  /** 业务状态码,0 表示成功 */
157
157
  code: number;
158
- /** 提示信息 */
159
- message: string;
160
158
  /** 业务数据 */
161
159
  data: T;
160
+ /** 提示信息 */
161
+ message: string;
162
162
  }
163
163
  /**
164
164
  * 请求配置
@@ -184,23 +184,19 @@ interface Result<T = unknown> {
184
184
  interface RequestConfig {
185
185
  /** API 基础路径 */
186
186
  baseURL?: string;
187
- /** 超时时间(毫秒),默认 15000 */
188
- timeout?: number;
189
- /** 额外请求头 */
190
- headers?: Record<string, string>;
191
- /** 是否携带 Cookie,默认 false */
192
- withCredentials?: boolean;
187
+ /**
188
+ * 错误处理器
189
+ * 处理非 2xx 响应和网络错误
190
+ */
191
+ errorHandler?: (error: Record<string, unknown>) => unknown;
193
192
  /**
194
193
  * Token 获取函数
195
194
  * 返回值将被设置到 `Authorization` 请求头
196
195
  * 返回 null/undefined 则不注入
197
196
  */
198
197
  getToken?: () => string | null | undefined;
199
- /**
200
- * Token 前缀,默认 "Bearer"
201
- * 设为空字符串则不添加前缀
202
- */
203
- tokenPrefix?: string;
198
+ /** 额外请求头 */
199
+ headers?: Record<string, string>;
204
200
  /**
205
201
  * 请求拦截器
206
202
  * 在 Token 注入之后执行,可用于添加签名、自定义 header 等
@@ -212,11 +208,15 @@ interface RequestConfig {
212
208
  * 返回值将作为请求的最终结果
213
209
  */
214
210
  responseInterceptor?: (response: Record<string, unknown>) => unknown;
211
+ /** 超时时间(毫秒),默认 15000 */
212
+ timeout?: number;
215
213
  /**
216
- * 错误处理器
217
- * 处理非 2xx 响应和网络错误
214
+ * Token 前缀,默认 "Bearer"
215
+ * 设为空字符串则不添加前缀
218
216
  */
219
- errorHandler?: (error: Record<string, unknown>) => unknown;
217
+ tokenPrefix?: string;
218
+ /** 是否携带 Cookie,默认 false */
219
+ withCredentials?: boolean;
220
220
  }
221
221
 
222
222
  export type { AntdConfig as A, ChunkRecoveryConfig as C, LifecycleHooks as L, MicroAppConfig as M, ProviderConfig as P, RequestConfig as R, AppConfig as a, AppContextValue as b, ChunkRecoveryEvent as c, ChunkRecoveryOutcome as d, ChunkRecoverySource as e, Result as f };
package/package.json CHANGED
@@ -1,10 +1,8 @@
1
1
  {
2
2
  "name": "@4399ywkf/core",
3
- "version": "5.3.1",
3
+ "version": "5.4.1",
4
4
  "description": "4399运维开发前端框架核心",
5
5
  "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
6
  "exports": {
9
7
  ".": {
10
8
  "types": "./dist/index.d.ts",
@@ -32,6 +30,8 @@
32
30
  },
33
31
  "./biome": "./biome.json"
34
32
  },
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
35
  "bin": {
36
36
  "ywkf": "./dist/cli/index.js"
37
37
  },
@@ -74,6 +74,7 @@
74
74
  "webpack-merge": "^6.0.1"
75
75
  },
76
76
  "devDependencies": {
77
+ "@4399ywkf/biome-config": "^1.1.0",
77
78
  "@types/node": "^22.13.10",
78
79
  "@types/react": "^19.2.14",
79
80
  "@types/react-dom": "^19.2.3",
@@ -100,10 +101,10 @@
100
101
  "scripts": {
101
102
  "build": "tsup",
102
103
  "dev": "tsup --watch",
103
- "test": "vitest run",
104
- "typecheck": "tsc --noEmit",
105
104
  "release": "npm version patch && npm publish --access public",
105
+ "release:major": "npm version major && npm publish --access public",
106
106
  "release:minor": "npm version minor && npm publish --access public",
107
- "release:major": "npm version major && npm publish --access public"
107
+ "test": "vitest run",
108
+ "typecheck": "tsc --noEmit"
108
109
  }
109
110
  }