Skip to content

Commit 6af7f8f

Browse files
authored
Merge pull request #167 from Rubik0000/fix/import-multiple-dots
Issue #166 Fix import of sass files without extension containing multiple dots (like common.mixins.scss)
2 parents b18b7f9 + 3770d7a commit 6af7f8f

File tree

9 files changed

+57
-5
lines changed

9 files changed

+57
-5
lines changed

src/plugin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import {OnLoadResult, Plugin} from 'esbuild'
22
import {dirname} from 'path'
33
import {SassPluginOptions} from './index'
4-
import {getContext, makeModule, modulesPaths, parseNonce, posixRelative} from './utils'
4+
import {getContext, makeModule, modulesPaths, parseNonce, posixRelative, DEFAULT_FILTER} from './utils'
55
import {useCache} from './cache'
66
import {createRenderer} from './render'
77
import {initAsyncCompiler} from 'sass-embedded'
88

9-
const DEFAULT_FILTER = /\.(s[ac]ss|css)$/
10-
119
/**
1210
*
1311
* @param options

src/render.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {dirname, parse, relative, resolve, sep} from 'path'
22
import fs, {readFileSync} from 'fs'
3-
import {createResolver, fileSyntax, sourceMappingURL} from './utils'
3+
import {createResolver, fileSyntax, sourceMappingURL, DEFAULT_FILTER} from './utils'
44
import {PartialMessage} from 'esbuild'
55
import * as sass from 'sass-embedded'
66
import {ImporterResult, initAsyncCompiler} from 'sass-embedded'
@@ -53,7 +53,7 @@ export function createRenderer(compiler: AsyncCompiler, options: SassPluginOptio
5353
function resolveRelativeImport(loadPath: string, filename: string): string | null {
5454
const absolute = resolve(loadPath, filename)
5555
const pathParts = parse(absolute)
56-
if (pathParts.ext) {
56+
if (DEFAULT_FILTER.test(pathParts.ext)) {
5757
return resolveImport(pathParts.dir + sep + pathParts.name, pathParts.ext)
5858
} else {
5959
return resolveImport(absolute)

src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {SyncOpts} from 'resolve'
99

1010
const cwd = process.cwd()
1111

12+
export const DEFAULT_FILTER = /\.(s[ac]ss|css)$/
13+
1214
export const posixRelative = require('path').sep === '/'
1315
? (path: string) => `css-chunk:${relative(cwd, path)}`
1416
: (path: string) => `css-chunk:${relative(cwd, path).replace(/\\/g, '/')}`

test/bugfixes.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,20 @@ describe('tests covering github issues', function () {
311311
'names': []
312312
})
313313
})
314+
315+
it('#166 Import of sass files without extension containing multiple dots (like common.mixins.scss)', async function () {
316+
const options = useFixture('../issues/166')
317+
318+
await esbuild.build({
319+
...options,
320+
entryPoints: ['./index.scss'],
321+
outdir: './out',
322+
bundle: true,
323+
plugins: [
324+
sassPlugin()
325+
]
326+
})
327+
328+
expect(readTextFile('out/index.css')).to.equalIgnoreSpaces(readTextFile('snapshot/index.css'))
329+
})
314330
})

test/issues/166/app.component.sass

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$_radius: 3px
2+
3+
.button
4+
border-radius: $_radius

test/issues/166/common.mixins.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$_padding: 10px;
2+
3+
@mixin padded {
4+
padding: $_padding;
5+
}

test/issues/166/common.styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a:active {
2+
color: crimson;
3+
}

test/issues/166/index.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@use "./common.mixins" as c;
2+
@use "./app.component";
3+
@use "./common.styles";
4+
5+
$font-stack: Helvetica, sans-serif;
6+
$primary-color: #333;
7+
8+
body {
9+
font: 100% $font-stack;
10+
color: $primary-color;
11+
@include c.padded;
12+
}

test/issues/166/snapshot/index.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* index.scss */
2+
.button {
3+
border-radius: 3px;
4+
}
5+
a:active {
6+
color: crimson;
7+
}
8+
body {
9+
font: 100% Helvetica, sans-serif;
10+
color: #333;
11+
padding: 10px;
12+
}

0 commit comments

Comments
 (0)