diff --git a/README.md b/README.md index 5bf6f7b..2ba3c63 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,21 @@ gulp.task('default', function () { }); ``` +If you are using a `postcss.config.js` file, you can pass PostCSS options as the first argument to gulp-postcss. + +This, for instance, will let PostCSS know what the final file destination path is, since it will be unaware of the path given to `gulp.dest()`: + +```js +var gulp = require('gulp'); +var postcss = require('gulp-postcss'); + +gulp.task('default', function () { + return gulp.src('in.scss') + .pipe(postcss({ to: 'out/in.css' })) + .pipe(gulp.dest('out')); +}); +``` + ## Using a custom processor ```js @@ -178,9 +193,10 @@ gulp.task('css', function () { ``` ```js +// postcss.config.js or .postcssrc.js module.exports = function (ctx) { var file = ctx.file; - var options = ctx.options; + var options = ctx; return { parser: file.extname === '.sss' ? : 'sugarss' : false, plugins: { diff --git a/index.js b/index.js index 7bcbb32..39757b5 100644 --- a/index.js +++ b/index.js @@ -127,11 +127,11 @@ function withConfigLoader(cb) { } else { configPath = file.dirname } + // @TODO: The options property is deprecated and should be removed in 10.0.0. + contextOptions.options = Object.assign({}, contextOptions) + contextOptions.file = file return postcssLoadConfig( - { - file: file, - options: contextOptions - }, + contextOptions, configPath ) }) diff --git a/test.js b/test.js index b397371..b493489 100644 --- a/test.js +++ b/test.js @@ -251,7 +251,7 @@ describe('PostCSS Guidelines', function () { it('should allow override of `to` processing option', function (cb) { - var stream = postcss([ doubler ], {to: 'overriden'}) + var stream = postcss([ doubler ], {to: 'overridden'}) postcssStub.process.returns(Promise.resolve({ css: '', warnings: function () { @@ -260,7 +260,7 @@ describe('PostCSS Guidelines', function () { })) stream.on('data', function () { - assert.equal(postcssStub.process.getCall(0).args[1].to, 'overriden') + assert.equal(postcssStub.process.getCall(0).args[1].to, 'overridden') cb() }) @@ -282,7 +282,7 @@ describe('PostCSS Guidelines', function () { var plugins = [ doubler ] var callback = sandbox.stub().returns({ plugins: plugins, - options: { to: 'overriden' } + options: { to: 'overridden' } }) var stream = postcss(callback) @@ -296,7 +296,7 @@ describe('PostCSS Guidelines', function () { stream.on('data', function () { assert.equal(callback.getCall(0).args[0], file) assert.equal(postcssStub.use.getCall(0).args[0], plugins) - assert.equal(postcssStub.process.getCall(0).args[1].to, 'overriden') + assert.equal(postcssStub.process.getCall(0).args[1].to, 'overridden') cb() }) @@ -316,7 +316,7 @@ describe('PostCSS Guidelines', function () { postcssLoadConfigStub.returns(Promise.resolve({ plugins: plugins, - options: { to: 'overriden' } + options: { to: 'overridden' } })) postcssStub.process.returns(Promise.resolve({ @@ -329,10 +329,11 @@ describe('PostCSS Guidelines', function () { stream.on('data', function () { assert.deepEqual(postcssLoadConfigStub.getCall(0).args[0], { file: file, + to: 'initial', options: { to: 'initial' } }) assert.equal(postcssStub.use.getCall(0).args[0], plugins) - assert.equal(postcssStub.process.getCall(0).args[1].to, 'overriden') + assert.equal(postcssStub.process.getCall(0).args[1].to, 'overridden') cb() }) @@ -402,7 +403,7 @@ describe('PostCSS Guidelines', function () { }) it('should not override `from` and `map` if using gulp-sourcemaps', function (cb) { - var stream = postcss([ doubler ], { from: 'overriden', map: 'overriden' }) + var stream = postcss([ doubler ], { from: 'overridden', map: 'overridden' }) var cssPath = __dirname + '/fixture.css' postcssStub.process.returns(Promise.resolve({ css: '',