Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
2.7 KiB
JavaScript
Raw Permalink Normal View History

/*
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",
"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",
"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",
"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",
"unsupported-@charset",
"unsupported-@namespace",
"unsupported-css-property",
2024-06-14 16:33:52 +08:00
"unsupported-css-nesting",
"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",
"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-08-01 10:51:31 +08:00
export default function esbuildPluginThrowWarnings({
allowDynamicRequire,
allowDynamicImport,
isAllowedWarning,
2022-08-01 10:51:31 +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,
};
build.onEnd((result) => {
if (result.errors.length > 0) {
return;
}
for (const warning of result.warnings) {
if (isAllowedWarning?.(warning)) {
continue;
}
2022-06-01 19:23:13 +08:00
if (
allowDynamicRequire &&
["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;
}
console.log(warning);
throw new Error(warning.text);
}
});
},
};
}