-
Notifications
You must be signed in to change notification settings - Fork 769
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
Introduce separate entry point for worker environments #1660
Conversation
6c260e6
to
e520500
Compare
Why is node 12 on fire? Is it because it's getting the wrong HTTP client? |
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.
Mostly code structure related comments.
Create a test project similar to ones we have and invoke the cloudflare build CLI on it from tests. |
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.
Few more comments. This is getting better and better with every commit!
…reviewer comments
b3a8791
to
94369db
Compare
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.
Great work! 🎉
* Separate stripe into worker and default entrypoints, needs tests for worker * Fix test, remove unused import * Actually require child_process * build * Convert tests to TypeScript, add browser field * Move more utils functions to nodeUtils * Use _utils defined on Stripe object * Add error messages to createNodeHttpClient and createNodeCryptoProvider * Move platform-specific utils to new PlatformFunctions classes, add tests * Abstract getUname to platform functions, set _platformFunctions on Webhooks * Make generic createCryptoProvider in Webhooks * Revert "Make generic createCryptoProvider in Webhooks" This reverts commit c8af4d5. * Remove stale file in lib * Create generic createHttpClient that creates FetchHttpClient by default in workers * Move getUname to PlatformFunctions (now returns a promise), and misc reviewer comments * Make generic createCryptoProvider in Webhooks * Removing this alias * Fix DefaultPlatformFunctions getUname, fix test * Add getMockPlatformFunctions test util, prefix _createCryptoProvider
* Separate stripe into worker and default entrypoints, needs tests for worker * Fix test, remove unused import * Actually require child_process * build * Convert tests to TypeScript, add browser field * Move more utils functions to nodeUtils * Use _utils defined on Stripe object * Add error messages to createNodeHttpClient and createNodeCryptoProvider * Move platform-specific utils to new PlatformFunctions classes, add tests * Abstract getUname to platform functions, set _platformFunctions on Webhooks * Make generic createCryptoProvider in Webhooks * Revert "Make generic createCryptoProvider in Webhooks" This reverts commit c8af4d5. * Remove stale file in lib * Create generic createHttpClient that creates FetchHttpClient by default in workers * Move getUname to PlatformFunctions (now returns a promise), and misc reviewer comments * Make generic createCryptoProvider in Webhooks * Removing this alias * Fix DefaultPlatformFunctions getUname, fix test * Add getMockPlatformFunctions test util, prefix _createCryptoProvider
Summary
Introduces an exports field to the package.json that defines a separate entry point for environments where Node.js built-in modules are not supported.
Major changes in this PR:
stripe.ts
andstripe.worker.ts
, move common code intostripe.common.ts
utils.ts
that depend on Node.js built-ins to theplatform
directory in aNodePlatformFunctions
class that inherits fromDefaultPlatformFunctions
_platformFunctions
property onto Stripe object. Use this to override functions that depend on Node-specific modules instripe.node.ts
Stripe.createNodeHttpClient
andStripe.createNodeCryptoProvider
to throw errors and override them instripe.node.ts
(won't be available for workers)Stripe.createHttpClient
that defaults toStripe.createNodeHttpClient
normally, andStripe.createFetchHttpClient
in workersTesting
I wasn't sure of a good way to add an automated test that mimics a worker environment. I tested this locally, and validated that the expected build errors have been resolved (see next section 'Remaining Work' for remaining errors).
The original build errors:
![Screen Shot 2023-01-17 at 12 46 53 PM](https://user-images.githubusercontent.com/97691964/213008875-9f9d8e5f-661e-41a4-b279-36e4ffe99345.png)
Now:
![Screen Shot 2023-01-19 at 10 52 44 AM](https://user-images.githubusercontent.com/97691964/213534311-5cadeae8-8217-484d-be25-368a33c3ff75.png)
Remaining Work
Stripe._emitter
andutils.checkForStream
to not useEventEmitter
for worker environments