Build: Add a plugin to throw unexpected warnings (#12463)
This commit is contained in:
1 parent
6fa3966d8a
commit
34dcd96922
2 files changed
+27
-1
No files matched your search
@@ -12,6 +12,7 @@ import esbuildPluginReplaceText from "./esbuild-plugins/replace-text.mjs";
|
||||
import esbuildPluginLicense from "./esbuild-plugins/license.mjs";
|
||||
import esbuildPluginUmd from "./esbuild-plugins/umd.mjs";
|
||||
import esbuildPluginVisualizer from "./esbuild-plugins/visualizer.mjs";
|
||||
import esbuildPluginThrowWarnings from "./esbuild-plugins/throw-warnings.mjs";
|
||||
import bundles from "./config.mjs";
|
||||
|
||||
const { __dirname, readJsonSync, require } = createEsmUtils(import.meta);
|
||||
@@ -170,6 +171,7 @@ function* getEsbuildOptions(bundle, buildOptions) {
|
||||
}),
|
||||
buildOptions.reports &&
|
||||
esbuildPluginVisualizer({ formats: buildOptions.reports }),
|
||||
esbuildPluginThrowWarnings(),
|
||||
].filter(Boolean),
|
||||
minify: shouldMinify,
|
||||
legalComments: "none",
|
||||
@@ -242,7 +244,9 @@ async function runBuild(bundle, esbuildOptions, buildOptions) {
|
||||
await esbuild.build({
|
||||
...esbuildOptions,
|
||||
define: {},
|
||||
plugins: plugins.filter(({ name }) => name === "umd"),
|
||||
plugins: plugins.filter(
|
||||
({ name }) => name === "umd" || name === "throw-warnings"
|
||||
),
|
||||
entryPoints: [outfile],
|
||||
allowOverwrite: true,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
const ignoredWarnings = new Set([
|
||||
// Duplicated case clause
|
||||
"This case clause will never be evaluated because it duplicates an earlier case clause",
|
||||
]);
|
||||
|
||||
export default function esbuildPluginThrowWarnings() {
|
||||
return {
|
||||
name: "throw-warnings",
|
||||
setup(build) {
|
||||
build.onEnd(({ warnings }) => {
|
||||
for (const warning of warnings) {
|
||||
if (ignoredWarnings.has(warning.text)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(warning);
|
||||
throw new Error(warning.text);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user