Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/gulp-autoprefixer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 51886049f1b2bf1e3ac0631ef2a48137f4acfe10
Choose a base ref
...
head repository: sindresorhus/gulp-autoprefixer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ede5a11ccc0fe77c12a8c58960d1fd91f8ddc779
Choose a head ref

Commits on Oct 28, 2017

  1. Test against Node.js v8 (#90)

    MarkHerhold authored and sindresorhus committed Oct 28, 2017
    Copy the full SHA
    60aead3 View commit details

Commits on Dec 29, 2017

  1. Drop dependency on deprecated gulp-util (#94)

    Fixes #93
    demurgos authored and sindresorhus committed Dec 29, 2017
    Copy the full SHA
    94f3447 View commit details
  2. Meta tweaks

    sindresorhus committed Dec 29, 2017
    Copy the full SHA
    27816c3 View commit details
  3. 4.1.0

    sindresorhus committed Dec 29, 2017
    Copy the full SHA
    d008588 View commit details

Commits on Feb 28, 2018

  1. Copy the full SHA
    7828646 View commit details
  2. Copy the full SHA
    e954e6e View commit details
  3. Meta tweaks

    sindresorhus committed Feb 28, 2018
    Copy the full SHA
    e526a78 View commit details
  4. 5.0.0

    sindresorhus committed Feb 28, 2018
    Copy the full SHA
    18a27be View commit details

Commits on Aug 26, 2018

  1. Require Node.js 6

    sindresorhus committed Aug 26, 2018
    Copy the full SHA
    ea0b7f8 View commit details
  2. Copy the full SHA
    c225cbd View commit details
  3. 6.0.0

    sindresorhus committed Aug 26, 2018
    Copy the full SHA
    dfe3919 View commit details

Commits on Apr 19, 2019

  1. Upgrade dependencies

    Fixes #110
    sindresorhus committed Apr 19, 2019
    Copy the full SHA
    7b080bf View commit details
  2. 6.1.0

    sindresorhus committed Apr 19, 2019
    Copy the full SHA
    adec1a7 View commit details

Commits on May 23, 2019

  1. Copy the full SHA
    83cc576 View commit details

Commits on Aug 18, 2019

  1. Require Node.js 8 and Gulp 4

    Fixes #113
    sindresorhus committed Aug 18, 2019
    1
    Copy the full SHA
    ab49120 View commit details
  2. 7.0.0

    sindresorhus committed Aug 18, 2019
    Copy the full SHA
    40fba84 View commit details

Commits on Oct 4, 2019

  1. Copy the full SHA
    da50fd2 View commit details
  2. 7.0.1

    sindresorhus committed Oct 4, 2019
    Copy the full SHA
    c5e7214 View commit details

Commits on Jan 1, 2021

  1. Copy the full SHA
    87ff53d View commit details

Commits on May 29, 2021

  1. Require Node.js 12 and upgrade dependencies

    Closes #119
    Fixes #118
    sindresorhus committed May 29, 2021
    Copy the full SHA
    a953087 View commit details
  2. 8.0.0

    sindresorhus committed May 29, 2021
    Copy the full SHA
    ede5a11 View commit details
Showing with 146 additions and 141 deletions.
  1. +1 −1 .editorconfig
  2. +1 −2 .gitattributes
  3. +22 −0 .github/workflows/main.yml
  4. +1 −0 .gitignore
  5. +1 −0 .npmrc
  6. +0 −5 .travis.yml
  7. +43 −35 index.js
  8. +5 −17 license
  9. +53 −43 package.json
  10. +5 −24 readme.md
  11. +14 −14 test.js
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

78 changes: 43 additions & 35 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
'use strict';
const gutil = require('gulp-util');
const fancyLog = require('fancy-log');
const PluginError = require('plugin-error');
const through = require('through2');
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 gutil.PluginError('gulp-autoprefixer', 'Streaming not supported'));
callback(new PluginError('gulp-autoprefixer', 'Streaming not supported'));
return;
}

postcss(autoprefixer(opts)).process(file.contents.toString(), {
map: file.sourceMap ? {annotation: false} : false,
from: file.path,
to: file.path
}).then(res => {
file.contents = Buffer.from(res.css);

if (res.map && file.sourceMap) {
applySourceMap(file, res.map.toString());
}

const warnings = res.warnings();

if (warnings.length > 0) {
gutil.log('gulp-autoprefixer:', '\n ' + warnings.join('\n '));
(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
}));
}

