Skip to content

Commit

Permalink
fix: Fix name conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ntt261298 committed May 27, 2022
1 parent 1cc987c commit 65b0ea9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ export async function jestPreviewConfigure(
});
}

let sassLoadFullPaths: string[] = [];
// Save sassLoadPaths to cache, so we can use it in the transformer
let sassLoadPathsConfig: string[] = [];
// Save sassLoadPathsConfig to cache, so we can use it in the transformer
if (sassLoadPaths) {
sassLoadFullPaths = sassLoadPaths.map((path) => `${process.cwd()}/${path}`);
sassLoadPathsConfig = sassLoadPaths.map(
(path) => `${process.cwd()}/${path}`,
);

createCacheFolderIfNeeded();

fs.writeFileSync(
path.join(CACHE_FOLDER, SASS_LOAD_PATHS_CONFIG),
JSON.stringify(sassLoadFullPaths),
JSON.stringify(sassLoadPathsConfig),
);
}

Expand All @@ -64,7 +66,7 @@ export async function jestPreviewConfigure(
'.css',
);

const sassLoadPathsConfig = sassLoadFullPaths.reduce(
const sassLoadPathsCLIConfig = sassLoadPathsConfig.reduce(
(currentConfig, nextLoadPath) =>
`${currentConfig} --load-path ${nextLoadPath}`,
'',
Expand All @@ -84,7 +86,7 @@ export async function jestPreviewConfigure(
'node_modules',
'.bin',
'sass',
)} ${cssFile} ${cssDestinationFile} --no-source-map ${sassLoadPathsConfig}`,
)} ${cssFile} ${cssDestinationFile} --no-source-map ${sassLoadPathsCLIConfig}`,
(err: any) => {
if (err) {
console.log(err);
Expand Down
8 changes: 4 additions & 4 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ function processSass(src: string, filename: string): TransformedSource {
SASS_LOAD_PATHS_CONFIG,
);

let sassLoadPaths: string[];
let sassLoadPathsConfig: string[];
if (fs.existsSync(sassLoadPathsConfigPath)) {
const sassLoadPathsString = fs
.readFileSync(path.join(CACHE_FOLDER, SASS_LOAD_PATHS_CONFIG), 'utf8')
.trim();
sassLoadPaths = JSON.parse(sassLoadPathsString);
sassLoadPathsConfig = JSON.parse(sassLoadPathsString);
} else {
sassLoadPaths = [];
sassLoadPathsConfig = [];
}

const cssResult = sass.compile(filename, {
loadPaths: sassLoadPaths,
loadPaths: sassLoadPathsConfig,
importers: [
{
// An importer that redirects relative URLs starting with "~" to `node_modules`
Expand Down

0 comments on commit 65b0ea9

Please sign in to comment.