Skip to content

Commit 04b7d41

Browse files
authored
fix: Revert deal with config file charset (#525) (#583)
This reverts commit c74eeb9.
1 parent c74eeb9 commit 04b7d41

File tree

4 files changed

+1
-23
lines changed

4 files changed

+1
-23
lines changed

Diff for: package.json

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"lodash": "4.17.11",
8686
"minimist": "1.2.0",
8787
"shelljs": "0.7.6",
88-
"strip-bom": "3.0.0",
8988
"strip-json-comments": "2.0.1"
9089
},
9190
"babel": {

Diff for: src/configLoader/getContent.js

+1-20
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import fs from 'fs';
22
import path from 'path';
33

44
import stripJSONComments from 'strip-json-comments';
5-
import isUTF8 from 'is-utf8';
6-
import stripBom from 'strip-bom';
75

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

@@ -19,7 +17,7 @@ export default getConfigContent;
1917
function readConfigContent (configPath) {
2018
const parsedPath = path.parse(configPath)
2119
const isRcFile = parsedPath.ext !== '.js' && parsedPath.ext !== '.json';
22-
const jsonString = readConfigFileContent(configPath);
20+
const jsonString = fs.readFileSync(configPath, 'utf-8');
2321
const parse = isRcFile ?
2422
(contents) => JSON.parse(stripJSONComments(contents)) :
2523
(contents) => JSON.parse(contents);
@@ -63,20 +61,3 @@ function getConfigContent (configPath, baseDirectory) {
6361
const content = readConfigContent(resolvedPath);
6462
return getNormalizedConfig(configBasename, content);
6563
};
66-
67-
/**
68-
* Read proper content from config file.
69-
* If the chartset of the config file is not utf-8, one error will be thrown.
70-
* @param {String} configPath
71-
* @return {String}
72-
*/
73-
function readConfigFileContent (configPath) {
74-
75-
let rawBufContent = fs.readFileSync(configPath);
76-
77-
if (!isUTF8(rawBufContent)) {
78-
throw new Error(`The config file at "${configPath}" contains invalid charset, expect utf8`);
79-
}
80-
81-
return stripBom(rawBufContent.toString("utf8"));
82-
}

Diff for: test/fixtures/invalid-charset.json

-98 Bytes
Binary file not shown.

Diff for: test/tests/configLoader.js

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ describe('configLoader', function () {
1313
.to.throw(/parsing json at/i);
1414
expect(() => getContent('invalid-json-rc', fixturesPath))
1515
.to.throw(/parsing json at/i);
16-
expect(() => getContent('invalid-charset.json', fixturesPath))
17-
.to.throw(/contains invalid charset/i);
1816
});
1917

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

0 commit comments

Comments
 (0)