ioBroker.js-controller icon indicating copy to clipboard operation
ioBroker.js-controller copied to clipboard

Prepare for ES Modules

Open AlCalzone opened this issue 3 years ago • 4 comments

Node 12.16+ supports the new EcmaScript modules and more and more packages are migrating. Currently all of them are also offering a CommonJS export, but that could change with time. At some point we will have to deal with that - meaning a migration of JS-Controller to ESM.

Helpful resources:

  • https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
  • https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html
  • https://www.npmjs.com/package/esm - can be used to polyfill support easily
  • https://nodejs.org/api/esm.html
  • https://nodejs.org/api/packages.html

AlCalzone avatar Jun 15 '21 22:06 AlCalzone

As there is actual no decision to do this now*, here are arguments:

Pro:

  • we don't have to worry that we suddenly have to implement it if a large number of modules just provide ESM
  • we do not lose functionality while CJS could still be used
  • we have a lot of time for transition

Contra:

  • a lot of work to do
  • now means starting with planning and prepare as soon as possible

Jey-Cee avatar Jan 13 '22 09:01 Jey-Cee

I think, now that we have everything running through a TS compile step, it would now be easy to provide ESM for the packages of this monorepo.

Not sure, if this should be a priority for next controller @AlCalzone @Apollon77 @GermanBluefox

https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html

foxriver76 avatar Sep 17 '23 15:09 foxriver76

In fact just building it will not bring us any step further. We need to find out how to make our adapter approach ESM compatible, what this means for adapter-core, how we handle compact mode :-) (and such - and I did not started with javascript adapter and esm deps gg) ... So yes if starting with this it makes sense to also build ESM :-) but I think this is just the beginning fo the story

Apollon77 avatar Sep 18 '23 07:09 Apollon77

I think internally it should be fine now. Compact mode is covered in https://github.com/ioBroker/ioBroker.js-controller/issues/1667 and the general Adapter approach needs to be done in adapter-core. So could this be closed or anything in the context of this ticket open?

For adapter-core we have a start at https://github.com/ioBroker/adapter-core/pull/576

foxriver76 avatar Mar 26 '24 11:03 foxriver76