- 
                Notifications
    You must be signed in to change notification settings 
- Fork 90
feat: Upgrade jitsi-meet-electron-sdk to ES Modules & fix #140 #438
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
base: master
Are you sure you want to change the base?
Conversation
| THank for your PR! Please drop the yarn lock file, we don't use yarn in this project. | 
| I've removed the yarn.lock file and pushed the changes. Please let me know if any further changes are needed..! | 
| For fixing linting error i renamed the eslintrc.js to eslintrc.cjs... | 
| Please be patient with us, this is a big change and needs to be tested very carefully. | 
| Hii @saghul ..I'm seeing the CI/Build win32-x64 and CI/Build win32-x86 checks failingg. Could you please provide some guidance on how to adress these issues? I'm not sure what's causing the failures | 
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.
@AmoghParmar please see the inline comment on why the tests fail
| @@ -1,25 +1,27 @@ | |||
| // eslint-disable-next-line no-undef | |||
| const sourceId2Coordinates = require('node-gyp-build')(__dirname + '/../../').sourceId2Coordinates; | |||
| import { sourceId2Coordinates } from 'node-gyp-build'; | |||
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.
The tests on win32 and win64 fail, because node-gyp-build needs some more tweaking than just an import, see https://www.npmjs.com/package/node-gyp-build for details.
And the tests are "just" doing that, ensuring that the native code import still works, @AmoghParmar
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 have a fundamental question: Is this a fully breaking change, ie. all users would need to switch to the import syntax when using the SDK or is this backwards compatible?
Apart from that 2 inline questions, @AmoghParmar
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.
Why is this file necessary in addition to the top-level binding.gyp?
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.
Initially "node_addons/sourceId2Coordinates/binding.gyp" was created to adress a particular build config issue related to the sourceId2Coordinates. While solving the CI build issue , i believed it needed its own "binding.gyp" to isolate and customize its build settings. However after further investigation , i improvise the code that issue could be resolved by modifiyng the top-level binding.gyp without requiring a sepearate "binding.gyp" within the "node_addons/sourceId2Coordinates" directory. So thats why i removed the "binding.gyp".
| "prebuild-win32-x86": "prebuildify -t 20.0.0 --strip", | ||
| "prebuild-win32-x64": "prebuildify -t 20.0.0 --strip" | ||
| "prebuild-win32-x64": "prebuildify -t 20.0.0 --strip", | ||
| "build": "npm run build:main", | 
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.
Maybe a stupid question, but why is webpack now required if this is "just" converted to a ES module?
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.
Maybe a stupid question, but why is webpack now required if this is "just" converted to a ES module?
As mentioned by @saghul in the issue #140 , The webpack is required for the renderer process. It optimizes and enables tree-shaking, for the browser environment. While ES modules handle import but webpack is necessary for browser specific build.
Please let me know if you have any further suggestions for improvementss..
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.
This tree-shaking can only happen where the SDK is used, not within the SDK itself, as only then the final entrypoint is available and unused parts eg of this sdk can be omitted for the renderer
Eg here we currently exclude it from tree-shaking and optimizing: https://github.com/jitsi/jitsi-meet-electron/blob/master/webpack.renderer.js#L78
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.
So with that I dont think webpack et al are required here in the SDK
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.
Thank you, @csett86. The externals configuration in jitsi-meet-electron/webpack.renderer.js (externals: [ { '@jitsi/electron-sdk': 'require('@jitsi/electron-sdk')' } ]) prevents webpack from processing the SDK.
Therefore, webpack optimizations like tree-shaking are inapplicable to the SDK's code. Consequently, webpack configurations within the SDK are redundant and should be removed.
Your clarification is appreciated. Please provide any further guidance...!!
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.
On that topic of tree-shaking: What I am also wondering: Does these entry-points for the screensharing tracker conflict with the whole ES module idea, as there files from the filesystem are loaded for screensharing
https://github.com/jitsi/jitsi-meet-electron-sdk/blob/master/screensharing/main.js#L182
https://github.com/jitsi/jitsi-meet-electron-sdk/blob/master/screensharing/main.js#L208
and for the alwaysontop window:
https://github.com/jitsi/jitsi-meet-electron-sdk/blob/master/alwaysontop/render/index.js#L201-L214
| 
 Thankyou @csett86, for your review and raising these imp quest.. For Backward compatibility this change is intended to be a fullyy breaking change.. The SDK will require users to adopt the  I knw this has significant implications but i believe the long term benefits regarding code org, tree-shaking which can make the code run faster, & alignment with modern JS practices justify the changess. | 
| @AmoghParmar Making this a breaking change is a dealbreaker for me, we need to keep the commonjs around, so please investigate how to expose it both as a commonjs and ES module | 
| 
 I agree with you @csett86 maintaining CommonJS compatibility is essential. We need to find a solution that allows us to modernize the code while ensuring backward compatibility... | 
| @csett86 If we bump the major, would this still be a dealbreaker? I wouldn't be against maintainig a v7 branch for a little longer while users update to a new version 8. WDYT? | 
| I would for now keep it compatible, and when we drop the legacy screensharing code (#434 (comment)) and anyway bump to v8, then we can also drop the commonJS. How much effort do you see in providing both a commonjs and a ES module entrypoint, @AmoghParmar? | 
| I have a hunch it would be a tall order. I may be wrong though! Numbers are free, we can do a v9, etc. Just an idea :-) | 
| Looking at https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c, if we switch this to pure ES modules, then also all users of the SDK have to do that, if I am not mistaken. Maybe I am also on a wrong track here, so happy to get your input @saghul, @AmoghParmar | 
| I'd need to double check, but IIRC it depends on what the app does. If it bundles the code with webpack for example it should Just Work (TM). We certainly need some clarity before we go breaking everything, for sure. | 
| i found some technquies that maybe can help us to achieve our need for dual commonJS and ES modules entry point. I need some time to explore these techniquess.. | 
| Just today the following post surfaced on hackernews, which seems more optimistic than what I linked before: https://antfu.me/posts/move-on-to-esm-only Esp the require(esm) in nodejs should help us for the parts running in the main thread of electron. So from that perspective I was probably too cautious in my previous comments | 
| But we still need to make sure that we bump the major before merging this | 
| Thanks for keeping an open mind and for the extra reading resource! | 
This PR request upgrades the repo 'jitsi-meet-electron-sdk' to use ES modules, and this will helps to improving organization code and also enabing performance through tree shaking.
The Changes are done:
Converted Common Js modules to ES modules : basically replaced 'require' with 'import' and 'module.exports' with 'export'.
Add 'type:module' in package.json : to indicate that project is now uses ES modules.