Skip to content

Commit

Permalink
fix(installer): invalid JSON.parse(.babelrc) (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coobaha authored and michael-ciniawsky committed Jun 30, 2017
1 parent 545c73f commit d2f393f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"homepage": "https://github.com/ericclemmons/npm-install-webpack-plugin#readme",
"dependencies": {
"cross-spawn": "^5.0.1",
"json5": "^0.5.1",
"memory-fs": "^0.4.1",
"resolve": "^1.2.0"
},
Expand Down
13 changes: 9 additions & 4 deletions src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ var fs = require("fs");
var path = require("path");
var resolve = require("resolve");
var util = require("util");
var JSON5 = require("json5");

var EXTERNAL = /^\w[a-z\-0-9\.]+$/; // Match "react", "path", "fs", "lodash.random", etc.
var PEERS = /UNMET PEER DEPENDENCY ([a-z\-0-9\.]+)@(.+)/gm;

var defaultOptions = {
dev: false,
peerDependencies: true,
var defaultOptions = {
dev: false,
peerDependencies: true,
quiet: false,
npm: 'npm',
};
Expand Down Expand Up @@ -68,7 +69,11 @@ module.exports.check = function check(request) {
module.exports.checkBabel = function checkBabel() {
try {
var babelrc = require.resolve(path.resolve(".babelrc"));
var babelOpts = JSON5.parse(fs.readFileSync(babelrc, "utf8"));
} catch (e) {
if (babelrc) {
console.info(".babelrc is invalid JSON5, babel deps are skipped")
}
// Babel isn't installed, don't install deps
return;
}
Expand All @@ -77,7 +82,7 @@ module.exports.checkBabel = function checkBabel() {
var options = Object.assign({
plugins: [],
presets: [],
}, JSON.parse(fs.readFileSync(babelrc, "utf8")));
}, babelOpts);

if (!options.env) {
options.env = {};
Expand Down

0 comments on commit d2f393f

Please sign in to comment.