Skip to content

Releases: amzn/style-dictionary

v4.0.0-prerelease.30

23 May 11:44
aeca085
Compare
Choose a tag to compare
v4.0.0-prerelease.30 Pre-release
Pre-release

Minor Changes

  • 7418c97: Add a couple of utilities for converting a regular Style Dictionary tokens object/file(s) to DTCG formatted tokens:

    • convertToDTCG
    • convertJSONToDTCG
    • convertZIPToDTCG

    Documentation of these utilities

v4.0.0-prerelease.29

17 May 11:52
9d61dcd
Compare
Choose a tag to compare
v4.0.0-prerelease.29 Pre-release
Pre-release

Minor Changes

  • cb94554: 'size/rem' transform to not transform tokens that already have a unit, such as "4px", this should not be transformed to "4rem".

Patch Changes

  • cb94554: Fix typeDtcgDelegate util $type property position to be allowed anywhere in the object, not just at the top.
  • 0972b26: Pass SD options to fileheaders and filters, to make it easier to use and adjust according to config or options like usesDTCG.
  • 4ec34fd: Pass options to all of the filter functions in our built-in transforms, to check for usesDTCG and $type property.
  • 0972b26: Add unfilteredAllTokens property in dictionary object for formats, which is an unfiltered version of allTokens property, or a flattened version of the unfilteredTokens property.

v4.0.0-prerelease.28

14 May 11:46
a140902
Compare
Choose a tag to compare
v4.0.0-prerelease.28 Pre-release
Pre-release

Minor Changes

  • 4225d78: Added the following transforms for CSS, and added them to the scss, css and less transformGroups:

    • fontFamily/css -> wraps font names with spaces in ' quotes
    • cubicBezier/css -> array value, put inside cubic-bezier() CSS function
    • strokeStyle/css/shorthand -> object value, transform to CSS shorthand
    • border/css/shorthand -> object value, transform to CSS shorthand
    • typography/css/shorthand -> object value, transform to CSS shorthand
    • transition/css/shorthand -> object value, transform to CSS shorthand
    • shadow/css/shorthand -> object value (or array of objects), transform to CSS shorthand

    The main intention here is to ensure that Style Dictionary is compliant with DTCG draft specification out of the box with regards to exporting to CSS, where object-value tokens are not supported without transforming them to shorthands (or expanding them, which is a different feature that was added in 4.0.0-prerelease.27).

Patch Changes

  • a5bafac: Colors that are not recognized by tinycolor2 as valid color formats (e.g. linear-gradient(...)) are now ignored by the builtin color transforms filter functions.

v4.0.0-prerelease.27

09 May 16:45
f6e7177
Compare
Choose a tag to compare
v4.0.0-prerelease.27 Pre-release
Pre-release

