styled-components-to-stylex-codemod 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -34
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +46 -19
- package/dist/{logger-DKelw2HS.mjs → logger-BLeJjMzG.mjs} +149 -20
- package/dist/logger-DC-1uogs.d.mts +452 -0
- package/dist/transform.d.mts +1 -2
- package/dist/transform.mjs +18014 -9848
- package/package.json +30 -27
- package/dist/logger-CNmtK-uJ.d.mts +0 -250
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "styled-components-to-stylex-codemod",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Codemod to transform styled-components to StyleX",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codemod",
|
|
@@ -32,43 +32,44 @@
|
|
|
32
32
|
"jscodeshift": "^17.3.0",
|
|
33
33
|
"postcss-selector-parser": "^7.1.1",
|
|
34
34
|
"postcss-value-parser": "^4.2.0",
|
|
35
|
-
"stylis": "^4.3.
|
|
35
|
+
"stylis": "^4.3.6"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@codemirror/lang-javascript": "^6.2.4",
|
|
39
39
|
"@emotion/is-prop-valid": "^1.4.0",
|
|
40
|
-
"@storybook/react": "^10.
|
|
41
|
-
"@
|
|
42
|
-
"@stylexjs/babel-plugin": "^0.17.4",
|
|
40
|
+
"@storybook/react-vite": "^10.2.7",
|
|
41
|
+
"@stylexjs/babel-plugin": "^0.17.5",
|
|
43
42
|
"@stylexjs/eslint-plugin": "^0.17.5",
|
|
44
|
-
"@stylexjs/stylex": "^0.17.
|
|
45
|
-
"@stylexjs/unplugin": "^0.17.
|
|
43
|
+
"@stylexjs/stylex": "^0.17.5",
|
|
44
|
+
"@stylexjs/unplugin": "^0.17.5",
|
|
46
45
|
"@types/jscodeshift": "^17.3.0",
|
|
47
|
-
"@types/node": "^25.
|
|
48
|
-
"@types/react": "^19.2.
|
|
46
|
+
"@types/node": "^25.2.1",
|
|
47
|
+
"@types/react": "^19.2.13",
|
|
49
48
|
"@types/react-dom": "^19.2.3",
|
|
50
|
-
"@types/stylis": "^4.2.
|
|
51
|
-
"@typescript-eslint/parser": "^8.
|
|
49
|
+
"@types/stylis": "^4.2.7",
|
|
50
|
+
"@typescript-eslint/parser": "^8.54.0",
|
|
52
51
|
"@uiw/react-codemirror": "^4.25.4",
|
|
53
|
-
"@vitejs/plugin-react": "^5.1.
|
|
54
|
-
"@vitest/coverage-v8": "^4.0.
|
|
52
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
53
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
55
54
|
"assert": "^2.1.0",
|
|
56
55
|
"concurrently": "^9.2.1",
|
|
57
56
|
"eslint": "^9.39.2",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"oxlint
|
|
57
|
+
"eslint-plugin-storybook": "10.2.7",
|
|
58
|
+
"knip": "^5.83.1",
|
|
59
|
+
"lefthook": "^2.1.0",
|
|
60
|
+
"oxfmt": "^0.28.0",
|
|
61
|
+
"oxlint": "^1.43.0",
|
|
62
|
+
"oxlint-tsgolint": "^0.11.4",
|
|
63
63
|
"path-browserify": "^1.0.1",
|
|
64
|
-
"react": "^19.2.
|
|
65
|
-
"react-dom": "^19.2.
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
64
|
+
"react": "^19.2.4",
|
|
65
|
+
"react-dom": "^19.2.4",
|
|
66
|
+
"react-select": "^5.10.2",
|
|
67
|
+
"storybook": "^10.2.7",
|
|
68
|
+
"styled-components": "^6.3.8",
|
|
69
|
+
"tsdown": "^0.20.3",
|
|
69
70
|
"typescript": "^5.9.3",
|
|
70
|
-
"vite": "^7.3.
|
|
71
|
-
"vitest": "^4.0.
|
|
71
|
+
"vite": "^7.3.1",
|
|
72
|
+
"vitest": "^4.0.18"
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|
|
74
75
|
"node": ">=22.20",
|
|
@@ -81,6 +82,7 @@
|
|
|
81
82
|
"test:run": "vitest run",
|
|
82
83
|
"test:coverage": "vitest run --coverage",
|
|
83
84
|
"format": "oxfmt",
|
|
85
|
+
"format:check": "oxfmt --check",
|
|
84
86
|
"lint": "concurrently 'pnpm:lint:oxlint' 'pnpm:lint:eslint'",
|
|
85
87
|
"lint:oxlint": "oxlint --type-aware --deny-warnings",
|
|
86
88
|
"lint:eslint": "eslint . --cache --max-warnings=0 --no-warn-ignored",
|
|
@@ -88,10 +90,11 @@
|
|
|
88
90
|
"typecheck:fixtures": "tsc -p test-cases/tsconfig.json --noEmit",
|
|
89
91
|
"typecheck:playground": "tsc -p playground/tsconfig.json --noEmit",
|
|
90
92
|
"typecheck": "concurrently 'pnpm:typecheck:*'",
|
|
91
|
-
"check": "concurrently 'pnpm:lint' 'pnpm:typecheck' 'pnpm:test:run' 'pnpm:knip'",
|
|
92
|
-
"ci": "pnpm lint && pnpm typecheck && pnpm test:run && pnpm knip && pnpm build",
|
|
93
|
+
"check": "concurrently 'pnpm:lint' 'pnpm:typecheck' 'pnpm:test:run' 'pnpm:knip' 'pnpm:storybook:build' 'pnpm:build' 'pnpm:format:check'",
|
|
94
|
+
"ci": "pnpm lint && pnpm typecheck && pnpm test:run && pnpm knip && pnpm storybook:build && pnpm build && pnpm format:check",
|
|
93
95
|
"knip": "knip",
|
|
94
96
|
"storybook": "storybook dev -p 6006",
|
|
97
|
+
"storybook:build": "storybook build",
|
|
95
98
|
"playground": "vite --config playground/vite.config.ts",
|
|
96
99
|
"build:playground": "vite build --config playground/vite.config.ts"
|
|
97
100
|
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
//#region src/adapter.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* Adapter - Single user entry point for customizing the codemod.
|
|
4
|
-
*/
|
|
5
|
-
type ThemeResolveContext = {
|
|
6
|
-
kind: "theme";
|
|
7
|
-
path: string;
|
|
8
|
-
/**
|
|
9
|
-
* Absolute path of the file currently being transformed.
|
|
10
|
-
* Useful for adapter logic that wants to branch by caller file.
|
|
11
|
-
*/
|
|
12
|
-
filePath?: string;
|
|
13
|
-
};
|
|
14
|
-
type CssVariableResolveContext = {
|
|
15
|
-
kind: "cssVariable";
|
|
16
|
-
name: string;
|
|
17
|
-
fallback?: string;
|
|
18
|
-
definedValue?: string;
|
|
19
|
-
/**
|
|
20
|
-
* Absolute path of the file currently being transformed.
|
|
21
|
-
* Useful for adapter logic that wants to branch by caller file.
|
|
22
|
-
*/
|
|
23
|
-
filePath?: string;
|
|
24
|
-
};
|
|
25
|
-
type CallResolveContext = {
|
|
26
|
-
/**
|
|
27
|
-
* Absolute path of the file currently being transformed.
|
|
28
|
-
* Useful for adapter logic that wants to branch by caller file.
|
|
29
|
-
*/
|
|
30
|
-
callSiteFilePath: string;
|
|
31
|
-
/**
|
|
32
|
-
* Imported name when the callee is a named import (including aliases).
|
|
33
|
-
* Example: `import { transitionSpeed as ts } ...; ts("x")` -> "transitionSpeed"
|
|
34
|
-
*/
|
|
35
|
-
calleeImportedName: string;
|
|
36
|
-
/**
|
|
37
|
-
* Import source for this call: either an absolute file path (relative imports)
|
|
38
|
-
* or the module specifier (package imports).
|
|
39
|
-
*/
|
|
40
|
-
calleeSource: {
|
|
41
|
-
kind: "absolutePath";
|
|
42
|
-
value: string;
|
|
43
|
-
} | {
|
|
44
|
-
kind: "specifier";
|
|
45
|
-
value: string;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Call arguments (only literals are surfaced precisely; everything else is `unknown`).
|
|
49
|
-
*/
|
|
50
|
-
args: Array<{
|
|
51
|
-
kind: "literal";
|
|
52
|
-
value: string | number | boolean | null;
|
|
53
|
-
} | {
|
|
54
|
-
kind: "unknown";
|
|
55
|
-
}>;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Context for `adapter.resolveValue(...)` (theme + css variables).
|
|
59
|
-
*
|
|
60
|
-
* Helper calls are handled separately via `adapter.resolveCall(...)`.
|
|
61
|
-
*/
|
|
62
|
-
type ResolveValueContext = ThemeResolveContext | CssVariableResolveContext;
|
|
63
|
-
/**
|
|
64
|
-
* Result for `adapter.resolveValue(...)` (theme + css variables).
|
|
65
|
-
*/
|
|
66
|
-
type ResolveValueResult = {
|
|
67
|
-
/**
|
|
68
|
-
* JS expression string to inline into generated output.
|
|
69
|
-
* Example: `vars.spacingSm` or `calcVars.baseSize`
|
|
70
|
-
*/
|
|
71
|
-
expr: string;
|
|
72
|
-
/**
|
|
73
|
-
* Import statements required by `expr`.
|
|
74
|
-
* These are rendered and merged into the file by the codemod.
|
|
75
|
-
*/
|
|
76
|
-
imports: ImportSpec[];
|
|
77
|
-
/**
|
|
78
|
-
* If true, the transformer should drop the corresponding `--name: ...` definition
|
|
79
|
-
* from the emitted style object (useful when replacing with StyleX vars).
|
|
80
|
-
*
|
|
81
|
-
* Note: Only meaningful for `{ kind: "cssVariable" }`.
|
|
82
|
-
*/
|
|
83
|
-
dropDefinition?: boolean;
|
|
84
|
-
};
|
|
85
|
-
type CallResolveResult = {
|
|
86
|
-
/**
|
|
87
|
-
* Disambiguates how the resolved expression is used:
|
|
88
|
-
* - "props": a StyleX style object suitable for passing to `stylex.props(...)`.
|
|
89
|
-
* - "create": a value that can be used inside `stylex.create(...)` (e.g. tokens/vars).
|
|
90
|
-
*/
|
|
91
|
-
usage: "props" | "create";
|
|
92
|
-
/**
|
|
93
|
-
* JS expression string to inline into generated output.
|
|
94
|
-
* Example (value): `vars.spacingSm`
|
|
95
|
-
* Example (styles): `borders.labelMuted`
|
|
96
|
-
*/
|
|
97
|
-
expr: string;
|
|
98
|
-
/**
|
|
99
|
-
* Import statements required by `expr`.
|
|
100
|
-
* These are rendered and merged into the file by the codemod.
|
|
101
|
-
*/
|
|
102
|
-
imports: ImportSpec[];
|
|
103
|
-
};
|
|
104
|
-
type ImportSource = {
|
|
105
|
-
kind: "absolutePath";
|
|
106
|
-
value: string;
|
|
107
|
-
} | {
|
|
108
|
-
kind: "specifier";
|
|
109
|
-
value: string;
|
|
110
|
-
};
|
|
111
|
-
type ImportSpec = {
|
|
112
|
-
from: ImportSource;
|
|
113
|
-
names: Array<{
|
|
114
|
-
imported: string;
|
|
115
|
-
local?: string;
|
|
116
|
-
}>;
|
|
117
|
-
};
|
|
118
|
-
interface ExternalStylesContext {
|
|
119
|
-
/** Absolute path of the file being transformed */
|
|
120
|
-
filePath: string;
|
|
121
|
-
/** Local name of the styled component */
|
|
122
|
-
componentName: string;
|
|
123
|
-
/** The export name (may differ from componentName for renamed exports) */
|
|
124
|
-
exportName: string;
|
|
125
|
-
/** Whether it's a default export */
|
|
126
|
-
isDefaultExport: boolean;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Configuration for a custom style merger function that combines stylex.props()
|
|
130
|
-
* results with external className/style props.
|
|
131
|
-
*
|
|
132
|
-
* When configured, generates cleaner output:
|
|
133
|
-
* `{...stylexProps(styles.foo, className, style)}`
|
|
134
|
-
* instead of the verbose pattern:
|
|
135
|
-
* `{...sx} className={[sx.className, className].filter(Boolean).join(" ")} style={{...sx.style, ...style}}`
|
|
136
|
-
*/
|
|
137
|
-
interface StyleMergerConfig {
|
|
138
|
-
/**
|
|
139
|
-
* Function name to use for merging (e.g., "stylexProps" or "mergeStylexProps").
|
|
140
|
-
*/
|
|
141
|
-
functionName: string;
|
|
142
|
-
/**
|
|
143
|
-
* Import source for the merger function.
|
|
144
|
-
* Example: `{ kind: "specifier", value: "@company/ui-utils" }`
|
|
145
|
-
*/
|
|
146
|
-
importSource: ImportSource;
|
|
147
|
-
}
|
|
148
|
-
interface Adapter {
|
|
149
|
-
/**
|
|
150
|
-
* Resolver for theme paths + CSS variables.
|
|
151
|
-
*
|
|
152
|
-
* Notes:
|
|
153
|
-
* - Return `{ expr, imports }` for both theme + css variables.
|
|
154
|
-
* - Optionally return `{ dropDefinition: true }` for css variables to remove the local `--x: ...` definition.
|
|
155
|
-
* - Return `null` to leave a value unresolved.
|
|
156
|
-
*/
|
|
157
|
-
resolveValue: (context: ResolveValueContext) => ResolveValueResult | null;
|
|
158
|
-
/**
|
|
159
|
-
* Resolver for helper calls found inside template interpolations.
|
|
160
|
-
*
|
|
161
|
-
* Return:
|
|
162
|
-
* - `{ usage: "props", expr, imports }` when the call resolves to a StyleX style object
|
|
163
|
-
* (usable as an argument to `stylex.props(...)`).
|
|
164
|
-
* - `{ usage: "create", expr, imports }` when the call resolves to a single CSS value
|
|
165
|
-
* (usable inside `stylex.create(...)` declarations).
|
|
166
|
-
* - `null` to leave the call unresolved (the file may bail with a warning depending on context).
|
|
167
|
-
*/
|
|
168
|
-
resolveCall: (context: CallResolveContext) => CallResolveResult | null;
|
|
169
|
-
/**
|
|
170
|
-
* Called for exported styled components to determine if they should support
|
|
171
|
-
* external className/style extension. Return true to generate wrapper with
|
|
172
|
-
* className/style/rest merging.
|
|
173
|
-
*/
|
|
174
|
-
shouldSupportExternalStyling: (context: ExternalStylesContext) => boolean;
|
|
175
|
-
/**
|
|
176
|
-
* Custom merger function for className/style combining.
|
|
177
|
-
* When provided, generates cleaner output using this function instead of
|
|
178
|
-
* the verbose className/style merging pattern.
|
|
179
|
-
* Set to `null` to use the verbose pattern (default).
|
|
180
|
-
*
|
|
181
|
-
* Expected merger function signature:
|
|
182
|
-
* ```typescript
|
|
183
|
-
* function merger(
|
|
184
|
-
* styles: StyleXStyles | StyleXStyles[],
|
|
185
|
-
* className?: string,
|
|
186
|
-
* style?: React.CSSProperties
|
|
187
|
-
* ): { className?: string; style?: React.CSSProperties }
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
styleMerger: StyleMergerConfig | null;
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Helper for nicer user authoring + type inference.
|
|
194
|
-
*
|
|
195
|
-
* `defineAdapter(...)` also performs runtime validation (helpful for JS consumers)
|
|
196
|
-
* and will throw a descriptive error message if the adapter shape is invalid.
|
|
197
|
-
*
|
|
198
|
-
* Usage:
|
|
199
|
-
* export default defineAdapter({
|
|
200
|
-
* resolveValue(ctx) {
|
|
201
|
-
* if (ctx.kind === "theme") {
|
|
202
|
-
* return {
|
|
203
|
-
* expr: `tokens.${ctx.path}`,
|
|
204
|
-
* imports: [
|
|
205
|
-
* { from: { kind: "specifier", value: "./tokens" }, names: [{ imported: "tokens" }] },
|
|
206
|
-
* ],
|
|
207
|
-
* };
|
|
208
|
-
* }
|
|
209
|
-
* return null;
|
|
210
|
-
* },
|
|
211
|
-
*
|
|
212
|
-
* resolveCall(ctx) {
|
|
213
|
-
* // Resolve helper calls inside template interpolations.
|
|
214
|
-
* // Return:
|
|
215
|
-
* // - { usage: "props", expr, imports } for StyleX styles (usable in stylex.props)
|
|
216
|
-
* // - { usage: "create", expr, imports } for a single value (usable in stylex.create)
|
|
217
|
-
* // - null to leave the call unresolved
|
|
218
|
-
* void ctx;
|
|
219
|
-
* return null;
|
|
220
|
-
* },
|
|
221
|
-
*
|
|
222
|
-
* // Enable className/style/rest support for exported components
|
|
223
|
-
* shouldSupportExternalStyling(ctx) {
|
|
224
|
-
* // Example: Enable for all exported components in a shared components folder
|
|
225
|
-
* return ctx.filePath.includes("/shared/components/");
|
|
226
|
-
* },
|
|
227
|
-
*
|
|
228
|
-
* // Optional: provide a custom merger, or use `null` for the default verbose merge output
|
|
229
|
-
* styleMerger: null,
|
|
230
|
-
* });
|
|
231
|
-
*/
|
|
232
|
-
declare function defineAdapter(adapter: Adapter): Adapter;
|
|
233
|
-
//#endregion
|
|
234
|
-
//#region src/internal/logger.d.ts
|
|
235
|
-
type Severity = "info" | "warning" | "error";
|
|
236
|
-
interface WarningLog {
|
|
237
|
-
severity: Severity;
|
|
238
|
-
type: "unsupported-feature" | "dynamic-node";
|
|
239
|
-
message: string;
|
|
240
|
-
loc?: {
|
|
241
|
-
line: number;
|
|
242
|
-
column: number;
|
|
243
|
-
};
|
|
244
|
-
context?: unknown;
|
|
245
|
-
}
|
|
246
|
-
interface CollectedWarning extends WarningLog {
|
|
247
|
-
filePath: string;
|
|
248
|
-
}
|
|
249
|
-
//#endregion
|
|
250
|
-
export { defineAdapter as i, WarningLog as n, Adapter as r, CollectedWarning as t };
|