1- var assign = require ( 'object-assign-deep' ) ;
2- var autoprefixer = require ( 'autoprefixer' ) ;
3- var bemLinter = require ( 'postcss-bem-linter' ) ;
4- var cssnano = require ( 'cssnano' ) ;
5- var difference = require ( 'lodash.difference' ) ;
6- var encapsulationPlugins = require ( './encapsulation' ) ;
7- var isEmpty = require ( 'lodash.isempty' ) ;
8- var postcss = require ( 'postcss' ) ;
9- var postcssEasyImport = require ( 'postcss-easy-import' ) ;
10- var reporter = require ( 'postcss-reporter' ) ;
11- var stylelint = require ( 'stylelint' ) ;
12- var stylelintConfigSuit = require ( 'stylelint-config-suitcss' ) ;
1+ 'use strict' ;
2+
3+ const assign = require ( 'object-assign-deep' ) ;
4+ const autoprefixer = require ( 'autoprefixer' ) ;
5+ const bemLinter = require ( 'postcss-bem-linter' ) ;
6+ const cssnano = require ( 'cssnano' ) ;
7+ const difference = require ( 'lodash.difference' ) ;
8+ const encapsulationPlugins = require ( './encapsulation' ) ;
9+ const isEmpty = require ( 'lodash.isempty' ) ;
10+ const postcssEasyImport = require ( 'postcss-easy-import' ) ;
11+ const reporter = require ( 'postcss-reporter' ) ;
12+ const stylelint = require ( 'stylelint' ) ;
13+ const stylelintConfigSuit = require ( 'stylelint-config-suitcss' ) ;
14+ let postcss = require ( 'postcss' ) ; // eslint-disable-line prefer-const
1315
1416module . exports = preprocessor ;
1517
@@ -18,7 +20,7 @@ module.exports = preprocessor;
1820 * and options to PostCSS plugins
1921 */
2022
21- var defaults = {
23+ const defaults = {
2224 debug : identity ,
2325 lint : true ,
2426 minify : false ,
@@ -31,8 +33,8 @@ var defaults = {
3133 'postcss-apply'
3234 ] ,
3335 autoprefixer : {
34- browsers : ' > 1%, last 2 versions, safari > 6, ie > 9, ' +
35- ' ios > 6, android > 4.3, samsung > 3, chromeandroid > 50'
36+ browsers : ` > 1%, last 2 versions, safari > 6, ie > 9,
37+ ios > 6, android > 4.3, samsung > 3, chromeandroid > 50`
3638 } ,
3739 'postcss-easy-import' : {
3840 transform : identity ,
@@ -62,14 +64,14 @@ var defaults = {
6264function preprocessor ( css , options , filename ) {
6365 options = mergeOptions ( options ) ;
6466
65- var plugins = [
67+ let plugins = [
6668 postcssEasyImport ( options [ 'postcss-easy-import' ] )
6769 ] ;
6870
6971 plugins = plugins . concat (
70- options . use . map ( function ( p ) {
71- var plugin = require ( p ) ;
72- var settings = options [ p ] ;
72+ options . use . map ( p => {
73+ const plugin = require ( p ) ;
74+ const settings = options [ p ] ;
7375 return settings ? plugin ( settings ) : plugin ;
7476 } )
7577 ) ;
@@ -88,15 +90,14 @@ function preprocessor(css, options, filename) {
8890 reporter ( options [ 'postcss-reporter' ] )
8991 ] ) ;
9092
91- var processor = postcss ( options . debug ( plugins ) ) ;
93+ const processor = postcss ( options . debug ( plugins ) ) ;
9294
9395 if ( options . minify ) {
9496 processor . use ( cssnano ( options . cssnano ) ) ;
9597 }
9698
97- return lintFile ( css , options , filename ) . then ( function ( result ) {
98- return processor . process ( result . css , options . postcss ) ;
99- } ) ;
99+ return lintFile ( css , options , filename )
100+ . then ( result => processor . process ( result . css , options . postcss ) ) ;
100101}
101102
102103/**
@@ -108,33 +109,31 @@ function preprocessor(css, options, filename) {
108109
109110function mergeOptions ( options ) {
110111 options = options || { } ;
111- var mergedOpts = assign ( { } , defaults , options ) ;
112- var easyImportOpts = mergedOpts [ 'postcss-easy-import' ] ;
113- var origTransform = easyImportOpts . transform ;
114- var origOnImport = easyImportOpts . onImport ;
112+ const mergedOpts = assign ( { } , defaults , options ) ;
113+ const easyImportOpts = mergedOpts [ 'postcss-easy-import' ] ;
114+ const origTransform = easyImportOpts . transform ;
115+ const origOnImport = easyImportOpts . onImport ;
115116
116117 if ( mergedOpts . root ) {
117118 easyImportOpts . root = mergedOpts . root ;
118119 }
119120
120- easyImportOpts . transform = function ( css , filename ) {
121- var transformedCss = origTransform ( css ) ;
122- return lintFile ( transformedCss , mergedOpts , filename ) . then ( function ( result ) {
123- return result . css ;
124- } ) ;
121+ easyImportOpts . transform = ( css , filename ) => {
122+ const transformedCss = origTransform ( css ) ;
123+ return lintFile ( transformedCss , mergedOpts , filename ) . then ( result => result . css ) ;
125124 } ;
126125
127- easyImportOpts . onImport = function ( importedFiles ) {
126+ easyImportOpts . onImport = importedFiles => {
128127 updateWatchTaskFiles ( importedFiles ) ;
129128 origOnImport ( importedFiles ) ;
130129 } ;
131130
132131 // Allow additional plugins to be merged with the defaults
133132 // but remove any duplicates so that it respects the new order
134133 if ( ! isEmpty ( options . use ) ) {
135- var plugins = difference ( mergedOpts . use , options . use ) ;
134+ const plugins = difference ( mergedOpts . use , options . use ) ;
136135 // Remove core plugins. Can't reorder them
137- var userPlugins = difference ( options . use , [
136+ const userPlugins = difference ( options . use , [
138137 'postcss-easy-import' ,
139138 'autoprefixer' ,
140139 'postcss-reporter'
@@ -153,7 +152,7 @@ function mergeOptions(options) {
153152 * @returns {Promise } Used by postcss-import transform
154153 */
155154function lintFile ( css , options , filename ) {
156- var processor = postcss ( ) ;
155+ const processor = postcss ( ) ;
157156
158157 if ( options . lint ) {
159158 processor
@@ -170,9 +169,7 @@ function lintFile(css, options, filename) {
170169 . use ( reporter ( options [ 'postcss-reporter' ] ) ) ;
171170
172171 if ( isPromise ( css ) ) {
173- return css . then ( function ( css ) { // eslint-disable-line no-shadow
174- return processor . process ( css , options . postcss ) ;
175- } ) ;
172+ return css . then ( css => processor . process ( css , options . postcss ) ) ; // eslint-disable-line no-shadow
176173 }
177174
178175 return processor . process ( css , options . postcss ) ;
0 commit comments