Skip to content

Releases: amzn/style-dictionary

v4.3.0

10 Dec 20:21
737a02b
Compare
Choose a tag to compare

Minor Changes

  • 302b466: Introduce a new entrypoint: style-dictionary/enums for most of the library's hard-coded string values. Most of these are built-in hooks names. This provides better type-safety for consumers as well as various maintainability related benefits for this library. See documentation for more info.
  • 5aad797: Add tailwind preset example, remove unused .editorconfig file
  • bd8be17: Add support for native .TS token & config file processing.
  • 209085d: Add tokenMap properties to Dictionary, which is a JavaScript Map structure of the tokens, which makes it easy to iterate as well as access tokens. Also add convertTokenData utility that allows to seemlessly convert between Map, Object or Array of tokens, and deprecate the flattenTokens utility in favor of that one.

Patch Changes

  • 2966cfd: handle DTCG-format tokens in typescript/es6-declarations formatter
  • 4a7bca7: add accessControl field to Android Compose template
  • f694f67: Fix Prettier imports, see https://prettier.io/docs/en/api#custom-parser-api-removed for more info.
  • fd8cdb4: handle DTCG-format tokens in javascript/es6 formatter
  • 6a6a409: Move prettier to dependencies since style-dictionary isn't really a prettier plugin and a direct dependency seems more accurate here.
  • 8a9cfa0: Fix outputReferencesTransformed util, would return true for tokens which original values were not strings.
  • 7a661bb: Fix font-style and font-weight logic for fonts.css.template.js

v4.2.0

11 Nov 17:19
325d161
Compare
Choose a tag to compare

Minor Changes

  • 0fcf229: Add a new built-in format javascript/esm that outputs an ES module JS default export.
  • d7b5836: Mark javascript/esm as nested, use Prettier on all JavaScript/TypeScript formats, use 3.x.x peerDependency so the user's installation is used when possible.
  • 4bf68a3: Apply stripMeta from "json" format to the new "javascript/esm" as well.
  • 8f1b4f0: Add new utility in style-dictionary/utils -> stripMeta for stripping metadata from tokens.
    This utility is used now as an opt-in for the built-in 'json' format by using options.stripMeta, which if set to true will strip Style Dictionary meta props.
    You can specify keep/strip (allow/blocklist) for granular control about which properties to keep or strip.

Patch Changes

  • 5e3a5af: Update .d.ts/js files type imports to use correct extensions rather than extensionless. This fixes some incompatibilities with latest TypeScript "NodeNext" moduleResolution.

v4.1.4

21 Oct 16:06
399de13
Compare
Choose a tag to compare

Patch Changes

  • a67ed31: Pass PlatformConfig as options param to platform-applied preprocessors.
  • 19aee32: Fix convertToBase64 util to support converting binary files such as fonts, for both Browser and NodeJS.

v4.1.3

03 Oct 20:22
9288a75
Compare
Choose a tag to compare

