electron-is-dev
Advanced tools
Comparing version 2.0.0 to 3.0.0
/** | ||
Check if [Electron](https://electronjs.org) is running in development. | ||
Check if Electron is running in development. | ||
@@ -10,3 +10,3 @@ This package must be used from the Electron main process. | ||
``` | ||
import isDev = require('electron-is-dev'); | ||
import isDev from 'electron-is-dev'; | ||
@@ -20,4 +20,4 @@ if (isDev) { | ||
*/ | ||
declare const electronIsDev: boolean; | ||
declare const isDev: boolean; | ||
export = electronIsDev; | ||
export default isDev; |
12
index.js
@@ -1,3 +0,2 @@ | ||
'use strict'; | ||
const electron = require('electron'); | ||
import electron from 'electron'; | ||
@@ -8,5 +7,8 @@ if (typeof electron === 'string') { | ||
const isEnvSet = 'ELECTRON_IS_DEV' in process.env; | ||
const getFromEnv = Number.parseInt(process.env.ELECTRON_IS_DEV, 10) === 1; | ||
const {env} = process; // eslint-disable-line n/prefer-global/process | ||
const isEnvSet = 'ELECTRON_IS_DEV' in env; | ||
const getFromEnv = Number.parseInt(env.ELECTRON_IS_DEV, 10) === 1; | ||
module.exports = isEnvSet ? getFromEnv : !electron.app.isPackaged; | ||
const isDev = isEnvSet ? getFromEnv : !electron.app.isPackaged; | ||
export default isDev; |
{ | ||
"name": "electron-is-dev", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Check if Electron is running in development", | ||
@@ -13,2 +13,10 @@ "license": "MIT", | ||
}, | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"scripts": { | ||
@@ -34,5 +42,5 @@ "test": "xo && tsd" | ||
"devDependencies": { | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.1" | ||
"tsd": "^0.30.3", | ||
"xo": "^0.56.0" | ||
} | ||
} |
@@ -11,7 +11,7 @@ # electron-is-dev | ||
```sh | ||
npm install electron-is-dev | ||
``` | ||
$ npm install electron-is-dev | ||
``` | ||
*Requires Electron 3 or later.* | ||
*Requires Electron 28 or later.* | ||
@@ -21,3 +21,3 @@ ## Usage | ||
```js | ||
const isDev = require('electron-is-dev'); | ||
import isDev from 'electron-is-dev'; | ||
@@ -33,2 +33,25 @@ if (isDev) { | ||
## FAQ | ||
### How is this different than [`app.isPackaged`](https://www.electronjs.org/docs/api/app#appispackaged-readonly)? | ||
This package existed long before that property. The benefit of this package is that you can override the value using an environment variable. | ||
### How do I use this in the renderer process? | ||
You can use [`contextBridge`](https://www.electronjs.org/docs/latest/api/context-bridge) in the [preload script](https://www.electronjs.org/docs/latest/tutorial/tutorial-preload) to manually expose the variable: | ||
```js | ||
import {contextBridge} from 'electron'; | ||
import isDev from 'electron-is-dev'; | ||
contextBridge.exposeInMainWorld('isDev', isDev); | ||
``` | ||
You can then access it in `globalThis` from the renderer process: | ||
```js | ||
console.log(globalThis.isDev); | ||
``` | ||
## Related | ||
@@ -35,0 +58,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
4279
25
58
1