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

Use ECMAScript modules nearly everywhere (bis) #8535

Closed
wants to merge 3 commits into from

Conversation

mxdvl
Copy link
Contributor

@mxdvl mxdvl commented Aug 10, 2023

What does this change?

Unify nearly all our modules to be ECMAScript modules, since it is supported in the current LTS version of Node https://nodejs.org/docs/latest-v18.x/api/esm.html

CommonJS modules get the explicit .cjs / .cts extension

Jest tests uses the unstable ESM mocking API, which requires mocked modules to be imported after the mock using dynamic imports.

CDK now uses the ESM version of ts-node which loads CommonJS for .cts files, reducing the difference between tsconfig.json files, which requires allowImportingTsExtensions to be true.

Why?

Reduce the amount of different way a module is interpreted based on the extension.

Before:

  • .js CommonJS JavaScript
  • .ts ESM TypeScript
  • .mjs ESM JavaScript (only a few files)
  • .ts CommonJS TypeScript (only a few files)

After:

  • .js ESM JavaScript
  • .ts ESM TypeScript
  • .cjs CommonJS JavaScript (only a few files)
  • .cts CommonJS Typescript (only a few files)

Another go at #8482

@mxdvl mxdvl added the Health label Aug 10, 2023
@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 2 times, most recently from 1bf2a2a to 9750681 Compare August 10, 2023 08:37
@github-actions
Copy link

github-actions bot commented Aug 10, 2023

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 5 times, most recently from a709690 to 8221e46 Compare August 21, 2023 15:28
@mxdvl mxdvl marked this pull request as ready for review August 21, 2023 15:50
@mxdvl mxdvl requested a review from a team as a code owner August 21, 2023 15:50
@mxdvl mxdvl added the run_chromatic Runs chromatic when label is applied label Aug 21, 2023
@github-actions
Copy link

"This PR is stale because it has been open 30 days with no activity. Unless a comment is added or the “stale” label removed, this will be closed in 3 days"

@github-actions github-actions bot added the Stale label Sep 21, 2023
@mxdvl mxdvl removed the Stale label Sep 21, 2023
@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 3 times, most recently from f0fa1e3 to 2ac0f21 Compare September 22, 2023 14:53
@mxdvl mxdvl changed the base branch from main to mxdvl/config-context-no-magic September 22, 2023 15:07
@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 3 times, most recently from a267a6b to 5ce3b13 Compare September 22, 2023 15:19
Base automatically changed from mxdvl/config-context-no-magic to main September 22, 2023 15:20
@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 2 times, most recently from e4405b9 to 4c2a634 Compare September 22, 2023 15:57
@mxdvl mxdvl force-pushed the mxdvl/esm-nearly-everywhere branch 9 times, most recently from a861787 to 2ae076f Compare September 26, 2023 12:45
Unify our files to be mostly ECMAScript modules, rather than mixed,
since it is supported in the current LTS version of Node
https://nodejs.org/docs/latest-v18.x/api/esm.html

CommonJS modules get the explicit `.cjs` / `.cts` extension

Jest tests uses the unstable ESM mocking API, which requires
mocked modules to be imported after the mock using dynamic imports.
https://jestjs.io/docs/ecmascript-modules#module-mocking-in-esm

CDK now uses the ESM version of `ts-node` which loads CommonJS
for `.cts` files, reducing the difference between tsconfig.json files,
which requires `allowImportingTsExtensions` to be true.
https://www.typescriptlang.org/tsconfig#allowImportingTsExtensions
- tests use jest’s unstable module mock
- CDK uses commonJS explicitly
@mxdvl
Copy link
Contributor Author

mxdvl commented Oct 24, 2023

I think this is best done piecemeal…

@mxdvl mxdvl closed this Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO NOT MERGE dotcom-rendering run_chromatic Runs chromatic when label is applied
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants