styled-components-to-stylex-codemod 0.0.17 → 0.0.19

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 CHANGED
@@ -34,6 +34,12 @@ const adapter = defineAdapter({
34
34
  },
35
35
  // Optional: use a helper for merging StyleX styles with external className/style
36
36
  styleMerger: null,
37
+ // Optional: customize the runtime theme hook import/call used for theme conditionals
38
+ // Defaults to { functionName: "useTheme", importSource: { kind: "specifier", value: "styled-components" } }
39
+ themeHook: {
40
+ functionName: "useTheme",
41
+ importSource: { kind: "specifier", value: "styled-components" },
42
+ },
37
43
  });
38
44
 
39
45
  await runTransform({
@@ -113,6 +119,30 @@ const adapter = defineAdapter({
113
119
  };
114
120
  },
115
121
 
122
+ /**
123
+ * Optional: inline styled(ImportedComponent) into an intrinsic element.
124
+ * When the base component can be resolved statically, return the target
125
+ * element, consumed props, and base StyleX declarations. Return undefined
126
+ * to keep normal styled(Component) behavior.
127
+ */
128
+ resolveBaseComponent(ctx) {
129
+ if (ctx.importSource !== "@company/ui" || ctx.importedName !== "Flex") {
130
+ return undefined;
131
+ }
132
+
133
+ const sx: Record<string, string> = { display: "flex" };
134
+ const consumedProps = ["column", "gap", "align"];
135
+
136
+ if (ctx.staticProps.column === true) {
137
+ sx.flexDirection = "column";
138
+ }
139
+ if (typeof ctx.staticProps.gap === "number") {
140
+ sx.gap = `${ctx.staticProps.gap}px`;
141
+ }
142
+
143
+ return { tagName: "div", consumedProps, sx };
144
+ },
145
+
116
146
  /**
117
147
  * Control which exported components accept external className/style
118
148
  * and/or polymorphic `as` prop. Return `{ styles, as }` flags.
@@ -133,6 +163,15 @@ const adapter = defineAdapter({
133
163
  functionName: "mergedSx",
134
164
  importSource: { kind: "specifier", value: "./lib/mergedSx" },
135
165
  },
166
+
167
+ /**
168
+ * Optional: customize the runtime theme hook used when wrappers need theme booleans.
169
+ * Defaults to useTheme from styled-components.
170
+ */
171
+ themeHook: {
172
+ functionName: "useDesignTheme",
173
+ importSource: { kind: "specifier", value: "@company/theme-hooks" },
174
+ },
136
175
  });
137
176
 
