diff --git a/index.js b/index.js index eb2dd6a..5739663 100644 --- a/index.js +++ b/index.js @@ -6,39 +6,39 @@ const applySourceMap = require('vinyl-sourcemaps-apply'); const autoprefixer = require('autoprefixer'); const postcss = require('postcss'); -module.exports = opts => { - return through.obj((file, enc, cb) => { +module.exports = options => { + return through.obj((file, encoding, callback) => { if (file.isNull()) { - cb(null, file); + callback(null, file); return; } if (file.isStream()) { - cb(new PluginError('gulp-autoprefixer', 'Streaming not supported')); + callback(new PluginError('gulp-autoprefixer', 'Streaming not supported')); return; } - postcss(autoprefixer(opts)).process(file.contents.toString(), { + postcss(autoprefixer(options)).process(file.contents.toString(), { map: file.sourceMap ? {annotation: false} : false, from: file.path, to: file.path - }).then(res => { - file.contents = Buffer.from(res.css); + }).then(result => { + file.contents = Buffer.from(result.css); - if (res.map && file.sourceMap) { - const map = res.map.toJSON(); + if (result.map && file.sourceMap) { + const map = result.map.toJSON(); map.file = file.relative; map.sources = map.sources.map(() => file.relative); applySourceMap(file, map); } - const warnings = res.warnings(); + const warnings = result.warnings(); if (warnings.length > 0) { fancyLog('gulp-autoprefixer:', '\n ' + warnings.join('\n ')); } - setImmediate(cb, null, file); + setImmediate(callback, null, file); }).catch(error => { const cssError = error.name === 'CssSyntaxError'; @@ -47,7 +47,7 @@ module.exports = opts => { } // Prevent stream unhandled exception from being suppressed by Promise - setImmediate(cb, new PluginError('gulp-autoprefixer', error, { + setImmediate(callback, new PluginError('gulp-autoprefixer', error, { fileName: file.path, showStack: !cssError })); diff --git a/package.json b/package.json index 378e57f..01266ef 100644 --- a/package.json +++ b/package.json @@ -30,18 +30,18 @@ "postcss-runner" ], "dependencies": { - "autoprefixer": "^9.1.3", + "autoprefixer": "^9.5.1", "fancy-log": "^1.3.2", "plugin-error": "^1.0.1", "postcss": "^7.0.2", - "through2": "^2.0.0", - "vinyl-sourcemaps-apply": "^0.2.0" + "through2": "^3.0.1", + "vinyl-sourcemaps-apply": "^0.2.1" }, "devDependencies": { - "ava": "*", + "ava": "^1.4.1", "gulp-sourcemaps": "^2.6.0", - "p-event": "^2.1.0", + "p-event": "^2.3.1", "vinyl": "^2.1.0", - "xo": "*" + "xo": "^0.24.0" } } diff --git a/test.js b/test.js index 107abe2..0b231f7 100644 --- a/test.js +++ b/test.js @@ -3,10 +3,10 @@ import test from 'ava'; import Vinyl from 'vinyl'; import sourceMaps from 'gulp-sourcemaps'; import pEvent from 'p-event'; -import m from '.'; +import autoprefixer from '.'; test('autoprefix CSS', async t => { - const stream = m(); + const stream = autoprefixer(); const data = pEvent(stream, 'data'); stream.end(new Vinyl({ @@ -27,7 +27,7 @@ test('generate source maps', async t => { const data = pEvent(write, 'data'); init - .pipe(m({ + .pipe(autoprefixer({ browsers: ['Firefox ESR'] })) .pipe(write); @@ -41,7 +41,7 @@ test('generate source maps', async t => { })); const file = await data; - t.is(file.sourceMap.mappings, 'AAAA;CACC,cAAc;CACd'); + t.is(file.sourceMap.mappings, 'AAAA;CACC,aAAa;AACd'); const contents = file.contents.toString(); t.true(/flex/.test(contents)); t.true(/sourceMappingURL=data:application\/json;charset=utf8;base64/.test(contents)); @@ -49,7 +49,7 @@ test('generate source maps', async t => { test('read upstream source maps', async t => { let testFile; - const stream = m(); + const stream = autoprefixer(); const write = sourceMaps.write(); const sourcesContent = [ 'a {\n display: flex;\n}\n',