deltachat-core-rust
deltachat-core-rust copied to clipboard
build(node): migrate from CommonJS to ESM modules
Closes #4948
PR is ready, but blocked by Desktop using CommonJS in the frontend: https://github.com/deltachat/deltachat-desktop/blob/69f3a76e853f20c4d1007dd0edb0c260dd6f4831/src/main/tsconfig.json#L6
It also explicitly uses require
here:
https://github.com/deltachat/deltachat-desktop/blob/69f3a76e853f20c4d1007dd0edb0c260dd6f4831/src/main/ipc.ts#L34
Converting to ESM would mean desktop needs a new refactoring as with ESM it needs to be imported via import
instead of require
, which makes the code async and thus would need a refactoring, because the current code relies on being synchronous.
https://github.com/deltachat/deltachat-desktop/blob/e2b23d328c1c1f409b35451b89661fe6a13c1613/src/main/ipc.ts#L34
So I would say this pr should wait until I migrated desktop away from using dc-node, or someone is willing to do that refactoring in desktop (including enough testing to make sure the new code works).
Converting to ESM would mean desktop needs a new refactoring as with ESM it needs to be imported via
import
instead ofrequire
, which makes the code async and thus would need a refactoring, because the current code relies on being synchronous.https://github.com/deltachat/deltachat-desktop/blob/e2b23d328c1c1f409b35451b89661fe6a13c1613/src/main/ipc.ts#L34
So I would say this pr should wait until I migrated desktop away from using dc-node, or someone is willing to do that refactoring in desktop (including enough testing to make sure the new code works).
Can't we use static import
statement instead of dynamic import()
? Error handling for failed import can be removed then as it will fail to compile anyway if static import
would not work.
I have opened https://github.com/deltachat/deltachat-desktop/pull/3796 for an attempt to make it work with desktop.
Can't we use static import statement instead of dynamic import()? Error handling for failed import can be removed then as it will fail to compile anyway if static import would not work.
No, because this is for catching node bindings errors like unable to find prebuild or unable to use prebuild. And then displaying a user visible message instead of just errors in the terminal.