From ab49120838d6ecd755138ef0123cc2384253e580 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 18 Aug 2019 22:30:21 +0200 Subject: [PATCH] Require Node.js 8 and Gulp 4 Fixes #113 --- .travis.yml | 2 +- index.js | 70 +++++++++++++++++++++++++++------------------------- package.json | 13 ++++++---- readme.md | 7 +++--- test.js | 2 +- 5 files changed, 50 insertions(+), 44 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2ae9d62..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: + - '12' - '10' - '8' - - '6' diff --git a/index.js b/index.js index 5739663..826d36c 100644 --- a/index.js +++ b/index.js @@ -18,39 +18,43 @@ module.exports = options => { return; } - postcss(autoprefixer(options)).process(file.contents.toString(), { - map: file.sourceMap ? {annotation: false} : false, - from: file.path, - to: file.path - }).then(result => { - file.contents = Buffer.from(result.css); - - if (result.map && file.sourceMap) { - const map = result.map.toJSON(); - map.file = file.relative; - map.sources = map.sources.map(() => file.relative); - applySourceMap(file, map); + (async () => { + try { + const result = await postcss(autoprefixer(options)).process(file.contents.toString(), { + map: file.sourceMap ? {annotation: false} : false, + from: file.path, + to: file.path + }); + + file.contents = Buffer.from(result.css); + + 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 = result.warnings(); + + if (warnings.length > 0) { + fancyLog('gulp-autoprefixer:', '\n ' + warnings.join('\n ')); + } + + setImmediate(callback, null, file); + } catch (error) { + const cssError = error.name === 'CssSyntaxError'; + + if (cssError) { + error.message += error.showSourceCode(); + } + + // Prevent stream unhandled exception from being suppressed by Promise + setImmediate(callback, new PluginError('gulp-autoprefixer', error, { + fileName: file.path, + showStack: !cssError + })); } - - const warnings = result.warnings(); - - if (warnings.length > 0) { - fancyLog('gulp-autoprefixer:', '\n ' + warnings.join('\n ')); - } - - setImmediate(callback, null, file); - }).catch(error => { - const cssError = error.name === 'CssSyntaxError'; - - if (cssError) { - error.message += error.showSourceCode(); - } - - // Prevent stream unhandled exception from being suppressed by Promise - setImmediate(callback, new PluginError('gulp-autoprefixer', error, { - fileName: file.path, - showStack: !cssError - })); - }); + })(); }); }; diff --git a/package.json b/package.json index 14aab2a..1f95d49 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=6" + "node": ">=8" }, "scripts": { "test": "xo && ava" @@ -30,18 +30,21 @@ "postcss-runner" ], "dependencies": { - "autoprefixer": "^9.5.1", + "autoprefixer": "^9.6.1", "fancy-log": "^1.3.2", "plugin-error": "^1.0.1", - "postcss": "^7.0.2", + "postcss": "^7.0.17", "through2": "^3.0.1", "vinyl-sourcemaps-apply": "^0.2.1" }, "devDependencies": { - "ava": "^1.4.1", + "ava": "^2.3.0", "gulp-sourcemaps": "^2.6.0", - "p-event": "^2.3.1", + "p-event": "^4.1.0", "vinyl": "^2.1.0", "xo": "^0.24.0" + }, + "peerDependencies": { + "gulp": ">=4" } } diff --git a/readme.md b/readme.md index 6cb6e1b..90bf82b 100644 --- a/readme.md +++ b/readme.md @@ -18,10 +18,9 @@ $ npm install --save-dev gulp-autoprefixer const gulp = require('gulp'); const autoprefixer = require('gulp-autoprefixer'); -gulp.task('default', () => +exports.default = () => ( gulp.src('src/app.css') .pipe(autoprefixer({ - browsers: ['last 2 versions'], cascade: false })) .pipe(gulp.dest('dist')) @@ -31,7 +30,7 @@ gulp.task('default', () => ## API -### autoprefixer([options]) +### autoprefixer(options?) #### options @@ -50,7 +49,7 @@ const sourcemaps = require('gulp-sourcemaps'); const autoprefixer = require('gulp-autoprefixer'); const concat = require('gulp-concat'); -gulp.task('default', () => +exports.default = () => ( gulp.src('src/**/*.css') .pipe(sourcemaps.init()) .pipe(autoprefixer()) diff --git a/test.js b/test.js index 0b231f7..909de5f 100644 --- a/test.js +++ b/test.js @@ -28,7 +28,7 @@ test('generate source maps', async t => { init .pipe(autoprefixer({ - browsers: ['Firefox ESR'] + overrideBrowserslist: ['Firefox ESR'] })) .pipe(write);