From 5e83c8ad5425bcbc331571b23bd6015712026cab Mon Sep 17 00:00:00 2001 From: Martino Pham Date: Sun, 7 Jun 2015 21:05:43 -0700 Subject: [PATCH] make an options local variable that defaults to the options from the closure, this to prevent the default options from being modified and propagated from call to call (i.e. options.from being set to file.path), resulting in the current file's path being ignored. --- index.js | 2 +- test/cssnext.js | 43 ++++++++++++++++++++++++++++++++++ test/fixtures/import.css | 1 + test/fixtures/import/index.css | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/import.css create mode 100644 test/fixtures/import/index.css diff --git a/index.js b/index.js index 2a1f135..95625c9 100644 --- a/index.js +++ b/index.js @@ -8,10 +8,10 @@ module.exports = function(options){ } function transform(options) { - options = options || {} return function(file, enc, cb){ var contents var transformed + var options = options || {} if(file.isStream()) { return cb( new PluginError("gulp-cssnext", "streaming not supported") diff --git a/test/cssnext.js b/test/cssnext.js index e859e9b..c92263a 100644 --- a/test/cssnext.js +++ b/test/cssnext.js @@ -67,3 +67,46 @@ tape("throws on cssnext error", function(test){ }) stream.end(file) }) + +tape("Resolves relative paths for consecutive files in different paths", function(test) { + var stream = cssnext() + var file = new gutil.File({ + base: "./fixtures/", + path: "./fixtures/import.css", + contents: new Buffer( + fs.readFileSync( + path.resolve(__dirname, "./fixtures/import.css"), + "utf8" + ) + ) + }) + stream.write(file) + + var file2 = new gutil.File({ + base : "./fixtures/import/", + path : "./fixtures/import/index.css", + contents : new Buffer( + fs.readFileSync( + path.resolve(__dirname, "./fixtures/import/index.css"), + "utf8" + ) + ) + }) + stream.write(file2) + + var count = 0; + stream.on("data", function(file){ + + test.equal( + file.contents.toString(), + fs.readFileSync( + path.resolve(__dirname, "./expected/index.css"), + "utf8" + ) + ) + ++count + if(count == 2) { + test.end() + } + }) +}) diff --git a/test/fixtures/import.css b/test/fixtures/import.css new file mode 100644 index 0000000..90be5f7 --- /dev/null +++ b/test/fixtures/import.css @@ -0,0 +1 @@ +@import './index.css'; diff --git a/test/fixtures/import/index.css b/test/fixtures/import/index.css new file mode 100644 index 0000000..011e968 --- /dev/null +++ b/test/fixtures/import/index.css @@ -0,0 +1 @@ +@import '../index.css';