diff --git a/rollup.config.js b/rollup.config.js index 344c7cf..f22f04e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,6 +5,9 @@ import dts from "rollup-plugin-dts"; import banner2 from 'rollup-plugin-banner2' import packageJson from "./package.json" assert { type: "json" }; +const version = packageJson.version ?? null; + + export default [ { input: "src/index.ts", @@ -26,7 +29,11 @@ export default [ commonjs(), typescript({ tsconfig: "./tsconfig.json" }), banner2(() => ` - "use client"; +"use client"; + +if (typeof window !== "undefined") { + window.CODEIUM_REACT_CODE_VERSION = ${version ? `${JSON.stringify(version)}` : null}; +} `) ], }, diff --git a/src/utils/identity.ts b/src/utils/identity.ts index 9590ebc..7b1ff39 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -23,7 +23,8 @@ export const getBrowserVersion = () => { */ export const getPackageVersion = () => { try { - return require('../../package.json').version; + // @ts-ignore + return window.CODEIUM_REACT_CODE_VERSION ? window.CODEIUM_REACT_CODE_VERSION : null; } catch (e) { return null; }