electron-store
Advanced tools
Comparing version 8.2.0 to 9.0.0
@@ -1,18 +0,16 @@ | ||
import {Except} from 'type-fest'; | ||
import Conf, {Schema as ConfSchema, Options as ConfOptions} from 'conf'; | ||
import {type Except} from 'type-fest'; | ||
import Conf, {type Options as ConfigOptions} from 'conf'; | ||
declare namespace ElectronStore { | ||
type Schema<T> = ConfSchema<T>; | ||
export {Schema} from 'conf'; | ||
type Options<T extends Record<string, any>> = Except<ConfOptions<T>, 'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'> & { | ||
/** | ||
Name of the storage file (without extension). | ||
export type Options<T extends Record<string, any>> = Except<ConfigOptions<T>, 'configName' | 'projectName' | 'projectVersion' | 'projectSuffix'> & { | ||
/** | ||
Name of the storage file (without extension). | ||
This is useful if you want multiple storage files for your app. Or if you're making a reusable Electron module that persists some data, in which case you should **not** use the name `config`. | ||
This is useful if you want multiple storage files for your app. Or if you're making a reusable Electron module that persists some data, in which case you should **not** use the name `config`. | ||
@default 'config' | ||
*/ | ||
readonly name?: string; | ||
}; | ||
} | ||
@default 'config' | ||
*/ | ||
readonly name?: string; | ||
}; | ||
@@ -22,4 +20,9 @@ /** | ||
*/ | ||
declare class ElectronStore<T extends Record<string, any> = Record<string, unknown>> extends Conf<T> { | ||
export default class ElectronStore<T extends Record<string, any> = Record<string, unknown>> extends Conf<T> { | ||
/** | ||
Initializer to set up the required `ipc` communication channels for the module when a `Store` instance is not created in the main process and you are creating a `Store` instance in the Electron renderer process only. | ||
*/ | ||
static initRenderer(): void; | ||
/** | ||
Changes are written to disk atomically, so if the process crashes during a write, it will not corrupt the existing store. | ||
@@ -29,3 +32,3 @@ | ||
``` | ||
import Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -55,10 +58,5 @@ type StoreType = { | ||
*/ | ||
constructor(options?: ElectronStore.Options<T>); | ||
constructor(options?: Options<T>); | ||
/** | ||
Initializer to set up the required `ipc` communication channels for the module when a `Store` instance is not created in the main process and you are creating a `Store` instance in the Electron renderer process only. | ||
*/ | ||
static initRenderer(): void; | ||
/** | ||
Open the storage file in the user's editor. | ||
@@ -70,3 +68,1 @@ | ||
} | ||
export = ElectronStore; |
29
index.js
@@ -1,5 +0,10 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const {app, ipcMain, ipcRenderer, shell} = require('electron'); | ||
const Conf = require('conf'); | ||
import process from 'node:process'; | ||
import path from 'node:path'; | ||
import { | ||
app, | ||
ipcMain, | ||
shell, | ||
} from 'electron'; // eslint-disable-line import/no-duplicates | ||
import electron from 'electron'; // eslint-disable-line import/no-duplicates | ||
import Conf from 'conf'; | ||
@@ -16,3 +21,3 @@ let isInitialized = false; | ||
defaultCwd: app.getPath('userData'), | ||
appVersion: app.getVersion() | ||
appVersion: app.getVersion(), | ||
}; | ||
@@ -33,3 +38,3 @@ | ||
class ElectronStore extends Conf { | ||
export default class ElectronStore extends Conf { | ||
constructor(options) { | ||
@@ -41,4 +46,4 @@ let defaultCwd; | ||
// to get the required data for the module otherwise, we pull from the main process. | ||
if (ipcRenderer) { | ||
const appData = ipcRenderer.sendSync('electron-store-get-data'); | ||
if (process.type === 'renderer') { | ||
const appData = electron.ipcRenderer.sendSync('electron-store-get-data'); | ||
@@ -56,8 +61,6 @@ if (!appData) { | ||
name: 'config', | ||
...options | ||
...options, | ||
}; | ||
if (!options.projectVersion) { | ||
options.projectVersion = appVersion; | ||
} | ||
options.projectVersion ||= appVersion; | ||
@@ -88,3 +91,1 @@ if (options.cwd) { | ||
} | ||
module.exports = ElectronStore; |
{ | ||
"name": "electron-store", | ||
"version": "8.2.0", | ||
"version": "9.0.0", | ||
"description": "Simple data persistence for your Electron app or module - Save and load user settings, app state, cache, etc", | ||
@@ -13,3 +13,11 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": { | ||
"types": "./index.d.ts", | ||
"default": "./index.js" | ||
}, | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"scripts": { | ||
@@ -39,11 +47,11 @@ "test": "xo && ava && tsd" | ||
"dependencies": { | ||
"conf": "^10.2.0", | ||
"type-fest": "^2.17.0" | ||
"conf": "^12.0.0", | ||
"type-fest": "^4.18.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"electron": "^12.0.4", | ||
"execa": "^5.0.0", | ||
"tsd": "^0.14.0", | ||
"xo": "^0.38.2" | ||
"ava": "^6.1.2", | ||
"electron": "^30.0.1", | ||
"execa": "^8.0.1", | ||
"tsd": "^0.31.0", | ||
"xo": "^0.58.0" | ||
}, | ||
@@ -55,3 +63,10 @@ "xo": { | ||
] | ||
}, | ||
"tsd": { | ||
"compilerOptions": { | ||
"module": "node16", | ||
"moduleResolution": "node16", | ||
"moduleDetection": "force" | ||
} | ||
} | ||
} |
@@ -15,8 +15,11 @@ # electron-store | ||
*Requires Electron 11 or later.* | ||
*Requires Electron 30 or later.* | ||
> [!NOTE] | ||
> This package is native [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) and no longer provides a CommonJS export. If your project uses CommonJS, you will have to [convert to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c). More info about [Electron and ESM](https://www.electronjs.org/docs/latest/tutorial/esm). Please don't open issues for questions regarding CommonJS and ESM. | ||
## Usage | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -72,3 +75,3 @@ const store = new Store(); | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -112,3 +115,3 @@ const schema = { | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -153,3 +156,3 @@ const store = new Store({ | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -252,3 +255,3 @@ console.log = someLogger.log; | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -370,3 +373,3 @@ const store = new Store(); | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -397,3 +400,3 @@ const store = new Store(); | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -406,3 +409,3 @@ Store.initRenderer(); | ||
```js | ||
const Store = require('electron-store'); | ||
import Store from 'electron-store'; | ||
@@ -427,4 +430,4 @@ const store = new Store(); | ||
```js | ||
const Store = require('electron-store'); | ||
const yaml = require('js-yaml'); | ||
import Store from 'electron-store'; | ||
import yaml from 'js-yaml'; | ||
@@ -431,0 +434,0 @@ const store = new Store({ |
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
20538
463
Yes
117
+ Addedatomically@2.0.3(transitive)
+ Addedconf@12.0.0(transitive)
+ Addeddebounce-fn@5.1.2(transitive)
+ Addeddot-prop@8.0.2(transitive)
+ Addedenv-paths@3.0.0(transitive)
+ Addedjson-schema-typed@8.0.1(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addedstubborn-fs@1.2.5(transitive)
+ Addedtype-fest@3.13.14.26.1(transitive)
+ Addeduint8array-extras@0.3.0(transitive)
+ Addedwhen-exit@2.1.3(transitive)
- Removedatomically@1.7.0(transitive)
- Removedconf@10.2.0(transitive)
- Removeddebounce-fn@4.0.0(transitive)
- Removeddot-prop@6.0.1(transitive)
- Removedenv-paths@2.2.1(transitive)
- Removedfind-up@3.0.0(transitive)
- Removedis-obj@2.0.0(transitive)
- Removedjson-schema-typed@7.0.3(transitive)
- Removedlocate-path@3.0.0(transitive)
- Removedmimic-fn@2.1.03.1.0(transitive)
- Removedonetime@5.1.2(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@3.0.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedpath-exists@3.0.0(transitive)
- Removedpkg-up@3.1.0(transitive)
- Removedtype-fest@2.19.0(transitive)
Updatedconf@^12.0.0
Updatedtype-fest@^4.18.1