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

ESM support will be required after Wechaty v0.69+ #96

Closed
huan opened this issue Sep 2, 2021 · 3 comments
Closed

ESM support will be required after Wechaty v0.69+ #96

huan opened this issue Sep 2, 2021 · 3 comments

Comments

@huan
Copy link
Member

huan commented Sep 2, 2021

Currently, the Wechaty ecosystem is moving from CommonJS to ES Modules.

The Wechaty will be Dual-ESM-CJS-Module supported, and the default mode will be under ESM.

In order to load Wechaty Puppet under ESM mode by setting the environment variable WECHATY_PUPPT, or by setting the options.puppet = 'wechaty-puppet-xxx', the puppet provider NPM module must support ESM.

If the puppet does not support ESM, then the Wechaty will run into the below issue: TypeError: MyPuppet is not a constructor

Link to: wechaty/puppet#148

P.S. I would love to send a PR to convert padlocal to ESM, if we can have all the unit tests passed and made the GitHub Action green.

@padlocal
Copy link
Collaborator

I am adapting ESM for PadLocal now, feeling a little confused by following questions:

  1. What are the maximum benifits of migrating to ESM for Wechaty?
  2. Can we just only adopt PURE ESM while Wechaty V1.x requires Node V16+?
  3. Is DUAL model to compatible with old ecosystem code that still use require?

@huan
Copy link
Member Author

huan commented Apr 30, 2022

Thanks for asking!

Here are my thoughts on those questions:

  1. What are the maximum benifits of migrating to ESM for Wechaty?

The ESM is the next version of the Node.js ecosystem modulized system specification, it comes with lots of benefits and will eventually replace all the old ones like CJS, AMD, UMD, etc, and the community is strongly suggested to head to it as soon as possible.

For Wechaty, it can make our JS code clean and more effective, and most important, follow the latest community standard.

  1. Can we just only adopt PURE ESM while Wechaty V1.x requires Node V16+?

Yes, we can.

The only downside of a PURE ESM module is that it can not be used by other CJS modules anymore.

For the Wechaty community especially with the v1.x, it will be OK because Wechaty is running under ESM mode by default.

  1. Is DUAL model to compatible with old ecosystem code that still use require?

Yes, the DUAL model means that when the model is running under CJS mode, it can be required()-ed.

@padlocal
Copy link
Collaborator

padlocal commented Jun 9, 2022

DONE!

Pelease checkout [email protected]

@padlocal padlocal closed this as completed Jun 9, 2022
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