Skip to content

Commit 22133d6

Browse files
committed
refactor(core): simplify version constant implementation
Remove complex fallback mechanism and use direct conditional assignment for version constant, reducing code complexity while maintaining same functionality. 简化版本常量实现,移除复杂的回退机制并使用直接条件赋值, 减少代码复杂度同时保持相同功能。 Change-Id: I98ed261c2d6f0c1129fc93fa098c38cf4d612c72 Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent daf2c75 commit 22133d6

1 file changed

Lines changed: 2 additions & 21 deletions

File tree

src/index.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,9 @@
1010

1111
// Version is injected at build time from package.json
1212
declare const __VERSION__: string;
13-
export const VERSION = (() => {
14-
// Use injected version if available (build time)
15-
if (typeof __VERSION__ !== 'undefined') {
16-
return __VERSION__;
17-
}
1813

19-
// Fallback to package.json version for direct execution
20-
try {
21-
// In ESM, we need to use import.meta.url to get the current file path
22-
const { readFileSync } = require('fs');
23-
const { fileURLToPath } = require('url');
24-
const { dirname, join } = require('path');
25-
26-
const currentFile = fileURLToPath(import.meta.url);
27-
const packageJsonPath = join(dirname(currentFile), '../../package.json');
28-
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
29-
return packageJson.version;
30-
} catch {
31-
// Final fallback
32-
return '0.0.0-dev';
33-
}
34-
})();
14+
export const VERSION =
15+
typeof __VERSION__ !== 'undefined' ? __VERSION__ : '0.0.0-dev';
3516

3617
// Config
3718
export { Config, type ConfigOptions } from './utils/config';

0 commit comments

Comments
 (0)