diff --git a/.changeset/tiny-parrots-relate.md b/.changeset/tiny-parrots-relate.md new file mode 100644 index 0000000000..853d812bb3 --- /dev/null +++ b/.changeset/tiny-parrots-relate.md @@ -0,0 +1,3 @@ +--- + +--- diff --git a/packages/react/transform/index.d.ts b/packages/react/transform/index.d.ts index a021924527..8cad2293dc 100644 --- a/packages/react/transform/index.d.ts +++ b/packages/react/transform/index.d.ts @@ -51,10 +51,33 @@ export interface DarkModeConfig { */ themeExpr: string } +/** + * {@inheritdoc CompatVisitorConfig.addComponentElement} + * @public + */ export interface AddComponentElementConfig { /** * @public * Whether to only add component element during compilation + * + * @example + * + * Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}. + * + * ```js + * import { defineConfig } from '@lynx-js/rspeedy' + * import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' + * + * export default defineConfig({ + * plugins: [ + * pluginReactLynx({ + * compat: { + * addComponentElement: { compilerOnly: true } + * }, + * }) + * ], + * }) + * ``` */ compilerOnly: boolean } diff --git a/packages/react/transform/src/swc_plugin_compat/mod.rs b/packages/react/transform/src/swc_plugin_compat/mod.rs index 63ba3783f2..8f0e9b583e 100644 --- a/packages/react/transform/src/swc_plugin_compat/mod.rs +++ b/packages/react/transform/src/swc_plugin_compat/mod.rs @@ -64,11 +64,32 @@ pub struct DarkModeConfig { pub theme_expr: String, } +/// {@inheritdoc CompatVisitorConfig.addComponentElement} +/// @public #[napi(object)] #[derive(Clone, Debug)] pub struct AddComponentElementConfig { /// @public /// Whether to only add component element during compilation + /// + /// @example + /// + /// Note that this only take effects on `Component` imported from {@link CompatVisitorConfig.oldRuntimePkg}. + /// + /// ```js + /// import { defineConfig } from '@lynx-js/rspeedy' + /// import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin' + /// + /// export default defineConfig({ + /// plugins: [ + /// pluginReactLynx({ + /// compat: { + /// addComponentElement: { compilerOnly: true } + /// }, + /// }) + /// ], + /// }) + /// ``` pub compiler_only: bool, } diff --git a/packages/rspeedy/plugin-react/api-extractor.json b/packages/rspeedy/plugin-react/api-extractor.json index 65b0c69ca6..4d86341359 100644 --- a/packages/rspeedy/plugin-react/api-extractor.json +++ b/packages/rspeedy/plugin-react/api-extractor.json @@ -3,4 +3,7 @@ */ { "extends": "../../../api-extractor.json", + "bundledPackages": [ + "@lynx-js/react-transform", + ], } diff --git a/packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md b/packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md index 8058967eff..3bc7af7b13 100644 --- a/packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md +++ b/packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md @@ -4,13 +4,45 @@ ```ts -import type { CompatVisitorConfig } from '@lynx-js/react/transform'; -import type { DefineDceVisitorConfig } from '@lynx-js/react/transform'; -import type { ExtractStrConfig } from '@lynx-js/react-webpack-plugin'; -import type { JsxTransformerConfig } from '@lynx-js/react/transform'; import { LAYERS } from '@lynx-js/react-webpack-plugin'; import type { RsbuildPlugin } from '@rsbuild/core'; -import type { ShakeVisitorConfig } from '@lynx-js/react/transform'; + +// @public +export interface AddComponentElementConfig { + compilerOnly: boolean +} + +// @public +export interface CompatVisitorConfig { + addComponentElement: boolean | AddComponentElementConfig + additionalComponentAttributes: Array + componentsPkg: Array + // Warning: (ae-forgotten-export) The symbol "DarkModeConfig" needs to be exported by the entry point index.d.ts + // + // @deprecated (undocumented) + darkMode?: boolean | DarkModeConfig + disableDeprecatedWarning: boolean + newRuntimePkg: string + oldRuntimePkg: Array + // @deprecated + removeComponentAttrRegex?: string + // @deprecated + simplifyCtorLikeReactLynx2: boolean + // @internal (undocumented) + target: 'LEPUS' | 'JS' | 'MIXED' +} + +// @public +export interface DefineDceVisitorConfig { + define: Record +} + +// @public +export interface ExtractStrConfig { + // @internal (undocumented) + extractedStrArr?: Array + strLength: number +} export { LAYERS } @@ -40,7 +72,6 @@ export interface PluginReactLynxOptions { experimental_isLazyBundle?: boolean; extractStr?: Partial | boolean; firstScreenSyncTiming?: 'immediately' | 'jsReady'; - jsx?: Partial | undefined; pipelineSchedulerConfig?: number; removeDescendantSelectorScope?: boolean; shake?: Partial | undefined; @@ -48,4 +79,11 @@ export interface PluginReactLynxOptions { targetSdkVersion?: string; } +// @public +export interface ShakeVisitorConfig { + pkgName: Array + removeCallParams: Array + retainProp: Array +} + ``` diff --git a/packages/rspeedy/plugin-react/package.json b/packages/rspeedy/plugin-react/package.json index 2d9dc659e6..c32dbabdce 100644 --- a/packages/rspeedy/plugin-react/package.json +++ b/packages/rspeedy/plugin-react/package.json @@ -48,6 +48,7 @@ }, "devDependencies": { "@lynx-js/react": "workspace:*", + "@lynx-js/react-transform": "workspace:*", "@lynx-js/rspeedy": "workspace:*", "@lynx-js/vitest-setup": "workspace:*", "@microsoft/api-extractor": "catalog:", diff --git a/packages/rspeedy/plugin-react/rslib.config.ts b/packages/rspeedy/plugin-react/rslib.config.ts index 33a469d08b..0f8271a612 100644 --- a/packages/rspeedy/plugin-react/rslib.config.ts +++ b/packages/rspeedy/plugin-react/rslib.config.ts @@ -3,7 +3,7 @@ import { TypiaRspackPlugin } from 'typia-rspack-plugin' export default defineConfig({ lib: [ - { format: 'esm', syntax: 'es2022', dts: true }, + { format: 'esm', syntax: 'es2022', dts: { bundle: true } }, ], source: { entry: { @@ -14,6 +14,11 @@ export default defineConfig({ }, tsconfigPath: './tsconfig.build.json', }, + output: { + externals: [ + '@rsbuild/core', + ], + }, tools: { rspack: { plugins: [ diff --git a/packages/rspeedy/plugin-react/src/index.ts b/packages/rspeedy/plugin-react/src/index.ts index 6f43b95d00..90896718e2 100644 --- a/packages/rspeedy/plugin-react/src/index.ts +++ b/packages/rspeedy/plugin-react/src/index.ts @@ -11,4 +11,12 @@ export { pluginReactLynx } from './pluginReactLynx.js' export type { PluginReactLynxOptions } from './pluginReactLynx.js' +export type { + AddComponentElementConfig, + CompatVisitorConfig, + DefineDceVisitorConfig, + ExtractStrConfig, + ShakeVisitorConfig, +} from '@lynx-js/react-transform' + export { LAYERS } from '@lynx-js/react-webpack-plugin' diff --git a/packages/rspeedy/plugin-react/src/pluginReactLynx.ts b/packages/rspeedy/plugin-react/src/pluginReactLynx.ts index 7b9525f0ed..3326e04812 100644 --- a/packages/rspeedy/plugin-react/src/pluginReactLynx.ts +++ b/packages/rspeedy/plugin-react/src/pluginReactLynx.ts @@ -15,10 +15,10 @@ import type { RsbuildPlugin } from '@rsbuild/core' import type { CompatVisitorConfig, DefineDceVisitorConfig, + ExtractStrConfig, JsxTransformerConfig, ShakeVisitorConfig, -} from '@lynx-js/react/transform' -import type { ExtractStrConfig } from '@lynx-js/react-webpack-plugin' +} from '@lynx-js/react-transform' import type { ExposedAPI } from '@lynx-js/rspeedy' import { applyAlias } from './alias.js' @@ -238,6 +238,8 @@ export interface PluginReactLynxOptions { /** * The `jsx` option controls how JSX is transformed. + * + * @internal */ jsx?: Partial | undefined diff --git a/packages/webpack/react-webpack-plugin/etc/react-webpack-plugin.api.md b/packages/webpack/react-webpack-plugin/etc/react-webpack-plugin.api.md index f527a43608..0abc7b9051 100644 --- a/packages/webpack/react-webpack-plugin/etc/react-webpack-plugin.api.md +++ b/packages/webpack/react-webpack-plugin/etc/react-webpack-plugin.api.md @@ -7,13 +7,11 @@ import type { CompatVisitorConfig } from '@lynx-js/react/transform'; import type { Compiler } from '@rspack/core'; import type { DefineDceVisitorConfig } from '@lynx-js/react/transform'; +import { ExtractStrConfig } from '@lynx-js/react/transform'; import type { JsxTransformerConfig } from '@lynx-js/react/transform'; import type { ShakeVisitorConfig } from '@lynx-js/react/transform'; -// @public -export interface ExtractStrConfig { - strLength: number; -} +export { ExtractStrConfig } // Warning: (ae-missing-release-tag) "LAYERS" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts b/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts index 78c6c45de0..48809ed1b5 100644 --- a/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts +++ b/packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts @@ -8,6 +8,7 @@ import { createRequire } from 'node:module'; import type { Chunk, Compilation, Compiler } from '@rspack/core'; import invariant from 'tiny-invariant'; +import type { ExtractStrConfig } from '@lynx-js/react/transform'; import { LynxTemplatePlugin } from '@lynx-js/template-webpack-plugin'; import { RuntimeGlobals } from '@lynx-js/webpack-runtime-globals'; @@ -16,23 +17,6 @@ import { createLynxProcessEvalResultRuntimeModule } from './LynxProcessEvalResul const require = createRequire(import.meta.url); -/** - * The options for extractStr. - * - * @public - */ -export interface ExtractStrConfig { - /** - * The minimum length of string literals to be extracted. - * - * @defaultValue `20` - * - * @public - */ - strLength: number; - /** @internal */ - extractedStrArr?: string[]; -} /** * The options for ReactWebpackPlugin * diff --git a/packages/webpack/react-webpack-plugin/src/index.ts b/packages/webpack/react-webpack-plugin/src/index.ts index c840daca6e..5b5c349a73 100644 --- a/packages/webpack/react-webpack-plugin/src/index.ts +++ b/packages/webpack/react-webpack-plugin/src/index.ts @@ -9,10 +9,8 @@ */ export { ReactWebpackPlugin } from './ReactWebpackPlugin.js'; -export type { - ReactWebpackPluginOptions, - ExtractStrConfig, -} from './ReactWebpackPlugin.js'; +export type { ReactWebpackPluginOptions } from './ReactWebpackPlugin.js'; +export type { ExtractStrConfig } from '@lynx-js/react/transform'; export { LAYERS } from './layer.js'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 593d7b7dc1..23dd570fa8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -428,6 +428,9 @@ importers: '@lynx-js/react': specifier: workspace:* version: link:../../react + '@lynx-js/react-transform': + specifier: workspace:* + version: link:../../react/transform '@lynx-js/rspeedy': specifier: workspace:* version: link:../core diff --git a/website/rspress.config.ts b/website/rspress.config.ts index e4ded28cd4..785be83fbb 100644 --- a/website/rspress.config.ts +++ b/website/rspress.config.ts @@ -46,6 +46,14 @@ const SIDEBARS = { createAPI({ name: 'react-rsbuild-plugin', skips: [ + // Transform options + 'AddComponentElementConfig', + 'CompatVisitorConfig', + 'DefineDceVisitorConfig', + 'ExtractStrConfig', + 'JsxTransformerConfig', + 'ShakeVisitorConfig', + 'PluginReactLynxOptions', ], }), @@ -169,6 +177,14 @@ const SIDEBARS_ZH = { base: 'zh/api', name: 'react-rsbuild-plugin', skips: [ + // Transform options + 'AddComponentElementConfig', + 'CompatVisitorConfig', + 'DefineDceVisitorConfig', + 'ExtractStrConfig', + 'JsxTransformerConfig', + 'ShakeVisitorConfig', + 'PluginReactLynxOptions', ], }),