Open jjrodcast opened 4 months ago
You can't really solve the way references are resolved using transforms. This is because transforms do not apply to tokens that contain references, unless you have a transitive transform, after which it will first resolve the ref and then defer the transformation until after the references have been resolved. So, that still doesn't allow you to fix the reference in the transformation.
I'm not sure why you're doing what you're doing but wouldn't it make sense to add the color object into the dictionary during the parsing (or preprocessing might make more sense here) lifecycle step in a way that makes the references work? So instead of doing something like:
const obj = ...; // your parsed content without the injected color object
obj.color = colorObject; // instead of this
// do this
obj = { ...obj, ...colorObject };
in that way, whatever props you got inside your injected colorObject are just spread on the root level of the dictionary/parsed file content.
Again, I would recommend using a preprocessor over a parser for this kind of thing, because parsing happens on a per-file basis while it sounds to me like you're just trying to inject something into the dictionary as a whole, which can be done after it's all be parsed and combined into a dictionary object.
Thanks I will check the preprocessors.
I'm working in a configuration for a project that that these files:
generic_tokens.sjon
andsemantic_tokens.json
and
I'm using a custom parser to add the
color
node in thegeneric_tokens.json
so in that way it will be parser by style-dictionary but when I'm trying to execute thebuild
command it throws an error that indicates the next:I understand that this is because i'm changing the structure of the
generic_tokens.json
adding thecolor
object in the root object, when I manually change the value from thesemantic_tokens.json
fromcharcoal.100.100
tocolor.charcoal.100.100
it works.How can I solve this problem using a custom transformer, I'm using the
transitive:true
but it throws the error anyway. Any sample code where can I see some help?