Skip to content
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

default export is not correct #7

Closed
dmackerman opened this issue Mar 21, 2022 · 2 comments · Fixed by #9
Closed

default export is not correct #7

dmackerman opened this issue Mar 21, 2022 · 2 comments · Fixed by #9

Comments

@dmackerman
Copy link

dmackerman commented Mar 21, 2022

Hello!

I tried importing the code in this way:

const styleDictionaryToFigma = require('@divriots/style-dictionary-to-figma');

But, found that it doesn't work. Needed to add .default.

const styleDictionaryToFigma = require('@divriots/style-dictionary-to-figma').default;

Also may I suggest you change the README to use the registerTransform method on StyleDictionary:

StyleDictionaryPackage.registerFormat({
  name: 'figmaTokensPlugin',
  formatter({ dictionary }) {
    const parsedTokens = styleDictionaryToFigma(dictionary.tokens);
    return JSON.stringify(parsedTokens, null, 2);
  }
});

Thanks!

@jorenbroekema
Copy link
Contributor

This is only true for the CommonJS entrypoint of this library, for ESM (modern way, which I recommend), the import is correct.

Perhaps it makes sense to not use default exports in combination with named exports, since this only works in ESM and not in CJS, meaning you get a slightly different API for CJS because it requires the .default prop. There's other issues with default exports as well that I was recently made aware of, imo making it an anti-pattern.

I'll do a breaking update on this lib that will straighten things out:

import { transform } from '@divriots/style-dictionary-to-figma';
const { transform } = require('@divriots/style-dictionary-to-figma');

As for your README suggestion, both ways work, either by registerFormat or in the format prop in the config, I just prefer doing everything in the config. I'll clarify it in the readme because I do think registerFormat is the one people are more acquainted with.

@jorenbroekema
Copy link
Contributor

Fixed in 0.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants