electron-builder
electron-builder copied to clipboard
macOS - PKG build - `scripts`option can't work.
- Electron-Builder Version:24.9.1
- Node Version: v20.11.1
- Electron Version: 28.2.1
- Electron Type (current, beta, nightly):current
- Target: macOS(pkg)
It's not working as the title suggests. An issue(#7299) was created a year ago, but it is still unresolved. As already pointed out, the cause
The --scripts options with the directory path is added to the pkgbuild command but the .plist file used in package build doesn't contains BundlePreInstallScriptPath or BundlePostInstallScriptPath keys which should contains scripts name (eg: preinstall.sh).
These keys are necessary to execute preinstall or postinstall script on pkg install.
I am also in the same situation and came to the same conclusion after reading /app-builder-lib/src/targets/pkg.ts
I've never built a pkg
before tbh. Are BundlePostInstallScriptPath
and BundlePreInstallScriptPath
supposed to point somewhere in Resources
dir with the scripts added there?
@mmaietta
Two configurations are required to use the preinstall/postinstall
scripts.
- Specify the script directory path with the
--scripts
option of thepkgbuild
command. (electron-builder'spkg/scripts
option / correct) - Specify the subsequent file path in the
BundlePostInstallScriptPath
attribute of theplist
file. (No processing)
Suppose you have a folder structure like this.
build
- pkg-scripts(`--scripts` option of the `pkgbuild` command)
- postinstall.sh (plist file setting)
It's correct plist file sample.
I have never used preinstall
script, but it should work the same way.
<!-- setting.plist -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>BundleHasStrictIdentifier</key>
<true/>
<key>BundleIsRelocatable</key>
<false/>
<key>BundleIsVersionChecked</key>
<true/>
<key>BundleOverwriteAction</key>
<string>upgrade</string>
<!-- here! -->
<key>BundlePostInstallScriptPath</key>
<string>postinstall.sh</string>
<!-- here! -->
<key>RootRelativeBundlePath</key>
<string>example.app</string>
</dict>
</array>
</plist>
Is it possible to have multiple post-install scripts? In order to not break previous functionality/API, I'm wondering if we need to allow an array with different type, like below, in order for electron-builder to pick up whether to add BundlePreInstallScriptPath
and/or BundlePostInstallScriptPath
scripts: [{ script: postinstall.sh, type: post }, { script: preinstall.sh, type: pre }]
Or maybe we can always assume the files will be named postinstall
and preinstall
?
Looking at the man page: https://www.manpagez.com/man/1/pkgbuild/
--scripts scripts-path
Archive the entire contents of scripts-path as the package
scripts. If this directory contains scripts named preinstall
and/or postinstall, these will be run as the top-level
scripts of the package. If you want to run scripts for spe-
cific bundles, you must specify those in a component property
list; see more at COMPONENT PROPERTY LIST. Any other files
under scripts-path will be used only if the top-level or com-
ponent-specific scripts invoke them.
It does seem that the files will need to be named as such, but wanted to confirm with you first since I'm currently not familiar with pkgbuild
Sorry, I don't really understand the detailed behavior beyond the explanation.
Or maybe we can always assume the files will be named postinstall and preinstall?
I'm sure the file names were fixed to postinstall
and preinstall
. At least that's what most users do, so I don't think there's any need to consider exceptions.
Is it possible to have multiple post-install scripts? In order to not break previous functionality/API, I'm wondering if we need to allow an array with different type, like below, in order for electron-builder to pick up whether to add BundlePreInstallScriptPath and/or BundlePostInstallScriptPath
You certainly need to think about PkgOption
...
It is impossible to call another file directly from pkg file (Just a guess!), so I think that if necessary, call another file from postinstall/preinstall.sh. For this reason, I think it would be a good idea to register two file paths as starting points.
If you want to make it simpler, you can check the existence of the file (and check whether it is executable or not) assuming that the pre/postinstall file is located in the root of the file path specified in scripts
. if you register it in the tag of the plist file only when it is OK, you do not need to play with the PkgOption
type at all.
Originally, pre/postinstall.sh seems to be able to nest additional directories on the plist side (as indicated by BundlePostInstallScriptPath
), but this approach does not support this. However, I think this is sufficient for 80-90% of use cases.
Would you be willing to test a patch via patch-package
if I were to implement a fix for this issue? I have a test pre/post-install script I can use with a basic echo
command to a file in /tmp dir, but would also like a real-world test with an application if possible
@mmaietta
Sorry for the delay, I patch with reference to the contents of the commit and place with both preinstall.sh
/postinstall.sh
directly under build/pkg-scripts
and it worked fine! 👏
The plist file was created correctly and the two shell file was executed. Thank you for fixing.🙇♂️