Design Token Migration Guide
Design Token Migration Guide
A design token migration guide helps teams transition from one token system state to another with minimal disruption. Migrations occur when introducing tokens to an existing codebase, restructuring token organization, renaming tokens en masse, or adopting new tooling. Successful migrations require careful planning, incremental execution, and thorough validation.
What Is Design Token Migration
Design token migration is the process of moving from one token system configuration to another. This encompasses various scenarios: adopting tokens where hardcoded values previously existed, transitioning from one token format or tool to another, reorganizing token structure or naming conventions, or consolidating multiple token systems into one.
Migrations affect both the token system itself and the consuming applications that reference tokens. Both aspects require planning and coordination.
How Design Token Migration Works
Migrations typically follow a phased approach that limits risk while maintaining system stability.
Assessment phase establishes the current state and defines the target state. What tokens exist today? What should the future system look like? What are the differences that migration must address?
Mapping phase connects current tokens to their future equivalents. Each existing token maps to either a new token name, a different token entirely, or removal. This mapping becomes the migration specification:
Old Token New Token
color.primary → color.action.primary
spacing.small → spacing.sm
color.gray.500 → color.neutral.500
deprecated.oldToken → [removed]
Tooling phase creates automation to execute the migration. Codemods transform code references. Build scripts produce both old and new token outputs during transition.
Execution phase applies migration in controlled increments. Rather than migrating everything simultaneously, teams migrate by application, by component, or by token category:
Week 1: Migrate color tokens in Application A
Week 2: Migrate spacing tokens in Application A
Week 3: Migrate Application B
...
Validation phase verifies that migrated code behaves correctly. Automated tests, visual regression testing, and manual review confirm that migration did not introduce problems.
Cleanup phase removes temporary scaffolding. Old token definitions, compatibility shims, and migration tooling are retired once migration completes.
Key Considerations
- Both old and new tokens should work during transition periods
- Automated migration reduces human error and scales to large codebases
- Incremental migration limits blast radius of any problems
- Rollback capability enables recovery if issues emerge
- Communication keeps all stakeholders informed of progress
- Documentation should be updated as migration proceeds
- Metrics should track migration progress quantitatively
- Sufficient testing coverage must exist before migration begins
Common Questions
How should codemod migration be implemented?
Codemods are automated code transformation scripts that update source files according to defined rules. For token migration, codemods replace old token references with new ones.
JavaScript codemods commonly use jscodeshift or babel:
// jscodeshift codemod for token renaming
module.exports = function(fileInfo, api) {
const j = api.jscodeshift;
const root = j(fileInfo.source);
const tokenMap = {
'color.primary': 'color.action.primary',
'spacing.small': 'spacing.sm'
};
root.find(j.Literal)
.filter(path => tokenMap[path.value])
.forEach(path => {
path.replace(j.literal(tokenMap[path.value]));
});
return root.toSource();
};
CSS codemods might use postcss:
const postcss = require('postcss');
const tokenMap = {
'--color-primary': '--color-action-primary',
'--spacing-small': '--spacing-sm'
};
module.exports = postcss.plugin('migrate-tokens', () => {
return root => {
root.walkDecls(decl => {
Object.entries(tokenMap).forEach(([old, newToken]) => {
if (decl.value.includes(`var(${old})`)) {
decl.value = decl.value.replace(
`var(${old})`,
`var(${newToken})`
);
}
});
});
};
});
Codemods should be tested extensively before running on production code. Dry-run modes that report changes without applying them help verify correctness.
How should migration progress be tracked?
Progress tracking provides visibility into migration status and helps identify stalled areas.
Quantitative metrics measure what percentage of references have migrated:
Token Migration Status
- Applications migrated: 8/12 (67%)
- Old token references remaining: 1,234
- New token references: 5,678
- Blocked migrations: 3
Dashboards visualize progress over time, showing migration velocity and projecting completion dates.
Per-application or per-component tracking identifies which areas lag behind. This granularity helps focus attention where needed.
Automated scanning produces metrics. Build processes can count token references, distinguishing old from new naming patterns.
Regular status reporting keeps stakeholders informed. Weekly summaries showing progress, blockers, and next steps maintain alignment.
What about migrations that cannot be fully automated?
Some migration scenarios resist full automation. Complex logic determining which token to use, tokens requiring contextual understanding, or patterns too varied for rule-based transformation need human intervention.
Semi-automated approaches handle what automation can while flagging cases requiring human review:
Automated migration: 85% of references
Manual review required: 15% of references
Manual review items:
- src/components/Card.tsx:45 - Conditional token selection
- src/styles/legacy.css:123 - Complex calculation
- src/utils/theme.js:67 - Dynamic token access
Prioritizing manual cases by importance ensures critical paths receive attention first.
Pairing automated and manual work keeps migration moving. Automation handles volume while humans address complexity.
Documentation of manual migration decisions helps others facing similar cases and creates reference for future migrations.
Summary
Design token migration guides teams through transitioning from one token system state to another. Successful migrations proceed through assessment, mapping, tooling, execution, validation, and cleanup phases. Codemods automate straightforward transformations while manual review handles complex cases. Progress tracking maintains visibility throughout the migration, enabling course correction and stakeholder communication.
Buoy scans your codebase for design system inconsistencies before they ship
Detect Design Drift Free