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

Removes direct UUID dep #474

Merged
merged 7 commits into from
May 21, 2020
Merged

Removes direct UUID dep #474

merged 7 commits into from
May 21, 2020

Conversation

jasonkarns
Copy link
Contributor

@jasonkarns jasonkarns commented May 7, 2020

Summary

UUID is already exposed in the js-sdk-utils package, so we should use it directly.
That will ensure de-duping, as well as automatic tree shaking of the uuid dep (because the utils package imports UUID via ESM).

Before
image

After
image

closes #479

@jasonkarns
Copy link
Contributor Author

Just realized the js-sdk-utils package exposes this same function... So why is it imported directly in optimizely-sdk? The versions now need bumped in both packages so that they'll de-dupe. But the bigger question is: if this is exposed in the utils package, why isn't the utils version being used instead of importing a second copy?

@mjc1283
Copy link
Contributor

mjc1283 commented May 7, 2020

Yes, good points. I think we need to remove this dependency from optimizely-sdk, use the version in utils, and update the version in utils to 8.0.0.

@jasonkarns jasonkarns mentioned this pull request May 8, 2020
3 tasks
@jasonkarns jasonkarns changed the title Bump UUID dep to leverage ESM Removes direct UUID dep May 8, 2020
@jasonkarns
Copy link
Contributor Author

PR now updated to remove the direct UUID dep. It's pulled in from js-sdk-utils. Updated tests to stub the correct function.

Also, the js-sdk-utils package is already using the ESM import of UUID, so no version bump is necessary. Indeed, keeping the version at v3* is probably preferable for a while because it increases the chances that downstream consumers can de-dupe UUID itself in their bundles.

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

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

LGTM, just one comment regarding the object property shorthand syntax.

packages/optimizely-sdk/lib/utils/fns/index.js Outdated Show resolved Hide resolved
@jasonkarns
Copy link
Contributor Author

As a side-note, something I encountered while updating the tests... because all the tests across this suite use the same fake UUID for stubbing the uuid function, when a sinon stub was not properly unstubbed, a stub from one test would poison other subsequent tests. I would strongly suggest using different dummy values between files/suites. That way when a test bleeds over to affect another test, the root cause can be identified much quicker (because the error message will be accurate and not masked by the fact that the UUID is "correct" but for the wrong reason).

Alternatively, since UUID generation is not an expensive operation, I would suggest that the stubbing should be updated to return a different value for each test. That is, remove the static stubbing entirely. Generate a UUID during setup and use that uuid as the stubbed value for the test. That way, a poisoned test run will more quickly expose the root cause; because the UUIDs won't be shared across tests.

@mjc1283
Copy link
Contributor

mjc1283 commented May 15, 2020

Everything LGTM, but I overlooked a process issue in my first review. Our packages are published independently, so we can't update optimizely-sdk to use the new stuff in utils until a new version of utils is published. If you could split up the utils changes into its own PR, I can merge that and get a new version published. Sorry for the extra overhead. The fixes here are much appreciated.

@jasonkarns
Copy link
Contributor Author

jasonkarns commented May 20, 2020

It probably got lost in the evolution of this PR, but back here I discovered that the version of UUID being used by the utils package is already ES compliant and tree-shakeable. This PR does contain a tweak to the utils package, but it's purely stylistic. The export of the generateUUID function can be exported directly without being wrapped in another function: https://github.com/optimizely/javascript-sdk/pull/474/files#diff-234d37a781c939ff5538faf0110c211c

However, that change does not need to be released for the optimizely-sdk package to consume the function from utils instead of UUID.

In other words, this PR is entirely focused on optimizely-sdk and can be merged as-is. The change within the utils package can be merged but can remain an unreleased tweak on master.

Copy link
Contributor

@mjc1283 mjc1283 left a comment

Choose a reason for hiding this comment

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

You're quite right - I missed that generateUUID was already exported. Thanks again.

@mjc1283 mjc1283 merged commit 2341a18 into optimizely:master May 21, 2020
@jasonkarns jasonkarns deleted the uuid branch May 22, 2020 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update UUID dependency for ESM
2 participants