You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "cyraid (via GitHub)" <gi...@apache.org> on 2024/07/18 10:25:46 UTC
[I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
cyraid opened a new issue, #279:
URL: https://github.com/apache/cordova-electron/issues/279
# Feature Request
Don't force "cdv-electron-main.js" in package.json.
## Motivation Behind Feature
I'm trying to use Electron-Vite because I want things like hot-reload, and had a lot of things setup till I realized `cordova prepare` was overwriting my package.json. I need it to be `./dist/main/main.js` because I'm using Typescript.
## Feature Description
In **/lib/PackageJsonParser.js** line 40/41:
```javascript
// Force settings that are not allowed to change.
this.package.main = 'cdv-electron-main.js';
```
Why would it be forced? Allow us to include it from other modules, or allow to set in config, and use:
```javascript
this.package.main = config.script() || 'cdv-electron-main.js';
```
## Alternatives or Workarounds
Just use Electron-Vite.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #279:
URL: https://github.com/apache/cordova-electron/issues/279#issuecomment-2237580142
Regarding typescript, most of the cordova tooling was written 10+ years ago. Consuming JS-authored packages from TS code is a pain since you don't really get proper type checking when importing JS packages into TS. So it only really makes sense if all the tooling is refactored to TS, or at least has JSDocs that explicitly declares types (which again, most of the codebase does not). Refactoring the codebase to TS is a massive project which most people who are volunteering their time don't have an interest in pursuing.
On the other hand, JS code can import TS-authored packages just fine, providing that they were compiled to JS first. If you're project is authored in TS, there shouldn't be any issues. You may have to check if the cordova bits are authored in commonjs or ES modules and be consistent however. I'm pretty sure CommonJS format is used.
For hot reload, traditionally that was done via `cordova-serve`, which produces a local webserver that hosts the platform files. Serve itself didn't do the hot reload part (that is detects file changes and triggers a refresh) but if hot reload libraries could be brought in. I however do not know if cordova-electron supports `cordova serve`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "cyraid (via GitHub)" <gi...@apache.org>.
cyraid commented on issue #279:
URL: https://github.com/apache/cordova-electron/issues/279#issuecomment-2237485035
@breautek I get that, and I considered that. But all that extra work when it could be easily configured? Fighting with the system? Why can't it be configured? I have a valid use case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #279:
URL: https://github.com/apache/cordova-electron/issues/279#issuecomment-2236450874
Like all platforms, everything inside `platforms/` is cordova managed and generated. Manually making modifications to any files within may get destroyed by cordova's prepare or build process.
It is possilbe to extend cordova's prepare/build processes via [Hooks](https://cordova.apache.org/docs/en/12.x/guide/appdev/hooks/index.html) and script a modification to a file. E.g. most platform files are generated during the `prepare` phase, therefore the `after_prepare` hook can usually be used to make a further modification _after_ Cordova has generated files.
Replacing `cdv-electron-main.js` is however not recommended. This is the main file for electron which Cordova implements the Cordova framework, manages plugins and exposes plugin APIs via context isolation. Replacing the file entirely would mean disabling all the cordova bits. So forcing this file as a main I believe is necessary and will be the reason I'm closing the ticket. If this is what you want to do, then you'll be honestly better of using electron directly. Using the hooks mentioned above, it is possible to manipulate this file however if necessary.
The electron NodeJS environment is akin to the Android's native java environment, or iOS's native objective-c environment. They are abstracted from app development. Typically these environments are exposed to the application's webview via an interface implemented by plugins. Electron platform is no exception to this. We don't have an explicit electron plugin guide at this time, but the [device plugin](https://github.com/apache/cordova-plugin-device/tree/master/src/electron) is a simple plugin to see how it exposes an API.
Further Reading:
- [Cordova Architecture](https://cordova.apache.org/docs/en/12.x/guide/overview/index.html)
- [Cordova Electron App Development](https://cordova.apache.org/docs/en/12.x/guide/platforms/electron/index.html)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "cyraid (via GitHub)" <gi...@apache.org>.
cyraid commented on issue #279:
URL: https://github.com/apache/cordova-electron/issues/279#issuecomment-2236812668
I would be including "cdc-electron-main.js" from one of my files via require/import. One of the reasons is I didn't wanna touch cdv-electron-main.js so I could update the file in the future if need be without having to redo any code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek closed issue #279: Don't force "cdv-electron-main.js" in package.json.
URL: https://github.com/apache/cordova-electron/issues/279
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org
Re: [I] Don't force "cdv-electron-main.js" in package.json. [cordova-electron]
Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #279:
URL: https://github.com/apache/cordova-electron/issues/279#issuecomment-2236816580
You should be able to acheive that via an `after_prepare` hook, to set main to your own main which imports the cordova's main.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org