@@ -6,15 +6,10 @@ var path = require('path');
6
6
7
7
var testFolder = path . resolve ( __dirname , '../' ) ;
8
8
var error = 'error' ;
9
- var filesWithTildeImports = [
10
- 'imports' , 'import-other-style' , 'import-css'
11
- ] ;
12
9
13
10
function createSpec ( ext ) {
14
11
var basePath = path . join ( testFolder , ext ) ;
15
- var nodeModulesPath = path . join ( testFolder , 'node_modules' ) ;
16
- var tildeReplacement = path . relative ( basePath , nodeModulesPath ) + path . sep ;
17
- var sassError ;
12
+ var testModulePath = path . relative ( basePath , path . join ( testFolder , 'node_modules' , 'test-module' ) ) ;
18
13
19
14
fs . readdirSync ( path . join ( testFolder , ext ) )
20
15
. filter ( function ( file ) {
@@ -23,41 +18,22 @@ function createSpec(ext) {
23
18
. map ( function ( file ) {
24
19
var fileName = path . join ( basePath , file ) ;
25
20
var fileWithoutExt = file . slice ( 0 , - ext . length - 1 ) ;
26
- var oldFileContent ;
27
- var newFileContent ;
28
21
var css ;
29
22
30
- if ( filesWithTildeImports . indexOf ( fileWithoutExt ) > - 1 ) {
31
- // We need to replace all occurrences of '~' with relative paths
32
- // so node-sass finds the imported files without webpack's resolving algorithm
33
- oldFileContent = fs . readFileSync ( fileName , 'utf8' ) ;
34
- newFileContent = oldFileContent . replace ( / ~ / g, tildeReplacement ) ;
35
- fs . writeFileSync ( fileName , newFileContent , 'utf8' ) ;
36
- }
37
-
38
- try {
39
- css = sass . renderSync ( {
40
- file : fileName ,
41
- includePaths : [
42
- path . join ( testFolder , ext , 'another' ) ,
43
- path . join ( testFolder , ext , 'from-include-path' )
44
- ]
45
- } ) . css ;
46
- fs . writeFileSync ( path . join ( basePath , 'spec' , fileWithoutExt + '.css' ) , css , 'utf8' ) ;
47
- } catch ( err ) {
48
- // Capture the sass error, but don't crash the script in order to roll-back all temporary file changes
49
- sassError = err ;
50
- }
51
-
52
- if ( filesWithTildeImports . indexOf ( fileWithoutExt ) > - 1 ) {
53
- fs . writeFileSync ( fileName , oldFileContent , 'utf8' ) ;
54
- }
23
+ css = sass . renderSync ( {
24
+ file : fileName ,
25
+ importer : function ( url ) {
26
+ return {
27
+ file : url . replace ( / ^ ~ t e s t - m o d u l e / , testModulePath )
28
+ } ;
29
+ } ,
30
+ includePaths : [
31
+ path . join ( testFolder , ext , 'another' ) ,
32
+ path . join ( testFolder , ext , 'from-include-path' )
33
+ ]
34
+ } ) . css ;
35
+ fs . writeFileSync ( path . join ( basePath , 'spec' , fileWithoutExt + '.css' ) , css , 'utf8' ) ;
55
36
} ) ;
56
-
57
- if ( sassError ) {
58
- // Now we can throw the sass error
59
- throw sassError ;
60
- }
61
37
}
62
38
63
39
module . exports = createSpec ;
0 commit comments