Closed FadyAmir223 closed 6 months ago
Sorry, I don't think it is possible to fix since there is no identifiable pattern. To prevent breaking the JavaScript accidentally, a strict className searching strategy has been implemented inside the non-AST based obfuscation.
enableJsAst
to true inside the config.
The className tracing strategy will be applied by enabling this option. This strategy enables the obfuscator to find out all className related variables.The line you mentioned (the following) is inside the js-ast.ts
and is not relevant to the config you provided.
if (t.isIdentifier(path.node.key) && path.node.key.name === "className")
The functions inside js-ast.ts
won't be activated when enableJsAst=false
(default config)
If there is no pattern we can create it, we may require developers to add marker like "next-css-obfuscator" in strings used by CVA then remove it in the bundle and obfuscate
Then removeMarkersAfterObfuscated
can be your friend~
I tried to apply partial obfuscation to the whole project, but for some reason cn() (tailwindMerge) didn't work as expected (e.g. rounded-full didn't overwrite rounded-md) so I think the solution is to enable a marker alongside the full obfuscation to cover the blind spots like CVA
You can achieve this using the following config,
module.exports = {
enableObfuscateMarkerClasses = true,
obfuscateMarkerClasses = [".jsx", "{your_custom_key}"]
// rest of your config...
}
The "class" .jsx
(js pattern) is the default marker for searching class names in non-AST based full obfuscation and it won't be removed after obfuscation is completed.
Type
Checklist
Environment
Describe the bug shadcn-ui uses CVA which the package doesn't recognize
the problem lies in the assumption that classes will be inlined after "className"
but in the bundle it puts the the string in a function then call it below
more complex example
it can be avoided by turning off removeOriginalCss option but I suggested the simplify variation like medium to reduce the size of css file, doing that defeats the purpose of the package
a suggested solution is to compare the conversion.json keys with the string boundary after ensuring that text inside is tailwind classes, but I'm sure you can come up with a better idea :)
Config