138
177
  await runTransform({
@@ -156,6 +195,8 @@ Adapters are the main extension point, see full example above. They let you cont
156
195
  - how helper calls are resolved (via `resolveCall({ ... })` returning `{ expr, imports }`; `null`/`undefined` bails the file)
157
196
  - which exported components should support external className/style extension and/or polymorphic `as` prop (`externalInterface`)
158
197
  - how className/style merging is handled for components accepting external styling (`styleMerger`)
198
+ - which runtime theme hook import/call to use for emitted wrapper theme conditionals (`themeHook`)
199
+ - how `styled(ImportedComponent)` wrapping an external base component can be inlined into an intrinsic element with static StyleX styles (`resolveBaseComponent`)
159
200
 
160
201
  #### Cross-file selectors (`consumerPaths`)
161
202
 
@@ -208,6 +249,50 @@ Troubleshooting prepass failures with `"auto"`:
208
249
  - check resolver inputs (import paths, tsconfig path aliases, and related module resolution config)
209
250
  - if needed, switch to a manual `externalInterface(ctx)` function to continue migration while you fix prepass inputs
210
251
 
252
+ #### Base component resolution (`resolveBaseComponent`)
253
+
254
+ Use this when you want to **replace a base component entirely** by inlining its styles. If your codebase has a layout primitive like `<Flex>` whose behavior is purely CSS, the codemod can eliminate the runtime import and render a plain `<div>` instead.
255
+
256
+ The resolver receives `ctx.importSource`, `ctx.importedName`, and `ctx.staticProps` (from `.attrs()` and JSX call sites). Return `{ tagName, consumedProps, sx }` to inline, or `undefined` to skip.
257
+
258
+ ```tsx
259
+ // Input
260
+ const Container = styled(Flex).attrs({ column: true, gap: 16 })`
261
+ padding: 8px;
262
+ `;
263
+ ```
264
+
265
+ ```ts
266
+ // Adapter
267
+ resolveBaseComponent(ctx) {
268
+ if (ctx.importedName !== "Flex") return undefined;
269
+ const sx: Record<string, string> = { display: "flex" };
270
+ if (ctx.staticProps.column === true) sx.flexDirection = "column";
271
+ if (typeof ctx.staticProps.gap === "number") sx.gap = `${ctx.staticProps.gap}px`;
272
+ return { tagName: "div", consumedProps: ["column", "gap", "align"], sx };
273
+ },
274
+ ```
275
+
276
+ ```tsx
277
+ // Output — Flex is gone, its styles are merged into stylex.create()
278
+ const styles = stylex.create({
279
+ container: { display: "flex", flexDirection: "column", gap: "16px", padding: "8px" },
280
+ });
281
+ ```
282
+
283
+ If the base component's styles already exist as a `stylex.create()` object, return `mixins` instead of (or alongside) `sx`. The codemod imports the mixin and includes it in `stylex.props(...)`:
284
+
285
+ ```ts
286
+ resolveBaseComponent(ctx) {
287
+ return {
288
+ tagName: "div",
289
+ consumedProps: ["column", "gap"],
290
+ mixins: [{ importSource: "./lib/mixins.stylex", importName: "mixins", styleKey: "flex" }],
291
+ };
292
+ },
293
+ // Output: <div {...stylex.props(mixins.flex, styles.container)} />
294
+ ```
295
+
211
296
  #### Dynamic interpolations
212
297
 
213
298
  When the codemod encounters an interpolation inside a styled template literal, it runs an internal dynamic resolution pipeline which covers common cases like:
@@ -263,7 +348,11 @@ export const truncate = stylex.create({
263
348
 
264
349
  The adapter maps your project's `props.theme.*` access, CSS variables, and helper calls to the StyleX equivalents from step 1. See [Usage](#usage) for the full API.
265
350
 
266
- ### 3. Verify, iterate, clean up
351
+ ### 3. Convert bottom-up (leaf components first)
352
+
353
+ When a component wraps another component that internally uses styled-components (e.g. `styled(GroupHeader)` where `GroupHeader` renders a `StyledHeader`), CSS cascade conflicts can arise after migration. Convert leaf files — the ones that don't wrap other styled-components — first, then work your way up. The codemod will bail with a warning if it detects this pattern.
354
+
355
+ ### 4. Verify, iterate, clean up
267
356
 
268
357
  Build and test your project. Review warnings — they tell you which files were skipped and why. Fix adapter gaps, re-run on remaining files, and repeat until done. [Report issues](https://github.com/skovhus/styled-components-to-stylex-codemod/issues) with input/output examples if the codemod produces incorrect results.
269
358
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as defineAdapter, i as AdapterInput, t as CollectedWarning } from "./logger-B7SOfCti.mjs";
1
+ import { a as defineAdapter, i as AdapterInput, t as CollectedWarning } from "./logger-DyMTX-U6.mjs";
2
2
 
3
3
  //#region src/run.d.ts
4
4
  interface RunTransformOptions {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as describeValue, r as assertValidAdapterInput, t as Logger } from "./logger-D-R2KB6I.mjs";
1
+ import { a as assertValidAdapterInput, o as describeValue, r as defineAdapter, t as Logger } from "./logger-D7X3KrX1.mjs";
2
2
  import { run } from "jscodeshift/src/Runner.js";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { dirname, join, resolve } from "node:path";
@@ -6,68 +6,6 @@ import { existsSync, readFileSync, realpathSync } from "node:fs";
6
6
  import { glob, writeFile } from "node:fs/promises";
7
7
  import { spawn } from "node:child_process";
8
8
 
9
- //#region src/adapter.ts
10
- /**
11
- * Adapter entry point for customizing the codemod.
12
- * Core concepts: value resolution hooks and adapter validation.
13
- */
14
- /**
15
- * Helper for nicer user authoring + type inference.
16
- *
17
- * `defineAdapter(...)` also performs runtime validation (helpful for JS consumers)
18
- * and will throw a descriptive error message if the adapter shape is invalid.
19
- *
20
- * Usage:
21
- * export default defineAdapter({
22
- * resolveValue(ctx) {
23
- * if (ctx.kind === "theme") {
24
- * return {
25
- * expr: `tokens.${ctx.path}`,
26
- * imports: [
27
- * { from: { kind: "specifier", value: "./tokens" }, names: [{ imported: "tokens" }] },
28
- * ],
29
- * };
30
- * }
31
- * // Return undefined to bail/skip the file
32
- * },
33
- *
34
- * resolveCall(ctx) {
35
- * // Resolve helper calls inside template interpolations.
36
- * // Use ctx.cssProperty to determine context:
37
- * // - If ctx.cssProperty exists → return a CSS value expression
38
- * // - If ctx.cssProperty is undefined → return a StyleX style object reference
39
- * // Return { expr, imports } or undefined to bail/skip the file
40
- * void ctx;
41
- * },
42
- *
43
- * resolveSelector(ctx) {
44
- * // Resolve imported values used in selector position.
45
- * // Return one of:
46
- * // - { kind: "media", expr, imports } for media queries (e.g., breakpoints.phone)
47
- * // - { kind: "pseudoAlias", values, styleSelectorExpr?, imports? } for pseudo-class expansion
48
- * // - undefined to bail/skip the file
49
- * void ctx;
50
- * },
51
- *
52
- * // Configure external interface for exported components
53
- * externalInterface(ctx) {
54
- * // Example: Enable styles and `as` for shared components folder
55
- * if (ctx.filePath.includes("/shared/components/")) {
56
- * return { styles: true, as: true };
57
- * }
58
- * return { styles: false, as: false };
59
- * },
60
- *
61
- * // Optional: provide a custom merger, or use `null` for the default verbose merge output
62
- * styleMerger: null,
63
- * });
64
- */
65
- function defineAdapter(adapter) {
66
- assertValidAdapterInput(adapter, "defineAdapter(adapter)");
67
- return adapter;
68
- }
69
-
70
- //#endregion
71
9
  //#region src/run.ts
72
10
  /**
73
11
  * Runs the codemod over input files with an adapter.
@@ -168,6 +106,17 @@ async function runTransform(options) {
168
106
  throw e;
169
107
  }
170
108
  };
109
+ const resolveBaseComponentWithLogging = (ctx) => {
110
+ if (!adapterInput.resolveBaseComponent) return;
111
+ try {
112
+ return adapterInput.resolveBaseComponent(ctx);
113
+ } catch (e) {
114
+ const msg = `adapter.resolveBaseComponent threw an error: ${e instanceof Error ? e.message : String(e)}`;
115
+ Logger.logError(msg, ctx.filePath, void 0, ctx);
116
+ Logger.markErrorAsLogged(e);
117
+ throw e;
118
+ }
119
+ };
171
120
  const patterns = Array.isArray(files) ? files : [files];
172
121
  const filePaths = [];
173
122
  const cwd = process.cwd();
@@ -194,7 +143,7 @@ async function runTransform(options) {
194
143
  ].join("\n"));
195
144
  const { createModuleResolver } = await import("./resolve-imports-BDk6Ms09.mjs");
196
145
  const sharedResolver = createModuleResolver();
197
- const { runPrepass } = await import("./run-prepass-C4Lv1FHf.mjs");
146
+ const { runPrepass } = await import("./run-prepass-ByjC18e6.mjs");
198
147
  const absoluteFiles = filePaths.map((f) => resolve(f));
199
148
  const absoluteConsumers = consumerFilePaths.map((f) => resolve(f));
200
149
  let prepassResult;
@@ -243,12 +192,14 @@ async function runTransform(options) {
243
192
  })();
244
193
  const adapterWithLogging = {
245
194
  styleMerger: resolvedAdapter.styleMerger,
195
+ themeHook: resolvedAdapter.themeHook,
246
196
  externalInterface(ctx) {
247
197
  return resolvedAdapter.externalInterface(ctx);
248
198
  },
249
199
  resolveValue: resolveValueWithLogging,
250
200
  resolveCall: resolveCallWithLogging,
251
- resolveSelector: resolveSelectorWithLogging
201
+ resolveSelector: resolveSelectorWithLogging,
202
+ resolveBaseComponent: adapterInput.resolveBaseComponent ? resolveBaseComponentWithLogging : void 0
252
203
  };
253
204
  const transformPath = (() => {
254
205
  const adjacent = join(__dirname, "transform.mjs");
@@ -35,6 +35,7 @@ function assertAdapterShape(candidate, where, allowAutoExtIf) {
35
35
  const resolveValue = obj?.resolveValue;
36
36
  const resolveCall = obj?.resolveCall;
37
37
  const resolveSelector = obj?.resolveSelector;
38
+ const resolveBaseComponent = obj?.resolveBaseComponent;
38
39
  const externalInterface = obj?.externalInterface;
39
40
  if (!candidate || typeof candidate !== "object") throw new Error([
40
41
  `${where}: expected an adapter object.`,
@@ -95,6 +96,19 @@ function assertAdapterShape(candidate, where, allowAutoExtIf) {
95
96
  "",
96
97
  `Docs/examples: ${ADAPTER_DOCS_URL}`
97
98
  ].join("\n"));
99
+ if (resolveBaseComponent !== void 0 && typeof resolveBaseComponent !== "function") throw new Error([
100
+ `${where}: adapter.resolveBaseComponent must be a function when provided.`,
101
+ `Received: resolveBaseComponent=${describeValue(resolveBaseComponent)}`,
102
+ "",
103
+ "Adapter shape:",
104
+ " {",
105
+ " resolveBaseComponent(context) {",
106
+ " return { tagName, consumedProps, sx?, mixins? } | undefined",
107
+ " }",
108
+ " }",
109
+ "",
110
+ `Docs/examples: ${ADAPTER_DOCS_URL}`
111
+ ].join("\n"));
98
112
  if (!(typeof externalInterface === "function" || allowAutoExtIf && externalInterface === "auto")) {
99
113
  const expected = allowAutoExtIf ? "adapter.externalInterface must be a function or \"auto\"." : "adapter.externalInterface must be a function.";
100
114
  throw new Error([`${where}: ${expected}`, `Received: externalInterface=${describeValue(externalInterface)}`].join("\n"));
@@ -112,23 +126,131 @@ function assertAdapterShape(candidate, where, allowAutoExtIf) {
112
126
  " }"
113
127
  ].join("\n"));
114
128
  const { functionName, importSource } = styleMerger;
115
- if (typeof functionName !== "string" || !functionName.trim()) throw new Error([`${where}: adapter.styleMerger.functionName must be a non-empty string.`, `Received: functionName=${describeValue(functionName)}`].join("\n"));
116
- if (!importSource || typeof importSource !== "object") throw new Error([
117
- `${where}: adapter.styleMerger.importSource must be an object.`,
118
- `Received: importSource=${describeValue(importSource)}`,
129
+ assertFunctionNameAndImportSource({
130
+ where,
131
+ configPath: "adapter.styleMerger",
132
+ functionName,
133
+ importSource,
134
+ specifierExample: "@company/ui-utils",
135
+ absolutePathExample: "/path/to/module.ts"
136
+ });
137
+ }
138
+ const themeHook = obj?.themeHook;
139
+ if (themeHook !== null && themeHook !== void 0) {
140
+ if (typeof themeHook !== "object") throw new Error([
141
+ `${where}: adapter.themeHook must be an object when provided.`,
142
+ `Received: themeHook=${describeValue(themeHook)}`,
119
143
  "",
120
144
  "Expected shape:",
121
- " { kind: \"specifier\", value: \"@company/ui-utils\" }",
122
- " or",
123
- " { kind: \"absolutePath\", value: \"/path/to/module.ts\" }"
145
+ " {",
146
+ " functionName: \"useTheme\",",
147
+ " importSource: { kind: \"specifier\", value: \"@company/theme-hooks\" }",
148
+ " }"
124
149
  ].join("\n"));
125
- const { kind, value } = importSource;
126
- if (kind !== "specifier" && kind !== "absolutePath") throw new Error([`${where}: adapter.styleMerger.importSource.kind must be "specifier" or "absolutePath".`, `Received: kind=${describeValue(kind)}`].join("\n"));
127
- if (typeof value !== "string" || !value.trim()) throw new Error([`${where}: adapter.styleMerger.importSource.value must be a non-empty string.`, `Received: value=${describeValue(value)}`].join("\n"));
150
+ const { functionName, importSource } = themeHook;
151
+ assertFunctionNameAndImportSource({
152
+ where,
153
+ configPath: "adapter.themeHook",
154
+ functionName,
155
+ importSource,
156
+ specifierExample: "@company/theme-hooks",
157
+ absolutePathExample: "/path/to/theme-hooks.ts"
158
+ });
128
159
  }
129
160
  }
161
+ function assertFunctionNameAndImportSource(args) {
162
+ const { where, configPath, functionName, importSource, specifierExample, absolutePathExample } = args;
163
+ if (typeof functionName !== "string" || !functionName.trim()) throw new Error([`${where}: ${configPath}.functionName must be a non-empty string.`, `Received: functionName=${describeValue(functionName)}`].join("\n"));
164
+ if (!importSource || typeof importSource !== "object") throw new Error([
165
+ `${where}: ${configPath}.importSource must be an object.`,
166
+ `Received: importSource=${describeValue(importSource)}`,
167
+ "",
168
+ "Expected shape:",
169
+ ` { kind: "specifier", value: "${specifierExample}" }`,
170
+ " or",
171
+ ` { kind: "absolutePath", value: "${absolutePathExample}" }`
172
+ ].join("\n"));
173
+ const { kind, value } = importSource;
174
+ if (kind !== "specifier" && kind !== "absolutePath") throw new Error([`${where}: ${configPath}.importSource.kind must be "specifier" or "absolutePath".`, `Received: kind=${describeValue(kind)}`].join("\n"));
175
+ if (typeof value !== "string" || !value.trim()) throw new Error([`${where}: ${configPath}.importSource.value must be a non-empty string.`, `Received: value=${describeValue(value)}`].join("\n"));
176
+ }
130
177
  const ADAPTER_DOCS_URL = `https://github.com/skovhus/styled-components-to-stylex-codemod#adapter`;
131
178
 
179
+ //#endregion
180
+ //#region src/adapter.ts
181
+ /**
182
+ * Adapter entry point for customizing the codemod.
183
+ * Core concepts: value resolution hooks and adapter validation.
184
+ */
185
+ const DEFAULT_THEME_HOOK = {
186
+ functionName: "useTheme",
187
+ importSource: {
188
+ kind: "specifier",
189
+ value: "styled-components"
190
+ }
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 undefined to bail/skip the file
210
+ * },
211
+ *
212
+ * resolveCall(ctx) {
213
+ * // Resolve helper calls inside template interpolations.
214
+ * // Use ctx.cssProperty to determine context:
215
+ * // - If ctx.cssProperty exists → return a CSS value expression
216
+ * // - If ctx.cssProperty is undefined → return a StyleX style object reference
217
+ * // Return { expr, imports } or undefined to bail/skip the file
218
+ * void ctx;
219
+ * },
220
+ *
221
+ * resolveSelector(ctx) {
222
+ * // Resolve imported values used in selector position.
223
+ * // Return one of:
224
+ * // - { kind: "media", expr, imports } for media queries (e.g., breakpoints.phone)
225
+ * // - { kind: "pseudoAlias", values, styleSelectorExpr?, imports? } for pseudo-class expansion
226
+ * // - undefined to bail/skip the file
227
+ * void ctx;
228
+ * },
229
+ *
230
+ * // Configure external interface for exported components
231
+ * externalInterface(ctx) {
232
+ * // Example: Enable styles and `as` for shared components folder
233
+ * if (ctx.filePath.includes("/shared/components/")) {
234
+ * return { styles: true, as: true };
235
+ * }
236
+ * return { styles: false, as: false };
237
+ * },
238
+ *
239
+ * // Optional: provide a custom merger, or use `null` for the default verbose merge output
240
+ * styleMerger: null,
241
+ *
242
+ * // Optional: customize runtime theme hook import/call used by emitted wrappers
243
+ * themeHook: {
244
+ * functionName: "useTheme",
245
+ * importSource: { kind: "specifier", value: "styled-components" },
246
+ * },
247
+ * });
248
+ */
249
+ function defineAdapter(adapter) {
250
+ assertValidAdapterInput(adapter, "defineAdapter(adapter)");
251
+ return adapter;
252
+ }
253
+
132
254
  //#endregion
133
255
  //#region src/internal/logger.ts
134
256
  /**
@@ -361,4 +483,4 @@ const SECTION_COLOR = "\x1B[36m";
361
483
  const RESET_COLOR = "\x1B[0m";
362
484
 
363
485
  //#endregion
364
- export { describeValue as i, assertValidAdapter as n, assertValidAdapterInput as r, Logger as t };
486
+ export { assertValidAdapterInput as a, assertValidAdapter as i, DEFAULT_THEME_HOOK as n, describeValue as o, defineAdapter as r, Logger as t };
@@ -232,6 +232,48 @@ type ImportSpec = {
232
232
  local?: string;
233
233
  }>;
234
234
  };
235
+ type ResolveBaseComponentStaticValue = string | number | boolean;
236
+ interface ResolveBaseComponentContext {
237
+ /**
238
+ * Import source for the wrapped base component.
239
+ * - package import: "@linear/orbiter/components/Flex"
240
+ * - relative import: resolved absolute path
241
+ */
242
+ importSource: string;
243
+ /**
244
+ * Imported binding name for the wrapped base component.
245
+ * Example: `import { Flex as OrbiterFlex } ...` -> importedName: "Flex"
246
+ */
247
+ importedName: string;
248
+ /**
249
+ * Static props from `.attrs({...})` and/or JSX call sites.
250
+ * Includes only literal values that can be resolved at codemod time.
251
+ */
252
+ staticProps: Record<string, ResolveBaseComponentStaticValue>;
253
+ /**
254
+ * Absolute path of the file currently being transformed.
255
+ * Useful for resolver logic that branches by caller file.
256
+ */
257
+ filePath: string;
258
+ }
259
+ interface ResolveBaseComponentMixinRef {
260
+ /** Import source for the mixin namespace/object (module specifier or absolute path) */
261
+ importSource: string;
262
+ /** Imported binding name for the mixin namespace/object (e.g., "mixins") */
263
+ importName: string;
264
+ /** Property key on the imported namespace/object (e.g., "flex") */
265
+ styleKey: string;
266
+ }
267
+ interface ResolveBaseComponentResult {
268
+ /** Intrinsic element to render after inlining (e.g., "div", "section") */
269
+ tagName: string;
270
+ /** Props consumed by the resolver and stripped from DOM forwarding */
271
+ consumedProps: string[];
272
+ /** Base StyleX declarations merged into stylex.create() (camelCase, no shorthands) */
273
+ sx?: Record<string, string>;
274
+ /** External StyleX mixin references included in stylex.props(...) */
275
+ mixins?: ResolveBaseComponentMixinRef[];
276
+ }
235
277
  /**
236
278
  * Context for `adapter.resolveSelector(...)`.
237
279
  *
@@ -348,6 +390,25 @@ interface StyleMergerConfig {
348
390
  */
349
391
  importSource: ImportSource;
350
392
  }
