Skip to content

Commit 89aba0e

Browse files
committed
fix: πŸ› try to use sass before node-sass
βœ… Closes: #163
1 parent 763d46f commit 89aba0e

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

Diff for: β€Žsrc/transformers/scss.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const transformer: Transformer<Options.Sass> = async ({
2828
let implementation = options?.implementation ?? sass;
2929

3030
if (implementation == null) {
31-
const mod = await importAny('node-sass', 'sass');
31+
const mod = await importAny('sass', 'node-sass');
3232

3333
// eslint-disable-next-line no-multi-assign
3434
implementation = sass = mod.default;

Diff for: β€Žtest/transformers/scss.test.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable global-require */
2+
/* eslint-disable @typescript-eslint/no-require-imports */
3+
14
import { resolve } from 'path';
25

36
import autoPreprocess from '../../src';
@@ -30,22 +33,34 @@ const implementation: Options.Sass['implementation'] = {
3033
};
3134

3235
describe('transformer - scss', () => {
33-
it('should prepend scss content via `data` option property - via default async render', async () => {
34-
const template = `<style lang="scss"></style>`;
36+
it('should return @imported files as dependencies - via default async render', async () => {
37+
const template = `<style lang="scss">@import "fixtures/style.scss";</style>`;
3538
const opts = autoPreprocess({
3639
scss: {
37-
prependData: '$color:red;div{color:$color}',
40+
// we force the node-sass implementation here because of
41+
// https://github.com/sveltejs/svelte-preprocess/issues/163#issuecomment-639694477
42+
implementation: require('node-sass'),
3843
},
3944
});
4045

4146
const preprocessed = await preprocess(template, opts);
4247

43-
expect(preprocessed.toString()).toContain('red');
48+
expect(preprocessed.dependencies).toContain(
49+
resolve(__dirname, '..', 'fixtures', 'style.scss').replace(/[\\/]/g, '/'),
50+
);
4451
});
4552

46-
it('should return @imported files as dependencies - via default async render', async () => {
53+
it('should return @imported files as dependencies - via renderSync', async () => {
4754
const template = `<style lang="scss">@import "fixtures/style.scss";</style>`;
48-
const opts = autoPreprocess();
55+
const opts = autoPreprocess({
56+
scss: {
57+
// we force the node-sass implementation here because of
58+
// https://github.com/sveltejs/svelte-preprocess/issues/163#issuecomment-639694477
59+
implementation: require('node-sass'),
60+
renderSync: true,
61+
},
62+
});
63+
4964
const preprocessed = await preprocess(template, opts);
5065

5166
expect(preprocessed.dependencies).toContain(
@@ -80,21 +95,6 @@ describe('transformer - scss', () => {
8095
expect(preprocessed.toString()).toContain('blue');
8196
});
8297

83-
it('should return @imported files as dependencies - via renderSync', async () => {
84-
const template = `<style lang="scss">@import "fixtures/style.scss";</style>`;
85-
const opts = autoPreprocess({
86-
scss: {
87-
renderSync: true,
88-
},
89-
});
90-
91-
const preprocessed = await preprocess(template, opts);
92-
93-
expect(preprocessed.dependencies).toContain(
94-
resolve(__dirname, '..', 'fixtures', 'style.scss').replace(/[\\/]/g, '/'),
95-
);
96-
});
97-
9898
it('should use the specified implementation via the `implementation` option property - via renderSync', async () => {
9999
const template = `<style lang="scss">h1{}</style>`;
100100
const opts = autoPreprocess({

0 commit comments

Comments
Β (0)