mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
28 lines
815 B
TypeScript
28 lines
815 B
TypeScript
import type { Plugin } from "esbuild";
|
|
|
|
export const removeTestIdsPlugin: Plugin = {
|
|
name: "react-remove-testids",
|
|
setup(build) {
|
|
build.onEnd((args) => {
|
|
// data-testid regexp
|
|
const regexp = /("data-testid":)(.*?)(?:(,)|(})|(\n))/gi;
|
|
|
|
// output files with `*.js`
|
|
const jsOutputFiles =
|
|
args.outputFiles?.filter(
|
|
(el) =>
|
|
el.path.endsWith(".cjs") ||
|
|
el.path.endsWith(".mjs") ||
|
|
el.path.endsWith(".js"),
|
|
) ?? [];
|
|
|
|
// replace data-testid in output files
|
|
for (const jsOutputFile of jsOutputFiles) {
|
|
const str = new TextDecoder("utf-8").decode(jsOutputFile.contents);
|
|
const newStr = str.replace(regexp, "$4");
|
|
jsOutputFile.contents = new TextEncoder().encode(newStr);
|
|
}
|
|
});
|
|
},
|
|
};
|