From d26711169f97188af5600ce48897e6332cb6b024 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 9 Nov 2016 15:01:07 -0800 Subject: [PATCH 1/4] Add a switch to flip between electron and node --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 00000000..8d3a3186 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +/** + * Detect Electron renderer process, which is node, but we should + * treat as a browser. + */ + +if ((process || {}).type === 'renderer') { + module.exports = require('./browser'); +} else { + module.exports = require('./node'); +} From 2ba1323100b915bdd6d51534c67d13d6669fdb7b Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 9 Nov 2016 15:01:14 -0800 Subject: [PATCH 2/4] Wire it up --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ab1c1c6..318c79d9 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "browserify": "9.0.3", "mocha": "*" }, - "main": "./node.js", + "main": "./index.js", "browser": "./browser.js", "component": { "scripts": { From dc86779d521186c444cee37cc712f23c3f6db886 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 9 Nov 2016 15:01:46 -0800 Subject: [PATCH 3/4] If we're in Electron, try to fallback to process.env.DEBUG if we've got it --- browser.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/browser.js b/browser.js index a31d6ff3..d82e9176 100644 --- a/browser.js +++ b/browser.js @@ -142,6 +142,12 @@ function load() { try { r = exports.storage.debug; } catch(e) {} + + // If debug isn't set in LS, and we're in Electron, try to load $DEBUG + if ('env' in (process || {})) { + r = process.env.DEBUG; + } + return r; } From 6d2cd136beeda6f58c6ed24c4ffabd07d3c5c721 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 9 Nov 2016 15:53:17 -0800 Subject: [PATCH 4/4] Save a stat --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 8d3a3186..b8bcd909 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ */ if ((process || {}).type === 'renderer') { - module.exports = require('./browser'); + module.exports = require('./browser.js'); } else { - module.exports = require('./node'); + module.exports = require('./node.js'); }