@42ailab/42plugin 0.1.9 → 0.1.10

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.ts +15 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@42ailab/42plugin",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "活水插件",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/cli.ts CHANGED
@@ -15,9 +15,22 @@ import {
15
15
  checkCommand,
16
16
  } from './commands';
17
17
 
18
- // 版本号在构建时通过 --define 注入
18
+ // 版本号:编译时通过 --define 注入,源码运行时从 package.json 读取
19
19
  declare const __VERSION__: string;
20
- const version: string = typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.0.0-dev';
20
+ async function getVersion(): Promise<string> {
21
+ // 编译后的二进制使用注入的版本号
22
+ if (typeof __VERSION__ !== 'undefined') {
23
+ return __VERSION__;
24
+ }
25
+ // 源码运行(bun run / npm)时从 package.json 读取
26
+ try {
27
+ const pkg = await import('../package.json');
28
+ return pkg.default?.version || pkg.version || '0.0.0-dev';
29
+ } catch {
30
+ return '0.0.0-dev';
31
+ }
32
+ }
33
+ const version: string = await getVersion();
21
34
 
22
35
  const program = new Command();
23
36