-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Integrate electron plugin #108
Integrate electron plugin #108
Conversation
Process::path(__DIR__.'/../../resources/js') | ||
->env($this->getEnvironmentVariables()) | ||
->forever() | ||
->run('npm ci ./electron-plugin/nativephp-electron-plugin-tarball.tgz', function (string $type, string $output) { |
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.
We need to do a clean install here, because the tarball version was locked. It won't update when changes where made to the electron-plugin otherwise
@@ -45,7 +45,7 @@ protected function getCommandArrays(string $type = 'install'): array | |||
{ | |||
$commands = [ | |||
'install' => [ | |||
'npm' => 'npm install', | |||
'npm' => 'npm ci', |
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.
We need to do a clean install here as well. Otherwise changes to electron-plugin wont come through.
For example when running npm run build:watch
from the plugin directory & running artisan native:serve
in a different terminal session.
Having to clean install all dependencies might slow things down a little bit. This is a tradeoff but it could be that the cache negates this. Did not benchmark this yet
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.
It would be great if we didn't have to ci
but could rather just force the electron-plugin
to be reinstalled from scratch...
@@ -0,0 +1,65 @@ | |||
{ | |||
"name": "@nativephp/electron-plugin", | |||
"version": "tarball", |
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 might seem weird. I removed the version at first, but npm pack
requires a package name and version.
the created taball then includes that version in the filename: nativephp-electron-plugin-tarball.tgz
.
In our case we need the tarball to have the same name, hence this string. The filename of the tarball is referenced in the Build command here:
electron/src/Commands/BuildCommand.php
Line 46 in 761d10e
->run('npm ci ./electron-plugin/nativephp-electron-plugin-tarball.tgz', function (string $type, string $output) { |
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 we randomised the version at runtime and injected this into the package.json, would that negate the need for ci
?
Does the version need to be anything specific (incrementing/increasing?) or can it just be random?
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 believe it can be random, but we'll have to store the latest version name so we can refer to it in the build script by name.
Can't think of any benefits for that approach from the top of my head. The end result will be the same with some extra overhead. Unless I'm missing something.
In the build script we're only doing a clean install of the plugin. The rest of the dependencies are updated as normal
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 serve command does do a clean install for everything. I'm not super happy with that yet.
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.
No, that feels very wasteful
I'll need to take a good look through this when I'm back from vacation, but this is really promising! Thanks so much 🙏🏼 |
I am not that familiar with how NodeJS handles it internally but would a Subpath Import mitigate the need for the whole tarball process? It most likely requires you to change the imports inside the plugin, but does not seem to use symbolic links. Seems to me to be the cleanest way to integrate the plugin without restructuring the entire project. |
@RobertWesner this is the first time I've come across @gwleuverink have you ever used that before? |
To check whether we can use subpath imports in place of the tarball I integrated the plugin here. Was more straightforward than expected and worked mostly out of the box, just had to change the plugin export to ES6. It does run without issue while using
Full log with
The confusing part here is @simonhamp, @gwleuverink, got any thoughts on this? |
No this is the first I hear of it. It looks promising 👀 Thanks for pitching in @RobertWesner!
The error is unfamiliar to me. Do you have a php executable in that path? |
@gwleuverink yes, the php executable exists and |
Finally managed to find the issue, let appPath = join(__dirname, '../../../../../resources/app/').replace('app.asar', 'app.asar.unpacked'); to let appPath = join(__dirname, '../../resources/app/').replace('app.asar', 'app.asar.unpacked'); I opened #109 with my changes. |
Closing in favour of #109 |
Summary
This PR pulls the electron plugin into this repo.
I've landed on the tarball approach @simonhamp proposed in https://github.com/orgs/NativePHP/discussions/348
A couple of changes had to be made in order to make it work. Because a lot of files changed I've listed the steps I took below. I've also commented the changes that might need some more clarification in the diff.
Couple things I did:
resources/js/electron-plugin
package.json
to point to the local dependencynative:serve
command to do a clean install (so changes in electron-plugin come through)native:build
command to pack the electron plugin as a tarball & do a clean install of the tarball after running npm update. Clean install is needed because the tarball is not versioned, it will not update otherwise.Note that this packing step is only needed when running
native:build
.For your consideration
I noticed I get a lot of linting squigglies in the electron plugin after moving it to this project. Probably a configuration issue. Would you like me to check that out in this PR or separately?
When making changes to the electron-plugin while running
build:watch
you still need to restart thenative:serve
command to see your changes. Might be good to add that to the docs Docs laravel#364When running the
native:build
&native:serve
command the electron plugin is not built, You have to do so beforehand if any changes where made. This makes sense, since a composer install will come with the latest compiled js. But might be confusing for contributors. Maybe something to consider for the docs.Closing
As before, feel free to disregard or use only as a reference if you're not up for merging. I realise there was no concrete ask to work on this. I was experimenting a little & figured I might as well finish it 😅 If you need me to make changes and I'll do so as soon as I can.