393
+ /**
394
+ * Configuration for the theme hook used when wrapper emission needs runtime theme access
395
+ * (e.g. theme boolean conditionals that cannot be fully lowered statically).
396
+ *
397
+ * Defaults to:
398
+ * - functionName: "useTheme"
399
+ * - importSource: { kind: "specifier", value: "styled-components" }
400
+ */
401
+ interface ThemeHookConfig {
402
+ /**
403
+ * Function name to call in emitted wrappers (e.g. "useTheme", "useDesignSystemTheme").
404
+ */
405
+ functionName: string;
406
+ /**
407
+ * Import source for the hook function.
408
+ * Example: `{ kind: "specifier", value: "@company/theme" }`
409
+ */
410
+ importSource: ImportSource;
411
+ }
351
412
  interface Adapter {
352
413
  /**
353
414
  * Resolver for theme paths + CSS variables + imported values.
@@ -385,6 +446,14 @@ interface Adapter {
385
446
  * - `undefined` to bail/skip the file
386
447
  */
387
448
  resolveSelector: (context: SelectorResolveContext) => SelectorResolveResult | undefined;
449
+ /**
450
+ * Optional resolver for inlining `styled(ImportedBase)` components.
451
+ *
452
+ * Return:
453
+ * - `{ tagName, consumedProps, sx?, mixins? }` to inline the base component
454
+ * - `undefined` to keep normal `styled(Component)` behavior
455
+ */
456
+ resolveBaseComponent?: (context: ResolveBaseComponentContext) => ResolveBaseComponentResult | undefined;
388
457
  /**
389
458
  * Called for exported styled components to determine their external interface.
390
459
  *
@@ -411,6 +480,13 @@ interface Adapter {
411
480
  * ```
412
481
  */
413
482
  styleMerger: StyleMergerConfig | null;
483
+ /**
484
+ * Optional theme hook import/call customization for wrapper code that needs runtime theme access.
485
+ *
486
+ * When omitted, defaults to:
487
+ * `{ functionName: "useTheme", importSource: { kind: "specifier", value: "styled-components" } }`
488
+ */
489
+ themeHook?: ThemeHookConfig;
414
490
  }
