From 42b4cf524bd955857a6ba85c667cf74971c67cdb Mon Sep 17 00:00:00 2001 From: luo chen Date: Wed, 16 Jul 2014 18:39:16 +0800 Subject: [PATCH] trying to fix "source file not found" problem when using with gulp-sourcemaps. --- .gitignore | 3 ++- index.js | 6 +----- package.json | 7 +++++-- test/gulp_test/gulpfile.coffee | 13 +++++++++++++ test/gulp_test/path1/file1.js | 1 + test/gulp_test/path2/file2.js | 1 + 6 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 test/gulp_test/gulpfile.coffee create mode 100644 test/gulp_test/path1/file1.js create mode 100644 test/gulp_test/path2/file2.js diff --git a/.gitignore b/.gitignore index b512c09..4a3df0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules \ No newline at end of file +node_modules +test/gulp_test/build diff --git a/index.js b/index.js index bf879e6..5316b9f 100644 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ module.exports = function(fileName, opts) { function endStream(){ if (!firstFile) return this.emit('end'); - var contentPath = path.join(firstFile.base, fileName), + var contentPath = path.join(process.cwd(), fileName), mapPath = contentPath + '.map'; if(!firstFile.sourceMap) { @@ -81,8 +81,6 @@ module.exports = function(fileName, opts) { sourceMap.file = path.basename(sourceMap.file); var contentFile = new File({ - cwd: firstFile.cwd, - base: firstFile.base, path: contentPath, contents: new Buffer(codeMap.code) }); @@ -91,8 +89,6 @@ module.exports = function(fileName, opts) { contentFile.sourceMap = sourceMap; } else { var mapFile = new File({ - cwd: firstFile.cwd, - base: firstFile.base, path: mapPath, contents: new Buffer(JSON.stringify(sourceMap, null, ' ')) }); diff --git a/package.json b/package.json index 910cef1..31b4fc2 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,10 @@ "source-map": "0.1.33" }, "devDependencies": { - "mocha": "^1.18.2", - "chai": "^1.9.0" + "chai": "^1.9.0", + "coffee-script": "^1.7.1", + "gulp": "^3.8.6", + "gulp-sourcemaps": "^1.1.0", + "mocha": "^1.18.2" } } diff --git a/test/gulp_test/gulpfile.coffee b/test/gulp_test/gulpfile.coffee new file mode 100644 index 0000000..ff52d12 --- /dev/null +++ b/test/gulp_test/gulpfile.coffee @@ -0,0 +1,13 @@ +gulp = require('gulp') +sourcemaps = require('gulp-sourcemaps') +concat = require('../..') + +gulp.task 'concat', -> + return gulp.src(['./path1/file1.js', './path2/file2.js']) + .pipe sourcemaps.init() + .pipe concat 'file.js' + .pipe sourcemaps.write('.', includeContent: true) + .pipe gulp.dest('./build') + +gulp.task 'default', ['concat'] + diff --git a/test/gulp_test/path1/file1.js b/test/gulp_test/path1/file1.js new file mode 100644 index 0000000..702f428 --- /dev/null +++ b/test/gulp_test/path1/file1.js @@ -0,0 +1 @@ +console.log("hello"); diff --git a/test/gulp_test/path2/file2.js b/test/gulp_test/path2/file2.js new file mode 100644 index 0000000..e5f9a3f --- /dev/null +++ b/test/gulp_test/path2/file2.js @@ -0,0 +1 @@ +console.log("world");