[wasm] feat: expose library version

This commit is contained in:
鲁树人 2024-09-19 00:00:30 +01:00
parent 3698c703fc
commit 87ac7aaa5d
2 changed files with 12 additions and 0 deletions

View File

@ -2,6 +2,9 @@ import { defineConfig } from 'rollup';
import { wasm } from '@rollup/plugin-wasm'; import { wasm } from '@rollup/plugin-wasm';
import replace from '@rollup/plugin-replace'; import replace from '@rollup/plugin-replace';
import { dts } from 'rollup-plugin-dts'; import { dts } from 'rollup-plugin-dts';
import { readFileSync } from 'node:fs';
const pkgJson = JSON.parse(readFileSync(new URL('package.json', import.meta.url), 'utf-8'));
function makePlugins({ sync }) { function makePlugins({ sync }) {
const plugins = []; const plugins = [];
@ -16,6 +19,7 @@ function makePlugins({ sync }) {
preventAssignment: true, preventAssignment: true,
values: { values: {
'process.env.UMC_INLINE_BUILD': JSON.stringify(String(sync ? 1 : 0)), 'process.env.UMC_INLINE_BUILD': JSON.stringify(String(sync ? 1 : 0)),
'process.env.UMC_VERSION': JSON.stringify(pkgJson.version),
}, },
}), }),
); );

View File

@ -21,4 +21,12 @@ function loader() {
} }
} }
/**
* Get package version.
* @returns {string}
*/
export function getUmcVersion() {
return process.env.UMC_VERSION;
}
export const ready = loader(); export const ready = loader();