Feature request: beforePack callback (or: using distributed Node version to run some scripts before packaging)
See original GitHub issue- Version: 22.9.1
- Electron Version: 11.3.1
- Electron Type (current, beta, nightly): current
- Target: darwin, windows
electron-builder already offers the afterPack
callback. However, before all the files are packaged into an asar, I need to run bytenode on some of them. Now, in order for bytenode to work properly, it needs to be executed using the Node binary which will be distributed with the app.
As of now, when I use asar, afterPack
executes when the files are already in the asar archive. The current workarounds I came up with:
- From within
afterPack
run code that will unpack asar, compile the files with bytenode and then create the asar archive again.- This already doesn’t play well with
asarUnpack
, as extracting the asar archive into anapp
folder copies those unpacked files there as well. So before creating the archive again I would need to remove paths fromasarUnpack
from myapp
folder. But I worry that in the future it’s going to cause problems withsmartUnpack
anyway.
- This already doesn’t play well with
- Use
extraResources
so that the files which need to be compiled with bytenode are not in the asar archive at all. Then compile them inafterPack
.- If those compiled files happen to require some node modules, then most probably I’d need to manipulate the
NODE_PATH
env variable so that Node knows where to find the modules (in the asar archive). I’m yet to check if this actually works.
- If those compiled files happen to require some node modules, then most probably I’d need to manipulate the
With something like beforePack
, I could run bytenode on selected files and then builder could just include them in the asar as usual, without needing to worry about asarUnpack
and smartUnpack
myself.
This is somewhat similar to #4600, but the author of that issue seems to have asked about sth like afterPack
.
Perhaps there’s a more straightforward way to solve my problem than beforePack
, in which case I’d highly appreciate any advice!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:13 (4 by maintainers)
Top GitHub Comments
I’m having a similar issue.
beforeBuild
doesn’t work because I want the hook to be called after the dependencies have been installed. AbeforePack
would be ideal. In electron-forge I could use anafterCopy
hook.Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.