styled-components-to-stylex-codemod 0.0.32 → 0.0.34
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/dist/index.d.mts +2 -2
- package/dist/index.mjs +5 -17
- package/dist/{logger-BFrY6Nmv.d.mts → logger-xD1SimCA.d.mts} +39 -2
- package/dist/{adapter-BP7bn_pZ.mjs → merge-markers-B58_cRdA.mjs} +41 -1
- package/dist/transform.d.mts +3 -1
- package/dist/transform.mjs +1645 -1075
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as ImportSource, i as AdapterInput, o as MarkerFileContext, s as defineAdapter, t as CollectedWarning } from "./logger-xD1SimCA.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/run.d.ts
|
|
4
4
|
interface RunTransformOptions {
|
|
@@ -107,4 +107,4 @@ interface RunTransformResult {
|
|
|
107
107
|
*/
|
|
108
108
|
declare function runTransform(options: RunTransformOptions): Promise<RunTransformResult>;
|
|
109
109
|
//#endregion
|
|
110
|
-
export { type AdapterInput, defineAdapter, runTransform };
|
|
110
|
+
export { type AdapterInput, type ImportSource, type MarkerFileContext, defineAdapter, runTransform };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as assertValidAdapterInput, r as defineAdapter, s as describeValue, t as mergeMarkerDeclarations } from "./merge-markers-B58_cRdA.mjs";
|
|
2
2
|
import { t as Logger } from "./logger-C2O81VeU.mjs";
|
|
3
3
|
import { run } from "jscodeshift/src/Runner.js";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
@@ -196,6 +196,7 @@ async function runTransform(options) {
|
|
|
196
196
|
styleMerger: resolvedAdapter.styleMerger,
|
|
197
197
|
themeHook: resolvedAdapter.themeHook,
|
|
198
198
|
useSxProp: resolvedAdapter.useSxProp,
|
|
199
|
+
usePhysicalProperties: resolvedAdapter.usePhysicalProperties,
|
|
199
200
|
externalInterface(ctx) {
|
|
200
201
|
return resolvedAdapter.externalInterface(ctx);
|
|
201
202
|
},
|
|
@@ -203,7 +204,8 @@ async function runTransform(options) {
|
|
|
203
204
|
resolveCall: resolveCallWithLogging,
|
|
204
205
|
resolveSelector: resolveSelectorWithLogging,
|
|
205
206
|
resolveBaseComponent: adapterInput.resolveBaseComponent ? resolveBaseComponentWithLogging : void 0,
|
|
206
|
-
resolveThemeCall: resolvedAdapter.resolveThemeCall
|
|
207
|
+
resolveThemeCall: resolvedAdapter.resolveThemeCall,
|
|
208
|
+
markerFile: resolvedAdapter.markerFile
|
|
207
209
|
};
|
|
208
210
|
const transformPath = (() => {
|
|
209
211
|
const adjacent = join(__dirname, "transform.mjs");
|
|
@@ -306,10 +308,6 @@ function createAutoPrepassFailureError(err, consumerPatterns, parser) {
|
|
|
306
308
|
/**
|
|
307
309
|
* Merge new sidecar marker content into an existing .stylex.ts file, preserving
|
|
308
310
|
* user-owned exports (e.g. defineVars). If the file doesn't exist, returns content as-is.
|
|
309
|
-
*
|
|
310
|
-
* New marker declarations (`export const XMarker = stylex.defineMarker()`) are
|
|
311
|
-
* appended only if they don't already exist in the file. The stylex import is
|
|
312
|
-
* ensured at the top.
|
|
313
311
|
*/
|
|
314
312
|
function mergeSidecarContent(sidecarPath, newContent) {
|
|
315
313
|
let existing;
|
|
@@ -318,17 +316,7 @@ function mergeSidecarContent(sidecarPath, newContent) {
|
|
|
318
316
|
} catch {
|
|
319
317
|
return newContent;
|
|
320
318
|
}
|
|
321
|
-
|
|
322
|
-
const newMarkers = [];
|
|
323
|
-
for (const m of newContent.matchAll(markerLineRe)) newMarkers.push(m[0]);
|
|
324
|
-
if (newMarkers.length === 0) return newContent;
|
|
325
|
-
const markersToAdd = newMarkers.filter((line) => !existing.includes(line));
|
|
326
|
-
if (markersToAdd.length === 0) return existing;
|
|
327
|
-
let merged = existing;
|
|
328
|
-
if (!merged.includes("@stylexjs/stylex")) merged = `import * as stylex from "@stylexjs/stylex";\n\n${merged}`;
|
|
329
|
-
const trailingNewline = merged.endsWith("\n") ? "" : "\n";
|
|
330
|
-
merged = merged + trailingNewline + markersToAdd.join("\n") + "\n";
|
|
331
|
-
return merged;
|
|
319
|
+
return mergeMarkerDeclarations(existing, newContent);
|
|
332
320
|
}
|
|
333
321
|
/** Run formatter commands on a list of files, logging warnings on failure. */
|
|
334
322
|
async function runFormatters(commands, files) {
|
|
@@ -500,6 +500,10 @@ type ExternalInterfaceResult = {
|
|
|
500
500
|
elementProps?: boolean; /** Whether cross-file consumers use JSX spread ({...props}) */
|
|
501
501
|
spreadProps?: boolean;
|
|
502
502
|
};
|
|
503
|
+
interface MarkerFileContext {
|
|
504
|
+
/** Absolute path of the file being transformed */
|
|
505
|
+
filePath: string;
|
|
506
|
+
}
|
|
503
507
|
/**
|
|
504
508
|
* Configuration for a custom style merger function that combines stylex.props()
|
|
505
509
|
* results with external className/style props.
|
|
@@ -647,6 +651,34 @@ interface Adapter {
|
|
|
647
651
|
*
|
|
648
652
|
*/
|
|
649
653
|
useSxProp: boolean;
|
|
654
|
+
/**
|
|
655
|
+
* Use physical CSS properties (`paddingTop`/`paddingRight`/`paddingBottom`/`paddingLeft`)
|
|
656
|
+
* instead of logical properties (`paddingBlock`/`paddingInline`) when expanding
|
|
657
|
+
* 2-value CSS shorthands like `padding: 4px 8px`.
|
|
658
|
+
*
|
|
659
|
+
* By default, the codemod uses logical properties which adapt to the writing direction
|
|
660
|
+
* (RTL/LTR), matching StyleX's ESLint plugin recommendations. Enable this if your
|
|
661
|
+
* codebase needs RTL support or prefer physical properties.
|
|
662
|
+
*
|
|
663
|
+
* @default false
|
|
664
|
+
*/
|
|
665
|
+
usePhysicalProperties?: boolean;
|
|
666
|
+
/**
|
|
667
|
+
* Optional function to customize where marker sidecar files (`stylex.defineMarker()`)
|
|
668
|
+
* are written. By default, markers are placed in a `.stylex.ts` file next to the source.
|
|
669
|
+
*
|
|
670
|
+
* When provided, the function receives the source file path and returns an `ImportSource`
|
|
671
|
+
* that determines both the import path in the transformed file and the file path where
|
|
672
|
+
* markers are written.
|
|
673
|
+
*
|
|
674
|
+
* Example:
|
|
675
|
+
* ```typescript
|
|
676
|
+
* markerFile(ctx) {
|
|
677
|
+
* return { kind: "absolutePath", value: "/path/to/shared/markers.stylex.ts" };
|
|
678
|
+
* }
|
|
679
|
+
* ```
|
|
680
|
+
*/
|
|
681
|
+
markerFile?: (context: MarkerFileContext) => ImportSource;
|
|
650
682
|
}
|
|
651
683
|
/**
|
|
652
684
|
* User-facing adapter input type accepted by `defineAdapter()`.
|
|
@@ -673,6 +705,8 @@ interface AdapterInput {
|
|
|
673
705
|
styleMerger: Adapter["styleMerger"];
|
|
674
706
|
themeHook?: Adapter["themeHook"];
|
|
675
707
|
useSxProp: Adapter["useSxProp"];
|
|
708
|
+
usePhysicalProperties?: Adapter["usePhysicalProperties"];
|
|
709
|
+
markerFile?: Adapter["markerFile"];
|
|
676
710
|
}
|
|
677
711
|
/**
|
|
678
712
|
* Helper for nicer user authoring + type inference.
|
|
@@ -736,6 +770,9 @@ interface AdapterInput {
|
|
|
736
770
|
* // Emit sx={} JSX attributes instead of {...stylex.props()} spreads (requires StyleX ≥0.18)
|
|
737
771
|
* useSxProp: false,
|
|
738
772
|
*
|
|
773
|
+
* // Opt out of logical properties — use paddingTop/Right/Bottom/Left instead of Block/Inline
|
|
774
|
+
* // usePhysicalProperties: true,
|
|
775
|
+
*
|
|
739
776
|
* // Optional: customize runtime theme hook import/call used by emitted wrappers
|
|
740
777
|
* themeHook: {
|
|
741
778
|
* functionName: "useTheme",
|
|
@@ -747,7 +784,7 @@ declare function defineAdapter<T extends AdapterInput>(adapter: T): T;
|
|
|
747
784
|
//#endregion
|
|
748
785
|
//#region src/internal/logger.d.ts
|
|
749
786
|
type Severity = "info" | "warning" | "error";
|
|
750
|
-
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 and @container are supported; @supports, 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: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "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" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "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: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "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: cross-file component selector target has no JSX usage in this file" | "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: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "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" | "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" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens";
|
|
787
|
+
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 and @container are supported; @supports, 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: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "Conditional `css` block: unsupported selector" | "Directional border helper styles are not supported" | "Multi-slot border interpolation could not be resolved" | "Resolved border helper value could not be expanded to longhand properties" | "Resolved conditional border variant could not be expanded to longhand properties" | "createGlobalStyle is not supported in StyleX. Global styles should be handled separately (e.g., in a CSS file or using CSS reset libraries)" | "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" | "Local helper function returns CSS that cannot be decomposed into individual properties" | "Local helper function computes CSS values that cannot be statically traced to the component prop" | "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: media query interpolation must be a simple imported reference (expressions like `value + 1` are not supported)" | "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: cross-file component selector target has no JSX usage in this file" | "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: unresolved interpolation in cross-component sibling selector" | "Unsupported selector: grouped reverse selector references different components" | "Unsupported selector: computed media query inside ancestor attribute selector" | "Unsupported selector: computed media query inside cross-component sibling selector" | "Unsupported selector: computed media query inside sibling selector" | "Unsupported selector: computed media query inside :has() component selector" | "Unsupported selector: cross-file :has() component selector not yet supported" | "Unsupported selector: unresolved interpolation in :has() component selector" | "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" | "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" | "Transient $-prefixed props renamed on exported component — update consumer call sites to use the new prop names" | "Shorthand property has an opaque value that StyleX will expand to longhands — use `directional` in resolveValue to return separate longhand tokens";
|
|
751
788
|
interface WarningLog {
|
|
752
789
|
severity: Severity;
|
|
753
790
|
type: WarningType;
|
|
@@ -761,4 +798,4 @@ interface CollectedWarning extends WarningLog {
|
|
|
761
798
|
filePath: string;
|
|
762
799
|
}
|
|
763
800
|
//#endregion
|
|
764
|
-
export {
|
|
801
|
+
export { ImportSource as a, AdapterInput as i, WarningLog as n, MarkerFileContext as o, Adapter as r, defineAdapter as s, CollectedWarning as t };
|
|
@@ -133,6 +133,14 @@ function assertAdapterShape(candidate, where, allowAutoExtIf) {
|
|
|
133
133
|
absolutePathExample: "/path/to/module.ts"
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
const markerFile = obj?.markerFile;
|
|
137
|
+
if (markerFile !== void 0 && markerFile !== null && typeof markerFile !== "function") throw new Error([
|
|
138
|
+
`${where}: adapter.markerFile must be a function when provided.`,
|
|
139
|
+
`Received: markerFile=${describeValue(markerFile)}`,
|
|
140
|
+
"",
|
|
141
|
+
"Expected signature:",
|
|
142
|
+
" markerFile(ctx: { filePath: string }) => { kind: \"specifier\" | \"absolutePath\", value: string }"
|
|
143
|
+
].join("\n"));
|
|
136
144
|
const themeHook = obj?.themeHook;
|
|
137
145
|
if (themeHook !== null && themeHook !== void 0) {
|
|
138
146
|
if (typeof themeHook !== "object") throw new Error([
|
|
@@ -254,6 +262,9 @@ const DEFAULT_THEME_HOOK = {
|
|
|
254
262
|
* // Emit sx={} JSX attributes instead of {...stylex.props()} spreads (requires StyleX ≥0.18)
|
|
255
263
|
* useSxProp: false,
|
|
256
264
|
*
|
|
265
|
+
* // Opt out of logical properties — use paddingTop/Right/Bottom/Left instead of Block/Inline
|
|
266
|
+
* // usePhysicalProperties: true,
|
|
267
|
+
*
|
|
257
268
|
* // Optional: customize runtime theme hook import/call used by emitted wrappers
|
|
258
269
|
* themeHook: {
|
|
259
270
|
* functionName: "useTheme",
|
|
@@ -266,4 +277,33 @@ function defineAdapter(adapter) {
|
|
|
266
277
|
return adapter;
|
|
267
278
|
}
|
|
268
279
|
//#endregion
|
|
269
|
-
|
|
280
|
+
//#region src/internal/merge-markers.ts
|
|
281
|
+
/**
|
|
282
|
+
* Shared utility for merging marker sidecar content.
|
|
283
|
+
* Core concepts: deduplication of defineMarker declarations across files.
|
|
284
|
+
*/
|
|
285
|
+
/** Regex matching a marker block: optional JSDoc comment followed by the export line. */
|
|
286
|
+
const MARKER_BLOCK_RE = /(?:\/\*\*[^]*?\*\/\n)?export const \w+ = stylex\.defineMarker\(\);/gm;
|
|
287
|
+
/** Regex matching just the export line (used for dedup checks). */
|
|
288
|
+
const MARKER_EXPORT_RE = /^export const \w+ = stylex\.defineMarker\(\);$/gm;
|
|
289
|
+
/**
|
|
290
|
+
* Merge marker declarations from `incoming` into `base`, appending only new
|
|
291
|
+
* marker blocks (JSDoc + export). Returns `base` unchanged if all markers already exist.
|
|
292
|
+
*/
|
|
293
|
+
function mergeMarkerDeclarations(base, incoming) {
|
|
294
|
+
const incomingExports = [...incoming.matchAll(MARKER_EXPORT_RE)].map((m) => m[0]);
|
|
295
|
+
if (incomingExports.length === 0) return base;
|
|
296
|
+
const newExportLines = incomingExports.filter((line) => !base.includes(line));
|
|
297
|
+
if (newExportLines.length === 0) return base;
|
|
298
|
+
const newExportSet = new Set(newExportLines);
|
|
299
|
+
const blocksToAdd = [...incoming.matchAll(MARKER_BLOCK_RE)].map((m) => m[0]).filter((block) => {
|
|
300
|
+
const exportLine = block.match(MARKER_EXPORT_RE);
|
|
301
|
+
return exportLine && newExportSet.has(exportLine[0]);
|
|
302
|
+
});
|
|
303
|
+
if (blocksToAdd.length === 0) return base;
|
|
304
|
+
let merged = base;
|
|
305
|
+
if (!merged.includes("@stylexjs/stylex")) merged = `import * as stylex from "@stylexjs/stylex";\n\n${merged}`;
|
|
306
|
+
return merged.trimEnd() + "\n\n" + blocksToAdd.join("\n\n") + "\n";
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
export { assertValidAdapter as a, isDirectionalResult as i, DEFAULT_THEME_HOOK as n, assertValidAdapterInput as o, defineAdapter as r, describeValue as s, mergeMarkerDeclarations as t };
|
package/dist/transform.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as WarningLog, r as Adapter } from "./logger-
|
|
1
|
+
import { n as WarningLog, r as Adapter } from "./logger-xD1SimCA.mjs";
|
|
2
2
|
import { API, FileInfo, Options } from "jscodeshift";
|
|
3
3
|
|
|
4
4
|
//#region src/internal/transform-types.d.ts
|
|
@@ -10,6 +10,8 @@ interface TransformResult {
|
|
|
10
10
|
warnings: WarningLog[];
|
|
11
11
|
/** Content for the sidecar .stylex.ts file (defineMarker declarations). Undefined when no markers needed. */
|
|
12
12
|
sidecarContent?: string;
|
|
13
|
+
/** Absolute file path for the sidecar file, when adapter.markerFile provides a custom location. */
|
|
14
|
+
sidecarFilePath?: string;
|
|
13
15
|
/** Bridge components emitted for unconverted consumer selectors. */
|
|
14
16
|
bridgeResults?: BridgeComponentResult[];
|
|
15
17
|
/** Transient prop renames for exported components, keyed by export name. */
|