Skip to content

Commit 5b0ac99

Browse files
authored
4.0.0 - deprecate support for node v4,v5. Address security vulnerabilities (#66)
* deprecate support for node v4,v5. Address security vulnerabilities * remove unnecessary file
1 parent e92b1fa commit 5b0ac99

10 files changed

+4693
-2981
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
end_of_line = lf
7+
indent_size = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
.idea
2-
*.node
3-
sandbox
2+
.coverage
43
node_modules
5-
coverage
64
test/**/*.generated.*
7-
test/**/*.min.css
5+
test/**/*.min.css

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,4 @@ node_js:
55
- "8"
66
- "7"
77
- "6"
8-
- "5"
9-
- "4"
10-
after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
8+
after_script: "cat ./.coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"

gulpfile.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

index.js

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,61 @@
1-
'use strict';
2-
31
const applySourceMap = require('vinyl-sourcemaps-apply');
42
const CleanCSS = require('clean-css');
53
const path = require('path');
64
const PluginError = require('plugin-error');
75
const through = require('through2');
86

9-
module.exports = function gulpCleanCSS(options, callback) {
10-
11-
options = Object.assign(options || {});
7+
module.exports = (options, callback) => {
128

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

16-
let transform = function (file, enc, cb) {
17-
18-
if (!file || !file.contents)
19-
return cb(null, file);
12+
return through.obj(function (file, enc, cb) {
2013

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

26-
if (file.sourceMap)
27-
options.sourceMap = JSON.parse(JSON.stringify(file.sourceMap));
28-
29-
let contents = file.contents ? file.contents.toString() : '';
30-
let pass = {[file.path]: {styles: contents}};
31-
if (!options.rebaseTo && options.rebase !== false) {
32-
options.rebaseTo = path.dirname(file.path);
19+
if (file.sourceMap) {
20+
_options.sourceMap = JSON.parse(JSON.stringify(file.sourceMap));
3321
}
3422

35-
new CleanCSS(options).minify(pass, function (errors, css) {
23+
const content = {
24+
[file.path]: {styles: file.contents.toString()}
25+
};
26+
if (!_options.rebaseTo && _options.rebase !== false) {
27+
_options.rebaseTo = path.dirname(file.path);
28+
}
3629

37-
if (errors)
30+
new CleanCSS(_options).minify(content, (errors, css) => {
31+
if (errors) {
3832
return cb(errors.join(' '));
33+
}
3934

40-
if (typeof callback === 'function') {
41-
let details = {
42-
'stats': css.stats,
43-
'errors': css.errors,
44-
'warnings': css.warnings,
45-
'path': file.path,
46-
'name': file.path.split(file.base)[1]
47-
};
48-
49-
if (css.sourceMap)
50-
details['sourceMap'] = css.sourceMap;
35+
let details = {
36+
'stats': css.stats,
37+
'errors': css.errors,
38+
'warnings': css.warnings,
39+
'path': file.path,
40+
'name': file.path.split(file.base)[1]
41+
};
5142

52-
callback(details);
43+
if (css.sourceMap) {
44+
details['sourceMap'] = css.sourceMap;
5345
}
46+
_callback(details);
5447

55-
file.contents = new Buffer(css.styles);
48+
file.contents = new Buffer.from(css.styles);
5649

5750
if (css.sourceMap) {
58-
59-
let map = JSON.parse(css.sourceMap);
60-
map.file = path.relative(file.base, file.path);
61-
map.sources = map.sources.map(function (src) {
62-
return path.relative(file.base, file.path)
51+
const iMap = JSON.parse(css.sourceMap);
52+
const oMap = Object.assign({}, iMap, {
53+
file: path.relative(file.base, file.path),
54+
sources: iMap.sources.map(() => path.relative(file.base, file.path))
6355
});
64-
65-
applySourceMap(file, map);
56+
applySourceMap(file, oMap);
6657
}
67-
6858
cb(null, file);
6959
});
70-
};
71-
72-
return through.obj(transform);
73-
};
60+
});
61+
};

0 commit comments

Comments
 (0)