Skip to content

Commit

Permalink
4.0.0 - deprecate support for node v4,v5. Address security vulnerabil…
Browse files Browse the repository at this point in the history
…ities (#66)

* deprecate support for node v4,v5. Address security vulnerabilities

* remove unnecessary file
  • Loading branch information
scniro authored Nov 21, 2018
1 parent e92b1fa commit 5b0ac99
Show file tree
Hide file tree
Showing 10 changed files with 4,693 additions and 2,981 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.idea
*.node
sandbox
.coverage
node_modules
coverage
test/**/*.generated.*
test/**/*.min.css
test/**/*.min.css
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ node_js:
- "8"
- "7"
- "6"
- "5"
- "4"
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
after_script: "cat ./.coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
20 changes: 0 additions & 20 deletions gulpfile.js

This file was deleted.

78 changes: 33 additions & 45 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,61 @@
'use strict';

const applySourceMap = require('vinyl-sourcemaps-apply');
const CleanCSS = require('clean-css');
const path = require('path');
const PluginError = require('plugin-error');
const through = require('through2');

module.exports = function gulpCleanCSS(options, callback) {

options = Object.assign(options || {});
module.exports = (options, callback) => {

if (arguments.length === 1 && Object.prototype.toString.call(arguments[0]) === '[object Function]')
callback = arguments[0];
let _options = Object.assign({}, options || {});
let _callback = callback || (o => undefined);

let transform = function (file, enc, cb) {

if (!file || !file.contents)
return cb(null, file);
return through.obj(function (file, enc, cb) {

if (file.isStream()) {
this.emit('error', new PluginError('gulp-clean-css', 'Streaming not supported!'));
return cb(null, file);
}

if (file.sourceMap)
options.sourceMap = JSON.parse(JSON.stringify(file.sourceMap));

let contents = file.contents ? file.contents.toString() : '';
let pass = {[file.path]: {styles: contents}};
if (!options.rebaseTo && options.rebase !== false) {
options.rebaseTo = path.dirname(file.path);
if (file.sourceMap) {
_options.sourceMap = JSON.parse(JSON.stringify(file.sourceMap));
}

new CleanCSS(options).minify(pass, function (errors, css) {
const content = {
[file.path]: {styles: file.contents.toString()}
};
if (!_options.rebaseTo && _options.rebase !== false) {
_options.rebaseTo = path.dirname(file.path);
}

if (errors)
new CleanCSS(_options).minify(content, (errors, css) => {
if (errors) {
return cb(errors.join(' '));
}

if (typeof callback === 'function') {
let details = {
'stats': css.stats,
'errors': css.errors,
'warnings': css.warnings,
'path': file.path,
'name': file.path.split(file.base)[1]
};

if (css.sourceMap)
details['sourceMap'] = css.sourceMap;
let details = {
'stats': css.stats,
'errors': css.errors,
'warnings': css.warnings,
'path': file.path,
'name': file.path.split(file.base)[1]
};

callback(details);
if (css.sourceMap) {
details['sourceMap'] = css.sourceMap;
}
_callback(details);

file.contents = new Buffer(css.styles);
file.contents = new Buffer.from(css.styles);

if (css.sourceMap) {

let map = JSON.parse(css.sourceMap);
map.file = path.relative(file.base, file.path);
map.sources = map.sources.map(function (src) {
return path.relative(file.base, file.path)
const iMap = JSON.parse(css.sourceMap);
const oMap = Object.assign({}, iMap, {
file: path.relative(file.base, file.path),
sources: iMap.sources.map(() => path.relative(file.base, file.path))
});

applySourceMap(file, map);
applySourceMap(file, oMap);
}

cb(null, file);
});
};

return through.obj(transform);
};
});
};
Loading

0 comments on commit 5b0ac99

Please sign in to comment.