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: d008588d84737dcc39e3595a76bad55f493b62c4
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
  • 17 commits
  • 8 files changed
  • 4 contributors

Commits on Feb 28, 2018

  1. Copy the full SHA
    7828646 View commit details
  2. Unverified

    No user is associated with the committer email.
    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. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    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

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7b080bf View commit details
  2. 6.1.0

    sindresorhus committed Apr 19, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    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

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    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

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    c5e7214 View commit details

Commits on Jan 1, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    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

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    a953087 View commit details
  2. 8.0.0

    sindresorhus committed May 29, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    coreyfarrell Corey Farrell
    Copy the full SHA
    ede5a11 View commit details
Showing with 133 additions and 121 deletions.
  1. +1 −2 .gitattributes
  2. +22 −0 .github/workflows/main.yml
  3. +0 −5 .travis.yml
  4. +41 −34 index.js
  5. +1 −1 license
  6. +53 −45 package.json
  7. +5 −24 readme.md
  8. +10 −10 test.js
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
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

75 changes: 41 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -6,48 +6,55 @@ 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(), {
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) {
fancyLog('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 PluginError('gulp-autoprefixer', err, {
fileName: file.path,
showStack: !cssError
}));
});
})();
});
};
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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:

98 changes: 53 additions & 45 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,55 @@
{
"name": "gulp-autoprefixer",
"version": "4.1.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",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2",
"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",
"vinyl": "^2.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)
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -3,21 +3,21 @@ 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({
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,8 +27,8 @@ test('generate source maps', async t => {
const data = pEvent(write, 'data');

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

@@ -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',