2022-06-19 19:12:51 +08:00
|
|
|
/*
|
|
|
|
|
Open https://esbuild.github.io/api/#log-override, run
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
[...document.querySelectorAll('details > summary > code')].map(code => code.textContent)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
in console to get all message ids.
|
|
|
|
|
*/
|
2022-06-01 19:23:13 +08:00
|
|
|
const ESBUILD_MESSAGE_IDS = [
|
2024-06-14 16:33:52 +08:00
|
|
|
"assert-to-with",
|
|
|
|
|
"assert-type-json",
|
2022-06-01 19:23:13 +08:00
|
|
|
"assign-to-constant",
|
2024-06-14 16:33:52 +08:00
|
|
|
"assign-to-define",
|
2022-06-19 19:12:51 +08:00
|
|
|
"assign-to-import",
|
2022-06-01 19:23:13 +08:00
|
|
|
"call-import-namespace",
|
2024-06-14 16:33:52 +08:00
|
|
|
"class-name-will-throw",
|
2022-06-01 19:23:13 +08:00
|
|
|
"commonjs-variable-in-esm",
|
|
|
|
|
"delete-super-property",
|
2024-06-14 16:33:52 +08:00
|
|
|
"direct-eval",
|
2022-06-01 19:23:13 +08:00
|
|
|
"duplicate-case",
|
2024-06-14 16:33:52 +08:00
|
|
|
"duplicate-class-member",
|
2022-06-01 19:23:13 +08:00
|
|
|
"duplicate-object-key",
|
|
|
|
|
"empty-import-meta",
|
|
|
|
|
"equals-nan",
|
|
|
|
|
"equals-negative-zero",
|
|
|
|
|
"equals-new-object",
|
|
|
|
|
"html-comment-in-js",
|
|
|
|
|
"impossible-typeof",
|
2022-06-19 19:12:51 +08:00
|
|
|
"indirect-require",
|
2022-06-01 19:23:13 +08:00
|
|
|
"private-name-will-throw",
|
|
|
|
|
"semicolon-after-return",
|
|
|
|
|
"suspicious-boolean-not",
|
2024-06-14 16:33:52 +08:00
|
|
|
"suspicious-define",
|
|
|
|
|
"suspicious-logical-operator",
|
|
|
|
|
"suspicious-nullish-coalescing",
|
2022-06-01 19:23:13 +08:00
|
|
|
"this-is-undefined-in-esm",
|
|
|
|
|
"unsupported-dynamic-import",
|
|
|
|
|
"unsupported-jsx-comment",
|
|
|
|
|
"unsupported-regexp",
|
|
|
|
|
"unsupported-require-call",
|
2022-06-19 19:12:51 +08:00
|
|
|
"css-syntax-error",
|
|
|
|
|
"invalid-@charset",
|
|
|
|
|
"invalid-@import",
|
|
|
|
|
"invalid-@layer",
|
|
|
|
|
"invalid-calc",
|
|
|
|
|
"js-comment-in-css",
|
2024-06-14 16:33:52 +08:00
|
|
|
"undefined-composes-from",
|
2022-06-19 19:12:51 +08:00
|
|
|
"unsupported-@charset",
|
|
|
|
|
"unsupported-@namespace",
|
|
|
|
|
"unsupported-css-property",
|
2024-06-14 16:33:52 +08:00
|
|
|
"unsupported-css-nesting",
|
2022-06-19 19:12:51 +08:00
|
|
|
"ambiguous-reexport",
|
2022-06-01 19:23:13 +08:00
|
|
|
"different-path-case",
|
2024-06-14 16:33:52 +08:00
|
|
|
"empty-glob",
|
2022-06-01 19:23:13 +08:00
|
|
|
"ignored-bare-import",
|
|
|
|
|
"ignored-dynamic-import",
|
|
|
|
|
"import-is-undefined",
|
|
|
|
|
"require-resolve-not-external",
|
2022-06-19 19:12:51 +08:00
|
|
|
"invalid-source-mappings",
|
|
|
|
|
"sections-in-source-map",
|
|
|
|
|
"missing-source-map",
|
|
|
|
|
"unsupported-source-map-comment",
|
|
|
|
|
"package.json",
|
2022-06-01 19:23:13 +08:00
|
|
|
"tsconfig.json",
|
|
|
|
|
];
|
|
|
|
|
const logOverride = Object.fromEntries(
|
|
|
|
|
ESBUILD_MESSAGE_IDS.map((id) => [id, "warning"]),
|
|
|
|
|
);
|
2022-03-15 22:07:36 +08:00
|
|
|
|
2022-08-01 10:51:31 +08:00
|
|
|
export default function esbuildPluginThrowWarnings({
|
|
|
|
|
allowDynamicRequire,
|
|
|
|
|
allowDynamicImport,
|
2026-10-02 03:39:47 +08:00
|
|
|
isAllowedWarning,
|
2022-08-01 10:51:31 +08:00
|
|
|
}) {
|
2022-03-15 22:07:36 +08:00
|
|
|
return {
|
|
|
|
|
name: "throw-warnings",
|
|
|
|
|
setup(build) {
|
2022-06-01 19:23:13 +08:00
|
|
|
const options = build.initialOptions;
|
|
|
|
|
options.logOverride = {
|
|
|
|
|
...logOverride,
|
|
|
|
|
...options.logOverride,
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-20 14:04:30 +08:00
|
|
|
build.onEnd((result) => {
|
|
|
|
|
if (result.errors.length > 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const warning of result.warnings) {
|
2026-10-02 03:39:47 +08:00
|
|
|
if (isAllowedWarning?.(warning)) {
|
2025-11-25 02:13:03 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-01 19:23:13 +08:00
|
|
|
if (
|
|
|
|
|
allowDynamicRequire &&
|
2022-06-19 19:12:51 +08:00
|
|
|
["unsupported-require-call", "indirect-require"].includes(
|
|
|
|
|
warning.id,
|
|
|
|
|
)
|
2022-06-01 19:23:13 +08:00
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 10:51:31 +08:00
|
|
|
if (
|
|
|
|
|
allowDynamicImport &&
|
|
|
|
|
warning.id === "unsupported-dynamic-import"
|
|
|
|
|
) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-15 22:07:36 +08:00
|
|
|
console.log(warning);
|
|
|
|
|
throw new Error(warning.text);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|