Skip to content

Commit 3a59549

Browse files
committed
fix(Compilers): fix sass imports
1 parent 19f0b82 commit 3a59549

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/livecodes/languages/scss/lang-scss-compiler.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { getLanguageCustomSettings } from '../../utils';
3838
});
3939
};
4040

41-
const result = sass.compileString(code, {
41+
const result = await sass.compileStringAsync(code, {
4242
...customSettings,
4343
syntax,
4444
importers: [
@@ -48,26 +48,33 @@ import { getLanguageCustomSettings } from '../../utils';
4848
},
4949
load(canonicalUrl: URL) {
5050
const urlString = canonicalUrl.href;
51+
const extension = '.' + language; // .scss or .sass
5152
return fetchStyles(urlString)
53+
.catch(() => fetchStyles(urlString + extension))
54+
.catch(() => fetchStyles(urlString + '.css'))
5255
.catch(() => {
5356
const urlParts = urlString.split('/');
5457
const filename = urlParts[urlParts.length - 1];
5558
const prefix = filename.startsWith('_') ? '' : '_';
56-
urlParts[urlParts.length - 1] = prefix + filename + '.scss';
59+
urlParts[urlParts.length - 1] = prefix + filename + extension;
5760
return fetchStyles(urlParts.join('/'));
5861
})
59-
.catch(() => fetchStyles(urlString + '.scss'))
62+
.catch(() => fetchStyles(urlString + '/_index' + extension))
6063
.catch(
6164
() =>
6265
new Promise((resolve, reject) => {
6366
fetch(urlString + '/package.json')
6467
.then((res) => res.json())
6568
.then((pkg) => {
66-
if (pkg.sass) {
67-
baseUrl = urlString + '/' + pkg.sass;
68-
resolve(fetchStyles(baseUrl));
69-
} else if (pkg.style) {
70-
baseUrl = urlString + '/' + pkg.style;
69+
let stylePath = pkg.style || pkg.sass;
70+
if (!stylePath) {
71+
const main = pkg.main;
72+
if (main && (main.endsWith(extension) || main.endsWith('.css'))) {
73+
stylePath = main;
74+
}
75+
}
76+
if (stylePath) {
77+
baseUrl = urlString + '/' + stylePath;
7178
resolve(fetchStyles(baseUrl));
7279
} else {
7380
reject('Not found');

0 commit comments

Comments
 (0)