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

[typescript] Support esbuild, second attempt #11465

Merged
merged 11 commits into from
Apr 6, 2022

Conversation

bodograumann
Copy link
Contributor

The first try in #11298 did not work, because it broke the commonjs output.

Now I have differentiated between the two. When es6 is activated, we build an esmodule and when it is deactivated we build the classic commonjs format. For commonjs we don’t need to change our imports, because the esmodule import restrictions don’t apply to the commonjs format. For esmodule output we use a default import.

To make sure everything works, I have added a new sample that has supportsES6 enabled. The tests for it use esbuild as bundler. (Unfortunately a bundler is needed in any case, because we include commonjs polyfills. Ideally the esmodule output could just run in the browser as-is, but that is something for another day.)

As before I have included proper typings for url-parse.
I also had to expose the RequiredError exception type to allow explicit casting to it, because typescript regards errors in catch as unknown these days.
Pet API tests are run against http://localhost/v2 as base server, to prevent HSTS in the browser from forcing https.
Finally, I added more fields to package.json that include the module type and entry point, to improve compatibility with node and bundlers, especially when generating esmodule output.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02)

@bodograumann
Copy link
Contributor Author

Ugh, seems pupeteer does not readily work in the pipeline:

/home/circleci/OpenAPITools/openapi-generator/samples/openapi3/client/petstore/typescript/tests/browser/node_modules/puppeteer/.local-chromium/linux-950341/chrome-linux/chrome: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory

I have added the chromium dependencies to circleci as per the pupeteer instructions. Hope this is the way to go.

@bodograumann bodograumann force-pushed the ts-url-parse-import branch 3 times, most recently from 69b39df to 5a9a281 Compare January 31, 2022 13:03
@bodograumann
Copy link
Contributor Author

Neither libgbm1 nor libgbm-dev can be installed :-|.
Is the ci base image too old @wing328 ?

@bodograumann bodograumann force-pushed the ts-url-parse-import branch 2 times, most recently from 005d2a5 to b090cbf Compare April 6, 2022 07:27
@bodograumann bodograumann force-pushed the ts-url-parse-import branch from b090cbf to d74436c Compare April 6, 2022 08:10
@bodograumann bodograumann force-pushed the ts-url-parse-import branch from d74436c to 44fd457 Compare April 6, 2022 08:31
@bodograumann
Copy link
Contributor Author

Yay it works! 🚀

Please have another look at this PR now.

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

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

LGTM

@macjohnny macjohnny merged commit 510f799 into OpenAPITools:master Apr 6, 2022
@macjohnny macjohnny added this to the 6.0.0 milestone Apr 6, 2022
cachescrubber pushed a commit to cachescrubber/openapi-generator that referenced this pull request Apr 9, 2022
* Install correct typings for url-parse

* Use es modules compat mode when es6 output is selected

* Consolidate typescript sample generation naming scheme

* Regenerate samples

* Create new typescript sample to test esmodules in browser

* Expose RequiredError type

* Make browser integration tests pass locally

* Remove cookie tests, because we don’t allow cross-origin cookies

* Add output type to package definition

* Execute new browser tests in pipeline

* Install headless chromium dependencies in circle ci
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants