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
Allow ASAR to work with child_process.spawn()
#9459
Comments
I get the caveats to supporting spawn, but there are valid use cases that would not be affected by the ASAR. I want to spawn an executable which is not packed in the asar, and to be able to configure the environment. I think it's worth documenting that inspecting the asar from another processes may fail, but at least supporting spawn would enable some of us to be able to use asar. |
For anyone looking for a temporary workaround, check out: https://github.com/sindresorhus/electron-util#fixpathforasarunpackpath |
@sindresorhus how to make the workaround work with electron-packager? |
@sindresorhus how can I use your fix with with modules like imagemin-optipng? Is there another way than manualy chage the module and prevent overwrites by the original module. The weird thing is that imagemin-jpegtran (uses spawn as well) works but imagemin-optipng doesnt. |
@sindresorhus Aha, I got this problem too. |
@midevnull you can try to set "asar" to false in package.json, like this "build": {
"asar": false
}, |
Or you can use |
check out: electron/electron#9459 for more details
pm2 use Client Object in pm2/lib/Client.js to start a Daemon
In theory,this method can be hacked
by this way, we are able to replace launchDaemon by ourself's, in which we can use fork to start Daemon |
To make my app work with ASAR, I am calling this helper function before the code that uses import * as child_process from "child_process"
/**
* To be used with 'asarUnpack' option in electron-builder.
*/
export function patchSpawnForASAR(): void {
const originalSpawn = child_process.spawn
const asarSpawn = (command: string, args?: string[], options?: object) => {
return originalSpawn(
command,
args ? args.map((arg) => arg.replace("app.asar", "app.asar.unpacked")) : undefined,
options
)
}
;(child_process as any).spawn = asarSpawn
} (paste into https://www.typescriptlang.org/play to get JavaScript version) |
You can include your executables as ExtraResources so they won't get packaged into ASAR archive. |
This is not entirely correct.
.spawn()
executes the binary directly by default, just as.execFile()
does..execFile()
actually uses.spawn()
underneath..spawn()
only runs the input in a shell if theshell
option is set.Not supporting
.spawn()
means a lot of apps are not able to use ASAR as they need the more flexible.spawn()
method. For example, I need the.spawn()
method so I can stream the output offfmpeg
while it's running..execFile()
only buffers and reports at the end.Would also make sense to support
.spawnSync()
for completeness.See #3512 for previous discussion.
The text was updated successfully, but these errors were encountered: