33const { type } = require ( "os" ) ;
44
55Object . defineProperty ( exports , "__esModule" , {
6- value : true ,
6+ value : true
77} ) ;
88exports . errorFactory = errorFactory ;
99exports . getLessImplementation = getLessImplementation ;
1010exports . getLessOptions = getLessOptions ;
1111exports . isUnsupportedUrl = isUnsupportedUrl ;
1212exports . normalizeSourceMap = normalizeSourceMap ;
1313var _path = _interopRequireDefault ( require ( "path" ) ) ;
14- function _interopRequireDefault ( e ) {
15- return e && e . __esModule ? e : { default : e } ;
16- }
14+ function _interopRequireDefault ( e ) { return e && e . __esModule ? e : { default : e } ; }
1715/* eslint-disable class-methods-use-this */
1816const trailingSlash = / [ / \\ ] $ / ;
1917
@@ -32,8 +30,7 @@ const IS_NATIVE_WIN32_PATH = /^[a-z]:[/\\]|^\\\\/i;
3230// - ~@org/
3331// - ~@org/package
3432// - ~@org/package/
35- const IS_MODULE_IMPORT =
36- / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
33+ const IS_MODULE_IMPORT = / ^ ~ ( [ ^ / ] + | [ ^ / ] + \/ | @ [ ^ / ] + [ / ] [ ^ / ] + | @ [ ^ / ] + \/ ? | @ [ ^ / ] + [ / ] [ ^ / ] + \/ ) $ / ;
3734const MODULE_REQUEST_REGEX = / ^ [ ^ ? ] * ~ / ;
3835
3936/**
@@ -51,7 +48,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
5148 mainFields : [ "less" , "style" , "main" , "..." ] ,
5249 mainFiles : [ "index" , "..." ] ,
5350 extensions : [ ".less" , ".css" ] ,
54- preferRelative : true ,
51+ preferRelative : true
5552 } ) ;
5653 class WebpackFileManager extends implementation . FileManager {
5754 supports ( filename ) {
@@ -105,10 +102,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
105102 async loadFile ( filename , ...args ) {
106103 let result ;
107104 try {
108- if (
109- IS_SPECIAL_MODULE_IMPORT . test ( filename ) ||
110- lessOptions . webpackImporter === "only"
111- ) {
105+ if ( IS_SPECIAL_MODULE_IMPORT . test ( filename ) || lessOptions . webpackImporter === "only" ) {
112106 const error = new Error ( ) ;
113107 error . type = "Next" ;
114108 throw error ;
@@ -121,18 +115,13 @@ function createWebpackLessPlugin(loaderContext, implementation) {
121115 try {
122116 result = await this . resolveFilename ( filename , ...args ) ;
123117 } catch ( webpackResolveError ) {
124- error . message =
125- `Less resolver error:\n${ error . message } \n\n` +
126- `Webpack resolver error details:\n${ webpackResolveError . details } \n\n` +
127- `Webpack resolver error missing:\n${ webpackResolveError . missing } \n\n` ;
118+ error . message = `Less resolver error:\n${ error . message } \n\n` + `Webpack resolver error details:\n${ webpackResolveError . details } \n\n` + `Webpack resolver error missing:\n${ webpackResolveError . missing } \n\n` ;
128119 return Promise . reject ( error ) ;
129120 }
130121 loaderContext . addDependency ( result ) ;
131122 return super . loadFile ( result , ...args ) ;
132123 }
133- const absoluteFilename = _path . default . isAbsolute ( result . filename )
134- ? result . filename
135- : _path . default . resolve ( "." , result . filename ) ;
124+ const absoluteFilename = _path . default . isAbsolute ( result . filename ) ? result . filename : _path . default . resolve ( "." , result . filename ) ;
136125 loaderContext . addDependency ( _path . default . normalize ( absoluteFilename ) ) ;
137126 return result ;
138127 }
@@ -141,7 +130,7 @@ function createWebpackLessPlugin(loaderContext, implementation) {
141130 install ( lessInstance , pluginManager ) {
142131 pluginManager . addFileManager ( new WebpackFileManager ( ) ) ;
143132 } ,
144- minVersion : [ 3 , 0 , 0 ] ,
133+ minVersion : [ 3 , 0 , 0 ]
145134 } ;
146135}
147136
@@ -154,23 +143,16 @@ function createWebpackLessPlugin(loaderContext, implementation) {
154143 * @returns {Object }
155144 */
156145function getLessOptions ( loaderContext , loaderOptions , implementation ) {
157- const options =
158- typeof loaderOptions . lessOptions === "function"
159- ? loaderOptions . lessOptions ( loaderContext ) || { }
160- : loaderOptions . lessOptions || { } ;
146+ const options = typeof loaderOptions . lessOptions === "function" ? loaderOptions . lessOptions ( loaderContext ) || { } : loaderOptions . lessOptions || { } ;
161147 const lessOptions = {
162148 plugins : [ ] ,
163149 relativeUrls : true ,
164150 // We need to set the filename because otherwise our WebpackFileManager will receive an undefined path for the entry
165151 filename : loaderContext . resourcePath ,
166- ...options ,
152+ ...options
167153 } ;
168154 const plugins = lessOptions . plugins . slice ( ) ;
169- const shouldUseWebpackImporter =
170- typeof loaderOptions . webpackImporter === "boolean" ||
171- loaderOptions . webpackImporter === "only"
172- ? loaderOptions . webpackImporter
173- : true ;
155+ const shouldUseWebpackImporter = typeof loaderOptions . webpackImporter === "boolean" || loaderOptions . webpackImporter === "only" ? loaderOptions . webpackImporter : true ;
174156 if ( shouldUseWebpackImporter ) {
175157 plugins . unshift ( createWebpackLessPlugin ( loaderContext , implementation ) ) ;
176158 }
@@ -179,7 +161,7 @@ function getLessOptions(loaderContext, loaderOptions, implementation) {
179161 // eslint-disable-next-line no-param-reassign
180162 pluginManager . webpackLoaderContext = loaderContext ;
181163 lessOptions . pluginManager = pluginManager ;
182- } ,
164+ }
183165 } ) ;
184166 lessOptions . plugins = plugins ;
185167 return lessOptions ;
@@ -207,9 +189,7 @@ function normalizeSourceMap(map) {
207189
208190 // `less` returns POSIX paths, that's why we need to transform them back to native paths.
209191 // eslint-disable-next-line no-param-reassign
210- newMap . sources = newMap . sources . map ( ( source ) =>
211- _path . default . normalize ( source ) ,
212- ) ;
192+ newMap . sources = newMap . sources . map ( source => _path . default . normalize ( source ) ) ;
213193 return newMap ;
214194}
215195function getLessImplementation ( loaderContext , implementation ) {
@@ -219,7 +199,7 @@ function getLessImplementation(loaderContext, implementation) {
219199 resolvedImplementation = require ( "less/lib/less-node/index.js" ) . default ;
220200 } else if ( typeof implementation === "string" ) {
221201 // eslint-disable-next-line import/no-dynamic-require, global-require
222- resolvedImplementation = require ( implementation ) ;
202+ resolvedImplementation = require ( implementation )
223203 }
224204 // eslint-disable-next-line consistent-return
225205 return resolvedImplementation ;
@@ -237,16 +217,9 @@ function getFileExcerptIfPossible(error) {
237217 return excerpt ;
238218}
239219function errorFactory ( error ) {
240- const message = [
241- "\n" ,
242- ...getFileExcerptIfPossible ( error ) ,
243- error . message . charAt ( 0 ) . toUpperCase ( ) + error . message . slice ( 1 ) ,
244- error . filename
245- ? ` Error in ${ _path . default . normalize ( error . filename ) } (line ${ error . line } , column ${ error . column } )`
246- : "" ,
247- ] . join ( "\n" ) ;
220+ const message = [ "\n" , ...getFileExcerptIfPossible ( error ) , error . message . charAt ( 0 ) . toUpperCase ( ) + error . message . slice ( 1 ) , error . filename ? ` Error in ${ _path . default . normalize ( error . filename ) } (line ${ error . line } , column ${ error . column } )` : "" ] . join ( "\n" ) ;
248221 const obj = new Error ( message , {
249- cause : error ,
222+ cause : error
250223 } ) ;
251224 obj . stack = null ;
252225 return obj ;
0 commit comments