@@ -9,6 +9,7 @@ import { Options } from './options';
9
9
import { createLogger } from './helpers/logger' ;
10
10
import * as postcss from 'postcss' ;
11
11
import * as postcssIcssSelectors from 'postcss-icss-selectors' ;
12
+ import * as dotenv from 'dotenv' ;
12
13
13
14
const removePlugin = postcss . plugin ( 'remove-mixins' , ( ) => ( css ) => {
14
15
css . walkRules ( ( rule ) => {
@@ -184,6 +185,26 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
184
185
} ;
185
186
}
186
187
188
+ // apply .env file at project root to current process environment ++ TODO: Instead, manually open .env and parse just the SASS_PATH part
189
+ const projectDir = info . project . getCurrentDirectory ( ) ;
190
+ dotenv . config ( { path : path . resolve ( projectDir , '.env' ) } ) ;
191
+
192
+ // manually convert relative paths in SASS_PATH to absolute, lest they be resolved relative to process.cwd which would almost certainly be wrong
193
+ if ( process . env . SASS_PATH ) {
194
+ const sassPaths = process . env . SASS_PATH . split ( path . delimiter ) ;
195
+
196
+ for (
197
+ var i = 0 , currPath = sassPaths [ i ] ;
198
+ i < sassPaths . length ;
199
+ currPath = sassPaths [ ++ i ]
200
+ ) {
201
+ if ( path . isAbsolute ( currPath ) ) continue ;
202
+ sassPaths [ i ] = path . resolve ( projectDir , currPath ) ; // resolve relative path against project directory
203
+ }
204
+ // update SASS_PATH with new paths
205
+ process . env . SASS_PATH = sassPaths . join ( path . delimiter ) ;
206
+ }
207
+
187
208
return info . languageService ;
188
209
}
189
210
0 commit comments