Skip to content

Commit 21e3086

Browse files
committed
fix: πŸ› make postcss config error explicit
βœ… Closes: #298
1 parent 00f065e commit 21e3086

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Diff for: β€Žsrc/transformers/postcss.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ async function process({
3333

3434
async function getConfigFromFile(
3535
options: Options.Postcss,
36-
): Promise<Options.Postcss | null> {
36+
): Promise<{ config: Options.Postcss | null; error: string | null }> {
3737
try {
3838
/** If not, look for a postcss config file */
3939
const { default: postcssLoadConfig } = await import(`postcss-load-config`);
@@ -43,12 +43,18 @@ async function getConfigFromFile(
4343
);
4444

4545
return {
46-
plugins: loadedConfig.plugins,
47-
// `postcss-load-config` puts all other props in a `options` object
48-
...loadedConfig.options,
46+
error: null,
47+
config: {
48+
plugins: loadedConfig.plugins,
49+
// `postcss-load-config` puts all other props in a `options` object
50+
...loadedConfig.options,
51+
},
4952
};
5053
} catch (e) {
51-
return null;
54+
return {
55+
config: null,
56+
error: e,
57+
};
5258
}
5359
}
5460

@@ -59,20 +65,20 @@ const transformer: Transformer<Options.Postcss> = async ({
5965
options = {},
6066
map,
6167
}) => {
62-
let fileConfig: Options.Postcss;
68+
let fileConfig: { config: Options.Postcss; error: string };
6369

6470
if (!options.plugins) {
6571
fileConfig = await getConfigFromFile(options);
66-
options = { ...options, ...fileConfig };
72+
options = { ...options, ...fileConfig.config };
6773
}
6874

6975
if (options.plugins || options.syntax || options.parser) {
7076
return process({ options, content, filename, sourceMap: map });
7177
}
7278

73-
if (fileConfig === null) {
79+
if (fileConfig.error !== null) {
7480
console.error(
75-
`[svelte-preprocess] PostCSS configuration was not passed. If you expect to load it from a file make sure to install "postcss-load-config" and try again.`,
81+
`[svelte-preprocess] PostCSS configuration was not passed or is invalid. If you expect to load it from a file make sure to install "postcss-load-config" and try again.\n\n${fileConfig.error}`,
7682
);
7783
}
7884

0 commit comments

Comments
Β (0)