-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinaries.js
32 lines (30 loc) · 1.19 KB
/
binaries.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const { app } = require( 'electron' );
const { execFileSync } = require( 'node:child_process' );
const { access } = require( 'node:fs/promises' );
const path = require( 'node:path' );
const binDir = path.join( app.getAppPath(), 'bin' );
const php = path.join( binDir, 'php' );
module.exports = {
php,
async composer () {
// We need an unpacked version of Composer because the phar file has a shebang line
// that breaks us, due to the fact that GUI-launched Electron apps don't inherit the
// parent environment in macOS and Linux. Instead, we extract Composer's executable
// sources from the phar file and point the PHP interpreter at them.
const composer = path.join( binDir, 'composer', 'bin', 'composer' );
try {
await access( composer );
} catch {
execFileSync(
php,
[ '-r', `(new Phar("composer.phar"))->extractTo("composer");` ],
{
cwd: binDir,
// This is an extremely generous timeout and should not be increased.
timeout: 30000,
},
);
}
return composer;
},
};