Patch Changes

  • 9376247: Make defaultMessage param in FileHeader type optional.
  • 43ccb42: (#1305): fix reference sorting in sortByReference function for DTCG token format, ensuring token references are declared after their targets
  • 26728b9: Fix filterTokens utility to deal with random metadata properties throughout token groups, without throwing errors.

v4.1.2

18 Sep 16:28
64a8214
Compare
Choose a tag to compare

Patch Changes

  • e9cce6a: Reuse static hooks in the constructor to set instance hooks prop, to avoid discarding built-in hooks overwrites by consumers.
  • b48d0e9: Add missing type interfaces, most notably the ExpandConfig types.

v4.1.1

12 Sep 16:34
1e784a0
Compare
Choose a tag to compare

Patch Changes

  • 5db3521: Add iosSwiftEnumOpts.className and iosSwiftAnyOpts.className formats property documentation
  • 23f8a25: Use cp and rmdir commands for copy_assets do and undo methods, since they affect directories, not files.

v4.1.0

28 Aug 15:51
ed64bee
Compare
Choose a tag to compare

Minor Changes

  • ccf27b7: Prevent duplicate redundant calls to StyleDictionary class methods by caching platform specific config & tokens results.

    Added reusable methods:

    • getPlatformTokens() -> grabs the tokens/allTokens(new! exportPlatform does not return this) for a specific platform, after running platform specific preprocessors and transforms. This replaces the old exportPlatform method which is now deprecated and will be removed in v5.
    • getPlatformConfig() -> grabs the processed/transformed PlatformConfig for a specific platform, replaces the now deprecated getPlatform method which will be removed in v5.

    The reasons for deprecating those methods and replacing them with new ones is to reduce method ambiguity and make them more pure.

    Add new options object to methods:

    • getPlatformTokens
    • getPlatformConfig
    • exportPlatform (deprecated, see above)
    • getPlatform (deprecated, see above)
    • formatPlatform
    • formatAllPlatforms
    • buildPlatform
    • buildAllPlatforms
    • cleanPlatform
    • cleanAllPlatforms

    with property cache, which if set to false, will disable this caching of generating the platform specific config / tokens, e.g.:

    await sd.exportPlatform('css', { cache: false });
    await sd.buildAllPlatforms('css', { cache: false });

    Expectation is that this is usually not useful for majority of users, unless for example you're testing multiple runs of StyleDictionary while changing tokens or platform configs in between those runs.

Patch Changes

  • 2ec9a44: size/rem transform to leave 0 (string or number) values as is, since 0 doesn't need a unit.

  • f317430: Added link to logging documentation inside all of the warnings and errors that refer to verbosity.

  • 6275983: Respect formatting options in scss map-deep/map-flat formats, those that make sense:

    • commentPosition
    • commentStyle
    • indentation

    Also export a new type interface FormattingOverrides, which is a limited version of FormattingOptions.
    These contain the formatting options that can be overridden by users, whereas the full version is meant for the format helper utilities such as createPropertyFormatter/formattedVariables.

v4.0.1

18 Jul 17:35
4575dd5
Compare
Choose a tag to compare

Patch Changes

  • e6cbf73: Fix type information for Config.parser
  • e8aea2f: Fix transitive color transform advanced example, migrate chroma-js to colorjs.io
  • 7afcffd: Fix bugs with expand tokens where they would run before instead of after user-configured preprocessors, and would fatally error on broken references. Broken refs should be tolerated at the expand stage, and errors will be thrown after preprocessor lifecycle if the refs are still broken at that point.
  • 922b6aa: Update memfs esm-fork dependency to allow named import Volume.
  • 61b6984: Fix 'filePath' missing from falsy token values
  • 3ae67e3: Upgrade memfs esm fork to publish types and bumping stream to fix unclear licensing issue with transitive dependency.

v4.0.0

28 Jun 21:17
f6c423f
Compare
Choose a tag to compare

For a more comprehensive migration guide from version 3.x.x to version 4.0.0,
visit the migration guide page

Major Changes

  • 6cc7f31: BREAKING:

    • usesReference util function is now usesReferences to be consistent plural form like the other reference util functions.

    • getReferences first and second parameters have been swapped to be consistent with resolveReferences, so value first, then the full token object (instead of the entire dictionary instance).

    • getReferences accepts a third options parameter which can be used to set reference Regex options as well as an unfilteredTokens object which can be used as a fallback when references are made to tokens that have been filtered out. There will be warnings logged for this.

    • format.formatter removed old function signature of (dictionary, platform, file) in favor of ({ dictionary, platform, options, file }).

    • Types changes:

      • Style Dictionary is entirely strictly typed now, and there will be .d.ts files published next to every file, this means that if you import from one of Style Dictionary's entrypoints, you automatically get the types implicitly with it. This is a big win for people using TypeScript, as the majority of the codebase now has much better types, with much fewer anys.
      • There is no more hand-written Style Dictionary module index.d.ts anymore that exposes all type interfaces on itself. This means that you can no longer grab types that aren't members of the Style Dictionary class directly from the default export of the main entrypoint. External types such as Parser, Transform, DesignTokens, etc. can be imported from the newly added types entrypoint:
      import type { DesignTokens, Transform, Parser } from 'style-dictionary/types';

      Please raise an issue if you find anything missing or suddenly broken.

      • Matcher, Transformer, Formatter, etc. are still available, although no longer directly but rather as properties on their parents, so Filter['matcher'], Transform['transformer'], Format['formatter']
  • dcbe2fb: - The project has been fully converted to ESM format, which is also the format that the browser uses.
    For users, this means you'll have to either use Style Dictionary in ESM JavaScript code, or dynamically import it into your CommonJS code.

    • StyleDictionary.extend() method is now asynchronous, which means it returns Promise<StyleDictionary.Core> instead of StyleDictionary.Core.
    • allProperties / properties was deprecated in v3, and is now removed from StyleDictionary.Core, use allTokens and tokens instead.
    • Templates and the method registerTemplate were deprecated in v3, now removed. Use Formats instead.
    • The package now uses package entrypoints, which means that what is importable from the package is locked down to just the specified entrypoints: style-dictionary & style-dictionary/fs. If more is needed, please raise an issue explaining which file you were importing and why you need it to be public API.
  • 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!'],
        },
      },
    };
  • 79bb201: BREAKING: Logging has been redesigned a fair bit and is more configurable now.

    Before:

    {
      "log": "error" // 'error' | 'warn'  -> 'warn' is the default value
    }

    After:

    {
      "log": {
        "warnings": "error", // 'error' | 'warn'  -> 'warn' is the default value
        "verbosity": "verbose", // 'default' | 'verbose' | 'silent'  -> 'default' is the default value
        "errors": {
          "brokenReferences": "console" // 'console' | 'throw' -> 'throw' is the default value
        }
      }
    }

    Log is now and object and the old "log" option is now "warnings".

    This configures whether the following five warnings will be thrown as errors instead of being logged as warnings:

    • Token value collisions (in the source)
    • Token name collisions (when exporting)
    • Missing "undo" function for Actions
    • File not created because no tokens found, or all of them filtered out
    • Broken references in file when using outputReferences, but referring to a token that's been filtered out

    Verbosity configures whether the following warnings/errors should display in a verbose manner:

    • Token collisions of both types (value & name)
    • Broken references due to outputReferences & filters
    • Token reference errors

    And it also configures whether success/neutral logs should be logged at all.
    Using "silent" (or --silent in the CLI) means no logs are shown apart from fatal errors.

  • 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: () => {}
          }
        },
      },
    };
  • a4542f4: BREAKING: StyleDictionaryInstance.properties & .allProperties have been removed. They were deprecated in v3 in favor of .tokens and .allTokens.

  • 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';
  • 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'],
        },
      },
    };
  • 502dbd1: BREAKING: All of our hooks, parsers, preprocessors, transforms, formats, actions, fileHeaders and filters, support async functions as well now. This means that the formatHelpers -> fileHeader helper method is now asynchronous, to support async fileheader functions.

    import StyleDictionary from 'style-dictionary';
    
    const { fileHeader } = StyleDictionary.formatHelpers;
    
    StyleDictionary.registerFormat({
      name: 'custom/css',
      // this can be async now, usually it is if you use fileHeader format helper, since that now always returns a Promise
      formatter: async function ({ dictionary, file, options }) {
        const { outputReferences } = options;
        return (
          // this helper is now async! because the user-passed file.fileHeader might be an async function
          (await fileHeader({ file })) +
          ':root {\n' +
          formattedVariables({ format: 'css', dictionary, outputReferences }) +
          '\n}\n'
        );
      },
    });
  • 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 `FormatFnArgument...

Read more

v4.0.0-prerelease.39

28 Jun 10:29
2497779
Compare
Choose a tag to compare
v4.0.0-prerelease.39 Pre-release
Pre-release

Patch Changes

  • 894f37c: Update glob esm browser fork to latest, resolve unclear licensing issue.
  • cb78c3d: Update typeDtcgDelegate utility to remove the $type on token group level between parsing/preprocessing step.