Skip to content

Commit

Permalink
use LD_LIBRARY_PATH to resolve the dynamic library (libpng12.so.0) path.
Browse files Browse the repository at this point in the history
  • Loading branch information
meowtec committed Jan 25, 2018
1 parent d2c5c33 commit f0e955f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Binary file modified bin/linux/moz-cjpeg
Binary file not shown.
Binary file modified bin/linux/pngquant
Binary file not shown.
14 changes: 9 additions & 5 deletions modules/optimizers/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ const platformAlias: {[key: string]: string} = {
const platform = os.platform()
const targetDir = platformAlias[platform] || platform

export const basePath = path.resolve(
__dirname,
'../../bin',
targetDir,
).replace('app.asar', 'app.asar.unpacked')

const getBin = (name: string) => {
if (platform === 'win32') {
name = name + '.exe'
}

return path.resolve(
__dirname,
'../../bin',
targetDir,
name
).replace('app.asar', 'app.asar.unpacked')
basePath,
name,
)
}

export const pngquant = getBin('pngquant')
Expand Down
10 changes: 10 additions & 0 deletions modules/optimizers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import log from 'electron-log'
import * as bins from './bin'
import { IOptimizeOptions } from '../common/constants'

const createEnv = () => {
return {
...process.env,
LD_LIBRARY_PATH: bins.basePath,
} as NodeJS.ProcessEnv
}

export type IOptimizeMethod = (
input: string,
output: string,
Expand All @@ -28,6 +35,7 @@ export const mozjpeg: IOptimizeMethod = (

return spawn(bins.mozjpeg, spawnArgs, {
capture: [ 'stdout', 'stderr' ],
env: createEnv(),
}).catch(e => {
throw new Error(e.message + '\n' + e.stderr)
})
Expand All @@ -51,6 +59,7 @@ export const pngquant: IOptimizeMethod = (

return spawn(bins.pngquant, spawnArgs, {
capture: [ 'stdout', 'stderr' ],
env: createEnv(),
}).catch(e => {
throw new Error(e.message + '\n' + e.stderr)
})
Expand All @@ -75,6 +84,7 @@ export const cwebp: IOptimizeMethod = (

return spawn(bins.cwebp, spawnArgs, {
capture: [ 'stdout', 'stderr' ],
env: createEnv(),
}).catch(e => {
throw new Error(e.message + '\n' + e.stderr)
})
Expand Down

0 comments on commit f0e955f

Please sign in to comment.