@infly/libs 2.4.0 → 2.4.2

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/README.md CHANGED
@@ -187,13 +187,13 @@ export default defineConfig({
187
187
  });
188
188
  ```
189
189
 
190
- 插件只在 `vite build` 时生效,默认向 `<head>` 注入 UTC ISO 8601 时间:
190
+ 插件只在 `vite build` 时生效,默认向 `<head>` 注入带 `+08:00` 的北京时间 ISO 8601 时间,不依赖构建机器或 Docker 的系统时区:
191
191
 
192
192
  ```html
193
- <meta name="build-timestamp" content="2026-09-30T03:25:38.000Z">
193
+ <meta name="build-timestamp" content="2026-09-30T11:25:38.000+08:00">
194
194
  ```
195
195
 
196
- 可通过 `timestamp` 固定时间以支持可复现测试,通过 `metaName` 调整字段名。未显式引入该插件的既有项目行为不变。
196
+ 可通过 `timestamp` 固定时间以支持可复现测试,通过 `metaName` 调整字段名。该字段记录创建构建插件时的时间,不是 Jenkins 部署完成时间;新格式与原 UTC 格式表示同一实际时刻,可继续用 `Date.parse()` 读取。未显式引入该插件的既有项目行为不变。独立消费者须更新公共包锁文件并重新构建,已发布镜像中的 HTML 不会自动变化。
197
197
 
198
198
  通用 workspace 与 Git 原语通过稳定子路径使用:
199
199
 
@@ -1,7 +1,7 @@
1
1
  export const BUILD_TIMESTAMP_META_NAME: "build-timestamp";
2
2
 
3
3
  export interface BuildTimestampPluginOptions {
4
- /** 固定构建时间;默认使用创建插件时的当前时间,并统一输出为 UTC ISO 8601。 */
4
+ /** 固定构建时间;默认使用创建插件时的当前时间,输出带 +08:00 的北京时间 ISO 8601。 */
5
5
  timestamp?: string | Date;
6
6
  /** 注入的 meta name;默认是 build-timestamp。 */
7
7
  metaName?: string;
@@ -5,7 +5,10 @@ function normalizeBuildTimestamp(value) {
5
5
  if (Number.isNaN(date.getTime())) {
6
6
  throw new TypeError("build timestamp must be a valid Date or date string");
7
7
  }
8
- return date.toISOString();
8
+ // 固定以北京时间展示,不受开发电脑或 Docker 的系统时区影响。
9
+ // 输出必须携带 +08:00,让机器读取后仍得到原来的实际时刻。
10
+ const beijingDate = new Date(date.getTime() + 8 * 60 * 60 * 1000);
11
+ return beijingDate.toISOString().replace(/Z$/, "+08:00");
9
12
  }
10
13
 
11
14
  function normalizeMetaName(value) {
@@ -17,7 +20,7 @@ function normalizeMetaName(value) {
17
20
  }
18
21
 
19
22
  /**
20
- * 创建一个只在 Vite build 时生效的插件,把 UTC 构建时间写入最终 index.html。
23
+ * 创建一个只在 Vite build 时生效的插件,把北京时间(UTC+8)写入最终 index.html。
21
24
  *
22
25
  * @param {{ timestamp?: string | Date, metaName?: string }} [options]
23
26
  * @returns {object}
package/index.d.ts ADDED
@@ -0,0 +1,277 @@
1
+ /**
2
+ * @infly/libs TypeScript 类型声明
3
+ *
4
+ * 为框架无关工具库提供基本类型支持,改善消费方的开发体验。
5
+ * 覆盖包根入口和全部显式稳定 sub-path exports。
6
+ */
7
+
8
+ declare module "@infly/libs" {
9
+ /**
10
+ * 初始化 @infly/libs。仅在显式调用时懒加载 Vue 2 适配器。
11
+ * @param projectRoot - 项目根目录路径
12
+ */
13
+ export function init(projectRoot?: string): void;
14
+
15
+ export const name: "@infly/libs";
16
+ export const framework: "agnostic";
17
+ }
18
+
19
+ declare module "@infly/libs/module/Uts.js" {
20
+ /**
21
+ * 通用工具方法聚合对象。
22
+ * 聚合了 @infly/ts-libs 的所有导出,向后兼容 Uts.xxx() 调用方式。
23
+ */
24
+ const Uts: Record<string, any>;
25
+ export default Uts;
26
+ }
27
+
28
+ declare module "@infly/libs/adapters/vue2/module/REST.js" {
29
+ interface RESTConfig {
30
+ baseURL?: string;
31
+ timeout?: number;
32
+ headers?: Record<string, string>;
33
+ }
34
+
35
+ interface RequestConfig {
36
+ params?: Record<string, any>;
37
+ headers?: Record<string, string>;
38
+ responseType?: string;
39
+ }
40
+
41
+ const REST: {
42
+ get<T = any>(url: string, config?: RequestConfig): Promise<T>;
43
+ post<T = any>(url: string, data?: any, config?: RequestConfig): Promise<T>;
44
+ put<T = any>(url: string, data?: any, config?: RequestConfig): Promise<T>;
45
+ delete<T = any>(url: string, config?: RequestConfig): Promise<T>;
46
+ };
47
+
48
+ export default REST;
49
+ }
50
+
51
+ declare module "@infly/libs/adapters/vue2/module/TokenService.js" {
52
+ interface TokenInfo {
53
+ token: string;
54
+ refreshToken?: string;
55
+ expiresAt?: number;
56
+ }
57
+
58
+ const TokenService: {
59
+ getToken(): string | null;
60
+ setToken(token: string): void;
61
+ removeToken(): void;
62
+ getRefreshToken(): string | null;
63
+ setRefreshToken(token: string): void;
64
+ };
65
+
66
+ export default TokenService;
67
+ }
68
+
69
+ // ---- 显式稳定 sub-path exports ----
70
+
71
+ declare module "@infly/libs/build" {
72
+ /** 构建环境标识(如 "prod" / "stage") */
73
+ export const ENV: string;
74
+
75
+ /** 构建上下文环境变量 */
76
+ export function createBuildContext(options?: Record<string, any>): Record<string, any>;
77
+
78
+ /** 解析构建上下文 */
79
+ export function parseBuildContext(options?: Record<string, any>): Record<string, any>;
80
+
81
+ /** 目标发布分支 */
82
+ export function getTargetBranch(packageJson: object, mode: string): string;
83
+
84
+ /** 更新公共包源码 */
85
+ export function updatePackageSources(rootDir: string, packages: any[], targetBranch: string): void;
86
+
87
+ /** 更新应用与 dist 仓库源码 */
88
+ export function updateAppAndDistSources(rootDir: string, packages: any[], targetBranch: string): void;
89
+
90
+ /** 更新全部源码 */
91
+ export function updateAllSources(rootDir: string, packages: any[], targetBranch: string): void;
92
+
93
+ /** dist 仓库任务清单 */
94
+ export function getDistRepoTasks(rootDir: string, packages: any[]): any[];
95
+
96
+ /** 打印 dry-run 源码更新计划 */
97
+ export function printDryRunSourceUpdatePlan(rootDir: string, packages: any[], targetBranch: string): void;
98
+
99
+ /** 批量 webhook 通知 */
100
+ export function postBatchWebhook(rootDir: string, options?: Record<string, any>): Promise<void>;
101
+
102
+ /** 启动批量预览 */
103
+ export function startBatchPreviews(rootDir: string, packages: any[], options?: Record<string, any>): Promise<any>;
104
+
105
+ /** 执行命令 */
106
+ export function run(command: string, args: string[], options?: Record<string, any>): Promise<void>;
107
+
108
+ /** 后台启动命令 */
109
+ export function spawnBackground(command: string, args: string[], options?: Record<string, any>): unknown;
110
+ }
111
+
112
+ declare module "@infly/libs/concurrency" {
113
+ /**
114
+ * 并发限流执行器。
115
+ * @param items - 待处理项
116
+ * @param concurrency - 最大并发数
117
+ * @param worker - 单项处理函数
118
+ */
119
+ export function runWithConcurrency<T>(
120
+ items: readonly T[],
121
+ concurrency: number,
122
+ worker: (item: T, index: number) => Promise<void> | void,
123
+ ): Promise<void>;
124
+ }
125
+
126
+ declare module "@infly/libs/progress" {
127
+ interface ProgressLineOptions {
128
+ label: string;
129
+ completed: number;
130
+ total: number;
131
+ path?: string;
132
+ }
133
+
134
+ export function formatProgressLine(options: ProgressLineOptions): string;
135
+
136
+ export function createProgressReporter(options?: Record<string, any>): {
137
+ start(message: string, total: number): void;
138
+ update(done: number, message?: string): void;
139
+ finish(message?: string): void;
140
+ };
141
+
142
+ export function formatSwitchSummary(
143
+ name: string,
144
+ totalMs: number,
145
+ dependencyResult: unknown,
146
+ timings?: unknown,
147
+ ): string;
148
+
149
+ export function formatSlowStatusDetails(details: unknown, thresholdMs?: number): string;
150
+ }
151
+
152
+ declare module "@infly/libs/npm-release" {
153
+ /** 解析稳定版本号,返回 [major, minor, patch] */
154
+ export function parseStableVersion(version: string): number[];
155
+
156
+ /** patch +1 */
157
+ export function bumpPatch(version: string): string;
158
+
159
+ /** 比较两个稳定版本号:左 > 右返回 1,相等返回 0,否则 -1 */
160
+ export function compareVersions(left: string, right: string): number;
161
+
162
+ /** 生成发布计划(含 registry 版本核对与目标版本计算;registryVersions 中为 null 表示从未发布的首次发布) */
163
+ export function buildReleasePlan(
164
+ packages: any[],
165
+ registryVersions: Record<string, string | null>,
166
+ options?: { prepared?: boolean },
167
+ ): any[];
168
+ }
169
+
170
+ declare module "@infly/libs/workspace-packages" {
171
+ export const DEPENDENCY_SECTIONS: string[];
172
+
173
+ export function normalizeWorkspacePath(filePath: string): string;
174
+
175
+ /** 发现 workspace 包 */
176
+ export function discoverWorkspacePackages(rootDir: string, options?: Record<string, any>): any[];
177
+
178
+ /** 包内部依赖名集合 */
179
+ export function getInternalDependencies(pkg: object, packageNames: string[]): string[];
180
+
181
+ /** 按变更路径计算受影响包(含反向 workspace 依赖方) */
182
+ export function selectAffectedWorkspacePackages(
183
+ changedPaths: string[],
184
+ packages: any[],
185
+ options?: Record<string, any>,
186
+ ): any[];
187
+ }
188
+
189
+ declare module "@infly/libs/workspace-config" {
190
+ export function readJson(filePath: string): any;
191
+
192
+ export function readWorkspaceList(content: string, sectionName: string): string[];
193
+
194
+ export function readWorkspaceSection(workspaceFile: string, sectionName: string): string[];
195
+
196
+ export function readWorkspaceSectionWithFallback(
197
+ workspaceFile: string,
198
+ sectionName: string,
199
+ fallbackSectionName: string,
200
+ ): string[];
201
+
202
+ export function expandWorkspacePattern(rootDir: string, pattern: string): string[];
203
+
204
+ export function getWorkspacePackages(
205
+ rootDir: string,
206
+ workspaceFile: string,
207
+ sectionName?: string,
208
+ fallbackSectionName?: string,
209
+ scriptName?: string,
210
+ ): any[];
211
+
212
+ export function toTurboFilter(value: unknown): string;
213
+ }
214
+
215
+ declare module "@infly/libs/cli/project-command" {
216
+ export function loadConfig(cwd?: string): { config: object; configDir: string };
217
+
218
+ export function resolveBuildPlatforms(targets: unknown, buildConfig: object, targetName: string): string[];
219
+
220
+ export function runProjectCommand(options?: Record<string, any>, dependencies?: Record<string, any>): Promise<object>;
221
+ }
222
+
223
+ declare module "@infly/libs/cli/select-option" {
224
+ /** 用户选择退出(取消)的哨兵值 */
225
+ export const EXIT_SELECTION: string;
226
+
227
+ export function makePromptCancellationSafe<T>(prompt: () => Promise<T>): Promise<T>;
228
+
229
+ export function selectOption(
230
+ message: string,
231
+ choices: Array<{ value: string; label?: string }>,
232
+ dependencies?: Record<string, any>,
233
+ ): Promise<string>;
234
+ }
235
+
236
+ declare module "@infly/libs/adapters/webpack/auto-export" {
237
+ /** 自动收集 require.context 下的文件导出 */
238
+ export function autoExportFiles(requireContext: unknown): Record<string, unknown>;
239
+
240
+ /** 将收集到的导出合并到目标对象 */
241
+ export function autoExportToModule(requireContext: unknown, targetExports: object): void;
242
+ }
243
+
244
+ declare module "@infly/libs/git/configure" {
245
+ export function configureMergeDriver(): void;
246
+
247
+ export function configureGitAliases(): void;
248
+ }
249
+
250
+ declare module "@infly/libs/git/submodule-status" {
251
+ interface SubmoduleInfo {
252
+ name: string;
253
+ path: string;
254
+ configuredBranch: string;
255
+ }
256
+
257
+ export function runGit(cwd: string, args: string[], options?: { allowFailure?: boolean }): string;
258
+
259
+ export function getConfiguredSubmodules(rootDir: string): SubmoduleInfo[];
260
+
261
+ export function getParentPointer(rootDir: string, submodulePath: string): string;
262
+
263
+ export function inspectSubmodule(rootDir: string, submodule: SubmoduleInfo): {
264
+ path: string;
265
+ branch: string;
266
+ head: string;
267
+ pointer: string;
268
+ originMaster: string;
269
+ state: string;
270
+ };
271
+ }
272
+
273
+ declare module "@infly/libs/git/submodules" {
274
+ export function normalizeRelativePath(value: string): string;
275
+
276
+ export function parseGitmodulesPaths(rootDir: string): string[];
277
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@infly/libs",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "不受前端框架限制的独立工具库",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "files": [
8
8
  "index.js",
9
+ "index.d.ts",
9
10
  "bin/",
10
11
  "compat/",
11
12
  "core/",
@@ -82,7 +83,8 @@
82
83
  "vitest": "^4.0.0",
83
84
  "eslint": "^9.0.0",
84
85
  "@eslint/js": "^9.0.0",
85
- "globals": "^15.0.0"
86
+ "globals": "^15.0.0",
87
+ "@vitest/coverage-v8": "4.1.10"
86
88
  },
87
89
  "peerDependencies": {
88
90
  "axios": "^0.27.2",