Major Changes

  • f2ed88b: BREAKING: File headers, when registered, are put inside the hooks.fileHeaders property now, as opposed to fileHeader.
    Note the change from singular to plural form here.

    Before:

    export default {
      fileHeader: {
        foo: (defaultMessages = []) => ['Ola, planet!', ...defaultMessages, 'Hello, World!'],
      },
    };

    After:

    export default {
      hooks: {
        fileHeaders: {
          foo: (defaultMessages = []) => ['Ola, planet!', ...defaultMessages, 'Hello, World!'],
        },
      },
    };
  • f2ed88b: BREAKING: Actions, when registered, are put inside the hooks.actions property now, as opposed to action.
    Note the change from singular to plural form here.

    Before:

    export default {
      action: {
        'copy-assets': {
          do: () => {}
          undo: () => {}
        }
      },
    };

    After:

    export default {
      hooks: {
        actions: {
          'copy-assets': {
            do: () => {}
            undo: () => {}
          }
        },
      },
    };
  • f2ed88b: Filters, when registered, are put inside the hooks.filters property now, as opposed to filter.
    Note the change from singular to plural form here.

    Before:

    export default {
      filter: {
        'colors-only': (token) => token.type === 'color,
      },
      platforms: {
        css: {
          files: [{
            format: 'css/variables',
            destination: '_variables.css',
            filter: 'colors-only',
          }],
        },
      },
    };

    After:

    export default {
      hooks: {
        filters: {
          'colors-only': (token) => token.type === 'color,
        },
      },
      platforms: {
        css: {
          files: [{
            format: 'css/variables',
            destination: '_variables.css',
            filter: 'colors-only',
          }],
        },
      },
    };

    In addition, when using registerFilter method, the name of the filter function is now filter instead of matcher.

    Before:

    import StyleDictionary from 'style-dictionary';
    
    StyleDictionary.registerFilter({
      name: 'colors-only',
      matcher: (token) => token.type === 'color',
    });

    After:

    import StyleDictionary from 'style-dictionary';
    
    StyleDictionary.registerFilter({
      name: 'colors-only',
      filter: (token) => token.type === 'color',
    });

    These changes also apply for the filter function (previously matcher) inside transforms.

  • f2ed88b: BREAKING: Transform groups, when registered, are put inside the hooks.transformGroups property now, as opposed to transformGroup.

    Before:

    export default {
      // register it inline or by SD.registerTransformGroup
      transformGroup: {
        foo: ['foo-transform'],
      },
    };

    After:

    export default {
      hooks: {
        transformGroups: {
          foo: ['foo-transform'],
        },
      },
    };
  • f2ed88b: BREAKING: Formats, when registered, are put inside the hooks.formats property now, as opposed to format.
    The formatter handler function has been renamed to format for consistency.

    The importable type interfaces have also been renamed, Formatter is now FormatFn and FormatterArguments is now FormatFnArguments.
    Note that you can also use Format['format'] instead of FormatFn, or Parameters<Format['format']> instead of FormatFnArguments, so these renames may not matter.

    Before:

    import StyleDictionary from 'style-dictionary';
    import type { Formatter, FormatterArguments } from 'style-dictionary/types';
    
    // register it with register method
    StyleDictionary.registerFormat({
      name: 'custom/json',
      formatter: ({ dictionary }) => JSON.stringify(dictionary, 2, null),
    });
    
    export default {
      // OR define it inline
      format: {
        'custom/json': ({ dictionary }) => JSON.stringify(dictionary, 2, null),
      },
      platforms: {
        json: {
          files: [
            {
              destination: 'output.json',
              format: 'custom/json',
            },
          ],
        },
      },
    };

    After:

    import StyleDictionary from 'style-dictionary';
    import type { FormatFn, FormatFnArguments } from 'style-dictionary/types';
    
    // register it with register method
    StyleDictionary.registerFormat({
      name: 'custom/json',
      format: ({ dictionary }) => JSON.stringify(dictionary, 2, null),
    });
    
    export default {
      // OR define it inline
      hooks: {
        formats: {
          'custom/json': ({ dictionary }) => JSON.stringify(dictionary, 2, null),
        },
      },
      platforms: {
        json: {
          files: [
            {
              destination: 'output.json',
              format: 'custom/json',
            },
          ],
        },
      },
    };
  • e83886c: BREAKING: preprocessors must now also be explicitly applied on global or platform level, rather than only registering it. This is more consistent with how the other hooks work and allows applying it on a platform level rather than only on the global level.

    preprocessors property that contains the registered preprocessors has been moved under a wrapping property called hooks.

    Before:

    export default {
      // register it inline or by SD.registerPreprocessor
      // applies automatically, globally
      preprocessors: {
        foo: (dictionary) => {
          // preprocess it
          return dictionary;
        },
      },
    };

    After:

    export default {
      // register it inline or by SD.registerPreprocessor
      hooks: {
        preprocessors: {
          foo: (dictionary) => {
            // preprocess it
            return dictionary;
          },
        },
      },
      // apply it globally
      preprocessors: ['foo'],
      platforms: {
        css: {
          // or apply is per platform
          preprocessors: ['foo'],
        },
      },
    };
  • 2f80da2: BREAKING: className, packageName, mapName, type, name, resourceType and resourceMap options for a bunch of built-in formats have been moved from file to go inside the file.options object, for API consistency reasons.

    Before:

    {
      "files": [
        {
          "destination": "tokenmap.scss",
          "format": "scss/map-deep",
          "mapName": "tokens"
        }
      ]
    }

    After:

    {
      "files": [
        {
          "destination": "tokenmap.scss",
          "format": "scss/map-deep",
          "options": {
            "mapName": "tokens"
          }
        }
      ]
    }
  • f2ed88b: BREAKING: Transforms, when registered, are put inside the hooks.transforms property now, as opposed to transform.
    The matcher property has been renamed to filter (to align with the Filter hook change), and the transformer handler function has been renamed to transform for consistency.

    Before:

    export default {
      // register it inline or by SD.registerTransform
      transform: {
        'color-transform': {
          type: 'value',
          matcher: (token) => token.type === 'color',
          transformer: (token) => token.value,
        },
      },
      platforms: {
        css: {
          // apply it per platform
          transforms: ['color-transform'],
        },
      },
    };

    After

    export default {
      // register it inline or by SD.registerTransform
      hooks: {
        transforms: {
          'color-transform': {
            type: 'value',
            filter: (token) => token.type === 'color',
            transform: (token) => token.value,
          },
        },
      },
      platforms: {
        css: {
          // apply it per platform
          transforms: ['color-transform'],
        },
      },
    };
  • f2ed88b: BREAKING: Parsers, when registered, are put inside the hooks.parsers property now, as opposed to parsers.
    parsers property has been repurposed: you will now also need to explicitly apply registered parsers by name in the parsers property, they no longer apply by default.
    When registering a parser, you must also supply a name property just like with all other hooks, and the parse function has been renamed to parser for consistency.

    Before:

    export default {
      // register it inline or by SD.registerPreprocessor
      parsers: [
        {
          pattern: /\.json5$/,
          parse: ({ contents, filePath }) => {
            return JSON5.parse(contents);
          },
        },
      ],
    };

    After:

    export default {
      hooks: {
        parsers: {
          name: 'json5-parser',
          pattern: /\.json5$/,
          parser: ({ contents, filePath }) => {
            return JSON5.parse(contents);
          },
        },
      },
      // apply it globally by name reference
      parsers: ['json5-parser'],
    };
  • 7b82150: BREAKING: For formats using the fileHeader formatHelpers utility, it will no longer display a timestamp in the fileHeader output by default. This is now an opt-in by setting file.formatting.fileHeaderTimestamp to true. The reason for making this opt-in now is that using Style Dictionary in the context of a CI (continuous integration) pipeline is a common use-case, and when running on pull request event, output files always show a diff in git due to the timestamp changing, which often just means that the diff is bloated by ...

