Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WNMGDS-2935] Make Sass token file changes backwards compatible #3230

Merged
merged 2 commits into from
Sep 17, 2024
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
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