11"use strict" ;
22
33const path = require ( "path" ) ;
4+
45const async = require ( "neo-async" ) ;
6+
7+ const pify = require ( "pify" ) ;
8+
9+ const semver = require ( "semver" ) ;
10+
511const formatSassError = require ( "./formatSassError" ) ;
612const webpackImporter = require ( "./webpackImporter" ) ;
713const normalizeOptions = require ( "./normalizeOptions" ) ;
8- const pify = require ( "pify" ) ;
9- const semver = require ( "semver" ) ;
1014
1115let nodeSassJobQueue = null ;
1216
@@ -20,7 +24,7 @@ function sassLoader(content) {
2024 const callback = this . async ( ) ;
2125 const isSync = typeof callback !== "function" ;
2226 const self = this ;
23- const resourcePath = this . resourcePath ;
27+ const { resourcePath } = this ;
2428
2529 function addNormalizedDependency ( file ) {
2630 // node-sass returns POSIX paths
@@ -43,36 +47,48 @@ function sassLoader(content) {
4347 return ;
4448 }
4549
50+ // eslint-disable-next-line import/no-extraneous-dependencies, global-require
4651 const render = getRenderFuncFromSassImpl ( options . implementation || require ( "node-sass" ) ) ;
4752
4853 render ( options , ( err , result ) => {
4954 if ( err ) {
5055 formatSassError ( err , this . resourcePath ) ;
51- err . file && this . dependency ( err . file ) ;
56+
57+ if ( err . file ) {
58+ this . dependency ( err . file ) ;
59+ }
60+
5261 callback ( err ) ;
5362 return ;
5463 }
5564
5665 if ( result . map && result . map !== "{}" ) {
66+ // eslint-disable-next-line no-param-reassign
5767 result . map = JSON . parse ( result . map ) ;
5868 // result.map.file is an optional property that provides the output filename.
5969 // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.
70+ // eslint-disable-next-line no-param-reassign
6071 delete result . map . file ;
6172 // The first source is 'stdin' according to node-sass because we've used the data input.
6273 // Now let's override that value with the correct relative path.
6374 // Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in normalizeOptions,
6475 // we know that this path is relative to process.cwd(). This is how node-sass works.
76+ // eslint-disable-next-line no-param-reassign
6577 result . map . sources [ 0 ] = path . relative ( process . cwd ( ) , resourcePath ) ;
6678 // node-sass returns POSIX paths, that's why we need to transform them back to native paths.
6779 // This fixes an error on windows where the source-map module cannot resolve the source maps.
6880 // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722
81+ // eslint-disable-next-line no-param-reassign
6982 result . map . sourceRoot = path . normalize ( result . map . sourceRoot ) ;
83+ // eslint-disable-next-line no-param-reassign
7084 result . map . sources = result . map . sources . map ( path . normalize ) ;
7185 } else {
86+ // eslint-disable-next-line no-param-reassign
7287 result . map = null ;
7388 }
7489
7590 result . stats . includedFiles . forEach ( addNormalizedDependency ) ;
91+
7692 callback ( null , result . css . toString ( ) , result . map ) ;
7793 } ) ;
7894}
@@ -84,29 +100,30 @@ function sassLoader(content) {
84100 * @returns {Function }
85101 */
86102function getRenderFuncFromSassImpl ( module ) {
87- const info = module . info ;
103+ const { info } = module ;
88104 const components = info . split ( "\t" ) ;
89105
90106 if ( components . length < 2 ) {
91- throw new Error ( " Unknown Sass implementation \"" + info + "\"." ) ;
107+ throw new Error ( ` Unknown Sass implementation " ${ info } ".` ) ;
92108 }
93109
94- const implementation = components [ 0 ] ;
95- const version = components [ 1 ] ;
110+ const [ implementation , version ] = components ;
96111
97112 if ( ! semver . valid ( version ) ) {
98- throw new Error ( " Invalid Sass version \"" + version + "\"." ) ;
113+ throw new Error ( ` Invalid Sass version " ${ version } ".` ) ;
99114 }
100115
101116 if ( implementation === "dart-sass" ) {
102117 if ( ! semver . satisfies ( version , "^1.3.0" ) ) {
103- throw new Error ( " Dart Sass version " + version + " is incompatible with ^1.3.0." ) ;
118+ throw new Error ( ` Dart Sass version ${ version } is incompatible with ^1.3.0.` ) ;
104119 }
120+
105121 return module . render . bind ( module ) ;
106122 } else if ( implementation === "node-sass" ) {
107123 if ( ! semver . satisfies ( version , "^4.0.0" ) ) {
108- throw new Error ( " Node Sass version " + version + " is incompatible with ^4.0.0." ) ;
124+ throw new Error ( ` Node Sass version ${ version } is incompatible with ^4.0.0.` ) ;
109125 }
126+
110127 // There is an issue with node-sass when async custom importers are used
111128 // See https://github.com/sass/node-sass/issues/857#issuecomment-93594360
112129 // We need to use a job queue to make sure that one thread is always available to the UV lib
@@ -118,7 +135,8 @@ function getRenderFuncFromSassImpl(module) {
118135
119136 return nodeSassJobQueue . push . bind ( nodeSassJobQueue ) ;
120137 }
121- throw new Error ( "Unknown Sass implementation \"" + implementation + "\"." ) ;
138+
139+ throw new Error ( `Unknown Sass implementation "${ implementation } ".` ) ;
122140}
123141
124142module . exports = sassLoader ;
0 commit comments