-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
feat: Node compatible ESM build #756
Conversation
Gonna review this on Monday - having the bundled preload script is really nice. |
No more weird manual bundle creation! |
This comment was marked as outdated.
This comment was marked as outdated.
? require.resolve('../../preload/legacy.js') | ||
: require.resolve('../../preload/index.js'); | ||
} catch (_) { | ||
try { | ||
// This could be ESM | ||
const currentDir = fileURLToPath(import.meta.url); | ||
// Use the CJS preload | ||
return resolve(currentDir, '..', '..', '..', '..', 'preload', 'index.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this will break with any bundlers, but if the e2e tests pass we should be fine I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preload injection mostly fails anyway with bundlers anyway and we fallback to custom protocol.
Once Electron v28 makes it to beta we can add some ESM main process bundler tests.
app.once('ready', () => { | ||
resolve(); | ||
if (app) { | ||
return app.isReady() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is app not defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code gets loaded into the Electron renderer rather than the main process.
We have code that displays a warning if you load the wrong code into the wrong process. Rollup requires tha we target module: esnext
and it then transpiles to CJS/ESM. The issue with this is that imports/side-effects are changed/moved and these bits of code get hit before our warning code!
This PR changes to using Rollup to build the output files.
This should fix main process ESM compatibility (#751) but since Electron v28 is still published under
electron-nightly
there is no easy way to add this to our test matrix until they publish a beta release.I have tested this locally with a nightly build but I don't think it's worth the effort or adding nightly support to our e2e test suite when there will likely be a beta built in a few weeks.
require.resolve