Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | /**
* TEMPORARY GLOBAL CSS Comparison Tool (TO BE REMOVED AFTER MIGRATION)
*
* Compare GLOBAL CSS custom properties coverage: sds-styling-hooks (source of truth) vs design-tokens
* We are considering sds-styling-hooks as the source of truth for CSS API completeness
* Focus on ensuring design-tokens generates all the same CSS custom properties for GLOBAL files
*
* COMPARES: Global files vs global files ({theme}.hooks.custom-props.css vs {theme}.hooks.custom-props.css)
* NOT: Scoped files - use temp-compare-css.js for scoped comparison
* NOT: .json files - use temp-compare-global-json.js for JSON comparison
*
* Usage:
* yarn temp:compare:global-css # Summary only
* yarn temp:compare:global-css --verbose # Show detailed issue tables
* yarn temp:compare:global-css --report # Show full table of all properties
*
* NOTE: This is a temporary migration tool that should be deleted once the
* design token migration from legacy (Theo) to modern (Style Dictionary + W3C)
* is complete and verified.
*/
import fs from 'fs';
import chalk from 'chalk';
import Table from 'cli-table3';
import { parseValidatorArgs, loadKnownIssues, colorSwatch, exitWithStatus } from './validator-utils.js';
const { isVerbose, isReport } = parseValidatorArgs();
const knownIssues = loadKnownIssues();
/**
* Add color swatches to hex colors and light-dark() values
*/
function addColorSwatches(value) {
if (!value || typeof value !== 'string') return value;
// Handle simple hex colors
if (value.match(/^#[0-9a-fA-F]{3,8}$/)) {
return `${colorSwatch(value)} ${value}`;
}
// Handle light-dark() function
const lightDarkMatch = value.match(/^light-dark\(([^,]+),\s*([^)]+)\)$/);
if (lightDarkMatch) {
const lightValue = lightDarkMatch[1].trim();
const darkValue = lightDarkMatch[2].trim();
// Add swatches to both light and dark values if they're hex colors
let formattedLight = lightValue;
let formattedDark = darkValue;
if (lightValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
formattedLight = `${colorSwatch(lightValue)} ${lightValue}`;
}
if (darkValue.match(/^#[0-9a-fA-F]{3,8}$/)) {
formattedDark = `${colorSwatch(darkValue)} ${darkValue}`;
}
return `light-dark(${formattedLight}, ${formattedDark})`;
}
return value;
}
console.log(
chalk.bold.blue(
'TEMPORARY GLOBAL CSS Comparison (TO BE REMOVED): sds-styling-hooks (source of truth) vs design-tokens (GLOBAL SCOPE ONLY)\n',
),
);
const themes = ['slds', 'cosmos'];
const extractProperties = (css) => {
const properties = new Map();
// Match CSS custom properties with their values
const regex = /--([a-zA-Z][\w-]*)\s*:\s*([^;]+);/g;
let match;
while ((match = regex.exec(css)) !== null) {
const name = match[1];
const value = match[2].trim();
properties.set(name, value);
}
return properties;
};
// Normalize values by stripping namespaces from var() references
const normalizeValue = (value) => {
// Replace var(--namespace-g-tokenname) with var(--tokenname)
return value.replace(/var\(--(?:slds-g-|cosmos-g-|sds-g-)([^)]+)\)/g, 'var(--$1)');
};
const allIssues = [];
let totalTests = 0;
let totalMatching = 0;
for (const theme of themes) {
const designTokensPath = `dist/themes/${theme}/${theme}.hooks.custom-props.css`;
const legacyPath = `../sds-styling-hooks/dist/themes/${theme}/${theme}.hooks.custom-props.css`;
try {
// Read both CSS files
const designTokensCSS = fs.readFileSync(designTokensPath, 'utf8');
const legacyCSS = fs.readFileSync(legacyPath, 'utf8');
// Extract properties from both files
const designTokensProps = extractProperties(designTokensCSS);
const allLegacyProps = extractProperties(legacyCSS);
// Filter to only include slds-g-* properties (our target namespace)
// Normalize cosmos-g-* to slds-g-* for comparison (handles legacy namespace bug)
// Exclude: sds-g-*, sds-duration-*, and other non-slds-g namespaces
const legacyProps = new Map();
for (const [prop, value] of allLegacyProps) {
if (prop.startsWith('slds-g-')) {
legacyProps.set(prop, value);
} else if (prop.startsWith('cosmos-g-')) {
// Normalize cosmos-g-* to slds-g-* for comparison
const normalizedProp = prop.replace('cosmos-g-', 'slds-g-');
legacyProps.set(normalizedProp, value);
}
}
const excludedCount = allLegacyProps.size - legacyProps.size;
console.log(chalk.bold(`\nTheme: ${theme.toUpperCase()}`));
console.log('='.repeat(50));
console.log(chalk.bold('\nGLOBAL SCOPE:'));
console.log(` sds-styling-hooks: ${legacyProps.size} properties`);
console.log(` design-tokens: ${designTokensProps.size} properties`);
if (excludedCount > 0) {
console.log(chalk.gray(` (Filtered to slds-g-* namespace: ${excludedCount} properties excluded)`));
}
// Calculate coverage with namespace mapping for Cosmos theme
const covered = [];
const missing = [];
const extra = [];
// Check each design-tokens property
for (const prop of designTokensProps.keys()) {
if (legacyProps.has(prop)) {
covered.push(prop);
} else if (prop.startsWith('slds-g-duration-')) {
// Duration tokens: we use consistent slds-g-* naming while legacy uses sds-duration-*
// Consider these covered as architectural improvements (consistent namespace)
covered.push(prop);
} else if (theme === 'cosmos' && prop.startsWith('slds-g-')) {
// For Cosmos theme, check if there's a cosmos-g-* equivalent in the full property set
const cosmosProp = prop.replace('slds-g-', 'cosmos-g-');
if (allLegacyProps.has(cosmosProp)) {
covered.push(prop); // Consider it covered by cosmos-g-* equivalent
} else {
extra.push(prop);
}
} else {
extra.push(prop);
}
}
// Check each legacy property to find missing ones
for (const prop of legacyProps.keys()) {
if (!designTokensProps.has(prop)) {
missing.push(prop);
}
}
// Check for value mismatches in covered properties
const valueMismatches = [];
for (const prop of covered) {
let legacyValue = legacyProps.get(prop);
const designTokensValue = designTokensProps.get(prop);
// For Cosmos theme, if we don't have direct match, check cosmos-g-* equivalent in the full property set
if (!legacyValue && theme === 'cosmos' && prop.startsWith('slds-g-')) {
const cosmosProp = prop.replace('slds-g-', 'cosmos-g-');
legacyValue = allLegacyProps.get(cosmosProp);
}
if (legacyValue) {
const normalizedLegacyValue = normalizeValue(legacyValue);
const normalizedDesignTokensValue = normalizeValue(designTokensValue);
if (normalizedLegacyValue !== normalizedDesignTokensValue) {
valueMismatches.push({
property: `--${prop}`,
legacy: legacyValue,
design: designTokensValue,
type: 'mismatch',
theme,
scope: 'global',
});
}
}
}
// Add missing and extra to issues
missing.forEach((prop) => {
allIssues.push({
property: `--${prop}`,
legacy: legacyProps.get(prop),
design: null,
type: 'missing',
theme,
scope: 'global',
});
});
extra.forEach((prop) => {
allIssues.push({
property: `--${prop}`,
legacy: null,
design: designTokensProps.get(prop),
type: 'extra',
theme,
scope: 'global',
});
});
allIssues.push(...valueMismatches);
totalTests += legacyProps.size;
totalMatching += covered.length - valueMismatches.length;
// Summary for this theme
const coveragePercent = ((covered.length / legacyProps.size) * 100).toFixed(1);
console.log(` ${chalk.green('✅')} Covered: ${covered.length} (${coveragePercent}%)`);
// Separate issues into new vs known for this theme
const themeKnownIssuesConfig = knownIssues.css_global?.[theme] || {};
const newMissing = missing.filter((p) => !themeKnownIssuesConfig.missing?.includes(`--${p}`)).length;
const newExtra = extra.filter((p) => !themeKnownIssuesConfig.extra?.includes(`--${p}`)).length;
const newMismatches = valueMismatches.filter(
(v) => !themeKnownIssuesConfig.value_mismatches?.includes(v.property),
).length;
const knownMissing = missing.length - newMissing;
const knownExtra = extra.length - newExtra;
const knownMismatches = valueMismatches.length - newMismatches;
const totalNew = newMissing + newExtra + newMismatches;
const totalKnown = knownMissing + knownExtra + knownMismatches;
// Show new issues
if (totalNew > 0) {
console.log(` ${chalk.red('❌')} New issues: ${totalNew}`);
if (newMismatches > 0) {
console.log(` ${chalk.red('❌')} Mismatches: ${newMismatches}`);
}
if (newMissing > 0) {
console.log(` ${chalk.red('❌')} Missing: ${newMissing}`);
}
if (newExtra > 0) {
console.log(` ${chalk.green('➕')} Extra: ${newExtra}`);
}
}
// Show known issues
if (totalKnown > 0) {
console.log(` ${chalk.yellow('⚠️')} Known issues: ${totalKnown}`);
if (knownMismatches > 0) {
console.log(` ${chalk.yellow('⚠️')} Mismatches: ${knownMismatches}`);
}
if (knownMissing > 0) {
console.log(` ${chalk.yellow('⚠️')} Missing: ${knownMissing}`);
}
if (knownExtra > 0) {
console.log(` ${chalk.yellow('⚠️')} Extra: ${knownExtra}`);
}
}
if (totalNew === 0 && totalKnown === 0) {
console.log(` ${chalk.green('✅')} Perfect match!`);
}
} catch (error) {
console.error(chalk.red(`Error processing ${theme}:`), error.message);
}
}
// Filter known issues (theme-specific)
let newIssues = [];
let knownIssuesList = [];
for (const issue of allIssues) {
const themeKnownIssues = knownIssues.css_global?.[issue.theme] || {};
const isKnown =
(issue.type === 'extra' && themeKnownIssues.extra?.includes(issue.property)) ||
(issue.type === 'missing' && themeKnownIssues.missing?.includes(issue.property)) ||
(issue.type === 'mismatch' && themeKnownIssues.value_mismatches?.includes(issue.property));
if (isKnown) {
knownIssuesList.push(issue);
} else {
newIssues.push(issue);
}
}
// Report mode: show full table of all properties
if (isReport) {
console.log(chalk.bold.blue('\n📋 All Global Properties:'));
console.log('='.repeat(50));
for (const theme of themes) {
// Collect all properties for this theme
const allProps = new Map();
// Read the CSS files again to get all properties
const designTokensPath = `dist/themes/${theme}/${theme}.hooks.custom-props.css`;
const legacyPath = `../sds-styling-hooks/dist/themes/${theme}/${theme}.hooks.custom-props.css`;
try {
const designTokensCSS = fs.readFileSync(designTokensPath, 'utf8');
const legacyCSS = fs.readFileSync(legacyPath, 'utf8');
const designTokensProps = extractProperties(designTokensCSS);
const allLegacyProps = extractProperties(legacyCSS);
// Filter to only include slds-g-* properties
const legacyProps = new Map();
for (const [prop, value] of allLegacyProps) {
if (prop.startsWith('slds-g-')) {
legacyProps.set(prop, value);
allProps.set(prop, { legacy: value, design: designTokensProps.get(prop) });
}
}
// Add design-tokens only properties
for (const [prop, value] of designTokensProps) {
if (prop.startsWith('slds-g-') && !allProps.has(prop)) {
allProps.set(prop, { legacy: null, design: value });
}
}
console.log(chalk.bold(`\n${theme.toUpperCase()} (${allProps.size} properties):\n`));
const table = new Table({
head: ['#', 'Property', 'sds-styling-hooks', 'design-tokens', 'Status'],
colWidths: [5, 40, 45, 45, 12],
style: { head: ['cyan'] },
wordWrap: true,
});
const sortedProps = Array.from(allProps.keys()).sort();
sortedProps.forEach((prop, index) => {
const { legacy, design } = allProps.get(prop);
let legacyValue = legacy || chalk.gray('—');
let designValue = design || chalk.gray('—');
let status = '';
// Add color swatches for hex colors and light-dark() values
if (typeof legacyValue === 'string') {
legacyValue = addColorSwatches(legacyValue);
}
if (typeof designValue === 'string') {
designValue = addColorSwatches(designValue);
}
// Determine status
if (!legacy) {
status = chalk.green('➕ Extra');
} else if (!design) {
status = chalk.red('❌ Missing');
} else if (normalizeValue(legacy) !== normalizeValue(design)) {
status = chalk.red('❌ Mismatch');
} else {
status = chalk.green('✓');
}
table.push([index + 1, `--${prop}`, legacyValue, designValue, status]);
});
console.log(table.toString());
} catch (error) {
console.error(chalk.red(`Error reading files for ${theme}: ${error.message}`));
}
}
console.log('');
}
// Verbose mode: show detailed issue tables
if (isVerbose && allIssues.length > 0) {
console.log(chalk.bold.blue('\n📋 Detailed Issues:'));
console.log('='.repeat(50));
// Group by theme
for (const theme of themes) {
const themeIssues = allIssues.filter((i) => i.theme === theme);
if (themeIssues.length === 0) continue;
// Separate new issues from known issues
const themeNewIssues = themeIssues.filter((issue) => {
const themeKnownIssues = knownIssues.css_global?.[theme] || {};
return !(
(issue.type === 'extra' && themeKnownIssues.extra?.includes(issue.property)) ||
(issue.type === 'missing' && themeKnownIssues.missing?.includes(issue.property)) ||
(issue.type === 'mismatch' && themeKnownIssues.value_mismatches?.includes(issue.property))
);
});
const themeKnownIssues = themeIssues.filter((issue) => {
const themeKnownIssuesConfig = knownIssues.css_global?.[theme] || {};
return (
(issue.type === 'extra' && themeKnownIssuesConfig.extra?.includes(issue.property)) ||
(issue.type === 'missing' && themeKnownIssuesConfig.missing?.includes(issue.property)) ||
(issue.type === 'mismatch' && themeKnownIssuesConfig.value_mismatches?.includes(issue.property))
);
});
// Show new issues first (if any)
if (themeNewIssues.length > 0) {
console.log(chalk.bold.red(`\n${theme.toUpperCase()} - NEW ISSUES:`));
const table = new Table({
head: ['#', 'Property', 'sds-styling-hooks', 'design-tokens', 'Type'],
colWidths: [5, 35, 45, 45, 15],
style: { head: ['red'] },
wordWrap: true,
});
themeNewIssues.forEach((issue, index) => {
let legacyValue = issue.legacy || '-';
let designValue = issue.design || '-';
// Add color swatches for hex colors and light-dark() values
if (typeof legacyValue === 'string') {
legacyValue = addColorSwatches(legacyValue);
}
if (typeof designValue === 'string') {
designValue = addColorSwatches(designValue);
}
// Add type label with icon
let typeDisplay = '';
if (issue.type === 'missing') {
typeDisplay = `${chalk.red('❌')} Missing`;
} else if (issue.type === 'extra') {
typeDisplay = `${chalk.green('➕')} Extra`;
} else if (issue.type === 'mismatch') {
typeDisplay = `${chalk.red('❌')} Mismatch`;
}
table.push([index + 1, issue.property, legacyValue, designValue, typeDisplay]);
});
console.log(table.toString());
}
// Show known issues in separate table
if (themeKnownIssues.length > 0) {
console.log(chalk.bold.yellow(`\n${theme.toUpperCase()} - KNOWN ISSUES:`));
const table = new Table({
head: ['#', 'Property', 'sds-styling-hooks', 'design-tokens', 'Type'],
colWidths: [5, 35, 45, 45, 15],
style: { head: ['yellow'] },
wordWrap: true,
});
themeKnownIssues.forEach((issue, index) => {
let legacyValue = issue.legacy || '-';
let designValue = issue.design || '-';
// Add color swatches for hex colors and light-dark() values
if (typeof legacyValue === 'string') {
legacyValue = addColorSwatches(legacyValue);
}
if (typeof designValue === 'string') {
designValue = addColorSwatches(designValue);
}
// Add type label with icon
let typeDisplay = '';
if (issue.type === 'missing') {
typeDisplay = `${chalk.yellow('⚠️')} Missing`;
} else if (issue.type === 'extra') {
typeDisplay = `${chalk.yellow('⚠️')} Extra`;
} else if (issue.type === 'mismatch') {
typeDisplay = `${chalk.yellow('⚠️')} Mismatch`;
}
table.push([index + 1, chalk.white(issue.property), legacyValue, designValue, typeDisplay]);
});
console.log(table.toString());
}
}
console.log('');
}
// Summary
console.log(chalk.bold.blue('\n📊 Summary:'));
console.log(`${totalMatching}/${totalTests} tests passed`);
console.log(`${chalk.green('✅')} Matching: ${totalMatching}`);
// Count by category for new issues
const newMismatches = newIssues.filter((i) => i.type === 'mismatch').length;
const newMissing = newIssues.filter((i) => i.type === 'missing').length;
const newExtra = newIssues.filter((i) => i.type === 'extra').length;
if (newIssues.length > 0) {
console.log(`${chalk.red('❌')} New failures: ${newIssues.length}`);
if (newMismatches > 0) {
console.log(` ${chalk.red('❌')} Mismatches: ${newMismatches}`);
}
if (newMissing > 0) {
console.log(` ${chalk.red('❌')} Missing: ${newMissing}`);
}
if (newExtra > 0) {
console.log(` ${chalk.green('➕')} Extra: ${newExtra}`);
}
}
// Count by category for known issues
const knownMismatches = knownIssuesList.filter((i) => i.type === 'mismatch').length;
const knownMissing = knownIssuesList.filter((i) => i.type === 'missing').length;
const knownExtra = knownIssuesList.filter((i) => i.type === 'extra').length;
if (knownIssuesList.length > 0) {
console.log(`${chalk.yellow('⚠️')} Known issues: ${knownIssuesList.length}`);
if (knownMismatches > 0) {
console.log(` ${chalk.yellow('⚠️')} Mismatches: ${knownMismatches}`);
}
if (knownMissing > 0) {
console.log(` ${chalk.yellow('⚠️')} Missing: ${knownMissing}`);
}
if (knownExtra > 0) {
console.log(` ${chalk.yellow('⚠️')} Extra: ${knownExtra}`);
}
}
if (!isVerbose && !isReport && (newIssues.length > 0 || knownIssuesList.length > 0)) {
console.log(chalk.gray('\nRun with --verbose to see detailed issues or --report to see all properties'));
}
exitWithStatus(newIssues.length, knownIssuesList.length);
|