-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
@@ -25,6 +29,10 @@ export default { | |||
} | |||
], | |||
plugins: [ | |||
replace({ | |||
'__VERSION__': version, | |||
preventAssignment: true |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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__`; |
There was a problem hiding this comment.
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
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