Skip to content

Commit

Permalink
fix: ensure sass output file has css extension
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightjack committed Jan 6, 2023
1 parent ecfd67b commit 9acf0c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/loaders/sass.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Loader, LoaderResult } from "../loader";

export const sassLoader: Loader = async (input, { options }) => {
export const sassLoader: Loader = async (input) => {
if (![".sass", ".scss"].includes(input.extension)) {
return;
}
Expand All @@ -14,7 +14,7 @@ export const sassLoader: Loader = async (input, { options }) => {
output.push({
contents: compileString(contents).css,
path: input.path,
extension: `.${options.ext || "css"}`
extension: ".css"
});

return output;
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/src/demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$color: green;

.test {
color: $color;
}
10 changes: 10 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("mkdist", () => {
const { writtenFiles } = await mkdist({ rootDir });
expect(writtenFiles.sort()).toEqual([
"dist/README.md",
"dist/demo.css",
"dist/foo.mjs",
"dist/foo.d.ts", // manual
"dist/index.mjs",
Expand Down Expand Up @@ -50,6 +51,7 @@ describe("mkdist", () => {
const { writtenFiles } = await mkdist({ rootDir, declaration: true });
expect(writtenFiles.sort()).toEqual([
"dist/README.md",
"dist/demo.css",
"dist/foo.mjs",
"dist/foo.d.ts",
"dist/index.mjs",
Expand All @@ -70,6 +72,14 @@ describe("mkdist", () => {
expect(await readFile(resolve(rootDir, "dist/foo.d.ts"), "utf8")).toMatch("manual declaration");
expect(await readFile(resolve(rootDir, "dist/bar/esm.d.mts"), "utf8")).toMatch("declare");
}, 50_000);

it("mkdist (sass compilation)", async () => {
const rootDir = resolve(__dirname, "fixture");
await mkdist({ rootDir });
const css = await readFile(resolve(rootDir, "dist/demo.css"), "utf8");

expect(css).toMatch("color: green");
});
});

describe("createLoader", () => {
Expand Down

0 comments on commit 9acf0c8

Please sign in to comment.