Skip to content

Commit d1328d8

Browse files
committed
test: fix tests
1 parent b67d3ac commit d1328d8

5 files changed

Lines changed: 41 additions & 15 deletions

File tree

packages/extract/src/extract-tokens.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
23
import type { TokenData, ExtractTokensOptions } from './types.js';
34

45
// Map variable name prefixes to categories
56
const CATEGORY_RULES: Array<{ test: (name: string) => boolean; category: string }> = [
6-
{ test: (n) => /^(box-)?shadow/.test(n), category: 'shadows' },
7+
{ test: (n) => /^shadow/.test(n), category: 'shadows' },
78
{ test: (n) => /^size-(xs|sm|md|lg|xl|xxl)$/.test(n), category: 'breakpoints' },
89
{ test: (n) => /^(font|line-height|heading|h\d-)/.test(n), category: 'typography' },
910
{ test: (n) => /^(spacer|height-)/.test(n), category: 'spacing' },
1011
{
1112
test: (n) =>
12-
/color$/.test(n) ||
13+
/^color-/.test(n) ||
1314
/^(white|black|gray|red|orange|yellow|green|teal|cyan|blue|indigo|purple|magenta)-/.test(n) ||
14-
/^(info|success|warning|danger|primary)-/.test(n) ||
1515
/^(body-bg|body-color)/.test(n),
1616
category: 'colors',
1717
},
@@ -25,7 +25,6 @@ function categorize(name: string): string | null {
2525
}
2626

2727
export function extractTokens(options: ExtractTokensOptions): TokenData {
28-
const content = fs.readFileSync(options.variablesPath, 'utf-8');
2928
const result: TokenData = {
3029
colors: {},
3130
typography: {},
@@ -34,11 +33,13 @@ export function extractTokens(options: ExtractTokensOptions): TokenData {
3433
shadows: {},
3534
};
3635

37-
// Match SCSS variable declarations: $name: value !default;
36+
const variablesContent = fs.readFileSync(options.variablesPath, 'utf-8');
37+
38+
// Parse SCSS variable declarations: $name: value !default;
3839
const varRegex = /^\$([a-z0-9-]+):\s*(.+?)\s*!default\s*;/gm;
3940
let match: RegExpExecArray | null;
4041

41-
while ((match = varRegex.exec(content)) !== null) {
42+
while ((match = varRegex.exec(variablesContent)) !== null) {
4243
const name = match[1];
4344
const value = match[2];
4445
const category = categorize(name);
@@ -51,5 +52,30 @@ export function extractTokens(options: ExtractTokensOptions): TokenData {
5152
}
5253
}
5354

55+
// Also parse theme map files in the themes/ directory next to _variables.scss
56+
const themesDir = path.join(path.dirname(options.variablesPath), 'themes');
57+
const lightThemePath = path.join(themesDir, '_light.scss');
58+
59+
if (fs.existsSync(lightThemePath)) {
60+
const themeContent = fs.readFileSync(lightThemePath, 'utf-8');
61+
62+
// Match map entries: key: value,
63+
// Handles multi-value entries like shadows by matching up to the trailing comma
64+
const mapEntryRegex = /^\s+([a-z0-9-]+):\s*(.+?),?\s*$/gm;
65+
66+
while ((match = mapEntryRegex.exec(themeContent)) !== null) {
67+
const name = match[1];
68+
const value = match[2].replace(/,\s*$/, '');
69+
const category = categorize(name);
70+
71+
if (category && !result[category][name]) {
72+
result[category][name] = {
73+
variable: `--ty-${name}`,
74+
value,
75+
};
76+
}
77+
}
78+
}
79+
5480
return result;
5581
}

packages/mcp/__tests__/extract-tokens.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ describe('extractTokens', () => {
1818
it('extracts color tokens', () => {
1919
const result = extractTokens({ variablesPath: VARIABLES_PATH });
2020

21-
expect(result.colors['primary-color']).toEqual({
22-
variable: '$primary-color',
21+
expect(result.colors['color-primary']).toEqual({
22+
variable: '--ty-color-primary',
2323
value: '#6e41bf',
2424
});
2525

26-
expect(result.colors['info-color']).toEqual({
27-
variable: '$info-color',
26+
expect(result.colors['color-info']).toEqual({
27+
variable: '--ty-color-info',
2828
value: '#1890ff',
2929
});
3030
});
@@ -33,7 +33,7 @@ describe('extractTokens', () => {
3333
const result = extractTokens({ variablesPath: VARIABLES_PATH });
3434

3535
expect(result.typography['font-size-base']).toEqual({
36-
variable: '$font-size-base',
36+
variable: '--ty-font-size-base',
3737
value: '1rem',
3838
});
3939
});
@@ -51,6 +51,6 @@ describe('extractTokens', () => {
5151
const result = extractTokens({ variablesPath: VARIABLES_PATH });
5252

5353
expect(result.shadows).toBeDefined();
54-
expect(result.shadows['box-shadow-sm']).toBeDefined();
54+
expect(result.shadows['shadow-sm']).toBeDefined();
5555
});
5656
});

packages/react/src/config-provider/scroll-lock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function resolveScrollLockTarget(container?: HTMLElement | Window | null): HTMLE
1414
return document.body;
1515
}
1616

17-
return container;
17+
return container as HTMLElement;
1818
}
1919

2020
export function acquireScrollLock(container?: HTMLElement | Window | null): () => void {

packages/react/src/config-provider/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { StaticConfig } from './static-config';
33
import { ConfigContextProps } from './config-context';
44

5-
export interface ConfigProviderProps extends ConfigContextProps {
5+
export interface ConfigProviderProps extends Omit<ConfigContextProps, 'theme'> {
66
// Props accept both ThemeMode and ThemeConfig so callers can provide token overrides.
77
// Context keeps `theme` normalized as ThemeMode and exposes ThemeConfig separately.
88
theme?: ConfigContextProps['theme'] | import('./token-utils').ThemeConfig;

packages/react/src/copy-to-clipboard/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseProps } from '../_utils/props';
33

44
export interface CopyToClipboardProps
55
extends BaseProps,
6-
React.PropsWithoutRef<JSX.IntrinsicElements['span']> {
6+
Omit<React.PropsWithoutRef<JSX.IntrinsicElements['span']>, 'onCopy'> {
77
text: string;
88
onCopy?: (copied: boolean, text: string) => void;
99
children?: React.ReactNode;

0 commit comments

Comments
 (0)