-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Semantic-tokens: Flat export deprecated tokens (Tree shakability in ESBuild) #34235
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
Merged
Mitch-At-Work
merged 6 commits into
microsoft:extended-tokens
from
Mitch-At-Work:user/mifraser/add-legacy-script
Apr 14, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3758552
Add legacy tokens back
Mitch-At-Work 35e770f
Add legacy token script back to test later
Mitch-At-Work e082fc0
Skip modifying legacy tokens
Mitch-At-Work 9124f32
Run legacy script and regen
Mitch-At-Work 671eb15
Update API
Mitch-At-Work 66ba6f7
Access token value directly
Mitch-At-Work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| // eslint-disable-next-line no-restricted-imports | ||
| import * as tokensPackage from '@fluentui/tokens'; | ||
| import { fluentOverrides } from './fluentOverrides'; | ||
| import { format } from 'prettier'; | ||
|
|
||
| const generateLegacyTokens = () => { | ||
| console.log('Importing required fluent legacy tokens as flat export'); | ||
|
|
||
| const semanticTokenFallbacks = Object.keys(fluentOverrides); | ||
| const comment = '// THIS FILE IS GENERATED AS PART OF THE BUILD PROCESS. DO NOT MANUALLY MODIFY THIS FILE\n'; | ||
|
|
||
| const generatedTokens = semanticTokenFallbacks.reduce((acc, t) => { | ||
| const fluent2Fallback = fluentOverrides[t].f2Token; | ||
| if (!fluent2Fallback) { | ||
| return ''; | ||
| } | ||
| if (!Object.keys(tokensPackage.tokens).includes(fluent2Fallback)) { | ||
| // Token does not exist in F2 tokens | ||
| // This should never occur, but let's flag if a mistake was made in fallback token names | ||
| throw new Error(`Fluent token ${fluentOverrides[t].f2Token} not found in fluent tokens`); | ||
| } | ||
| const tokenValue = tokensPackage.tokens[fluent2Fallback as keyof typeof tokensPackage.tokens]; | ||
| const token = `/** | ||
| * CSS custom property value for the {@link @fluentui/tokens#${fluent2Fallback} | \`${fluent2Fallback}\`} design token. | ||
| * @public | ||
| */ | ||
| export const ${fluent2Fallback} = '${tokenValue}';\n`; | ||
|
|
||
| return acc + token; | ||
| }, ''); | ||
|
|
||
| const dir = path.join(__dirname, '../src/legacy'); | ||
|
|
||
| if (!fs.existsSync(dir)) { | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| } | ||
|
|
||
| // Run prettier to format the generated tokens | ||
| const formattedText = format(comment + generatedTokens, { | ||
| parser: 'typescript', | ||
| singleQuote: true, | ||
| printWidth: 120, | ||
| }); | ||
|
|
||
| fs.writeFile(path.join(dir, 'tokens.ts'), formattedText, err => { | ||
| if (err) { | ||
| throw err; | ||
| } | ||
| console.log('Legacy tokens reference created'); | ||
| }); | ||
| }; | ||
|
|
||
| generateLegacyTokens(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,16 @@ | ||
| // THIS FILE IS GENERATED AS PART OF THE BUILD PROCESS. DO NOT MANUALLY MODIFY THIS FILE | ||
| import { tokens } from '@fluentui/tokens'; | ||
| import { strokewidthDefaultRaw, backgroundCtrlBrandRestRaw } from '../../control/variables'; | ||
| import { colorStrokeFocus2 } from '../../legacy/tokens'; | ||
| import { | ||
| ctrlFocusPositionFigmaonlyRaw, | ||
| ctrlFocusInnerStrokewidthRaw, | ||
| ctrlFocusInnerStrokeRaw, | ||
| ctrlFocusOuterStrokewidthRaw, | ||
| ctrlFocusOuterStrokeRaw, | ||
| } from './variables'; | ||
|
|
||
| export const ctrlFocusPositionFigmaonly = `var(${ctrlFocusPositionFigmaonlyRaw})`; | ||
| export const ctrlFocusInnerStrokewidth = `var(${ctrlFocusInnerStrokewidthRaw}, var(${strokewidthDefaultRaw}))`; | ||
| export const ctrlFocusInnerStroke = `var(${ctrlFocusInnerStrokeRaw})`; | ||
| export const ctrlFocusOuterStrokewidth = `var(${ctrlFocusOuterStrokewidthRaw})`; | ||
| export const ctrlFocusOuterStroke = `var(${ctrlFocusOuterStrokeRaw}, var(${backgroundCtrlBrandRestRaw}, ${tokens.colorStrokeFocus2}))`; | ||
| export const ctrlFocusOuterStroke = `var(${ctrlFocusOuterStrokeRaw}, var(${backgroundCtrlBrandRestRaw}, ${colorStrokeFocus2}))`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.