electron-util
Version:
Useful utilities for Electron apps and modules
32 lines (27 loc) • 1.29 kB
TypeScript
export declare const isElectron: boolean;
/**
Check the app is using [ASAR](https://electronjs.org/docs/tutorial/application-packaging/).
*/
export declare const isUsingAsar: boolean | undefined;
/**
Electron version.
@example
```
'1.7.9'
```
*/
export declare const electronVersion: string;
/**
ASAR is great, but it has [limitations when it comes to executing binaries](https://electronjs.org/docs/tutorial/application-packaging/#executing-binaries-inside-asar-archive).
For example, [`child_process.spawn()` is not automatically handled](https://github.com/electron/electron/issues/9459).
So you would have to unpack the binary, for example, with the [`asarUnpack`](https://www.electron.build/configuration/configuration#configuration-asarUnpack) option in `electron-builder`.
This creates a problem as the path to the binary changes, but your `path.join(__dirname, 'binary')` is not changed.
To make it work you need to fix the path. That's the purpose of this method.
Before:
/Users/sindresorhus/Kap.app/Contents/Resources/app.asar/node_modules/foo/binary
After:
/Users/sindresorhus/Kap.app/Contents/Resources/app.asar.unpacked/node_modules/foo/binary
@param path - A path in your app.
@returns The fixed path.
*/
export declare const fixPathForAsarUnpack: (path: string) => string;