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

Transition package from CJS to ESM #310

Open
Tracked by #8306
christian-bromann opened this issue May 25, 2022 · 3 comments
Open
Tracked by #8306

Transition package from CJS to ESM #310

christian-bromann opened this issue May 25, 2022 · 3 comments

Comments

@christian-bromann
Copy link
Contributor

As part of the v8 effort we are currently migrating over to ESM as many packages will stop support CJS in the future. This means we have to transition all plugins to ESM as well, ideally with continuous support for CJS.

@chmanie
Copy link
Member

chmanie commented May 25, 2022

Nice! Do you have any form of general migration guide that also touches on the topic of keeping support for CJS?

@christian-bromann
Copy link
Contributor Author

Not really but I would refer to this document: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm. In regards of supporting both: I don't have a clear solution to this but I plan to have a compiler (e.g. rollup, maybe another TS config) that bundles the files as CJS modules. The package.json then needs to look like this:

  "main": "./build/index.cjs.js",
  "type": "module",
  "module": "./build/index.js",
  "exports": {
    ".": [
      {
        "import": "./build/index.js",
        "require": "./build/index.cjs.js"
      },
      "./build/index.cjs.js"
    ]
  },
  "types": "./build/index.d.ts",
  "typeScriptVersion": "3.8.3",

@christian-bromann
Copy link
Contributor Author

Update: my initial assumption that CJS services/reporters would stop working when running WebdriverIO within ESM context is wrong. They continue to work as is without any changes required. However I still suggest to do this ESM transition eventually as dependencies might migrate to ESM and stop working. Given WebdriverIO dynamically imports services and plugins there is no need to build a hybrid package for CJS and ESM. Plugins can just export ESM code and it will work fine for users running CJS and ESM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants