-
-
Couldn't load subscription status.
- Fork 1k
chore: ESM for localization #2255
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
chore: ESM for localization #2255
Conversation
|
I don't understand exactly the implications of this, I need to look at it slowly. |
|
Android is using cordova. Which is just webview in the app. It doesn't have access to things like filesystem in a way NWjs/node has. So using filesystem loader won't work 😕 I think previous solution with XHR request would be needed. Maybe just change it so that messages with initial load are baked in somewhere and switchign the language would load the new ones async |
|
We removed chrome to have only one coding for all, it seems it will be impossible! Or at least we need to go back and return to old code... |
|
One thing more @WalcoFPV said it has included the nw apis to Cordova. So maybe the fs will work but I don't know if it needs some hack to do it. |
I included the Chrome apis, not the nw apis. But the node modules should work with Cordova as well. I think, we must separate all the functionnalities depending on Cordova apis and Nwjs apis and create our proper apis. For example, creating an object This will not fix the issue with the |
|
I think this code is a good case to try to get to a final solution. We are using one module as i18next backend that internally uses the node fs api. |
|
I think using an API wrapper is the right approach here. Luckily we now only need two implementations of it, for NW.js and Cordova, and not one for Chrome Web apps as well. |
|
I'm not too sure if I'm understanding what kind of wrapper are we talking about:
@WalcoFPV you are the only one here with enough knowledge about Cordova. Do you know if 1 is possible? If true, have you time to try to make a working code, starting for example with this PR? Is a good example of what we want. If not possible then we need to pass to option 2, and remove the use of Node plugins. I think is good that we can use modules, with the approach of this PR or another one if someone knows a better approach, using import if require is not supported by Cordova. |
|
@McGiverGim: I guess all of the above. :-) Also, thanks to the open nature of JavaScript, it is possible to polyfill functionality, and have wrappers that transparently replace native functionality, even if it is called from within modules. But having some sort of abstraction layer, and preferrable one not implemented and maintained by us, is the way to go in my opinion. |
|
I think this is outdated now since we have reverted the change to the fs backend for i18n. What should we do with it? |
|
I'm not too sure, this is s good example that we can need at some moment, but true, at this moment and for this scenario is not needed. |
|
This wasn't really tied to the fs. I'll adapt this one to the current master and will push it this weekend. It will setup general steps on how to migrate other parts of the app to modules. |
a148a9a to
45f6a40
Compare
| @@ -1,4 +1,4 @@ | |||
| 'use strict'; | |||
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.
Modules are in strict mode by default
| @@ -1,10 +1,12 @@ | |||
| 'use strict'; | |||
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.
strict mode is default mode when using modules.
|
Adjusted to use xhr backend now and some cordova changes. Also remove some of the @WalcoFPV or someone with access to android, it would be good to verify that it works. I've only run some smoke tests on android emulator. |
45f6a40 to
fb74de3
Compare
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 it works in the emulator it must work in the real device. At least a device with the same configuration/versions that the emulator. We can have problem with different devices, but this will happen we test it in an Android or not. Until merged and used by others with different devices we will never be sure, but this will happen with any change we do.
To me is ok, I think is a demo of how to use modules with import in our "new" Configurator. I think is valuable and we can merge it.
|
Yep, I think this pretty much covers most of the cases. There will be things like |
Yes, that is probably the worst, because the |
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.
@chmelevskij one thing more, the tests are failing. I didn't remember the tests... I had the same problem when I tried to do this...
They are configured to be executed in a Chrome browser...
Can you check at them?
20105c3 to
580213f
Compare
580213f to
73172bd
Compare
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.
Good job! Thanks for fixing this!
Co-authored-by: Míguel Ángel Mulero Martínez <mcgivergim@gmail.com>
|
Kudos, SonarCloud Quality Gate passed!
|
@McGiverGim I've moved localisation.js to modules. However there is one small caveat is because it's in NWJS.
NWJS exposes
requirein the UI and allows importing native modules that way. But, it doesn't allow consuming in built node modules through ESM. So,import fs from 'fs'won't work.I've added a solution where I just replace the import as string, but it's quite unstable. Haven't tried it but if another part of the app is migrated to
import/exportit will brake I think.It is quite a unique issue, since usually you either run in browser or in node, this one is a mix.
I could potentially write a rollup plugin for this if it pops up quite often 🤔