Last active
October 21, 2019 11:11
-
-
Save akozhemiakin/98eca9185b3ba560c8993ce187028b98 to your computer and use it in GitHub Desktop.
Asar-aware path functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from 'fs'; | |
import * as _path from 'path'; | |
export const normalizeElectronPath = (s: string): string => { | |
const alp = s.replace(/app\.asar(?!\.unpacked)/g, 'app.asar.unpacked'); | |
let inAsarUnpacked = false; | |
if (fs.existsSync(alp)) { | |
inAsarUnpacked = true; | |
} else { | |
try { | |
require.resolve(alp); | |
inAsarUnpacked = true; | |
} catch(e) {} | |
} | |
return inAsarUnpacked ? alp : s; | |
} | |
export const join = (...args: string[]): string => { | |
return normalizeElectronPath(_path.join.apply(undefined, args)); | |
} | |
export const resolve = (...args: string[]): string => { | |
return normalizeElectronPath(_path.resolve.apply(undefined, args)); | |
} | |
export const normalize = (p: string): string => { | |
return normalizeElectronPath(_path.normalize.apply(undefined, [p])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment