amzn / style-dictionary

A build system for creating cross-platform styles.
https://styledictionary.com
Apache License 2.0
3.85k stars 537 forks source link

Resolve local modules #662

Open fjeldsoe opened 3 years ago

fjeldsoe commented 3 years ago

Hi.

First off, I've started using SD and I think its great!

I'm making my tokens in CommonJS (Actually ESM compiled to CommonJS because SD doesn't consume ES Modules to my knowledge), but when resolving modules, SD only looks at node_modules. I have a tsconfig.json file in my project, with a paths configuration, that I would like to use when importing helper functions/modules in my token files.

I've searched the issue tracker, but can't find any issue regarding this, and can't find anything about it in the docs. I think it would be a nice feature, to be able to resolve local modules like node_modules.

If this is already possible, then please enlighten me :)

dbanksdesign commented 3 years ago

Thank you for bringing this to our attention! It would be very helpful to see an example package setup that has this issue because it is hard for me to imagine what is going on. If you could post a gist or github repo or a project on something like stackblitz like this: https://stackblitz.com/edit/style-dictionary-example we can better troubleshoot the issue.

This could be me making incorrect assumptions about the setup, but I think you could run style dictionary in an ESM without compiling to CommonJS if you run Style Dictionary directly in a JS file like:

import StyleDictionary from 'style-dictionary';

StyleDictionary.extend({
  // config
}).buildAllPlatforms()

And then run that file in node rather than calling the style-dictionary CLI.

fjeldsoe commented 3 years ago

@dbanksdesign thank you for replying. I've made a simple example, that is a fraction of my setup, but it should give you an idea of what I mean: https://stackblitz.com/edit/node-9rkspu

In src/style-dictionary/tokens/fonts.ts I would like to be able to resolve my helper functions module like this: import { lineHeight, rem } from 'helpers/units';