Skip to content

Instantly share code, notes, and snippets.

@akozhemiakin
Last active October 21, 2019 11:11
Show Gist options
  • Save akozhemiakin/98eca9185b3ba560c8993ce187028b98 to your computer and use it in GitHub Desktop.
Save akozhemiakin/98eca9185b3ba560c8993ce187028b98 to your computer and use it in GitHub Desktop.
Asar-aware path functions
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