Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit d2f393f

Browse files
Coobahamichael-ciniawsky
authored andcommitted
fix(installer): invalid JSON.parse(.babelrc) (#49)
1 parent 545c73f commit d2f393f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"homepage": "https://github.com/ericclemmons/npm-install-webpack-plugin#readme",
3939
"dependencies": {
4040
"cross-spawn": "^5.0.1",
41+
"json5": "^0.5.1",
4142
"memory-fs": "^0.4.1",
4243
"resolve": "^1.2.0"
4344
},

src/installer.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ var fs = require("fs");
33
var path = require("path");
44
var resolve = require("resolve");
55
var util = require("util");
6+
var JSON5 = require("json5");
67

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

10-
var defaultOptions = {
11-
dev: false,
12-
peerDependencies: true,
11+
var defaultOptions = {
12+
dev: false,
13+
peerDependencies: true,
1314
quiet: false,
1415
npm: 'npm',
1516
};
@@ -68,7 +69,11 @@ module.exports.check = function check(request) {
6869
module.exports.checkBabel = function checkBabel() {
6970
try {
7071
var babelrc = require.resolve(path.resolve(".babelrc"));
72+
var babelOpts = JSON5.parse(fs.readFileSync(babelrc, "utf8"));
7173
} catch (e) {
74+
if (babelrc) {
75+
console.info(".babelrc is invalid JSON5, babel deps are skipped")
76+
}
7277
// Babel isn't installed, don't install deps
7378
return;
7479
}
@@ -77,7 +82,7 @@ module.exports.checkBabel = function checkBabel() {
7782
var options = Object.assign({
7883
plugins: [],
7984
presets: [],
80-
}, JSON.parse(fs.readFileSync(babelrc, "utf8")));
85+
}, babelOpts);
8186

8287
if (!options.env) {
8388
options.env = {};

0 commit comments

Comments
 (0)