From 2c43f21245d746a25208b8941776e302451bb247 Mon Sep 17 00:00:00 2001 From: "Henry Q. Dineen" Date: Wed, 12 Nov 2025 09:10:24 -0500 Subject: [PATCH] [types] fix @stylexjs/babel plugin cjs compat # Conflicts: # packages/typescript-tests/package.json --- .../@stylexjs/babel-plugin/src/index.d.ts | 86 +++++++++++-------- packages/typescript-tests/src/babel-plugin.ts | 14 +++ 2 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 packages/typescript-tests/src/babel-plugin.ts diff --git a/packages/@stylexjs/babel-plugin/src/index.d.ts b/packages/@stylexjs/babel-plugin/src/index.d.ts index 92eb029ad..ed92a57f5 100644 --- a/packages/@stylexjs/babel-plugin/src/index.d.ts +++ b/packages/@stylexjs/babel-plugin/src/index.d.ts @@ -1,4 +1,3 @@ -// Solves the issue: https://github.com/facebook/stylex/issues/889 /** * Copyright (c) Meta Platforms, Inc. and affiliates. * @@ -10,44 +9,55 @@ import type { PluginObj } from '@babel/core'; import type { StyleXOptions } from './utils/state-manager'; -export type Options = StyleXOptions; /** * Entry point for the StyleX babel plugin. */ declare function styleXTransform(): PluginObj; -declare function stylexPluginWithOptions( - options: Partial, -): [typeof styleXTransform, Partial]; -/** - * - * @param rules An array of CSS rules that has been generated and collected from all JS files - * in a project - * @returns A string that represents the final CSS file. - * - * This function take an Array of CSS rules, de-duplicates them, sorts them priority and generates - * a final CSS file. - * - * When Stylex is correctly configured, the babel plugin will return an array of CSS rule objects. - * You're expected to concatenate all the Rules into a single Array and use this function to convert - * that into the final CSS file. - * - * End-users can choose to not use this function and use their own logic instead. - */ -export type Rule = [string, { ltr: string; rtl?: null | string }, number]; -declare function processStylexRules( - rules: Array, - config?: - | boolean - | { - useLayers?: boolean; - enableLTRRTLComments?: boolean; - legacyDisableLayers?: boolean; - }, -): string; -export type StyleXTransformObj = Readonly<{ - (): PluginObj; - withOptions: typeof stylexPluginWithOptions; - processStylexRules: typeof processStylexRules; -}>; -declare const $$EXPORT_DEFAULT_DECLARATION$$: StyleXTransformObj; -export default $$EXPORT_DEFAULT_DECLARATION$$; + +declare namespace styleXTransform { + export type Options = StyleXOptions; + + /** + * + * @param rules An array of CSS rules that has been generated and collected from all JS files + * in a project + * @returns A string that represents the final CSS file. + * + * This function take an Array of CSS rules, de-duplicates them, sorts them priority and generates + * a final CSS file. + * + * When Stylex is correctly configured, the babel plugin will return an array of CSS rule objects. + * You're expected to concatenate all the Rules into a single Array and use this function to convert + * that into the final CSS file. + * + * End-users can choose to not use this function and use their own logic instead. + */ + export type Rule = [ + string, + { + ltr: string; + rtl?: null | string; + constKey?: string; + constVal?: string | number; + }, + number, + ]; + + export function withOptions( + options: Partial, + ): [typeof styleXTransform, Partial]; + + export function processStylexRules( + rules: Array, + config?: + | boolean + | { + useLayers?: boolean; + enableLTRRTLComments?: boolean; + legacyDisableLayers?: boolean; + useLegacyClassnamesSort?: boolean; + }, + ): string; +} + +export = styleXTransform; diff --git a/packages/typescript-tests/src/babel-plugin.ts b/packages/typescript-tests/src/babel-plugin.ts new file mode 100644 index 000000000..79273d944 --- /dev/null +++ b/packages/typescript-tests/src/babel-plugin.ts @@ -0,0 +1,14 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * + */ + +/* eslint-disable no-unused-vars */ + +import stylexBabelPlugin from '@stylexjs/babel-plugin'; + +const css = stylexBabelPlugin.processStylexRules([]);