@longzai-intelligence-builder/utils 0.2.12
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/dist/index.d.ts +33 -0
- package/dist/index.js +1 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +34 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
//#region src/version.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* 读取 `cwd/package.json` 的 `version`,返回 JSON 字符串字面量。
|
|
5
|
+
*
|
|
6
|
+
* 返回值可直接作为 builder `define` 字段的值,无需调用方再 `JSON.stringify`。
|
|
7
|
+
*
|
|
8
|
+
* **典型用法**(构建期版本号注入):
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* // lzi-builder.config.ts
|
|
12
|
+
* import { defineBundleConfig } from '@longzai-intelligence-builder/esm';
|
|
13
|
+
* import { readPackageVersionString } from '@longzai-intelligence-builder/utils';
|
|
14
|
+
*
|
|
15
|
+
* export default defineBundleConfig({
|
|
16
|
+
* define: {
|
|
17
|
+
* 'process.env.CLI_VERSION': readPackageVersionString(),
|
|
18
|
+
* },
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* 源码中的 `process.env.CLI_VERSION` 在构建期被 rolldown 静态替换为版本号字面量
|
|
23
|
+
* (如 `"0.2.12"`),不依赖运行时文件查找。发布只发 `dist`(无旁挂 package.json)
|
|
24
|
+
* 的场景下,经全局 bin 符号链接调用也能输出正确版本。
|
|
25
|
+
*
|
|
26
|
+
* package.json 缺 `version` 字段时回退为空字符串字面量 `'""'`,不抛错。
|
|
27
|
+
*
|
|
28
|
+
* @param cwd - package.json 所在目录(@default process.cwd())
|
|
29
|
+
* @returns JSON 字符串字面量,如 `'"0.2.12"'`;缺 version 时为 `'""'`
|
|
30
|
+
*/
|
|
31
|
+
declare function readPackageVersionString(cwd?: string): string;
|
|
32
|
+
//#endregion
|
|
33
|
+
export { readPackageVersionString };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{readFileSync as e}from"node:fs";import{join as t}from"node:path";function n(n=process.cwd()){let r=JSON.parse(e(t(n,`package.json`),`utf8`));return JSON.stringify(r.version??``)}export{n as readPackageVersionString};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-builder/utils",
|
|
3
|
+
"version": "0.2.12",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "lzi-builder",
|
|
21
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
22
|
+
"prepublishOnly": "bun run build:prod",
|
|
23
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
24
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
25
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
26
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
|
|
27
|
+
"lint": "oxlint && oxfmt --check",
|
|
28
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
29
|
+
"test": "bun test",
|
|
30
|
+
"test:watch": "bun test --watch",
|
|
31
|
+
"test:coverage": "bun test --coverage",
|
|
32
|
+
"clean": "lzi-dev-cli clean"
|
|
33
|
+
}
|
|
34
|
+
}
|