Skip to content

Commit

Permalink
Require Electron 28 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 13, 2024
1 parent d0986db commit 8e0dbe5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ jobs:
fail-fast: false
matrix:
node-version:
- 14
- 20
- 18
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
8 changes: 4 additions & 4 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
Check if [Electron](https://electronjs.org) is running in development.
Check if Electron is running in development.
This package must be used from the Electron main process.
You can force development mode by setting the `ELECTRON_IS_DEV` environment variable to `1`.
@example
```
import isDev = require('electron-is-dev');
import isDev from 'electron-is-dev';
if (isDev) {
console.log('Running in development');
Expand All @@ -16,6 +16,6 @@ if (isDev) {
}
```
*/
declare const electronIsDev: boolean;
declare const isDev: boolean;

export = electronIsDev;
export default isDev;
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict';
const electron = require('electron');
import electron from 'electron';

if (typeof electron === 'string') {
throw new TypeError('Not running in an Electron environment!');
}

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;
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import isDev = require('./index.js');
import isDev from './index.js';

expectType<boolean>(isDev);
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && tsd"
},
Expand All @@ -30,7 +38,7 @@
"app"
],
"devDependencies": {
"tsd": "^0.14.0",
"xo": "^0.38.1"
"tsd": "^0.30.3",
"xo": "^0.56.0"
}
}
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ This package must be used from the Electron main process.

## Install

```
$ npm install electron-is-dev
```sh
npm install electron-is-dev
```

*Requires Electron 3 or later.*
*Requires Electron 28 or later.*

## Usage

```js
const isDev = require('electron-is-dev');
import isDev from 'electron-is-dev';

if (isDev) {
console.log('Running in development');
Expand All @@ -39,8 +39,8 @@ This package existed long before that property. The benefit of this package is t
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
const {contextBridge} = require('electron');
const isDev = require('electron-is-dev');
import {contextBridge} from 'electron';
import isDev from 'electron-is-dev';

contextBridge.exposeInMainWorld('isDev', isDev);
```
Expand Down

0 comments on commit 8e0dbe5

Please sign in to comment.