Read more

v4.0.0-prerelease.26

16 Apr 11:09
76d5ab4
Compare
Choose a tag to compare
v4.0.0-prerelease.26 Pre-release
Pre-release

Minor Changes

  • 3485467: Fix some inconsistencies in some of the templates, usually with regards to spaces/newlines

Patch Changes

  • 6cfce97: Fix logging to be ordered by platform when building or cleaning platforms. This now happens in parallel, resulting in the logs being ordered randomly which was a small regression to the logging experience.
  • 061c67e: Hotfix to address outputReferencesTransformed util not handling object-value tokens properly.

v4.0.0-prerelease.25

12 Apr 12:59
50a69dc
Compare
Choose a tag to compare
v4.0.0-prerelease.25 Pre-release
Pre-release

Major Changes

  • 0b81a08: BREAKING: no longer wraps tokens of type asset in double quotes. Rather, we added a transform asset/url that will wrap such tokens inside url("") statements, this transform is applied to transformGroups scss, css and less.

Minor Changes

  • 2da5130: Added outputReferencesTransformed utility function to pass into outputReferences option, which will not output references for values that have been transitively transformed.

Patch Changes

  • 47face0: Token merging behavior changed so that upon token collisions, metadata props aren't accidentally merged together.

v4.0.0-prerelease.24

05 Apr 09:41
27d0622
Compare
Choose a tag to compare
v4.0.0-prerelease.24 Pre-release
Pre-release

Major Changes

  • 5e167de: BREAKING: moved formatHelpers away from the StyleDictionary class and export them in 'style-dictionary/utils' entrypoint instead.

    Before

    import StyleDictionary from 'style-dictionary';
    
    const { fileHeader, formattedVariables } = StyleDictionary.formatHelpers;

    After

    import { fileHeader, formattedVariables } from 'style-dictionary/utils';
  • 90095a6: BREAKING: Allow specifying a function for outputReferences, conditionally outputting a ref or not per token. Also exposes outputReferencesFilter utility function which will determine whether a token should be outputting refs based on whether those referenced tokens were filtered out or not.

    If you are maintaining a custom format that allows outputReferences option, you'll need to take into account that it can be a function, and pass the correct options to it.

    Before:

    StyleDictionary.registerFormat({
      name: 'custom/es6',
      formatter: async (dictionary) => {
        const { allTokens, options, file } = dictionary;
        const { usesDtcg } = options;
    
        const compileTokenValue = (token) => {
          let value = usesDtcg ? token.$value : token.value;
          const originalValue = usesDtcg ? token.original.$value : token.original.value;
    
          // Look here 👇
          const shouldOutputRefs = outputReferences && usesReferences(originalValue);
    
          if (shouldOutputRefs) {
            // ... your code for putting back the reference in the output
            value = ...
          }
          return value;
        }
        return `${allTokens.reduce((acc, token) => `${acc}export const ${token.name} = ${compileTokenValue(token)};\n`, '')}`;
      },
    });

    After

    StyleDictionary.registerFormat({
      name: 'custom/es6',
      formatter: async (dictionary) => {
        const { allTokens, options, file } = dictionary;
        const { usesDtcg } = options;
    
        const compileTokenValue = (token) => {
          let value = usesDtcg ? token.$value : token.value;
          const originalValue = usesDtcg ? token.original.$value : token.original.value;
    
          // Look here 👇
          const shouldOutputRef =
            usesReferences(original) &&
            (typeof options.outputReferences === 'function'
              ? outputReferences(token, { dictionary, usesDtcg })
              : options.outputReferences);
    
          if (shouldOutputRefs) {
            // ... your code for putting back the reference in the output
            value = ...
          }
          return value;
        }
        return `${allTokens.reduce((acc, token) => `${acc}export const ${token.name} = ${compileTokenValue(token)};\n`, '')}`;
      },
    });

v4.0.0-prerelease.23

27 Mar 10:19
de2c394
Compare
Choose a tag to compare
v4.0.0-prerelease.23 Pre-release
Pre-release

Patch Changes

  • f8c40f7: fix(types): add missing type keyword for type export from index.d.ts

v4.0.0-prerelease.22

26 Mar 23:08
3537e8d
Compare
Choose a tag to compare
v4.0.0-prerelease.22 Pre-release
Pre-release

Patch Changes

  • daa78e1: Added missing type exports

v4.0.0-prerelease.21

26 Mar 16:42
be346a8
Compare
Choose a tag to compare
v4.0.0-prerelease.21 Pre-release
Pre-release

Minor Changes

  • 8b6fff3: Fixes some noisy warnings still being outputted even when verbosity is set to default.

    We also added log.warning "disabled" option for turning off warnings altogether, meaning you only get success logs and fatal errors.
    This option can be used from the CLI as well using the --no-warn flag.

Patch Changes

  • 77ae35f: Fix scenario of passing absolute paths in Node env, do not remove leading slash in absolute paths.