Skip to content
Open
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
16 changes: 13 additions & 3 deletions build-tools/utils/__tests__/token-versions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,37 @@ const { getTokenVersions } = require('../token-versions');
const variablesMap = {
borderRadiusButton: 'border-radius-button',
borderWidthField: 'border-width-field',
colorChartsPurple300: 'color-charts-purple-300',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding more token examples; I feel like I'll probably release the color token changes in smaller batches than all of "color-*" at once.

colorBorderButtonNormalDefault: 'color-border-button-normal-default',
colorBackgroundPopover: 'color-background-popover',
colorTextControlDisabled: 'color-text-control-disabled',
colorTextAccent: 'color-text-accent',
spaceScaledM: 'space-scaled-m',
sizeIconMedium: 'size-icon-m',
fontFamilyBase: 'font-family-base',
shadowModal: 'shadow-modal',
Comment thread
avinashbot marked this conversation as resolved.
};

test('versions border tokens matched by the default groups and leaves others (incl. border colors) version-less', () => {
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',
fontFamilyBase: 'v3-1',
});
});

test('assigns the version of the first matching group', () => {
const groups = [
{ pattern: /^color-border-/, version: 'v3-2' },
{ pattern: /^color-text-/, version: 'v3-2' },
{ pattern: /^color-/, version: 'v3-1' },
];
expect(getTokenVersions(variablesMap, groups)).toEqual({
colorBackgroundPopover: 'v3-1',
colorBorderButtonNormalDefault: 'v3-2',
colorTextAccent: 'v3-1',
colorChartsPurple300: 'v3-1',
colorTextAccent: 'v3-2',
colorTextControlDisabled: 'v3-2',
});
});

Expand All @@ -37,6 +47,6 @@ test('a catch-all group versions every token', () => {
});

test('returns an empty map when no group matches', () => {
const groups = [{ pattern: /^color-background-/, version: 'v3-1' }];
const groups = [{ pattern: /^motion-duration-/, version: 'v3-1' }];
expect(getTokenVersions(variablesMap, groups)).toEqual({});
});
9 changes: 7 additions & 2 deletions build-tools/utils/token-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
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.
const versionGroups = [{ pattern: /^border-/, version: DEFAULT_TOKEN_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 },
];

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