From 01f230e448e01fc4e64e55dbb6c611fcce76aa71 Mon Sep 17 00:00:00 2001 From: Ryo Narita Date: Tue, 5 Oct 2021 13:42:05 +0900 Subject: [PATCH] Use is-electron package for accurate environment identification --- package-lock.json | 1 + package.json | 1 + src/fs-shim.js | 13 +------------ 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9abd176..ac1ea8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "ipfs-pubsub-1on1": "~0.0.6", + "is-electron": "^2.2.0", "is-node": "^1.0.2", "localstorage-down": "^0.6.7", "logplease": "^1.2.14", diff --git a/package.json b/package.json index 0e27905..2934497 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "main": "src/OrbitDB.js", "dependencies": { "ipfs-pubsub-1on1": "~0.0.6", + "is-electron": "^2.2.0", "is-node": "^1.0.2", "localstorage-down": "^0.6.7", "logplease": "^1.2.14", diff --git a/src/fs-shim.js b/src/fs-shim.js index b295c39..bf607a0 100644 --- a/src/fs-shim.js +++ b/src/fs-shim.js @@ -1,16 +1,5 @@ /* eslint-disable */ -// adapted from https://github.com/cheton/is-electron - (c) Cheton Wu -const isElectron = () => { - if (typeof window !== 'undefined' && typeof window.process === 'object') { - return true - } - - if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) { - return true - } - - return false -} +const isElectron = require('is-electron') const fs = (!isElectron() && (typeof window === 'object' || typeof self === 'object')) ? null : eval('require("fs")')