Skip to content

Commit

Permalink
fix: Revert deal with config file charset (#525) (#583)
Browse files Browse the repository at this point in the history
This reverts commit c74eeb9.
  • Loading branch information
jimthedev committed Oct 20, 2018
1 parent c74eeb9 commit 04b7d41
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 23 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -85,7 +85,6 @@
"lodash": "4.17.11",
"minimist": "1.2.0",
"shelljs": "0.7.6",
"strip-bom": "3.0.0",
"strip-json-comments": "2.0.1"
},
"babel": {
Expand Down
21 changes: 1 addition & 20 deletions src/configLoader/getContent.js
Expand Up @@ -2,8 +2,6 @@ import fs from 'fs';
import path from 'path';

import stripJSONComments from 'strip-json-comments';
import isUTF8 from 'is-utf8';
import stripBom from 'strip-bom';

import { getNormalizedConfig } from '../configLoader';

Expand All @@ -19,7 +17,7 @@ export default getConfigContent;
function readConfigContent (configPath) {
const parsedPath = path.parse(configPath)
const isRcFile = parsedPath.ext !== '.js' && parsedPath.ext !== '.json';
const jsonString = readConfigFileContent(configPath);
const jsonString = fs.readFileSync(configPath, 'utf-8');
const parse = isRcFile ?
(contents) => JSON.parse(stripJSONComments(contents)) :
(contents) => JSON.parse(contents);
Expand Down Expand Up @@ -63,20 +61,3 @@ function getConfigContent (configPath, baseDirectory) {
const content = readConfigContent(resolvedPath);
return getNormalizedConfig(configBasename, content);
};

/**
* Read proper content from config file.
* If the chartset of the config file is not utf-8, one error will be thrown.
* @param {String} configPath
* @return {String}
*/
function readConfigFileContent (configPath) {

let rawBufContent = fs.readFileSync(configPath);

if (!isUTF8(rawBufContent)) {
throw new Error(`The config file at "${configPath}" contains invalid charset, expect utf8`);
}

return stripBom(rawBufContent.toString("utf8"));
}
Binary file removed test/fixtures/invalid-charset.json
Binary file not shown.
2 changes: 0 additions & 2 deletions test/tests/configLoader.js
Expand Up @@ -13,8 +13,6 @@ describe('configLoader', function () {
.to.throw(/parsing json at/i);
expect(() => getContent('invalid-json-rc', fixturesPath))
.to.throw(/parsing json at/i);
expect(() => getContent('invalid-charset.json', fixturesPath))
.to.throw(/contains invalid charset/i);
});

it('parses json files with comments', function () {
Expand Down

0 comments on commit 04b7d41

Please sign in to comment.