415
491
  /**
416
492
  * User-facing adapter input type accepted by `defineAdapter()`.
@@ -424,6 +500,7 @@ interface AdapterInput {
424
500
  resolveValue: Adapter["resolveValue"];
425
501
  resolveCall: Adapter["resolveCall"];
426
502
  resolveSelector: Adapter["resolveSelector"];
503
+ resolveBaseComponent?: Adapter["resolveBaseComponent"];
427
504
  /**
428
505
  * Called for exported styled components to determine their external interface.
429
506
  *
@@ -433,6 +510,7 @@ interface AdapterInput {
433
510
  */
434
511
  externalInterface: "auto" | Adapter["externalInterface"];
435
512
  styleMerger: Adapter["styleMerger"];
513
+ themeHook?: Adapter["themeHook"];
436
514
  }
437
515
  /**
438
516
  * Helper for nicer user authoring + type inference.
@@ -483,13 +561,19 @@ interface AdapterInput {
483
561
  *
484
562
  * // Optional: provide a custom merger, or use `null` for the default verbose merge output
485
563
  * styleMerger: null,
564
+ *
565
+ * // Optional: customize runtime theme hook import/call used by emitted wrappers
566
+ * themeHook: {
567
+ * functionName: "useTheme",
568
+ * importSource: { kind: "specifier", value: "styled-components" },
569
+ * },
486
570
  * });
487
571
  */
