-
Notifications
You must be signed in to change notification settings - Fork 944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix exposing of .env variables in Create React App #560
base: master
Are you sure you want to change the base?
Changes from 10 commits
b7816c0
3d42235
80ae3ae
fb16b70
c9c6c70
76e69d2
11cc167
f348d51
52d06bf
0fa1a28
4065feb
9a8a9cd
86c9684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,9 +25,11 @@ | |
"license": "MIT", | ||
"scripts": { | ||
"lint": "xo", | ||
"test": "npm run test:node && npm run test:browser", | ||
"test:node": "istanbul cover _mocha -- test.js", | ||
"test": "npm --node run test:node && npm --electron run test:electron && npm run test:browser", | ||
"test:browser": "karma start --single-run", | ||
"test:node": "istanbul cover --dir coverage/node -x test.js node_modules/mocha/bin/_mocha", | ||
"test:electron": "istanbul cover --dir coverage/electron -x test.js node_modules/mocha/bin/_mocha", | ||
"posttest": "istanbul report --include coverage/**/coverage.json", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. combines coverage for node + electron. |
||
"test:coverage": "cat ./coverage/lcov.info | coveralls" | ||
}, | ||
"dependencies": { | ||
|
@@ -42,6 +44,7 @@ | |
"karma-browserify": "^6.0.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-mocha": "^1.3.0", | ||
"karma-mocha-reporter": "^2.2.5", | ||
"mocha": "^5.2.0", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"xo": "^0.23.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,14 @@ exports.load = load; | |
exports.useColors = useColors; | ||
exports.storage = localstorage(); | ||
|
||
/** | ||
* Are we in Electron? | ||
* @returns {boolean} | ||
*/ | ||
function isElectron() { | ||
return typeof process !== 'undefined' && (process.type === 'renderer' || process.__nwjs); | ||
} | ||
|
||
/** | ||
* Colors. | ||
*/ | ||
|
@@ -106,7 +114,7 @@ function useColors() { | |
// NB: In an Electron preload script, document will be defined but not fully | ||
// initialized. Since we know we're in Chrome, we'll just detect this case | ||
// explicitly | ||
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) { | ||
if (isElectron()) { | ||
return true; | ||
} | ||
|
||
|
@@ -204,20 +212,12 @@ function save(namespaces) { | |
* @api private | ||
*/ | ||
function load() { | ||
let r; | ||
try { | ||
r = exports.storage.getItem('debug'); | ||
return exports.storage.getItem('debug'); | ||
} catch (error) { | ||
// Swallow | ||
// XXX (@Qix-) should we be logging these? | ||
} | ||
|
||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG | ||
if (!r && typeof process !== 'undefined' && 'env' in process) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the critical part that was exposing |
||
r = process.env.DEBUG; | ||
} | ||
|
||
return r; | ||
} | ||
|
||
/** | ||
|
@@ -242,18 +242,23 @@ function localstorage() { | |
} | ||
} | ||
|
||
module.exports = require('./common')(exports); | ||
if (isElectron()) { | ||
module.exports = exports; | ||
module.exports.humanize = require('ms'); | ||
} else { | ||
module.exports = require('./common')(exports); | ||
|
||
const {formatters} = module.exports; | ||
const {formatters} = module.exports; | ||
|
||
/** | ||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. | ||
*/ | ||
/** | ||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. | ||
*/ | ||
|
||
formatters.j = function (v) { | ||
try { | ||
return JSON.stringify(v); | ||
} catch (error) { | ||
return '[UnexpectedJSONParseError]: ' + error.message; | ||
} | ||
}; | ||
formatters.j = function (v) { | ||
try { | ||
return JSON.stringify(v); | ||
} catch (error) { | ||
return '[UnexpectedJSONParseError]: ' + error.message; | ||
} | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
exports = require('./browser'); | ||
|
||
const browserLoad = exports.load; | ||
|
||
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG | ||
exports.load = function () { | ||
let r = browserLoad(); | ||
if (!r && 'env' in process) { | ||
r = process.env.DEBUG; | ||
} | ||
return r; | ||
}; | ||
|
||
module.exports = require('./common')(exports); | ||
|
||
const {formatters} = module.exports; | ||
|
||
/** | ||
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default. | ||
*/ | ||
|
||
formatters.j = function (v) { | ||
try { | ||
return JSON.stringify(v); | ||
} catch (error) { | ||
return '[UnexpectedJSONParseError]: ' + error.message; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we can see that browser env was selected.