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

[core] Upgrade to ES-Modules for core #26238

Merged
merged 244 commits into from
Feb 20, 2024
Merged

[core] Upgrade to ES-Modules for core #26238

merged 244 commits into from
Feb 20, 2024

Conversation

mpodwysocki
Copy link
Member

@mpodwysocki mpodwysocki commented Jun 16, 2023

Packages impacted by this PR

  • @azure/abort-controller
  • @azure/core-auth
  • @azure/core-client
  • @azure-rest/core-client
  • @azure/core-http-compat
  • @azure/core-lro
  • @azure/core-paging
  • @azure/core-rest-pipeline
  • @azure/core-sse
  • @azure/core-tracing
  • @azure/core-util
  • @azure/core-xml
  • @azure/logger
  • @typespec/ts-http-runtime

Issues associated with this PR

Describe the problem that is addressed by this PR

This migrates the core packages from a hybrid of CJS and ESM to an ESM solution using tshy. The core is now ESM, implemented as a module, and projects using tshy to CommonJS and ESM.

The ESM build targets we will target include:

  • ESM (Node)
  • Browser
  • React-Native
  • Bun
  • Deno

This will allow each system to pick up the correct output instead of picking the browser bundle which has happened in the past. Currently, our bun and deno support is strictly through npm compatibility and we are not forking logic at this point for those runtimes.

In order to support ESM, sinon does not allow for ESM module mocking, so we looked for an alterative in vitest. This PR also migrates all core packages stated above from Mocha/Chai for Node and Mocha/Chai/Karma for the browser to using vitest for all tests. Currently, the system builds a test bundle which targets the correct files such as those targeted for the browser, eg log-browser.mts becomes log.js in the compiled output.

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?

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

Provide a list of related PRs (if any)

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

azure-sdk commented Jun 16, 2023

API change check

API changes are not detected in this pull request.

Copy link
Member

@witemple-msft witemple-msft left a comment

Choose a reason for hiding this comment

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

No violations of the dev-tool revised code have been detected in this pull request.

@xirzec
Copy link
Member

xirzec commented Feb 8, 2024

No violations of the dev-tool revised code have been detected in this pull request.

For some reason I have the urge to comment "good bot" like in reddit threads. 🤣

But thank you for taking a look @witemple-msft !

@mpodwysocki mpodwysocki enabled auto-merge (squash) February 20, 2024 17:13
@mpodwysocki mpodwysocki merged commit 3b785dc into main Feb 20, 2024
13 checks passed
@mpodwysocki mpodwysocki deleted the feat/core-modulear branch February 20, 2024 17:42
sofiar-msft pushed a commit to sofiar-msft/azure-sdk-for-js that referenced this pull request Apr 11, 2024
### Packages impacted by this PR

- @azure/abort-controller
- @azure/core-auth
- @azure/core-client
- @azure-rest/core-client
- @azure/core-http-compat
- @azure/core-lro
- @azure/core-paging
- @azure/core-rest-pipeline
- @azure/core-sse
- @azure/core-tracing
- @azure/core-util
- @azure/core-xml
- @azure/logger
- @typespec/ts-http-runtime

### Issues associated with this PR


### Describe the problem that is addressed by this PR

This migrates the core packages from a hybrid of CJS and ESM to an ESM
solution using [`tshy`](https://github.com/isaacs/tshy). The core is now
ESM, implemented as a module, and projects using `tshy` to CommonJS and
ESM.

The ESM build targets we will target include:  
- ESM (Node)
- Browser
- React-Native
- Bun
- Deno

This will allow each system to pick up the correct output instead of
picking the browser bundle which has happened in the past. Currently,
our bun and deno support is strictly through npm compatibility and we
are not forking logic at this point for those runtimes.

In order to support ESM, `sinon` does not allow for ESM module mocking,
so we looked for an alterative in `vitest`. This PR also migrates all
core packages stated above from Mocha/Chai for Node and Mocha/Chai/Karma
for the browser to using `vitest` for all tests. Currently, the system
builds a test bundle which targets the correct files such as those
targeted for the browser, eg `log-browser.mts` becomes `log.js` in the
compiled output.

### 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?


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


### Provide a list of related PRs _(if any)_


### 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](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)

---------

Co-authored-by: Deyaaeldeen Almahallawi <dealmaha@microsoft.com>
Co-authored-by: Maor Leger <maorleger@users.noreply.github.com>
Co-authored-by: Jeremy Meng <jeremy.ymeng@gmail.com>
Copy link

@mcgear mcgear Jun 1, 2024

Choose a reason for hiding this comment

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

This change seems to have broken some things for us, relating to process.versions being undefined in our Deno project.

Copy link
Member

Choose a reason for hiding this comment

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

@mcgear thanks for the feedback! Could you please log a new issue? It's hard to track things in a merged PR.

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.

10 participants