From 40233a67065f7e506f36648f8d5e218f69a0b40a Mon Sep 17 00:00:00 2001 From: Naman Goel Date: Sat, 21 Dec 2024 12:47:51 +0300 Subject: [PATCH] fix: Babel plugin should no longer require 'rootDir' --- apps/nextjs-example/babel.config.js | 1 - .../__tests__/stylex-transform-create-theme-test.js | 2 ++ .../__tests__/stylex-transform-define-vars-test.js | 2 ++ packages/babel-plugin/src/utils/state-manager.js | 6 +++--- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/nextjs-example/babel.config.js b/apps/nextjs-example/babel.config.js index 44ae5a20..d8f7b5dc 100644 --- a/apps/nextjs-example/babel.config.js +++ b/apps/nextjs-example/babel.config.js @@ -24,7 +24,6 @@ module.exports = { }, unstable_moduleResolution: { type: 'commonJS', - rootDir: path.join(__dirname, '../..'), }, }, ], diff --git a/packages/babel-plugin/__tests__/stylex-transform-create-theme-test.js b/packages/babel-plugin/__tests__/stylex-transform-create-theme-test.js index d9df9447..a77f8190 100644 --- a/packages/babel-plugin/__tests__/stylex-transform-create-theme-test.js +++ b/packages/babel-plugin/__tests__/stylex-transform-create-theme-test.js @@ -21,6 +21,8 @@ const defaultOpts = { classNamePrefix, }; +// NOTE: While `rootDir` is optional now, It is needed in the +// test environment still. const rootDir = '/stylex/packages/'; function transform(source, opts = defaultOpts) { diff --git a/packages/babel-plugin/__tests__/stylex-transform-define-vars-test.js b/packages/babel-plugin/__tests__/stylex-transform-define-vars-test.js index 78c95553..1542b98d 100644 --- a/packages/babel-plugin/__tests__/stylex-transform-define-vars-test.js +++ b/packages/babel-plugin/__tests__/stylex-transform-define-vars-test.js @@ -21,6 +21,8 @@ const defaultOpts = { debug: false, }; +// NOTE: While `rootDir` is optional now, It is needed in the +// test environment still. const rootDir = '/stylex/packages/'; function transform(source, opts = defaultOpts) { diff --git a/packages/babel-plugin/src/utils/state-manager.js b/packages/babel-plugin/src/utils/state-manager.js index 6918ff48..017f7f88 100644 --- a/packages/babel-plugin/src/utils/state-manager.js +++ b/packages/babel-plugin/src/utils/state-manager.js @@ -36,7 +36,7 @@ export type ImportPathResolution = type ModuleResolution = | $ReadOnly<{ type: 'commonJS', - rootDir?: string, + rootDir?: ?string, themeFileExtension?: ?string, }> | $ReadOnly<{ @@ -53,7 +53,7 @@ type ModuleResolution = const CheckModuleResolution: Check = z.unionOf3( z.object({ type: z.literal('commonJS'), - rootDir: z.string(), + rootDir: z.unionOf(z.nullish(), z.string()), themeFileExtension: z.unionOf(z.nullish(), z.string()), }), z.object({ @@ -75,7 +75,7 @@ export type StyleXOptions = $ReadOnly<{ runtimeInjection: boolean | ?string | $ReadOnly<{ from: string, as: string }>, treeshakeCompensation?: boolean, genConditionalClasses: boolean, - unstable_moduleResolution: ?ModuleResolution, + unstable_moduleResolution?: ?ModuleResolution, aliases?: ?$ReadOnly<{ [string]: string | $ReadOnlyArray }>, ... }>;