-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat!: Remove all uses of CJS, add named Flagsmith export #163
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rolodato
changed the title
Remove all uses of CJS, add named Flagsmith export
feat!: Remove all uses of CJS, add named Flagsmith export
Oct 22, 2024
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.
Looks great to me. One main question about a possible breaking change that wasn't listed in the description. Once that's understood, I think we can move forward and get this released.
matthewelwell
approved these changes
Nov 7, 2024
Bonus - hashing is now over 100x faster Index: tests/engine/unit/utils/utils.bench.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/tests/engine/unit/utils/utils.bench.ts b/tests/engine/unit/utils/utils.bench.ts
new file mode 100644
--- /dev/null (date 1730987845619)
+++ b/tests/engine/unit/utils/utils.bench.ts (date 1730987845619)
@@ -0,0 +1,17 @@
+import {bench} from "vitest";
+import {
+ getHashedPercentateForObjIds,
+ getHashedPercentateForObjIdsOld
+} from "../../../../flagsmith-engine/utils/hashing/index.js";
+import {randomUUID as uuidv4} from "crypto";
+
+bench('old hashing', () => {
+ const _ = getHashedPercentateForObjIdsOld([uuidv4()])
+}, {
+ signal: AbortSignal.timeout(10000)
+})
+bench('new hashing', () => {
+ const _ = getHashedPercentateForObjIds([uuidv4()])
+}, {
+ signal: AbortSignal.timeout(10000)
+}) % npx vitest bench
Benchmarking is an experimental feature.
Breaking changes might not follow SemVer, please pin Vitest's version when using it.
DEV v2.1.2 /Users/rolodato/source/flagsmith/flagsmith-nodejs-client
✓ tests/engine/unit/utils/utils.bench.ts (2) 1303ms
name hz min max mean p75 p99 p995 p999 rme samples
· old hashing 4,372.66 0.1842 0.3767 0.2287 0.2331 0.3018 0.3185 0.3650 ±0.39% 2187
· new hashing 578,653.03 0.0014 1.3175 0.0017 0.0016 0.0028 0.0030 0.0053 ±1.63% 289327 fastest
BENCH Summary
new hashing - tests/engine/unit/utils/utils.bench.ts
132.33x faster than old hashing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current beta version of this library doesn't work when used from ESM:
Removing this use of
require
reveals another use ofmodule.exports
, which is CJS and does not get compiled:Fixing this makes everything work:
As a bonus, we can add
Flagsmith
as a named export, for consistency:Important: this is a breaking change for CJS users, as
require
now returns an object instead of theFlagsmith
class:This PR also has some QoL changes:
esModuleInterop
- compiled code doesn't change, but this makes the code truly ESM-only