diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..31705c6 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,46 @@ +{ + "env": { + "node": true + }, + "extends": [ + "eslint:recommended" + ], + "globals": { + "Promise": true + }, + "rules": { + "semi": [ + 2, + "never" + ], + "no-cond-assign": [ + 2, + "except-parens" + ], + "no-unused-expressions": 2, + "indent": [ + 2, + 2, + { + "SwitchCase": 1 + } + ], + "comma-style": 2, + "max-len": [ + 2, + { + "code": 100, + "ignoreComments": true + } + ], + "new-cap": 2, + "strict": 0, + "no-trailing-spaces": 2, + "no-undef": 2, + "no-unused-vars": 2, + "quotes": [ + 2, + "single" + ] + } +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..cef15de --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Test + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + npm-test: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: ['18', '20', '21'] + + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - run: | + npm install + npm test + + - uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index b0e3907..a31e983 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ node_modules npm-debug.log .DS_Store +.nyc_output/ +coverage/ +package-lock.json +yarn.lock diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 130ba0a..0000000 --- a/.jshintrc +++ /dev/null @@ -1,16 +0,0 @@ -{ - "asi": true, - "boss": true, - "browser": true, - "node": true, - "expr": true, - "indent": 2, - "laxcomma": true, - "maxlen": 100, - "newcap": true, - "strict": false, - "trailing": true, - "undef": true, - "unused": true, - "quotmark": "single" -} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..f2db076 --- /dev/null +++ b/.npmignore @@ -0,0 +1,27 @@ +*.log +*.pid +*.seed +.editorconfig +.eslintrc* +.eslintignore +.gitignore +.grunt +.lock-wscript +.node_repl_history +.stylelintrc* +.travis.yml +.vscode +.nyc_output +appveyor.yml +coverage +gulpfile.js +lib-cov +logs +node_modules +npm-debug.log* +pids +test +test.js +yarn.lock +flake.lock +flake.nix diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ff60bcb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -sudo: false -language: node_js -node_js: - - stable - - 6 - - 4 - - 0.12 diff --git a/README.md b/README.md index d77ed06..1f52ee4 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ -# gulp-postcss [![Build Status](https://api.travis-ci.org/postcss/gulp-postcss.png)](https://travis-ci.org/postcss/gulp-postcss) +# gulp-postcss + +![Build Status](https://github.com/postcss/gulp-postcss/actions/workflows/test.yml/badge.svg?branch=main) +[![Coverage Status](https://img.shields.io/coveralls/postcss/gulp-postcss.svg)](https://coveralls.io/r/postcss/gulp-postcss) [PostCSS](https://github.com/postcss/postcss) gulp plugin to pipe CSS through several plugins, but parse CSS only once. ## Install - $ npm install --save-dev gulp-postcss + $ npm install --save-dev postcss gulp-postcss Install required [postcss plugins](https://www.npmjs.com/browse/keyword/postcss-plugin) separately. E.g. for autoprefixer, you need to install [autoprefixer](https://github.com/postcss/autoprefixer) package. @@ -45,6 +48,30 @@ gulp.task('css', function () { }); ``` +## Using with .pcss extension + +For using gulp-postcss to have input files in .pcss format and get .css output need additional library like gulp-rename. + +```js +var postcss = require('gulp-postcss'); +var gulp = require('gulp'); +const rename = require('gulp-rename'); + +gulp.task('css', function () { + return gulp.src('./src/*.pcss') + .pipe(postcss()) + .pipe(rename({ + extname: '.css' + })) + .pipe(gulp.dest('./dest')); +}); +``` + +This is done for more explicit transformation. According to [gulp plugin guidelines](https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/guidelines.md#guidelines) + +> Your plugin should only do one thing, and do it well. + + ## Passing additional options to PostCSS The second optional argument to gulp-postcss is passed to PostCSS. @@ -65,13 +92,28 @@ 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 var postcss = require('gulp-postcss'); var cssnext = require('postcss-cssnext'); var opacity = function (css, opts) { - css.eachDecl(function(decl) { + css.walkDecls(function(decl) { if (decl.prop === 'opacity') { decl.parent.insertAfter(decl, { prop: '-ms-filter', @@ -151,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: { @@ -161,11 +204,44 @@ module.exports = function (ctx) { 'postcss-modules': options.modules ? {} : false } } -}) +}; ``` ## Changelog +* 10.0.0 + * Released with the same changes as 9.1.0 + +* 9.1.0 **deprecated, because it breaks semver by dropping support for node <18** + * Bump postcss-load-config to ^5.0.0 + * Ensure options are passed to plugins when using postcss.config.js #170 + * Update deps + * Drop support for node <18 + * Add flake.nix for local dev with `nix develop` + +* 9.0.1 + * Bump postcss-load-config to ^3.0.0 + +* 9.0.0 + * Bump PostCSS to 8.0 + * Drop Node 6 support + * PostCSS is now a peer dependency + +* 8.0.0 + * Bump PostCSS to 7.0 + * Drop Node 4 support + +* 7.0.1 + * Drop dependency on gulp-util + +* 7.0.0 + * Bump PostCSS to 6.0 + * Smaller module size + * Use eslint instead of jshint + +* 6.4.0 + * Add more details to `PluginError` object + * 6.3.0 * Integrated with postcss-load-config * Added a callback to configure postcss on per-file-basis diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0593d2e --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1705084402, + "narHash": "sha256-i+ipI7VgXV+nLi5ZwZ0xCamvD6Iu59vDHe6S2YOoW+Q=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "f65e5ea4794033885e1dafff7e8632e4f8cd1909", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a7bb65f --- /dev/null +++ b/flake.nix @@ -0,0 +1,17 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShell = pkgs.mkShell { + buildInputs = [ pkgs.nodejs_21 ]; + }; + }); +} diff --git a/index.js b/index.js index 2541037..39757b5 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ var Stream = require('stream') var postcss = require('postcss') var applySourceMap = require('vinyl-sourcemaps-apply') -var gutil = require('gulp-util') +var fancyLog = require('fancy-log') +var PluginError = require('plugin-error') var path = require('path') @@ -25,10 +26,10 @@ module.exports = withConfigLoader(function (loadConfig) { : {} var options = { - from: file.path - , to: file.path + from: file.path, + to: file.path, // Generate a separate source map for gulp-sourcemaps - , map: file.sourceMap ? { annotation: false } : false + map: file.sourceMap ? { annotation: false } : false } loadConfig(file) @@ -39,7 +40,7 @@ module.exports = withConfigLoader(function (loadConfig) { if (configOpts.hasOwnProperty(opt) && !isProtected[opt]) { options[opt] = configOpts[opt] } else { - gutil.log( + fancyLog.info( 'gulp-postcss:', file.relative + '\nCannot override ' + opt + ' option, because it is required by gulp-sourcemaps' @@ -55,7 +56,7 @@ module.exports = withConfigLoader(function (loadConfig) { var map var warnings = result.warnings().join('\n') - file.contents = new Buffer(result.css) + file.contents = Buffer.from(result.css) // Apply source map to the chain if (file.sourceMap) { @@ -68,7 +69,7 @@ module.exports = withConfigLoader(function (loadConfig) { } if (warnings) { - gutil.log('gulp-postcss:', file.relative + '\n' + warnings) + fancyLog.info('gulp-postcss:', file.relative + '\n' + warnings) } setImmediate(function () { @@ -79,13 +80,17 @@ module.exports = withConfigLoader(function (loadConfig) { function handleError (error) { var errorOptions = { fileName: file.path, showStack: true } if (error.name === 'CssSyntaxError') { - error = error.message + '\n\n' + error.showSourceCode() + '\n' + errorOptions.error = error + errorOptions.fileName = error.file || file.path + errorOptions.lineNumber = error.line + errorOptions.showProperties = false errorOptions.showStack = false + error = error.message + '\n\n' + error.showSourceCode() + '\n' } // Prevent stream’s unhandled exception from // being suppressed by Promise setImmediate(function () { - cb(new gutil.PluginError('gulp-postcss', error, errorOptions)) + cb(new PluginError('gulp-postcss', error, errorOptions)) }) } @@ -100,8 +105,8 @@ function withConfigLoader(cb) { if (Array.isArray(plugins)) { return cb(function () { return Promise.resolve({ - plugins: plugins - , options: options + plugins: plugins, + options: options }) }) } else if (typeof plugins === 'function') { @@ -122,10 +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/package.json b/package.json index e1d8fbb..1888201 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,27 @@ { "name": "gulp-postcss", - "version": "6.3.0", + "nyc": { + "lines": 100, + "statements": 100, + "functions": 100, + "branches": 100, + "reporter": [ + "lcov", + "text" + ], + "cache": true, + "all": true, + "check-coverage": true + }, + "version": "10.0.0", "description": "PostCSS gulp plugin", "main": "index.js", + "engines": { + "node": ">=18" + }, "scripts": { - "test": "mocha test.js" + "pretest": "eslint *.js", + "test": "nyc mocha test.js" }, "repository": { "type": "git", @@ -23,15 +40,22 @@ }, "homepage": "https://github.com/postcss/gulp-postcss", "dependencies": { - "gulp-util": "^3.0.8", - "postcss": "^5.2.10", - "postcss-load-config": "^1.1.0", + "fancy-log": "^2.0.0", + "plugin-error": "^2.0.1", + "postcss-load-config": "^5.0.0", "vinyl-sourcemaps-apply": "^0.2.1" }, "devDependencies": { - "gulp-sourcemaps": "^1.11.0", - "mocha": "^3.2.0", - "proxyquire": "^1.7.4", - "sinon": "^1.17.3" + "eslint": "^5.16.0", + "gulp-sourcemaps": "^2.6.5", + "mocha": "^10.2.0", + "nyc": "^15.1.0", + "postcss": "^8.0.0", + "proxyquire": "^2.1.0", + "sinon": "^6.3.5", + "vinyl": "^2.2.0" + }, + "peerDependencies": { + "postcss": "^8.0.0" } } diff --git a/test.js b/test.js index 58d2773..b493489 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,10 @@ -/* global it, afterEach, beforeEach, describe, Promise */ +/* eslint-env node, mocha */ +/* eslint max-len: ["off"] */ var assert = require('assert') -var gutil = require('gulp-util') +var Vinyl = require('vinyl') +var fancyLog = require('fancy-log') +var PluginError = require('plugin-error') var sourceMaps = require('gulp-sourcemaps') var postcss = require('./index') var proxyquire = require('proxyquire') @@ -37,30 +40,57 @@ it('should transform css with multiple processors', function (cb) { cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a { color: black }') + stream.write(new Vinyl({ + contents: Buffer.from('a { color: black }') })) stream.end() }) +it('should not transform css with out any processor', function (cb) { + + var css = 'a { color: black }' + + var stream = postcss(function(){ + return {} + }) + + stream.on('data', function (file) { + var result = file.contents.toString('utf8') + var target = css + assert.equal( result, target ) + cb() + }) + + stream.write(new Vinyl({ + contents: Buffer.from(css) + })) + + stream.end() + +}) it('should correctly wrap postcss errors', function (cb) { var stream = postcss([ doubler ]) stream.on('error', function (err) { - assert.ok(err instanceof gutil.PluginError) + assert.ok(err instanceof PluginError) assert.equal(err.plugin, 'gulp-postcss') + assert.equal(err.column, 1) + assert.equal(err.lineNumber, 1) + assert.equal(err.name, 'CssSyntaxError') + assert.equal(err.reason, 'Unclosed block') assert.equal(err.showStack, false) - assert.equal(err.fileName, 'testpath') + assert.equal(err.source, 'a {') + assert.equal(err.fileName, path.resolve('testpath')) cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a {'), - path: 'testpath' + stream.write(new Vinyl({ + contents: Buffer.from('a {'), + path: path.resolve('testpath') })) stream.end() @@ -72,18 +102,19 @@ it('should respond with error on stream files', function (cb) { var stream = postcss([ doubler ]) stream.on('error', function (err) { - assert.ok(err instanceof gutil.PluginError) + assert.ok(err instanceof PluginError) assert.equal(err.plugin, 'gulp-postcss') assert.equal(err.showStack, true) - assert.equal(err.fileName, 'testpath') + assert.equal(err.message, 'Streams are not supported!') + assert.equal(err.fileName, path.resolve('testpath')) cb() }) var streamFile = { isStream: function () { return true }, isNull: function() { return false }, - path: 'testpath' - }; + path: path.resolve('testpath') + } stream.write(streamFile) @@ -104,15 +135,15 @@ it('should generate source maps', function (cb) { .pipe(write) write.on('data', function (file) { - assert.equal(file.sourceMap.mappings, 'AAAA,IAAI,aAAY,CAAZ,aAAY,CAAZ,aAAY,CAAZ,YAAY,EAAE') + assert.equal(file.sourceMap.mappings, 'AAAA,IAAI,YAAW,EAAX,YAAW,EAAX,YAAW,EAAX,aAAa') assert(/sourceMappingURL=data:application\/json;(?:charset=\w+;)?base64/.test(file.contents.toString())) cb() }) - init.write(new gutil.File({ + init.write(new Vinyl({ base: __dirname, path: __dirname + '/fixture.css', - contents: new Buffer('a { color: black }') + contents: Buffer.from('a { color: black }') })) init.end() @@ -135,10 +166,10 @@ it('should correctly generate relative source map', function (cb) { cb() }) - init.write(new gutil.File({ + init.write(new Vinyl({ base: __dirname + '/src', path: __dirname + '/src/fixture.css', - contents: new Buffer('a { color: black }') + contents: Buffer.from('a { color: black }') })) init.end() @@ -148,29 +179,36 @@ it('should correctly generate relative source map', function (cb) { describe('PostCSS Guidelines', function () { - var sandbox = sinon.sandbox.create() - var CssSyntaxError = function (message, sourceCode) { + var sandbox = sinon.createSandbox() + var CssSyntaxError = function (message, source) { this.name = 'CssSyntaxError' this.message = message - this.sourceCode = sourceCode + this.source = source this.showSourceCode = function () { - return this.sourceCode + return this.source + } + this.toString = function(){ + var code = this.showSourceCode() + if ( code ) { + code = '\n\n' + code + '\n' + } + return this.name + ': ' + this.message + code } } var postcssStub = { - use: function () {} - , process: function () {} + use: function () {}, + process: function () {} } var postcssLoadConfigStub var postcss = proxyquire('./index', { postcss: function (plugins) { postcssStub.use(plugins) return postcssStub - } - , 'postcss-load-config': function (ctx, configPath) { + }, + 'postcss-load-config': function (ctx, configPath) { return postcssLoadConfigStub(ctx, configPath) - } - , 'vinyl-sourcemaps-apply': function () { + }, + 'vinyl-sourcemaps-apply': function () { return {} } }) @@ -190,8 +228,8 @@ describe('PostCSS Guidelines', function () { var stream = postcss([ doubler ]) var cssPath = __dirname + '/src/fixture.css' postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) @@ -202,9 +240,9 @@ describe('PostCSS Guidelines', function () { cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + stream.write(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath })) stream.end() @@ -213,21 +251,21 @@ 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 () { + css: '', + warnings: function () { return [] } })) 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() }) - stream.write(new gutil.File({ - contents: new Buffer('a {}') + stream.write(new Vinyl({ + contents: Buffer.from('a {}') })) stream.end() @@ -237,20 +275,20 @@ describe('PostCSS Guidelines', function () { it('should take plugins and options from callback', function (cb) { var cssPath = __dirname + '/fixture.css' - var file = new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + var file = new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath }) var plugins = [ doubler ] var callback = sandbox.stub().returns({ - plugins: plugins - , options: { to: 'overriden' } + plugins: plugins, + options: { to: 'overridden' } }) var stream = postcss(callback) postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) @@ -258,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() }) @@ -269,32 +307,33 @@ describe('PostCSS Guidelines', function () { it('should take plugins and options from postcss-load-config', function (cb) { var cssPath = __dirname + '/fixture.css' - var file = new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + var file = new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath }) var stream = postcss({ to: 'initial' }) var plugins = [ doubler ] postcssLoadConfigStub.returns(Promise.resolve({ - plugins: plugins - , options: { to: 'overriden' } + plugins: plugins, + options: { to: 'overridden' } })) postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) stream.on('data', function () { assert.deepEqual(postcssLoadConfigStub.getCall(0).args[0], { - file: file - , options: { to: 'initial' } + 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() }) @@ -307,8 +346,8 @@ describe('PostCSS Guidelines', function () { var stream = postcss() postcssLoadConfigStub.returns(Promise.resolve({ plugins: [] })) postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) @@ -316,9 +355,9 @@ describe('PostCSS Guidelines', function () { assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], __dirname) cb() }) - stream.end(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + stream.end(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath })) }) @@ -327,8 +366,8 @@ describe('PostCSS Guidelines', function () { var stream = postcss({ config: '/absolute/path' }) postcssLoadConfigStub.returns(Promise.resolve({ plugins: [] })) postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) @@ -336,9 +375,9 @@ describe('PostCSS Guidelines', function () { assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], '/absolute/path') cb() }) - stream.end(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + stream.end(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath })) }) @@ -347,31 +386,31 @@ describe('PostCSS Guidelines', function () { var stream = postcss({ config: './relative/path' }) postcssLoadConfigStub.returns(Promise.resolve({ plugins: [] })) postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) stream.on('data', function () { - assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], __dirname + '/relative/path') + assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], path.join(__dirname, 'relative/path')) cb() }) - stream.end(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath - , base: __dirname + stream.end(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath, + base: __dirname })) }) 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: '' - , warnings: function () { + css: '', + warnings: function () { return [] - } - , map: { + }, + map: { toJSON: function () { return { sources: [], @@ -381,21 +420,21 @@ describe('PostCSS Guidelines', function () { } })) - sandbox.stub(gutil, 'log') + sandbox.stub(fancyLog, 'info') stream.on('data', function () { assert.deepEqual(postcssStub.process.getCall(0).args[1].from, cssPath) assert.deepEqual(postcssStub.process.getCall(0).args[1].map, { annotation: false }) - var firstMessage = gutil.log.getCall(0).args[1] - var secondMessage = gutil.log.getCall(1).args[1] + var firstMessage = fancyLog.info.getCall(0).args[1] + var secondMessage = fancyLog.info.getCall(1).args[1] assert(firstMessage, '/fixture.css\nCannot override from option, because it is required by gulp-sourcemaps') assert(secondMessage, '/fixture.css\nCannot override map option, because it is required by gulp-sourcemaps') cb() }) - var file = new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + var file = new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath }) file.sourceMap = {} stream.end(file) @@ -404,17 +443,18 @@ describe('PostCSS Guidelines', function () { it('should not output js stack trace for `CssSyntaxError`', function (cb) { var stream = postcss([ doubler ]) - var cssSyntaxError = new CssSyntaxError('message', 'sourceCode') + var cssSyntaxError = new CssSyntaxError('messageText', 'sourceCode') postcssStub.process.returns(Promise.reject(cssSyntaxError)) stream.on('error', function (error) { assert.equal(error.showStack, false) - assert.equal(error.message, 'message' + '\n\nsourceCode\n') + assert.equal(error.message, 'messageText\n\nsourceCode\n') + assert.equal(error.source, 'sourceCode') cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a {}') + stream.write(new Vinyl({ + contents: Buffer.from('a {}') })) stream.end() @@ -432,22 +472,22 @@ describe('PostCSS Guidelines', function () { } } - sandbox.stub(gutil, 'log') + sandbox.stub(fancyLog, 'info') postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [new Warning('msg1'), new Warning('msg2')] } })) stream.on('data', function () { - assert(gutil.log.calledWith('gulp-postcss:', 'src' + path.sep + 'fixture.css\nmsg1\nmsg2')) + assert(fancyLog.info.calledWith('gulp-postcss:', 'src' + path.sep + 'fixture.css\nmsg1\nmsg2')) cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + stream.write(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath })) stream.end() @@ -464,8 +504,8 @@ describe('PostCSS Guidelines', function () { var stream = postcss([ doubler ], options) var cssPath = __dirname + '/src/fixture.css' postcssStub.process.returns(Promise.resolve({ - css: '' - , warnings: function () { + css: '', + warnings: function () { return [] } })) @@ -480,9 +520,9 @@ describe('PostCSS Guidelines', function () { cb() }) - stream.write(new gutil.File({ - contents: new Buffer('a {}') - , path: cssPath + stream.write(new Vinyl({ + contents: Buffer.from('a {}'), + path: cssPath })) stream.end()