Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions build-tools/utils/__tests__/token-versions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ const variablesMap = {
shadowModal: 'shadow-modal',
};

test('versions border + typography tokens matched by the default groups and leaves others (incl. border colors) version-less', () => {
expect(getTokenVersions(variablesMap)).toEqual({
borderRadiusButton: 'v3-1',
borderWidthField: 'v3-1',
colorChartsPurple300: 'v3-1',
fontFamilyBase: 'v3-1',
});
test('versions every token using the default fallback group', () => {
expect(getTokenVersions(variablesMap)).toEqual(mapValues(variablesMap, () => 'v3-1'));
});

test('assigns the version of the first matching group', () => {
Expand Down
14 changes: 3 additions & 11 deletions build-tools/utils/token-versions.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

const DEFAULT_TOKEN_VERSION = 'v3-1';

// Groups map a token-name pattern (matched against the token's CSS variable name) to a version.
// Tokens matching no group stay version-less and keep the legacy value-based hashes. Tokens are
// being migrated in batches (one batch per line), and eventually all tokens will be migrated to
// the new format.
const versionGroups = [
{ pattern: /^border-/, version: DEFAULT_TOKEN_VERSION },
{ pattern: /^(font|letter-spacing|line-height)-/, version: DEFAULT_TOKEN_VERSION },
{ pattern: /^color-(charts|severity)-/, version: DEFAULT_TOKEN_VERSION },
];
// Groups map a token-name pattern (matched against the token's CSS variable name)
// to a version. The fallback group (/^.*$/) should always be at the end.
const versionGroups = [{ pattern: /^.*$/, version: 'v3-1' }];

// Builds the token -> version allowlist from the full token -> cssName map.
function getTokenVersions(variablesMap, groups = versionGroups) {
Expand Down
Loading