Skip to content

Commit

Permalink
[WNMGDS-2935] Make Sass token file changes backwards compatible (#3230)
Browse files Browse the repository at this point in the history
* Make our Figma changes backwards compatible with respect to the sass var files

* In the unit tests, acknowledge but don't snapshot the duplicated files
  • Loading branch information
pwolfert authored Sep 17, 2024
1 parent a902f5d commit 6038634
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/design-system-tokens/src/css/translate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ describe('tokenFilesToCssFiles', () => {

describe('tokenFilesToScssFiles', () => {
it('matches snapshot', () => {
expect(tokenFilesToScssFiles(tokensByFile)).toMatchSnapshot();
const files = tokenFilesToScssFiles(tokensByFile);

// Acknowledge but don't snapshot the duplicated files
expect(files['core-component-tokens.scss']).toBeTruthy();
expect(files['core-tokens.scss']).toBeTruthy();
expect(files['cmsgov-component-tokens.scss']).toBeTruthy();
expect(files['cmsgov-tokens.scss']).toBeTruthy();
delete files['core-component-tokens.scss'];
delete files['core-tokens.scss'];
delete files['cmsgov-component-tokens.scss'];
delete files['cmsgov-tokens.scss'];

expect(files).toMatchSnapshot();
});
});

Expand Down
8 changes: 8 additions & 0 deletions packages/design-system-tokens/src/css/translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ export function tokenFilesToScssFiles(tokensByFile: FlattenedTokensByFile): Outp
const scssVars = tokensToSassVars(themeTokens, systemTokens, themeName === 'core');
const scssFileName = `${themeName}-theme.scss`;
obj[scssFileName] = scssVars;

// TODO: We're duplicating these files for backwards compatibility so teams currently
// using the Sass variables don't have to change anything, but at some point we'll
// want to force a change. This may coincide with the removal of Sass entirely.
const deprecatedVars = `// Use of this file is deprecated. Please use "${scssFileName}" instead.\n${scssVars}`;
obj[`${themeName}-tokens.scss`] = deprecatedVars;
obj[`${themeName}-component-tokens.scss`] = deprecatedVars;

return obj;
}, {} as Record<string, string>);
}
Expand Down

0 comments on commit 6038634

Please sign in to comment.