-
Notifications
You must be signed in to change notification settings - Fork 3
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 Theo support to Rollup configuration #788
Conversation
💥 No ChangesetLatest commit: 5124da6 Merging this PR will not cause any packages to be released. If these changes should not cause updates to packages in this repo, this is fine 🙂 If these changes should be published to npm, you need to add a changeset. Click here to learn what changesets are, and how to add one. Click here if you're a maintainer who wants to add a changeset to this PR |
@calebeby When I go through my own testing steps, Typescript complains that it can't figure out the types from the token file. Any ideas for how I could resolve that? |
@tylersticka You can add a declaration block like this: https://github.com/cloudfour/cloudfour.com-patterns/blob/v-next/src/types.ts#L1-L4 In this case, each yaml file can have infinitely many declare module '*.yml' {
const tokens: Record<string, any>;
export = tokens;
} Then it only allows importing as namespace, for some reason: import * as colors from '../../design-tokens/colors.yml';
console.log(colors.purple_light); |
@calebeby Would we be able to avoid this issue somehow if we made a new Theo module, like a Module definitions are pretty simple. Here's the Is there some way we could add more info that way, or is it more that Typescript doesn't know how we're using it within our project JS file? (Apologies if these are dumb questions.) |
@tylersticka That would only work if it actually writes There is a similar problem with CSS Modules, and they solved it by automatically writing |
There is a discussion here: salesforce-ux/theo#174 (comment) |
If we do it that way, do you know if Rollup's tree-shaking will remove the unused variables for us, or will all of |
Awesome! So in that case, I think your first suggestion probably makes the most sense for now. Do you agree? |
Yeah probably. But for now, that is probably the easiest solution 👍 Maybe in the future we can add an npm script that generates .d.ts files for each yml file, (or we can make the rollup or webpack plugin do it), but for now that isn't necessary |
@calebeby One issue with that approach... it looks like we'll have to disable the I might take a look at the other approach later unless you're aware of a quick fix. |
I would be fine with disabling that rule globally, I did not realize it was enabled |
@calebeby After making these changes and using one of the tokens,
Previously |
@calebeby Looking at this again, I think I can generate modules and declarations pretty easily. Trying it out instead. Might be nicer to use overall. |
This is no longer necessary now that #790 has been merged. |
Overview
Adds support for importing tokens from Theo configuration files in YAML format. (There is a Rollup plugin for Theo, but it appears to only transform to CSS.)
Tokens use the
module.js
format, which converts tokens into ES exports.So given a token file like this:
And JavaScript source like this:
The compiled JavaScript will look like this:
This also adds usage examples in JavaScript to the design token pages.
Screenshots
Testing
npm run build
dist/cloudfour-patterns.js
.