Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .changeset/dirty-paws-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@lynx-js/template-webpack-plugin": minor
"@lynx-js/react-rsbuild-plugin": minor
---

Use `@upupming/type-config` for Lynx configuration types. Now you can configure Lynx configurations with type safety and autocompletion in `pluginReactLynx`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lynx-js/type-config ?


```js
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin';
import { defineConfig } from '@lynx-js/rspeedy';

export default defineConfig({
plugins: [
pluginReactLynx({
debugInfoOutside: false,
enableICU: true,
pipelineSchedulerConfig: 65535,
/// ...any options supported by `@upupming/type-config`
}),
],
});
```
8 changes: 4 additions & 4 deletions packages/react/transform/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface AddComponentElementConfig {
compilerOnly: boolean
}
/**
* {@inheritdoc PluginReactLynxOptions.compat}
* {@inheritdoc ReactLynxOptions.compat}
* @public
*/
export interface CompatVisitorConfig {
Expand Down Expand Up @@ -363,7 +363,7 @@ export interface CssScopeVisitorConfig {
filename: string
}
/**
* {@inheritdoc PluginReactLynxOptions.defineDCE}
* {@inheritdoc ReactLynxOptions.defineDCE}
* @public
*/
export interface DefineDceVisitorConfig {
Expand Down Expand Up @@ -426,7 +426,7 @@ export interface DynamicImportVisitorConfig {
layer: string
}
/**
* {@inheritdoc PluginReactLynxOptions.extractStr}
* {@inheritdoc ReactLynxOptions.extractStr}
* @public
*/
export interface ExtractStrConfig {
Expand Down Expand Up @@ -465,7 +465,7 @@ export interface RefreshVisitorConfig {
library?: Array<string>
}
/**
* {@inheritdoc PluginReactLynxOptions.shake}
* {@inheritdoc ReactLynxOptions.shake}
* @public
*/
export interface ShakeVisitorConfig {
Expand Down
50 changes: 37 additions & 13 deletions packages/rspeedy/plugin-react/etc/react-rsbuild-plugin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
```ts

import { LAYERS } from '@lynx-js/react-webpack-plugin';
import type { CompilerOptions as LynxCompilerOptions } from '@upupming/type-config';
import type { Config as LynxConfig } from '@upupming/type-config';
import type { RsbuildPlugin } from '@rsbuild/core';

// @public
Expand Down Expand Up @@ -46,36 +48,58 @@ export interface ExtractStrConfig {

export { LAYERS }

export { LynxCompilerOptions }

export { LynxConfig }

// @public
export function pluginReactLynx(userOptions?: PluginReactLynxOptions): RsbuildPlugin[];

// @public
export interface PluginReactLynxOptions {
export type PluginReactLynxOptions = Omit<LynxCompilerOptions, keyof ReactLynxDefaultCompilerOptions> & ReactLynxDefaultCompilerOptions & Omit<LynxConfig, keyof ReactLynxDefaultLynxConfig> & ReactLynxDefaultLynxConfig & ReactLynxOptions;

// @public
export interface ReactLynxDefaultCompilerOptions {
debugInfoOutside?: Required<LynxCompilerOptions>['debugInfoOutside'];
defaultDisplayLinear?: Required<LynxCompilerOptions>['defaultDisplayLinear'];
enableCSSInvalidation?: Required<LynxCompilerOptions>['enableCSSInvalidation'];
enableCSSSelector?: Required<LynxCompilerOptions>['enableCSSSelector'];
enableRemoveCSSScope?: Required<LynxCompilerOptions>['enableRemoveCSSScope'] | undefined;
// @deprecated
targetSdkVersion?: Required<LynxCompilerOptions>['targetSdkVersion'];
}

// @public
export interface ReactLynxDefaultLynxConfig {
enableA11y?: Required<LynxConfig>['enableA11y'];
enableAccessibilityElement?: Required<LynxConfig>['enableAccessibilityElement'];
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
enableCSSInheritance?: Required<LynxConfig>['enableCSSInheritance'];
enableNewGesture?: Required<LynxConfig>['enableNewGesture'];
removeDescendantSelectorScope?: Required<LynxConfig>['removeDescendantSelectorScope'];
}

// @public
export interface ReactLynxOptions {
compat?: Partial<CompatVisitorConfig> & {
disableCreateSelectorQueryIncompatibleWarning?: boolean;
} | undefined;
customCSSInheritanceList?: string[] | undefined;
debugInfoOutside?: boolean;
defaultDisplayLinear?: boolean;
defineDCE?: Partial<DefineDceVisitorConfig> | undefined;
enableAccessibilityElement?: boolean;
enableCSSInheritance?: boolean;
enableCSSInvalidation?: boolean;
enableCSSSelector?: boolean;
enableNewGesture?: boolean;
enableRemoveCSSScope?: boolean | undefined;
enableSSR?: boolean;
engineVersion?: string;
// @alpha
experimental_isLazyBundle?: boolean;
extractStr?: Partial<ExtractStrConfig> | boolean;
firstScreenSyncTiming?: 'immediately' | 'jsReady';
removeDescendantSelectorScope?: boolean;
shake?: Partial<ShakeVisitorConfig> | undefined;
// @deprecated
targetSdkVersion?: string;
}

// Warning: (ae-forgotten-export) The symbol "RequiredNotUndefined" needs to be exported by the entry point index.d.ts
// Warning: (ae-missing-release-tag) "ResolvedPluginReactLynxOptions" is part of the package's API, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export type ResolvedPluginReactLynxOptions = Omit<LynxCompilerOptions, keyof ReactLynxDefaultCompilerOptions> & RequiredNotUndefined<ReactLynxDefaultCompilerOptions> & Omit<LynxConfig, keyof ReactLynxDefaultLynxConfig> & RequiredNotUndefined<ReactLynxDefaultLynxConfig> & Required<ReactLynxOptions>;

// @public
export interface ShakeVisitorConfig {
pkgName: Array<string>
Expand Down
5 changes: 4 additions & 1 deletion packages/rspeedy/plugin-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
"@lynx-js/runtime-wrapper-webpack-plugin": "workspace:*",
"@lynx-js/template-webpack-plugin": "workspace:*",
"@lynx-js/use-sync-external-store": "workspace:*",
"background-only": "workspace:^"
"@upupming/type-config": "0.0.1",
"background-only": "workspace:^",
"object.pick": "^1.3.0"
},
"devDependencies": {
"@lynx-js/react": "workspace:*",
Expand All @@ -56,6 +58,7 @@
"@rsbuild/core": "catalog:rsbuild",
"@rsbuild/plugin-sass": "1.4.0",
"@rsbuild/plugin-typed-css-modules": "1.1.1",
"@types/object.pick": "^1.3.4",
"rsbuild-plugin-arethetypeswrong": "0.1.1",
"rsbuild-plugin-publint": "0.3.3",
"source-map": "^0.7.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/rspeedy/plugin-react/src/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import type {
} from '@lynx-js/css-extract-webpack-plugin'
import { LAYERS } from '@lynx-js/react-webpack-plugin'

import type { PluginReactLynxOptions } from './pluginReactLynx.js'
import type { ResolvedPluginReactLynxOptions } from './pluginReactLynx.js'

export function applyCSS(
api: RsbuildPluginAPI,
options: Required<PluginReactLynxOptions>,
options: ResolvedPluginReactLynxOptions,
): void {
const {
enableRemoveCSSScope,
Expand Down
38 changes: 10 additions & 28 deletions packages/rspeedy/plugin-react/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
RsbuildPluginAPI,
Rspack,
} from '@rsbuild/core'
import { compilerOptionsKeys, configKeys } from '@upupming/type-config'
import pick from 'object.pick'
import type { UndefinedOnPartialDeep } from 'type-fest'

import { LAYERS, ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'
Expand All @@ -20,7 +22,7 @@ import {
WebEncodePlugin,
} from '@lynx-js/template-webpack-plugin'

import type { PluginReactLynxOptions } from './pluginReactLynx.js'
import type { ResolvedPluginReactLynxOptions } from './pluginReactLynx.js'

const PLUGIN_NAME_REACT = 'lynx:react'
const PLUGIN_NAME_TEMPLATE = 'lynx:template'
Expand All @@ -33,26 +35,16 @@ const EMPTY_HASH = ''

export function applyEntry(
api: RsbuildPluginAPI,
options: Required<PluginReactLynxOptions>,
options: ResolvedPluginReactLynxOptions,
): void {
const {
compat,
customCSSInheritanceList,
debugInfoOutside,
defaultDisplayLinear,
enableAccessibilityElement,
enableCSSInheritance,
enableCSSInvalidation,
enableCSSSelector,
enableNewGesture,
enableRemoveCSSScope,
firstScreenSyncTiming,
enableSSR,
removeDescendantSelectorScope,
targetSdkVersion,
extractStr: originalExtractStr,

experimental_isLazyBundle,

...otherOptions
} = options

const { config, logger } = api.useExposed<ExposedAPI>(
Expand Down Expand Up @@ -169,21 +161,11 @@ export function applyEntry(
DEFAULT_DIST_PATH_INTERMEDIATE,
entryName,
),
customCSSInheritanceList,
debugInfoOutside,
defaultDisplayLinear,
enableA11y: true,
enableAccessibilityElement,
enableCSSInheritance,
enableCSSInvalidation,
enableCSSSelector,
enableNewGesture,
enableRemoveCSSScope: enableRemoveCSSScope ?? true,
removeDescendantSelectorScope,
targetSdkVersion,

experimental_isLazyBundle,
cssPlugins: [],

...pick(otherOptions, compilerOptionsKeys),
...pick(otherOptions, configKeys),
}])
.end()
})
Expand Down Expand Up @@ -221,7 +203,7 @@ export function applyEntry(
return name
})
},
targetSdkVersion,
targetSdkVersion: otherOptions.targetSdkVersion,
// Inject runtime wrapper for all `.js` but not `main-thread.js` and `main-thread.[hash].js`.
test: /^(?!.*main-thread(?:\.[A-Fa-f0-9]*)?\.js$).*\.js$/,
experimental_isLazyBundle,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspeedy/plugin-react/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { RsbuildPluginAPI } from '@rsbuild/core'

import { LAYERS } from '@lynx-js/react-webpack-plugin'

import type { PluginReactLynxOptions } from './pluginReactLynx.js'
import type { ResolvedPluginReactLynxOptions } from './pluginReactLynx.js'

export function applyGenerator(
api: RsbuildPluginAPI,
options: Required<PluginReactLynxOptions>,
options: ResolvedPluginReactLynxOptions,
): void {
api.modifyBundlerChain({
order: 'pre',
Expand Down
10 changes: 9 additions & 1 deletion packages/rspeedy/plugin-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
*/

export { pluginReactLynx } from './pluginReactLynx.js'
export type { PluginReactLynxOptions } from './pluginReactLynx.js'
export type {
PluginReactLynxOptions,
ResolvedPluginReactLynxOptions,
LynxCompilerOptions,
ReactLynxDefaultCompilerOptions,
LynxConfig,
ReactLynxDefaultLynxConfig,
ReactLynxOptions,
} from './pluginReactLynx.js'

export type {
AddComponentElementConfig,
Expand Down
4 changes: 2 additions & 2 deletions packages/rspeedy/plugin-react/src/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { RsbuildPluginAPI, Rspack } from '@rsbuild/core'

import { LAYERS, ReactWebpackPlugin } from '@lynx-js/react-webpack-plugin'

import type { PluginReactLynxOptions } from './pluginReactLynx.js'
import type { ResolvedPluginReactLynxOptions } from './pluginReactLynx.js'

export function applyLoaders(
api: RsbuildPluginAPI,
options: Required<PluginReactLynxOptions>,
options: ResolvedPluginReactLynxOptions,
): void {
const {
compat,
Expand Down
Loading
Loading