Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: embed version at compile time #237

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

kwasniew
Copy link
Contributor

@kwasniew kwasniew commented Jan 15, 2025

About the changes

Removes requiring version at runtime with require: 3615f15#diff-258035e5968f6bf645400d417f310218d7d9a9a10606a3c34e7f55db193f58f3R3

Instead we're using the rollup replace plugin to read the version at build time and replace __VERSION__ placeholder with the actual version number.

As a result other packages depending on this one don't need to understand require calls and also we're not exposing the whole package.json file at runtime.

To verify my claim above you can build the package and check the build directory after this change vs before this change.

Important files

Discussion points

@@ -25,6 +29,10 @@ export default {
}
],
plugins: [
replace({
'__VERSION__': version,
preventAssignment: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required by the warning from the package. more info here: https://www.npmjs.com/package/@rollup/plugin-replace

@@ -1383,7 +1381,8 @@ test('Should add `x-unleash` headers', async () => {
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

const expectedHeaders = {
'x-unleash-sdk': `unleash-js@${packageJSON.version}`,
// will be replaced at build time with the actual version
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are working on pre-build version so no replacement

@@ -0,0 +1 @@
export const sdkVersion = `unleash-js@__VERSION__`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

centralizing this to avoid typos in multiple places

@thomasheartman thomasheartman merged commit b2e385d into main Jan 16, 2025
3 checks passed
@thomasheartman thomasheartman deleted the embed-version-at-compile-time branch January 16, 2025 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants