@@ -88,53 +88,69 @@ PathCache.prototype.allDeps = function() {
88
88
function resolvers ( options , webpackResolver ) {
89
89
var evaluator = new Evaluator ( nodes . null , options ) ;
90
90
var whenWebpackResolver = whenNodefn . lift ( webpackResolver ) ;
91
- return [
92
- // Stylus's normal resolver for single files.
93
- function ( context , path ) {
94
- // Stylus adds .styl to paths for normal "paths" lookup if it isn't there.
95
- if ( ! / .s t y l $ / . test ( path ) ) {
96
- path += '.styl' ;
97
- }
98
91
99
- var paths = options . paths . concat ( context ) ;
100
- var found = utils . find ( path , paths , options . filename )
101
- if ( found ) {
102
- return normalizePaths ( found ) ;
103
- }
104
- } ,
105
- // Stylus's normal resolver for node_modules packages. Cannot locate paths
106
- // inside a package.
107
- function ( context , path ) {
108
- // Stylus calls the argument name. If it exists it should match the name
109
- // of a module in node_modules.
110
- if ( ! path ) {
111
- return null ;
112
- }
92
+ // Stylus's normal resolver for single files.
93
+ var stylusFile = function ( context , path ) {
94
+ // Stylus adds .styl to paths for normal "paths" lookup if it isn't there.
95
+ if ( ! / .s t y l $ / . test ( path ) ) {
96
+ path += '.styl' ;
97
+ }
113
98
114
- var paths = options . paths . concat ( context ) ;
115
- var found = utils . lookupIndex ( path , paths , options . filename ) ;
116
- if ( found ) {
117
- return { path : normalizePaths ( found ) , index : true } ;
118
- }
119
- } ,
120
- // Fallback to resolving with webpack's configured resovler.
121
- function ( context , path ) {
122
- // Follow the webpack stylesheet idiom of '~path' meaning a path in a
123
- // modules folder and a unprefixed 'path' meaning a relative path like
124
- // './path'.
125
- path = loaderUtils . urlToRequest ( path , options . root ) ;
126
- // First try with a '.styl' extension.
127
- return whenWebpackResolver ( context , path + '.styl' )
128
- // If the user adds ".styl" to resolve.extensions, webpack can find
129
- // index files like stylus but it uses all of webpack's configuration,
130
- // by default for example the module could be web_modules.
131
- . catch ( function ( ) { return whenWebpackResolver ( context , path ) ; } )
132
- . catch ( function ( ) { return null ; } )
133
- . then ( function ( result ) {
134
- return Array . isArray ( result ) && result [ 1 ] && result [ 1 ] . path || result
135
- } ) ;
99
+ var paths = options . paths . concat ( context ) ;
100
+ var found = utils . find ( path , paths , options . filename )
101
+ if ( found ) {
102
+ return normalizePaths ( found ) ;
103
+ }
104
+ } ;
105
+
106
+ // Stylus's normal resolver for node_modules packages. Cannot locate paths
107
+ // inside a package.
108
+ var stylusIndex = function ( context , path ) {
109
+ // Stylus calls the argument name. If it exists it should match the name
110
+ // of a module in node_modules.
111
+ if ( ! path ) {
112
+ return null ;
136
113
}
137
- ] ;
114
+
115
+ var paths = options . paths . concat ( context ) ;
116
+ var found = utils . lookupIndex ( path , paths , options . filename ) ;
117
+ if ( found ) {
118
+ return { path : normalizePaths ( found ) , index : true } ;
119
+ }
120
+ } ;
121
+
122
+ // Fallback to resolving with webpack's configured resovler.
123
+ var webpackResolve = function ( context , path ) {
124
+ // Follow the webpack stylesheet idiom of '~path' meaning a path in a
125
+ // modules folder and a unprefixed 'path' meaning a relative path like
126
+ // './path'.
127
+ path = loaderUtils . urlToRequest ( path , options . root ) ;
128
+ // First try with a '.styl' extension.
129
+ return whenWebpackResolver ( context , path + '.styl' )
130
+ // If the user adds ".styl" to resolve.extensions, webpack can find
131
+ // index files like stylus but it uses all of webpack's configuration,
132
+ // by default for example the module could be web_modules.
133
+ . catch ( function ( ) { return whenWebpackResolver ( context , path ) ; } )
134
+ . catch ( function ( ) { return null ; } )
135
+ . then ( function ( result ) {
136
+ return Array . isArray ( result ) && result [ 1 ] && result [ 1 ] . path || result
137
+ } ) ;
138
+ } ;
139
+
140
+ if ( options . preferPathResolver === 'webpack' ) {
141
+ return [
142
+ webpackResolve ,
143
+ stylusFile ,
144
+ stylusIndex
145
+ ] ;
146
+ }
147
+ else {
148
+ return [
149
+ stylusFile ,
150
+ stylusIndex ,
151
+ webpackResolve
152
+ ] ;
153
+ }
138
154
}
139
155
140
156
function reduceResolvers ( resolvers , context , path ) {
0 commit comments