488
572
  declare function defineAdapter<T extends AdapterInput>(adapter: T): T;
489
573
  //#endregion
490
574
  //#region src/internal/logger.d.ts
491
575
  type Severity = "info" | "warning" | "error";
492
- type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: @-rules (e.g., @media, @supports) are not supported" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "Unsupported interpolation: member expression" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: unknown component selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Sibling selector broadened: & + & (adjacent) becomes general sibling (~) in StyleX — interleaved non-matching elements will no longer block the match" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead";
576
+ type WarningType = "`css` helper function switch must return css templates in all branches" | "`css` helper usage as a function call (css(...)) is not supported" | "`css` helper used outside of a styled component template cannot be statically transformed" | "Adapter helper call in border interpolation did not resolve to a single CSS value" | "Adapter resolveCall returned an unparseable styles expression" | "Adapter resolveCall returned an unparseable value expression" | "Adapter resolveCall returned StyleX styles for helper call where a CSS value was expected" | "Adapter resolveCall returned undefined for helper call" | "Adapter resolveBaseComponent threw an error" | "Adapter resolved StyleX styles cannot be applied under nested selectors/at-rules" | "Adapter resolved StyleX styles inside pseudo selector but did not provide cssText for property expansion — add cssText to resolveCall result to enable pseudo-wrapping" | 'Adapter resolveCall cssText could not be parsed as CSS declarations — expected semicolon-separated property: value pairs (e.g. "white-space: nowrap; overflow: hidden;")' | "Adapter resolveValue returned an unparseable value expression" | "Adapter resolveValue returned undefined for imported value" | "Arrow function: body is not a recognized pattern (expected ternary, logical, call, or member expression)" | "Arrow function: conditional branches could not be resolved to static or theme values" | "Arrow function: helper call body is not supported" | "Arrow function: indexed theme lookup pattern not matched" | "Arrow function: logical expression pattern not supported" | "Arrow function: prop access cannot be converted to style function for this CSS property" | "Arrow function: theme access path could not be resolved" | "Component selectors like `${OtherComponent}:hover &` are not directly representable in StyleX. Manual refactor is required" | "Conditional `css` block: !important is not supported in StyleX" | "Conditional `css` block: @-rules (e.g., @media, @supports) are not supported" | "CSS block contains unsupported at-rule (only @media is supported; @supports, @container, etc. require manual handling)" | "Conditional `css` block: dynamic interpolation could not be resolved to a single component prop" | "Conditional `css` block: failed to parse expression" | "Conditional `css` block: missing CSS property name" | "Conditional `css` block: missing interpolation expression" | "Conditional `css` block: mixed static/dynamic values with non-theme expressions cannot be safely transformed" | "Conditional `css` block: multiple interpolation slots in a single property value" | "Conditional `css` block: ternary branch value could not be resolved (imported values require adapter support)" | "Conditional `css` block: ternary expressions inside pseudo selectors are not supported" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "Dynamic styles inside pseudo elements (::before/::after) are not supported by StyleX. See https://github.com/facebook/stylex/issues/1396" | "Failed to parse theme expressions" | "Heterogeneous background values (mix of gradients and colors) not currently supported" | "Higher-order styled factory wrappers (e.g. hoc(styled)) are not supported" | "Imported CSS helper mixins: cannot determine inherited properties for correct pseudo selector handling" | "Styled-components specificity hacks like `&&` / `&&&` are not representable in StyleX" | "Theme-dependent block-level conditional could not be fully resolved (branches may contain dynamic interpolations)" | "Theme-dependant call expression could not be resolved (e.g. theme helper calls like theme.highlight() are not supported)" | "Theme value with fallback (props.theme.X ?? / || default) cannot be resolved statically — use adapter.resolveValue to map theme paths to StyleX tokens" | "Theme-dependent nested prop access requires a project-specific theme source (e.g. useTheme())" | "Theme-dependent template literals require a project-specific theme source (e.g. useTheme())" | "Theme prop overrides on styled components are not supported" | "Universal selectors (`*`) are currently unsupported" | "Unsupported call expression (expected imported helper(...) or imported helper(...)(...))" | "Unsupported conditional test in shouldForwardProp" | "Unsupported shouldForwardProp pattern (only !prop.startsWith(), ![].includes(prop), and prop !== are supported)" | "Unsupported interpolation: arrow function" | "Unsupported interpolation: call expression" | "Unsupported interpolation: identifier" | "Unsupported interpolation: member expression" | "Unsupported interpolation: property" | "Unsupported interpolation: unknown" | "Unsupported nested conditional interpolation" | "Unsupported prop-based inline style expression cannot be safely inlined" | "Unsupported prop-based inline style props.theme access is not supported" | "Unsupported selector interpolation: imported value in selector position" | "Unsupported selector: class selector" | "Unsupported selector: comma-separated selectors must all be simple pseudos or pseudo-elements" | "Unsupported selector: descendant pseudo selector (space before pseudo)" | "Unsupported selector: descendant/child/sibling selector" | "Unsupported selector: interpolated pseudo selector" | "Unsupported selector: sibling combinator" | "Unsupported selector: unresolved interpolation in sibling selector" | "Unsupported selector: ambiguous element selector" | "Unsupported selector: attribute selector on unsupported element" | "Unsupported selector: element selector on exported component" | "Unsupported selector: element selector with combined ancestor and child pseudos" | "Unsupported selector: element selector with dynamic children" | "Unsupported selector: element selector with plain intrinsic children" | "Unsupported selector: element selector pseudo collision" | "Unsupported selector: unresolved interpolation in cross-file component selector" | "Unsupported selector: unresolved interpolation in descendant component selector" | "Unsupported selector: unresolved interpolation in element selector" | "Unsupported selector: unresolved interpolation in reverse component selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: unknown component selector" | "Unsupported css`` mixin: after-base mixin style is not a plain object" | "Unsupported css`` mixin: nested contextual conditions in after-base mixin" | "Unsupported css`` mixin: cannot infer base default for after-base contextual override (base value is non-literal)" | "css`` helper function interpolation references closure variable that cannot be hoisted" | "Sibling selector broadened: & + & (adjacent) becomes general sibling (~) in StyleX — interleaved non-matching elements will no longer block the match" | "Using styled-components components as mixins is not supported; use css`` mixins or strings instead" | "styled(ImportedComponent) wraps a component whose file contains internal styled-components — convert the base component's file first to avoid CSS cascade conflicts";
493
577
  interface WarningLog {
494
578
  severity: Severity;
495
579
  type: WarningType;
@@ -652,7 +652,8 @@ async function runPrepass(options) {
652
652
  const crossFileInfo = {
653
653
  selectorUsages,
654
654
  componentsNeedingMarkerSidecar,
655
- componentsNeedingGlobalSelectorBridge
655
+ componentsNeedingGlobalSelectorBridge,
656
+ styledDefFiles: createExternalInterface ? styledDefFiles : void 0
656
657
  };
657
658
  {
658
659
  const elapsed = ((performance.now() - t0) / 1e3).toFixed(1);
@@ -1,4 +1,4 @@
1
- import { n as WarningLog, r as Adapter } from "./logger-B7SOfCti.mjs";
1
+ import { n as WarningLog, r as Adapter } from "./logger-DyMTX-U6.mjs";
2
2
  import "stylis";
3
3
  import { API, FileInfo, Options } from "jscodeshift";
4
4
 
@@ -46,6 +46,8 @@ interface CrossFileInfo {
46
46
  selectorUsages: CrossFileSelectorUsage[];
47
47
  /** Component names in this file that need a global selector bridge className (consumer not transformed) */
48
48
  bridgeComponentNames?: Set<string>;
49
+ /** Global map: files that define styled-components → set of local names. Used for cascade conflict detection. */
50
+ styledDefFiles?: Map<string, Set<string>>;
49
51
  }
50
52
  interface CrossFileSelectorUsage {
51
53
  /** Local name in the consumer file (e.g. "CollapseArrowIcon") */