-
-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add setting option to exclude mode from token value #309
base: main
Are you sure you want to change the base?
Conversation
* new setting to allow to only preserve mode in token name but exclude it from token value * add documentation in README.md * extend Checkbox component to ember Info component inline to the checkbox label * update jest moduleMapper to resolve "@src"
@lukasoppermann hi! |
Hey @0m4r, this is good, I just have to review it. I will probably remove the contributors section. I am happy for it to be added, but then we need to do a new PR and add all people who contributed. |
(I am not close to a computer to test at the moment) But, could you help me to replicate your settings with a screenshot? The "new" behavior should be setup by ticking off the "old" checkbox, and tick on the "new" one. ...now that I think about it may not be the best user experience, tho 😓 |
Hey, I updated the naming a bit but this does not matter. However, no matter if the new setting is on or off, it never adds the mode to the name. Adding to the name for me means it should be in the json structure {
base: { // <- (collection)
light: { // <- (mode)
green: {...} This is also how the name is referenced in the value (if the new setting is on). But this does not happen. I expect (but could not test it) that we are missing something in the export or somewhere. I also did not log the name to see if it is actually added. Just FYI I am on vacation for two weeks very soon, so I may not answer for two weeks. |
I have run a few tests and reported the findings here: |
Some updates but not working
Hey @0m4r are you still on this? I agree that the UX seems a bit confusing. Any idea how to fix it? |
Hi Lukas, I am still interested to fix this, but in the last weeks I have not really got a lot of time to spend on this. Let me come back to you with some ideas... |
Add setting configuration to add the mode name to the token name or value. Both token name and value can have the mode added, only one of them or none.
hi @lukasoppermann ,
by combining them, name and value can both be generated including the mode name, only one of them or none. The problem with values that reference variables in the same mode remains unresolved. (I have not updated screenshots and docs yet - I wanted to have a review of the current idea before completing all the work ) |
Pull Request Test Coverage Report for Build 11630838963Details
💛 - Coveralls |
@lukasoppermann I have now completed the work on this PR and updated the README.md. The code is not great, I know... still, what do you think? |
<div className="grid-2-col"> | ||
<div> | ||
<Checkbox | ||
label="Add mode to design token name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label="Add mode to design token name" | |
label="Add mode to design token name (if 2 or more modes)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this one, thanks for the suggestion.
} | ||
info={{ | ||
width: 240, | ||
label:"If enabled, the exported json will include the mode of the variables in the token name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
label:"If enabled, the exported json will include the mode of the variables in the token name" | |
label:"If enabled, the exported json will include the mode of the variables in the token path, if more than 1 mode exists." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this one, thanks for the suggestion.
@@ -0,0 +1 @@ | |||
legacy-peer-deps=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this @0m4r?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to avoid the warning about peer-dependencies, if I remove that line I get this sort of output when I do npm install
type of commands:
npm warn ERESOLVE overriding peer dependency
npm warn While resolving: [email protected]
npm warn Found: [email protected]
npm warn node_modules/react
npm warn dev react@"^18.2.0" from the root project
npm warn 3 more (react-dom, react-outside-click-handler, use-immer)
npm warn
npm warn Could not resolve dependency:
npm warn peer react@"^0.14 || ^15.0.0 || ^16.0.0-alpha" from [email protected]
npm warn node_modules/airbnb-prop-types
npm warn airbnb-prop-types@"^2.15.0" from [email protected]
npm warn node_modules/react-outside-click-handler
npm warn
npm warn Conflicting peer dependency: [email protected]
npm warn node_modules/react
npm warn peer react@"^0.14 || ^15.0.0 || ^16.0.0-alpha" from [email protected]
npm warn node_modules/airbnb-prop-types
npm warn airbnb-prop-types@"^2.15.0" from [email protected]
npm warn node_modules/react-outside-click-handler
npm warn deprecated [email protected]: See https://github.com/lydell/source-map-url#deprecated
npm warn deprecated [email protected]: Deprecated: Use @typescript-eslint/eslint-plugin instead
Hey @0m4r, sorry for the late reply. I added a few comments. However, it seems that this PR introduces a memory leak. You can see it if you run it locally. I ran it in a project with a lot of tokens and modes. It runs fine with only one mode. I did not test if just adding a mode breaks it already, but it may. Don't know if you have an idea. I don't know why it breaks. |
Uhm, I did try with a few different Figmna projects, but none of them is really "huge". |
Could be this. I have aliases from the same collection and from collections in other libraries. Happy to test again. If I can just disable the function to test if it is this one, let me know how |
yeah, that would help... (and, to be honest, I have not even considered the use case of variables in other libraries...) @lukasoppermann the easiest way is probably to edit (worth asking, I guess, I am trying to generate a huge design token file, what's the best way to import it back to Figma as Figma variables? I am trying some plugins but none of them does work...) |
src/utilities/getVariables.ts
Outdated
@@ -74,29 +110,31 @@ export const getVariables = (figma: PluginAPI, settings: Settings) => { | |||
// get collection name and modes | |||
const { variableCollectionId } = variable | |||
const { name: collection, modes } = collections[variableCollectionId] | |||
|
|||
if (modes.length > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0m4r, when I comment out this if clause and the content inside it does not break. So, the leak is probably in detectVariableReferencesInCollection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(you cannot share the Figma file you run your test, right?)
@lukasoppermann I found a fix that should work around the memory leak issue for now. let me know what you do think about this change |
Hey @0m4r I am still running into the issue. I tried to make some time to debug, but I am too blocked atm. Do you have an idea what creates this memory leak? |
Hi @lukasoppermann , yeah, the problem is that when it tries to "resolve" the same mode or same collection variable reference it iterates the current variable against any other. As far as I can tell, as of now, this is the only way to detect this situation (happy to be told wrong on this!). The problem is that when the numbers are huge, this generates a memory leak - and when it succeeds it takes anyway a huge amount of time. I am going to check this one again, but I think I would like to add an additional "beta flag" to enable resolving the same mode/collection variable references. This way, at least the initial problem of the mode names in the token name or value can probably be pushed forward. |
Hey @0m4r, so it is better. Only if I set It does nothing and just closes. I think if you can bring up a Figma error notification and abort, we could at least merge it.
I currently don't understand why this happens, so I would not know a better error code. We just need to deal with the error for now. |
@lukasoppermann I am not able to replicate the problem. I tried all the possible switches combinations for the mode name but I have got no errors. |
@0m4r there is no error, it just does nothing. I am assuming you abort due to some error? As you can see in the video, it works fine with the left option disabled. I waited for a couple minutes, but nothing happens once the option is enabled and I export. CleanShot.2024-11-01.at.12.32.42.mp4 |
Thanks for the video, I have been trying before to replicate the error you have shown in the recording but it did work for me. |
@0m4r I don't know if it is related to the tokens referencing tokens from another file? |
I am looking into it. I have noticed that if I use the plugin in watch mode (npm run start) it all seems working. |
@lukasoppermann I think I have nailed it down to where the issue occurs. I have tried changing a bit the code to optimize the way the data to download is generated (moved away from (code pushed) |
Fix #308