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

[OpenAI] Bundle using rollup v3 #27258

Merged
merged 3 commits into from
Sep 27, 2023
Merged

[OpenAI] Bundle using rollup v3 #27258

merged 3 commits into from
Sep 27, 2023

Conversation

deyaaeldeen
Copy link
Member

Packages impacted by this PR

@azure/openai

Issues associated with this PR

Fixes #27227
Fixes #27226

Describe the problem that is addressed by this PR

@azure/openai depends on v4 of formdata-node and v1.7.2 of form-data-encoder. However, those are outdated versions and we should depend on recent versions of those libraries instead but the recent versions are ESM-only. I couldn't find a way to bundle ESM code into cjs using rollup v2, our current rollup version. With rollup v3, you can bundle ESM-only code if you import it with dynamic imports and this PR does exactly that.

What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?

N/A

Are there test cases added in this PR? (If not, why?)

N/A

Provide a list of related PRs (if any)

N/A

Command used to generate this PR:**(Applicable only to SDK release request PRs)

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

@azure-sdk
Copy link
Collaborator

API change check

API changes are not detected in this pull request.

Copy link
Member

@minhanh-phan minhanh-phan left a comment

Choose a reason for hiding this comment

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

This is awesome :shipit:

Copy link
Member

@xirzec xirzec left a comment

Choose a reason for hiding this comment

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

Nice! Was there anything tricky about the rollup upgrade?

/cc @jeremymeng since we probably want to upgrade across the repro soon

@jeremymeng
Copy link
Member

This is nice! I think a few pure ESM dependencies are causing problem to tests so we haven't upgrade them. After we bump rollup to v3, and add next ESM depedency, we could probably refactoring the config to be shareable.

Deferred import pattern looks a bit unusal comparing to the synchronous one though.

@deyaaeldeen
Copy link
Member Author

Was there anything tricky about the rollup upgrade?

@xirzec The main one is that I couldn't use the rollup-plugin-sourcemaps plugin as discussed in #26665 and it is not clear to me yet how affected are we with that.

@xirzec
Copy link
Member

xirzec commented Sep 27, 2023

Deferred import pattern looks a bit unusal comparing to the synchronous one though.

Yeah, I was considering if we wanted to make some utility helper for this kind of thing, though I'm not sure if rollup would be able to analyze it if we abstracted it (e.g. by passing a string for the module name)

@deyaaeldeen
Copy link
Member Author

Deferred import pattern looks a bit unusal comparing to the synchronous one though.

It is pretty much a requirement for ESM-only dependencies if they should be imported in cjs. ESM loads modules asynchronously so cjs will need to load them asynchronously as well. There has been discussion in adding a sync dynamic import function in NodeJS but it didn't go anywhere, see nodejs/modules#454

@deyaaeldeen deyaaeldeen merged commit c1bad73 into main Sep 27, 2023
25 checks passed
@deyaaeldeen deyaaeldeen deleted the openai/rollup3 branch September 27, 2023 20:39
deyaaeldeen added a commit that referenced this pull request Sep 29, 2023
### Packages impacted by this PR
All libraries

### Issues associated with this PR
Fixes #26665

### Describe the problem that is addressed by this PR
We need to upgrade Rollup to v3 so our cjs bundles could import ES
modules among other goodness.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?
See the linked issue for discussion of the upgrade. Credit to @xirzec
for writing up the sourcemaps plugin in-house replacement!

### Are there test cases added in this PR? _(If not, why?)_
N/A

### Provide a list of related PRs _(if any)_
[N/A](#27258)

### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [x] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants