Skip to content

Commit

Permalink
fix: uniform sass error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Anidetrix committed May 13, 2020
1 parent 23d6645 commit 49655a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
6 changes: 1 addition & 5 deletions __tests__/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

exports[`less not found 1`] = `"You need to install \`less\` package in order to process Less files"`;

exports[`load-sass not found 1`] = `
"You need to install one of the following packages:
\`node-sass\`, \`sass\`
in order to process Sass files"
`;
exports[`load-sass not found 1`] = `"You need to install \`node-sass\` or \`sass\` package in order to process Sass files"`;

exports[`load-sass wrong implementation 1`] = `"Could not load \`swass\` Sass implementation"`;

Expand Down
17 changes: 10 additions & 7 deletions src/loaders/sass/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ import loadModule from "../../utils/load-module";
type SassImplementation = NonNullable<SASSLoaderOptions["impl"]>;
const allSassIDs = ["node-sass", "sass"] as const;

const idFmt = allSassIDs
.map((id, i, arr) => {
const newId = `\`${id}\``;
if (i === arr.length - 2) return newId;
if (i === arr.length - 1) return `or ${newId}`;
return `${newId},`;
})
.join(" ");

export async function loadSass(impl?: SassImplementation): Promise<[Sass, SassImplementation]> {
const sassIDs = impl ? ([impl] as const) : allSassIDs;

Expand All @@ -16,11 +25,5 @@ export async function loadSass(impl?: SassImplementation): Promise<[Sass, SassIm
if (impl) throw new Error(`Could not load \`${impl}\` Sass implementation`);
}

throw new Error(
[
"You need to install one of the following packages:",
allSassIDs.map(id => `\`${id}\``).join(", "),
"in order to process Sass files",
].join("\n"),
);
throw new Error(`You need to install ${idFmt} package in order to process Sass files`);
}

0 comments on commit 49655a4

Please sign in to comment.