deltachat-core-rust icon indicating copy to clipboard operation
deltachat-core-rust copied to clipboard

build(node): migrate from CommonJS to ESM modules

Open link2xt opened this issue 1 year ago • 4 comments

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

link2xt avatar Nov 10 '23 01:11 link2xt

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).

Simon-Laux avatar Apr 29 '24 23:04 Simon-Laux

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).

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.

link2xt avatar Apr 30 '24 11:04 link2xt

I have opened https://github.com/deltachat/deltachat-desktop/pull/3796 for an attempt to make it work with desktop.

link2xt avatar Apr 30 '24 15:04 link2xt

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.

Simon-Laux avatar Apr 30 '24 16:04 Simon-Laux