-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4.0.0 - deprecate support for node v4,v5. Address security vulnerabil…
…ities (#66) * deprecate support for node v4,v5. Address security vulnerabilities * remove unnecessary file
- Loading branch information
Showing
10 changed files
with
4,693 additions
and
2,981 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}); | ||
}; |
Oops, something went wrong.