setImmediate(cb, null, file);
}).catch(err => {
const cssError = err.name === 'CssSyntaxError';

if (cssError) {
err.message += err.showSourceCode();
}

// Prevent stream unhandled exception from being suppressed by Promise
setImmediate(cb, new gutil.PluginError('gulp-autoprefixer', err, {
fileName: file.path,
showStack: !cssError
}));
});
})();
});
};
22 changes: 5 additions & 17 deletions license
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
96 changes: 53 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
{
"name": "gulp-autoprefixer",
"version": "4.0.0",
"description": "Prefix CSS",
"license": "MIT",
"repository": "sindresorhus/gulp-autoprefixer",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4.5"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"gulpplugin",
"autoprefixer",
"postcss",
"css",
"prefix",
"prefixes",
"stylesheet",
"preprocess",
"postcss-runner"
],
"dependencies": {
"autoprefixer": "^7.0.0",
"gulp-util": "^3.0.0",
"postcss": "^6.0.1",
"through2": "^2.0.0",
"vinyl-sourcemaps-apply": "^0.2.0"
},
"devDependencies": {
"ava": "*",
"gulp-sourcemaps": "^2.6.0",
"p-event": "^1.1.0",
"xo": "*"
}
"name": "gulp-autoprefixer",
"version": "8.0.0",
"description": "Prefix CSS",
"license": "MIT",
"repository": "sindresorhus/gulp-autoprefixer",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=12"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"gulpplugin",
"autoprefixer",
"postcss",
"css",
"prefix",
"prefixes",
"stylesheet",
"preprocess",
"postcss-runner"
],
"dependencies": {
"autoprefixer": "^10.2.6",
"fancy-log": "^1.3.3",
"plugin-error": "^1.0.1",
"postcss": "^8.3.0",
"through2": "^4.0.2",
"vinyl-sourcemaps-apply": "^0.2.1"
},
"devDependencies": {
"ava": "^2.4.0",
"gulp-sourcemaps": "^3.0.0",
"p-event": "^4.2.0",
"vinyl": "^2.2.1",
"xo": "^0.39.0"
},
"peerDependencies": {
"gulp": ">=4"
},
"peerDependenciesMeta": {
"gulp": {
"optional": true
}
}
}
29 changes: 5 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,40 @@
# gulp-autoprefixer [![Build Status](https://travis-ci.org/sindresorhus/gulp-autoprefixer.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-autoprefixer)
# gulp-autoprefixer

> Prefix CSS with [Autoprefixer](https://github.com/postcss/autoprefixer)
*Issues with the output should be reported on the Autoprefixer [issue tracker](https://github.com/postcss/autoprefixer/issues).*


---

<p align="center">👾</p>
<p align="center"><b>Improve your JavaScript skills with this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos.</b><br>Try his free <a href="https://javascript30.com/friend/AWESOME">JavaScript 30 course</a> for a taste of what to expect. You might also like his <a href="https://ReactForBeginners.com/friend/AWESOME">React</a> & <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> course.</p>

---


## Install

```
$ npm install --save-dev gulp-autoprefixer
```


## Usage

```js
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'))
);
```


## API

### autoprefixer([options])
### autoprefixer(options?)

#### options

Type: `Object`
Type: `object`

See the Autoprefixer [options](https://github.com/postcss/autoprefixer#options).


## Source Maps

Use [gulp-sourcemaps](https://github.com/gulp-sourcemaps/gulp-sourcemaps) like this:
@@ -58,7 +45,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())
@@ -68,12 +55,6 @@ gulp.task('default', () =>
);
```


## Tip

If you use other PostCSS based tools, like `cssnano`, you may want to run them together using [`gulp-postcss`](https://github.com/postcss/autoprefixer#gulp) instead of `gulp-autoprefixer`. It will be faster, as the CSS is parsed only once for all PostCSS based tools, including Autoprefixer.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
28 changes: 14 additions & 14 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import path from 'path';
import test from 'ava';
import gutil from 'gulp-util';
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 gutil.File({
stream.end(new Vinyl({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture', 'fixture.css'),
contents: Buffer.from('a {\n\tdisplay: flex;\n}')
contents: Buffer.from('::placeholder {\n\tcolor: gray;\n}')
}));

const file = await data;
t.true(/-/.test(file.contents.toString()));
t.regex(file.contents.toString(), /-/);
t.is(file.relative, 'fixture.css');
});

@@ -27,12 +27,12 @@ test('generate source maps', async t => {
const data = pEvent(write, 'data');

init
.pipe(m({
browsers: ['Firefox ESR']
.pipe(autoprefixer({
overrideBrowserslist: ['Firefox ESR']
}))
.pipe(write);

init.end(new gutil.File({
init.end(new Vinyl({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture', 'fixture.css'),
@@ -41,15 +41,15 @@ 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));
t.regex(contents, /flex/);
t.regex(contents, /sourceMappingURL=data:application\/json;charset=utf8;base64/);
});

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',
@@ -61,7 +61,7 @@ test('read upstream source maps', async t => {
stream.pipe(write);

stream.end(
testFile = new gutil.File({
testFile = new Vinyl({
cwd: __dirname,
base: path.join(__dirname, 'fixture'),
path: path.join(__dirname, 'fixture', 'fixture.css'),