Skip to content

Commit eb98923

Browse files
authored
Skip URL imports in the SCSS compiler (#2289)
1 parent b697baa commit eb98923

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

โ€Žpackages/knip/src/compilers/scss.tsโ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getUrlSpecifier, isScopedPackage, isTildePackage, splitSpec } from './shared.ts';
22
import type { CompilerSync } from './types.ts';
3+
import { hasUrlScheme } from '../util/url.ts';
34

45
// https://sass-lang.com/documentation/at-rules/
56

@@ -35,7 +36,7 @@ export const compiler: CompilerSync = text => {
3536
continue;
3637
}
3738
let spec = match[2];
38-
if (!spec || spec.startsWith('sass:')) continue;
39+
if (!spec || spec.startsWith('//') || hasUrlScheme(spec)) continue;
3940
let isBare = Boolean(match[1]) || isScopedPackage(spec);
4041
if (isTildePackage(spec)) {
4142
spec = spec.slice(1);

โ€Žpackages/knip/test/compilers/scss-url.test.tsโ€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@ import _$3 from './query.jpg';
3232
import _$4 from '@fontsource-variable/archivo/files/archivo.woff2';`
3333
);
3434
});
35+
36+
test('Skip SCSS imports with a URL scheme', () => {
37+
const scss = `@import 'https://fonts.googleapis.com/css2?family=Roboto';
38+
@import '//fonts.googleapis.com/css2?family=Roboto';
39+
@import "http://example.com/a.css";
40+
@use 'sass:math';
41+
@import './local';`;
42+
43+
assert.equal(
44+
compiler(scss, 'styles.scss'),
45+
`import _$0 from './local.scss';
46+
import _$1 from './_local.scss';
47+
import _$2 from './local.sass';
48+
import _$3 from './_local.sass';`
49+
);
50+
});

0 commit comments

Comments
ย (0)