@infly/libs 2.2.13 → 2.2.14
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 +18 -0
- package/build/vite/index.d.ts +30 -0
- package/build/vite/index.js +50 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -165,6 +165,24 @@ const {
|
|
|
165
165
|
|
|
166
166
|
`build/build-utils/*` 是包内实现目录,不作为新的跨仓调用入口。应用选择、产品线、环境和构建顺序仍由调用方负责;该入口不改变 `infly-libs beforeBuild`、`afterBuild` 的现有行为。
|
|
167
167
|
|
|
168
|
+
Vite 应用需要在最终 `index.html` 中记录构建时间时,使用显式入口 `@infly/libs/build/vite`:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
import { createBuildTimestampPlugin } from "@infly/libs/build/vite";
|
|
172
|
+
|
|
173
|
+
export default defineConfig({
|
|
174
|
+
plugins: [createBuildTimestampPlugin()],
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
插件只在 `vite build` 时生效,默认向 `<head>` 注入 UTC ISO 8601 时间:
|
|
179
|
+
|
|
180
|
+
```html
|
|
181
|
+
<meta name="build-timestamp" content="2026-09-30T03:25:38.000Z">
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
可通过 `timestamp` 固定时间以支持可复现测试,通过 `metaName` 调整字段名。未显式引入该插件的既有项目行为不变。
|
|
185
|
+
|
|
168
186
|
通用 workspace 与 Git 原语通过稳定子路径使用:
|
|
169
187
|
|
|
170
188
|
```javascript
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const BUILD_TIMESTAMP_META_NAME: "build-timestamp";
|
|
2
|
+
|
|
3
|
+
export interface BuildTimestampPluginOptions {
|
|
4
|
+
/** 固定构建时间;默认使用创建插件时的当前时间,并统一输出为 UTC ISO 8601。 */
|
|
5
|
+
timestamp?: string | Date;
|
|
6
|
+
/** 注入的 meta name;默认是 build-timestamp。 */
|
|
7
|
+
metaName?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface BuildTimestampHtmlTag {
|
|
11
|
+
tag: "meta";
|
|
12
|
+
attrs: {
|
|
13
|
+
name: string;
|
|
14
|
+
content: string;
|
|
15
|
+
};
|
|
16
|
+
injectTo: "head";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 使用最小结构化契约,避免把 @infly/libs 自身的 Vite 小版本类型泄漏给消费方。
|
|
21
|
+
*/
|
|
22
|
+
export interface BuildTimestampVitePlugin {
|
|
23
|
+
name: "infly-build-timestamp";
|
|
24
|
+
apply: "build";
|
|
25
|
+
transformIndexHtml(): BuildTimestampHtmlTag[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createBuildTimestampPlugin(
|
|
29
|
+
options?: BuildTimestampPluginOptions,
|
|
30
|
+
): BuildTimestampVitePlugin;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const BUILD_TIMESTAMP_META_NAME = "build-timestamp";
|
|
2
|
+
|
|
3
|
+
function normalizeBuildTimestamp(value) {
|
|
4
|
+
const date = value === undefined ? new Date() : value instanceof Date ? value : new Date(value);
|
|
5
|
+
if (Number.isNaN(date.getTime())) {
|
|
6
|
+
throw new TypeError("build timestamp must be a valid Date or date string");
|
|
7
|
+
}
|
|
8
|
+
return date.toISOString();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function normalizeMetaName(value) {
|
|
12
|
+
const metaName = value === undefined ? BUILD_TIMESTAMP_META_NAME : String(value).trim();
|
|
13
|
+
if (!/^[A-Za-z][A-Za-z0-9._:-]*$/.test(metaName)) {
|
|
14
|
+
throw new TypeError("build timestamp metaName must be a valid HTML meta name");
|
|
15
|
+
}
|
|
16
|
+
return metaName;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 创建一个只在 Vite build 时生效的插件,把 UTC 构建时间写入最终 index.html。
|
|
21
|
+
*
|
|
22
|
+
* @param {{ timestamp?: string | Date, metaName?: string }} [options]
|
|
23
|
+
* @returns {object}
|
|
24
|
+
*/
|
|
25
|
+
function createBuildTimestampPlugin(options = {}) {
|
|
26
|
+
const buildTimestamp = normalizeBuildTimestamp(options.timestamp);
|
|
27
|
+
const metaName = normalizeMetaName(options.metaName);
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: "infly-build-timestamp",
|
|
31
|
+
apply: "build",
|
|
32
|
+
transformIndexHtml() {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
tag: "meta",
|
|
36
|
+
attrs: {
|
|
37
|
+
name: metaName,
|
|
38
|
+
content: buildTimestamp,
|
|
39
|
+
},
|
|
40
|
+
injectTo: "head",
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports = {
|
|
48
|
+
BUILD_TIMESTAMP_META_NAME,
|
|
49
|
+
createBuildTimestampPlugin,
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infly/libs",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.14",
|
|
4
4
|
"description": "不受前端框架限制的独立工具库",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -29,6 +29,11 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": "./index.js",
|
|
31
31
|
"./build": "./build/index.js",
|
|
32
|
+
"./build/vite": {
|
|
33
|
+
"types": "./build/vite/index.d.ts",
|
|
34
|
+
"require": "./build/vite/index.js",
|
|
35
|
+
"default": "./build/vite/index.js"
|
|
36
|
+
},
|
|
32
37
|
"./concurrency": "./core/async/concurrency.js",
|
|
33
38
|
"./progress": "./cli/progress.js",
|
|
34
39
|
"./npm-release": "./release/npm-plan.js",
|