-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathinstall.js
43 lines (37 loc) · 1.39 KB
/
install.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
33
34
35
36
37
38
39
40
41
42
43
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import binBuild from 'bin-build';
import bin from './index.js';
(async () => {
try {
// On linux platforms with non-intel architectures, bin-wrapper still
// downloads and tries to execute the x86_64 ELF. This results in the
// binary file being interpreted as a shell script, which creates a
// dangling file that can make npm or yarn crash at installation. This
// condition prevents this from happening.
//
// See https://github.com/imagemin/gifsicle-bin/issues/124#issuecomment-1222646680
if (process.platform === 'linux' && !['ia32', 'x64'].includes(process.arch)) {
throw Error(`Unsupported platform: ${process.platform}/${process.arch}.`);
}
await bin.run(['--version']);
console.log('pngquant pre-build test passed successfully');
} catch(error) {
console.warn(error.message);
console.warn('pngquant pre-build test failed');
console.info('compiling from source');
try {
const source = fileURLToPath(new URL('../vendor/source/pngquant.tar.gz', import.meta.url));
await binBuild.file(source, [
'rm ./INSTALL',
`./configure --prefix="${bin.dest()}"`,
`make install BINPREFIX="${bin.dest()}"`,
]);
console.log('pngquant built successfully');
} catch (error) {
console.error(error.stack);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
}
})();