@@ -1499,6 +1499,42 @@ function loadPreprocessor(
1499
1499
}
1500
1500
}
1501
1501
1502
+ // in unix, scss might append `location.href` in environments that shim `location`
1503
+ // see https://github.com/sass/dart-sass/issues/710
1504
+ function cleanScssBugUrl ( url : string ) {
1505
+ if (
1506
+ // check bug via `window` and `location` global
1507
+ typeof window !== 'undefined' &&
1508
+ typeof location !== 'undefined'
1509
+ ) {
1510
+ const prefix = location . href . replace ( / \/ $ / , '' )
1511
+ return url . replace ( prefix , '' )
1512
+ } else {
1513
+ return url
1514
+ }
1515
+ }
1516
+
1517
+ function fixScssBugImportValue (
1518
+ data : Sass . ImporterReturnType
1519
+ ) : Sass . ImporterReturnType {
1520
+ // the scss bug doesn't load files properly so we have to load it ourselves
1521
+ // to prevent internal error when it loads itself
1522
+ if (
1523
+ // check bug via `window` and `location` global
1524
+ typeof window !== 'undefined' &&
1525
+ typeof location !== 'undefined' &&
1526
+ data &&
1527
+ // @ts -expect-error
1528
+ data . file &&
1529
+ // @ts -expect-error
1530
+ data . contents == null
1531
+ ) {
1532
+ // @ts -expect-error
1533
+ data . contents = fs . readFileSync ( data . file , 'utf-8' )
1534
+ }
1535
+ return data
1536
+ }
1537
+
1502
1538
// .scss/.sass processor
1503
1539
const scss : SassStylePreprocessor = async (
1504
1540
source ,
@@ -1507,11 +1543,14 @@ const scss: SassStylePreprocessor = async (
1507
1543
resolvers
1508
1544
) => {
1509
1545
const render = loadPreprocessor ( PreprocessLang . sass , root ) . render
1546
+ // NOTE: `sass` always runs it's own importer first, and only falls back to
1547
+ // the `importer` option when it can't resolve a path
1510
1548
const internalImporter : Sass . Importer = ( url , importer , done ) => {
1549
+ importer = cleanScssBugUrl ( importer )
1511
1550
resolvers . sass ( url , importer ) . then ( ( resolved ) => {
1512
1551
if ( resolved ) {
1513
1552
rebaseUrls ( resolved , options . filename , options . alias , '$' )
1514
- . then ( ( data ) => done ?.( data ) )
1553
+ . then ( ( data ) => done ?.( fixScssBugImportValue ( data ) ) )
1515
1554
. catch ( ( data ) => done ?.( data ) )
1516
1555
} else {
1517
1556
done ?.( null )
@@ -1556,7 +1595,7 @@ const scss: SassStylePreprocessor = async (
1556
1595
}
1557
1596
} )
1558
1597
} )
1559
- const deps = result . stats . includedFiles
1598
+ const deps = result . stats . includedFiles . map ( ( f ) => cleanScssBugUrl ( f ) )
1560
1599
const map : ExistingRawSourceMap | undefined = result . map
1561
1600
? JSON . parse ( result . map . toString ( ) )
1562
1601
: undefined
0 commit comments