Closed okadurin closed 1 month ago
Yeah this is probably a regression of the v4 restructure of the StyleDictionary object and how hooks are now registered.
I'm guessing the desired behavior when a hook under name X already exists is:
https://github.com/amzn/style-dictionary/blob/v4/lib/Register.js#L100 The code here is what's wrong, it's using deepmerge for registering hooks but merging is not appropriate here is the desired behavior is overriding, instead it should be:
target.hooks = {
...target.hooks,
transforms: {
...target.hooks.transforms,
[name]: {
type,
filter,
transitive: !!transitive,
transform: transformFn,
},
},
});
And repeat that pattern for the other 7 hooks as well within that Register class.
PRs welcome!
In
v4
if trying to register atransform
with the name which is already registered internally, the customtransform
function will never be called. Instead the internal one will be called. Inv3
it worked. Either becausename/camel
was not defined internally or because the library allowed overridingtransforms
, not sure. Here is example of the code. Transform group is defined at the config object.If renaming
name/camel
it starts working.This could be a documentation update (if any) or the code could be updated so that if the user registers a transformer with the internal name, then the library allows to override it. Maybe it's not even internal names. Maybe it just ignores
registerTransform
for the same name after it was registered once. I did not check that. For me I just renamed thetransform
and the code began to work.