From 9acf0c84b316aa7579ae7bafd42ff548d2ea6a50 Mon Sep 17 00:00:00 2001 From: Marco Solazzi Date: Fri, 6 Jan 2023 19:10:50 +0900 Subject: [PATCH] fix: ensure sass output file has css extension --- src/loaders/sass.ts | 4 ++-- test/fixture/src/demo.scss | 5 +++++ test/index.test.ts | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/fixture/src/demo.scss diff --git a/src/loaders/sass.ts b/src/loaders/sass.ts index c9c841a7..e8e84dba 100644 --- a/src/loaders/sass.ts +++ b/src/loaders/sass.ts @@ -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; } @@ -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; diff --git a/test/fixture/src/demo.scss b/test/fixture/src/demo.scss new file mode 100644 index 00000000..d4f43ffe --- /dev/null +++ b/test/fixture/src/demo.scss @@ -0,0 +1,5 @@ +$color: green; + +.test { + color: $color; +} diff --git a/test/index.test.ts b/test/index.test.ts index 3e99fb2f..11d82f96 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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", @@ -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", @@ -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", () => {