gulp-minify-css
Advanced tools
Comparing version 0.4.5 to 0.4.6
80
index.js
@@ -0,4 +1,6 @@ | ||
'use strict'; | ||
var path = require('path'), | ||
gutil = require('gulp-util'), | ||
CleanCSS = require('clean-css'), | ||
PluginError = require('gulp-util').PluginError, | ||
CleanCSS = require('clean-css'), | ||
through2 = require('through2'), | ||
@@ -17,13 +19,12 @@ BufferStreams = require('bufferstreams'), | ||
if (options.cache && | ||
(cached = cache.get(file.path)) && | ||
cached.raw === rawContents && | ||
objectIsEqual(cached.options, options)) { | ||
(cached = cache.get(file.path)) && | ||
cached.raw === rawContents && | ||
objectIsEqual(cached.options, options)) { | ||
// cache hit | ||
done(null, cached.minified); | ||
// cache hit | ||
done(null, cached.minified); | ||
} else { | ||
// cache miss or cache not enabled | ||
new CleanCSS(options).minify(rawContents, function (errors, css) { | ||
new CleanCSS(options).minify(rawContents, function(errors, css) { | ||
if (options.cache) { | ||
@@ -37,3 +38,8 @@ cache.put(file.path, { | ||
done(errors, css); | ||
if (errors) { | ||
done(new PluginError('minify-css', errors.join(', '))); | ||
return; | ||
} | ||
done(null, css); | ||
}); | ||
@@ -45,12 +51,14 @@ } | ||
function minifyCSSTransform(opt, file) { | ||
// Return a callback function handling the buffered content | ||
return function(err, buf, cb) { | ||
if (err) { | ||
cb(new PluginError('minify-css', err)); | ||
return; | ||
} | ||
// Handle any error | ||
if(err) cb(gutil.PluginError('minify-css', err)); | ||
// Use the buffered content | ||
minify(opt, file, buf, function (errors, data) { | ||
// Bring it back to streams | ||
minify(opt, file, buf, function(errors, data) { | ||
if (errors) { | ||
cb(new PluginError('minify-css', errors)); | ||
return; | ||
} | ||
cb(null, new Buffer(data.styles)); | ||
@@ -62,7 +70,7 @@ }); | ||
// Plugin function | ||
function minifyCSSGulp(opt){ | ||
if (!opt) opt = {}; | ||
function minifyCSSGulp (opt) { | ||
opt = opt || {}; | ||
function modifyContents(file, enc, done){ | ||
if(file.isNull()) { | ||
function modifyContents(file, enc, done) { | ||
if (file.isNull()) { | ||
done(null, file); | ||
@@ -72,3 +80,3 @@ return; | ||
if(file.isStream()) { | ||
if (file.isStream()) { | ||
file.contents = file.contents.pipe(new BufferStreams(minifyCSSTransform(opt, file))) | ||
@@ -85,3 +93,3 @@ .on('error', this.emit.bind(this, 'error')); | ||
opt.relativeTo = relativeToTmp || path.resolve(path.dirname(file.path)); | ||
// Enable sourcemap support if initialized file comes in. | ||
@@ -93,3 +101,7 @@ if (file.sourceMap) { | ||
try { | ||
minify(opt, file, file.contents, function (errors, newContents) { | ||
minify(opt, file, file.contents, function(err, newContents) { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
@@ -99,29 +111,29 @@ // Restore original "relativeTo" value | ||
file.contents = new Buffer(newContents.styles); | ||
if (newContents.sourceMap && file.sourceMap) { | ||
// clean-css gives bad 'sources' and 'file' properties because we | ||
// clean-css gives bad 'sources' and 'file' properties because we | ||
// pass in raw css instead of a file. So we fix those here. | ||
var map = JSON.parse(newContents.sourceMap); | ||
map.file = path.relative(file.base, file.path); | ||
map.sources = map.sources.map(function(src){ | ||
if(src === '__stdin__.css'){ | ||
map.sources = map.sources.map(function(src) { | ||
if (src === '__stdin__.css') { | ||
return path.relative(file.base, file.path); | ||
}else if(path.resolve( src ) === path.normalize( src )){ | ||
} else if (path.resolve(src) === path.normalize(src)) { | ||
// Path is absolute so imported file had no existing source map. | ||
// Trun absolute path in to path relative to file.base. | ||
return path.relative(file.base, src); | ||
}else{ | ||
} else { | ||
return src; | ||
} | ||
}); | ||
applySourceMap(file, map); | ||
} | ||
done(errors ? errors[0] : null, file); | ||
done(null, file); | ||
}); | ||
} catch (err) { | ||
this.emit('error', new gutil.PluginError('minify-css', err, { fileName: file.path } )); | ||
return done(null, file); | ||
this.emit('error', new PluginError('minify-css', err, {fileName: file.path})); | ||
done(null, file); | ||
} | ||
@@ -128,0 +140,0 @@ } |
{ | ||
"name": "gulp-minify-css", | ||
"description": "Minify css with clean-css.", | ||
"version": "0.4.5", | ||
"repository": "https://github.com/jonathanepollack/gulp-minify-css.git", | ||
"homepage": "https://github.com/jonathanepollack/gulp-minify-css", | ||
"version": "0.4.6", | ||
"repository": "jonathanepollack/gulp-minify-css", | ||
"keywords": [ | ||
"gulpplugin", | ||
"minify", | ||
"css" | ||
"optimize", | ||
"optimise", | ||
"compress", | ||
"css", | ||
"clean-css" | ||
], | ||
"main": "./index.js", | ||
"licenses": [ | ||
{ | ||
"type": "MIT", | ||
"url": "https://github.com/jonathanepollack/gulp-minify-css/blob/master/LICENSE" | ||
} | ||
], | ||
"files": [ | ||
"index.js" | ||
], | ||
"engines": { | ||
@@ -17,9 +28,12 @@ "node": ">= 0.10" | ||
"scripts": { | ||
"test": "mocha" | ||
"pretest": "jscs *.js test/*.js && eslint *.js test/*.js", | ||
"test": "mocha", | ||
"coverage": "istanbul cover _mocha", | ||
"coveralls": "${npm_package_scripts_coverage} && istanbul-coveralls" | ||
}, | ||
"dependencies": { | ||
"gulp-util": "~3.0.1", | ||
"clean-css": "~3.0.4", | ||
"gulp-util": "^3.0.3", | ||
"clean-css": "^3.0.4", | ||
"through2": "^0.6.1", | ||
"bufferstreams": "0.0.2", | ||
"bufferstreams": "^1.0.1", | ||
"memory-cache": "0.0.5", | ||
@@ -29,3 +43,4 @@ "vinyl-sourcemaps-apply": "^0.1.4" | ||
"devDependencies": { | ||
"chai": "^1.9.0", | ||
"chai": "^2.0.0", | ||
"eslint": "^0.14.1", | ||
"event-stream": "^3.1.0", | ||
@@ -35,10 +50,15 @@ "gulp": "^3.8.8", | ||
"gulp-stylus": "^2.0.0", | ||
"mocha": "^1.21.4", | ||
"istanbul": "^0.3.6", | ||
"istanbul-coveralls": "^1.0.1", | ||
"jscs": "^1.11.3", | ||
"mocha": "^2.1.0", | ||
"proxyquire": "^1.0.1" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT" | ||
} | ||
] | ||
"jscsConfig": { | ||
"preset": "google", | ||
"disallowMultipleVarDecl": null, | ||
"maximumLineLength": 98, | ||
"requireBlocksOnNewline": true, | ||
"validateLineBreaks": "LF" | ||
} | ||
} |
@@ -1,2 +0,3 @@ | ||
[![Build Status](https://travis-ci.org/jonathanepollack/gulp-minify-css.png?branch=master)](https://travis-ci.org/jonathanepollack/gulp-minify-css) | ||
[![Build Status](https://travis-ci.org/jonathanepollack/gulp-minify-css.svg?branch=master)](https://travis-ci.org/jonathanepollack/gulp-minify-css) | ||
[![Coverage Status](https://img.shields.io/coveralls/jonathanepollack/gulp-minify-css.svg)](https://coveralls.io/r/jonathanepollack/gulp-minify-css) | ||
@@ -33,3 +34,3 @@ ## Breaking Changes from v0.3 to v0.4 (due to clean-css) | ||
``` | ||
```sh | ||
npm install --save-dev gulp-minify-css | ||
@@ -45,3 +46,3 @@ ``` | ||
gulp.task('minify-css', function() { | ||
gulp.src('./static/css/*.css') | ||
return gulp.src('./static/css/*.css') | ||
.pipe(minifyCSS({keepBreaks:true})) | ||
@@ -85,3 +86,3 @@ .pipe(gulp.dest('./dist/')) | ||
gulp.task('minify-css', function() { | ||
gulp.src('./src/*.css') | ||
return gulp.src('./src/*.css') | ||
.pipe(sourcemaps.init()) | ||
@@ -88,0 +89,0 @@ .pipe(minifyCSS()) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
119
1
11731
11
4
118
2
+ Addedbufferstreams@1.1.3(transitive)
+ Addedclean-css@3.4.28(transitive)
+ Addedcommander@2.8.1(transitive)
+ Addedgraceful-readlink@1.0.1(transitive)
+ Addedsource-map@0.4.4(transitive)
- Removedbufferstreams@0.0.2(transitive)
- Removedclean-css@3.0.10(transitive)
- Removedcommander@2.5.1(transitive)
Updatedbufferstreams@^1.0.1
Updatedclean-css@^3.0.4
Updatedgulp-util@^3.0.3