diff --git a/src/configure.ts b/src/configure.ts index a39f9075..951e05bd 100644 --- a/src/configure.ts +++ b/src/configure.ts @@ -31,16 +31,18 @@ export async function jestPreviewConfigure( }); } - let sassLoadPaths: string[] = []; - // Save sassLoadPaths to cache, so we can use it in the transformer - if (sassLoadPaths) { - sassLoadPaths = sassLoadPaths.map((path) => `${process.cwd()}/${path}`); + let sassLoadPathsConfig: string[] = []; + // Save sassLoadPathsConfig to cache, so we can use it in the transformer + if (sassLoadPaths.length > 0) { + sassLoadPathsConfig = sassLoadPaths.map( + (path) => `${process.cwd()}/${path}`, + ); createCacheFolderIfNeeded(); fs.writeFileSync( path.join(CACHE_FOLDER, SASS_LOAD_PATHS_CONFIG), - JSON.stringify(sassLoadPaths), + JSON.stringify(sassLoadPathsConfig), ); } @@ -60,7 +62,7 @@ export async function jestPreviewConfigure( '.css', ); - const sassLoadPathsConfig = sassLoadPaths.reduce( + const sassLoadPathsCLIConfig = sassLoadPathsConfig.reduce( (currentConfig, nextLoadPath) => `${currentConfig} --load-path ${nextLoadPath}`, '', @@ -74,7 +76,7 @@ export async function jestPreviewConfigure( // Todo: Support import ~ for configured scss // Currently, we cannot find the option to pass `importer` to sass CLI: https://sass-lang.com/documentation/cli/dart-sass#options exec( - `./node_modules/.bin/sass ${cssFile} ${cssDestinationFile} --no-source-map ${sassLoadPathsConfig}`, + `./node_modules/.bin/sass ${cssFile} ${cssDestinationFile} --no-source-map ${sassLoadPathsCLIConfig}`, (err: any) => { if (err) { console.log(err); diff --git a/src/transform.ts b/src/transform.ts index 9d75321a..b61ea0db 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -136,18 +136,18 @@ function processSass(src: string, filename: string): string { SASS_LOAD_PATHS_CONFIG, ); - let sassLoadPaths: string[]; + let sassLoadPathsConfig: string[]; if (fs.existsSync(sassLoadPathsConfigPath)) { - const sassLoadPathsString = fs + const sassLoadPathsConfigString = fs .readFileSync(path.join(CACHE_FOLDER, SASS_LOAD_PATHS_CONFIG), 'utf8') .trim(); - sassLoadPaths = JSON.parse(sassLoadPathsString); + sassLoadPathsConfig = JSON.parse(sassLoadPathsConfigString); } else { - sassLoadPaths = []; + sassLoadPathsConfig = []; } const cssResult = sass.compile(filename, { - loadPaths: sassLoadPaths, + loadPaths: sassLoadPathsConfig, importers: [ { // An importer that redirects relative URLs starting with "~" to `node_modules`