@@ -95,7 +95,15 @@ function resolvePathImporter({
95
95
See also: https://github.com/sass/dart-sass/blob/006e6aa62f2417b5267ad5cdb5ba050226fab511/lib/src/importer/node/implementation.dart
96
96
*/
97
97
98
- let containingPath = fileURLToPath ( containingUrl ) ;
98
+ let containingPath = containingUrl
99
+ ? fileURLToPath ( containingUrl )
100
+ : asset . filePath ;
101
+ if ( ! containingUrl ) {
102
+ // If containingUrl is not provided, then url should be an absolute file:/// URL.
103
+ let filePath = fileURLToPath ( url ) ;
104
+ url = path . relative ( path . dirname ( containingPath ) , filePath ) ;
105
+ }
106
+
99
107
let paths = [ path . dirname ( containingPath ) ] ;
100
108
if ( loadPaths ) {
101
109
paths . push ( ...loadPaths ) ;
@@ -110,17 +118,39 @@ function resolvePathImporter({
110
118
) ;
111
119
}
112
120
121
+ // The importer should look for stylesheets by adding the prefix _ to the URL's basename,
122
+ // and by adding the extensions .sass and .scss if the URL doesn't already have one of those extensions.
113
123
const urls = [ url ] ;
114
124
const urlFileName = path . basename ( url ) ;
115
125
if ( urlFileName [ 0 ] !== '_' ) {
116
- urls . push ( path . join ( path . dirname ( url ) , `_${ urlFileName } ` ) ) ;
126
+ urls . push ( path . posix . join ( path . dirname ( url ) , `_${ urlFileName } ` ) ) ;
117
127
}
118
128
129
+ let ext = path . extname ( urlFileName ) ;
130
+ if ( ext !== '.sass' && ext !== '.scss' ) {
131
+ for ( let url of [ ...urls ] ) {
132
+ urls . push ( url + '.sass' ) ;
133
+ urls . push ( url + '.scss' ) ;
134
+ }
135
+ }
136
+
137
+ // If none of the possible paths is valid, the importer should perform the same resolution on the URL followed by /index.
138
+ urls . push ( path . posix . join ( url , 'index.sass' ) ) ;
139
+ urls . push ( path . posix . join ( url , 'index.scss' ) ) ;
140
+ urls . push ( path . posix . join ( url , '_index.sass' ) ) ;
141
+ urls . push ( path . posix . join ( url , '_index.scss' ) ) ;
142
+
119
143
if ( url [ 0 ] !== '~' ) {
120
144
for ( let p of paths ) {
121
145
for ( let u of urls ) {
122
- const filePath = path . resolve ( p , u ) ;
123
- if ( await asset . fs . exists ( filePath ) ) {
146
+ let filePath = path . resolve ( p , u ) ;
147
+ let stat ;
148
+ try {
149
+ stat = await asset . fs . stat ( filePath ) ;
150
+ } catch ( err ) {
151
+ // ignore.
152
+ }
153
+ if ( stat ?. isFile ( ) ) {
124
154
return pathToFileURL ( filePath ) ;
125
155
}
126
156
0 commit comments