@@ -9,7 +9,6 @@ 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' ;
13
12
14
13
const removePlugin = postcss . plugin ( 'remove-mixins' , ( ) => ( css ) => {
15
14
css . walkRules ( ( rule ) => {
@@ -29,6 +28,8 @@ function getPostCssConfig(dir: string) {
29
28
}
30
29
}
31
30
31
+ const sassPathRegex = / ^ S A S S _ P A T H = ( .+ ) / m;
32
+
32
33
function init ( { typescript : ts } : { typescript : typeof ts_module } ) {
33
34
let _isCSS : isCSSFn ;
34
35
@@ -185,23 +186,29 @@ function init({ typescript: ts }: { typescript: typeof ts_module }) {
185
186
} ;
186
187
}
187
188
188
- // apply .env file at project root to current process environment ++ TODO: Instead, manually open .env and parse just the SASS_PATH part
189
189
const projectDir = info . project . getCurrentDirectory ( ) ;
190
- dotenv . config ( { path : path . resolve ( projectDir , '.env' ) } ) ;
190
+ const dotenvPath = path . resolve ( projectDir , '.env' ) ; // MAYBE TODO: custom .env file name/path in Options?
191
+
192
+ // Manually open .env and parse just the SASS_PATH part,
193
+ // because we don't *need* to apply the full .env to this environment,
194
+ // and we are not sure doing so wouldn't have side effects
195
+ const dotenv = fs . readFileSync ( dotenvPath , { encoding : 'utf8' } ) ;
196
+ const sassPathMatch = sassPathRegex . exec ( dotenv ) ;
191
197
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 ) ;
198
+ if ( sassPathMatch && sassPathMatch [ 1 ] ) {
199
+ const sassPaths = sassPathMatch [ 1 ] . split ( path . delimiter ) ;
195
200
201
+ // Manually convert relative paths in SASS_PATH to absolute,
202
+ // lest they be resolved relative to process.cwd which would almost certainly be wrong
196
203
for (
197
204
var i = 0 , currPath = sassPaths [ i ] ;
198
205
i < sassPaths . length ;
199
206
currPath = sassPaths [ ++ i ]
200
207
) {
201
208
if ( path . isAbsolute ( currPath ) ) continue ;
202
- sassPaths [ i ] = path . resolve ( projectDir , currPath ) ; // resolve relative path against project directory
209
+ sassPaths [ i ] = path . resolve ( projectDir , currPath ) ; // resolve path relative to project directory
203
210
}
204
- // update SASS_PATH with new paths
211
+ // join modified array and assign to environment SASS_PATH
205
212
process . env . SASS_PATH = sassPaths . join ( path . delimiter ) ;
206
213
}
207
214
0 commit comments