Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -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')


Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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 () {
Expand All @@ -89,7 +90,7 @@ module.exports = withConfigLoader(function (loadConfig) {
// 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))
})
}

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
},
"homepage": "https://github.com/postcss/gulp-postcss",
"dependencies": {
"gulp-util": "^3.0.8",
"fancy-log": "^1.3.2",
"plugin-error": "^0.1.2",
"postcss": "^6.0.0",
"postcss-load-config": "^1.2.0",
"vinyl-sourcemaps-apply": "^0.2.1"
Expand All @@ -50,6 +51,7 @@
"mocha": "^3.4.2",
"nyc": "^11.0.3",
"proxyquire": "^1.8.0",
"sinon": "^2.3.5"
"sinon": "^2.3.5",
"vinyl": "^2.1.0"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vinyl should be in the devDependencies

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review, but vinyl is already in the devDependencies. 😄

https://github.com/ohbarye/gulp-postcss/blob/6f15b5127f66ba7c360625c1b5e2fec4f51c575e/package.json#L47-L56

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I got confused.

}
}
50 changes: 26 additions & 24 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
/* 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')
Expand Down Expand Up @@ -38,7 +40,7 @@ it('should transform css with multiple processors', function (cb) {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a { color: black }')
}))

Expand All @@ -61,7 +63,7 @@ it('should not transform css with out any processor', function (cb) {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer(css)
}))

Expand All @@ -74,7 +76,7 @@ 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)
Expand All @@ -86,7 +88,7 @@ it('should correctly wrap postcss errors', function (cb) {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a {'),
path: path.resolve('testpath')
}))
Expand All @@ -100,7 +102,7 @@ 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.message, 'Streams are not supported!')
Expand Down Expand Up @@ -138,7 +140,7 @@ it('should generate source maps', function (cb) {
cb()
})

init.write(new gutil.File({
init.write(new Vinyl({
base: __dirname,
path: __dirname + '/fixture.css',
contents: new Buffer('a { color: black }')
Expand All @@ -164,7 +166,7 @@ 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 }')
Expand Down Expand Up @@ -238,7 +240,7 @@ describe('PostCSS Guidelines', function () {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
}))
Expand All @@ -262,7 +264,7 @@ describe('PostCSS Guidelines', function () {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a {}')
}))

Expand All @@ -273,7 +275,7 @@ describe('PostCSS Guidelines', function () {
it('should take plugins and options from callback', function (cb) {

var cssPath = __dirname + '/fixture.css'
var file = new gutil.File({
var file = new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
})
Expand Down Expand Up @@ -305,7 +307,7 @@ 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({
var file = new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
})
Expand Down Expand Up @@ -352,7 +354,7 @@ describe('PostCSS Guidelines', function () {
assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], __dirname)
cb()
})
stream.end(new gutil.File({
stream.end(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
}))
Expand All @@ -372,7 +374,7 @@ describe('PostCSS Guidelines', function () {
assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], '/absolute/path')
cb()
})
stream.end(new gutil.File({
stream.end(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
}))
Expand All @@ -392,7 +394,7 @@ describe('PostCSS Guidelines', function () {
assert.deepEqual(postcssLoadConfigStub.getCall(0).args[1], path.join(__dirname, 'relative/path'))
cb()
})
stream.end(new gutil.File({
stream.end(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath,
base: __dirname
Expand All @@ -417,19 +419,19 @@ 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({
var file = new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
})
Expand All @@ -450,7 +452,7 @@ describe('PostCSS Guidelines', function () {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a {}')
}))

Expand All @@ -469,7 +471,7 @@ describe('PostCSS Guidelines', function () {
}
}

sandbox.stub(gutil, 'log')
sandbox.stub(fancyLog, 'info')
postcssStub.process.returns(Promise.resolve({
css: '',
warnings: function () {
Expand All @@ -478,11 +480,11 @@ describe('PostCSS Guidelines', function () {
}))

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({
stream.write(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
}))
Expand Down Expand Up @@ -517,7 +519,7 @@ describe('PostCSS Guidelines', function () {
cb()
})

stream.write(new gutil.File({
stream.write(new Vinyl({
contents: new Buffer('a {}'),
path: cssPath
}))
Expand Down