Skip to content

Commit

Permalink
Merge pull request #98 from shinnn/graceful-fs
Browse files Browse the repository at this point in the history
Introduce graceful-fs and strip-bom
  • Loading branch information
Florian Reiterer committed Feb 26, 2015
2 parents 6adb749 + 669b5e4 commit a140edf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
var through = require('through2');
var fs = require('fs');
var fs = require('graceful-fs');
var path = require('path');
var File = require('vinyl');
var convert = require('convert-source-map');
var stripBom = require('strip-bom');

var PLUGIN_NAME = 'gulp-sourcemap';
var urlRegex = /^https?:\/\//;
Expand Down Expand Up @@ -54,7 +55,7 @@ module.exports.init = function init(options) {
sourcePath = path.dirname(mapFile);

try {
sourceMap = JSON.parse(fs.readFileSync(mapFile).toString());
sourceMap = JSON.parse(stripBom(fs.readFileSync(mapFile, 'utf8')));
} catch(e) {}
}

Expand Down Expand Up @@ -88,7 +89,7 @@ module.exports.init = function init(options) {
try {
if (options.debug)
console.log(PLUGIN_NAME + '-init: No source content for "' + source + '". Loading from file.');
sourceContent = fs.readFileSync(absPath).toString();
sourceContent = stripBom(fs.readFileSync(absPath, 'utf8'));
} catch (e) {
if (options.debug)
console.warn(PLUGIN_NAME + '-init: source file not found: ' + absPath);
Expand Down Expand Up @@ -180,7 +181,7 @@ module.exports.write = function write(destPath, options) {
try {
if (options.debug)
console.log(PLUGIN_NAME + '-write: No source content for "' + sourceMap.sources[i] + '". Loading from file.');
sourceMap.sourcesContent[i] = fs.readFileSync(sourcePath).toString();
sourceMap.sourcesContent[i] = stripBom(fs.readFileSync(sourcePath, 'utf8'));
} catch (e) {
if (options.debug)
console.warn(PLUGIN_NAME + '-write: source file not found: ' + sourcePath);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"license": "ISC",
"dependencies": {
"convert-source-map": "^0.5.0",
"graceful-fs": "^3.0.5",
"strip-bom": "^1.0.0",
"through2": "^0.6.3",
"vinyl": "^0.4.6"
},
Expand Down

0 comments on commit a140edf

Please sign in to comment.