@lynx-js/react-canary 0.114.4-canary-20251105-a86df859 → 0.114.4-canary-20251105-83952a01

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @lynx-js/react
2
2
 
3
- ## 0.114.4-canary-20251105053610-a86df859327b435d0a0066337d4bf750c3321b45
3
+ ## 0.114.4-canary-20251105085604-83952a0151ce3347e0f93e2d6f1c64481d0ad130
4
4
 
5
5
  ### Patch Changes
6
6
 
@@ -28,6 +28,20 @@
28
28
 
29
29
  - Add profile for list `update-list-info`. ([#1480](https://github.com/lynx-family/lynx-stack/pull/1480))
30
30
 
31
+ - Support testing React Compiler in testing library. Enable React Compiler by setting the `experimental_enableReactCompiler` option of `createVitestConfig` to `true`. ([#1269](https://github.com/lynx-family/lynx-stack/pull/1269))
32
+
33
+ ```js
34
+ import { defineConfig, mergeConfig } from "vitest/config";
35
+ import { createVitestConfig } from "@lynx-js/react/testing-library/vitest-config";
36
+
37
+ const defaultConfig = await createVitestConfig({
38
+ runtimePkgName: "@lynx-js/react",
39
+ experimental_enableReactCompiler: true,
40
+ });
41
+
42
+ export default mergeConfig(defaultConfig, config);
43
+ ```
44
+
31
45
  ## 0.114.3
32
46
 
33
47
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react-canary",
3
- "version": "0.114.4-canary-20251105-a86df859",
3
+ "version": "0.114.4-canary-20251105-83952a01",
4
4
  "description": "ReactLynx is a framework for developing Lynx applications with familiar React.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -5,7 +5,7 @@
5
5
  Rslib v0.15.0
6
6
 
7
7
  info build started...
8
- ready built in 0.14 s
8
+ ready built in 0.16 s
9
9
 
10
10
  File (esm) Size 
11
11
  dist/index.js 10.1 kB
@@ -51,6 +51,123 @@ const createVitestConfig = async (options)=>{
51
51
  let runtimeAlias = [];
52
52
  if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_config_dirname);
53
53
  const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
54
+ preactAlias.forEach((alias)=>{
55
+ alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
56
+ });
57
+ const reactAlias = [
58
+ {
59
+ find: /^react$/,
60
+ replacement: vitest_config_require.resolve(runtimeOSSPkgName, {
61
+ paths: [
62
+ runtimeDir
63
+ ]
64
+ })
65
+ },
66
+ {
67
+ find: /^react\/jsx-runtime$/,
68
+ replacement: vitest_config_require.resolve(path.posix.join(runtimeOSSPkgName, 'jsx-runtime'), {
69
+ paths: [
70
+ runtimeDir
71
+ ]
72
+ })
73
+ },
74
+ {
75
+ find: /^react\/jsx-dev-runtime$/,
76
+ replacement: vitest_config_require.resolve(path.posix.join(runtimeOSSPkgName, 'jsx-dev-runtime'), {
77
+ paths: [
78
+ runtimeDir
79
+ ]
80
+ })
81
+ }
82
+ ];
83
+ function transformReactCompilerPlugin() {
84
+ let rootContext, compilerDeps, babel;
85
+ function resolveCompilerDeps(rootContext) {
86
+ const missingBabelPackages = [];
87
+ const [babelPath, babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath] = [
88
+ '@babel/core',
89
+ 'babel-plugin-react-compiler',
90
+ '@babel/plugin-syntax-jsx',
91
+ "@babel/plugin-syntax-typescript"
92
+ ].map((name)=>{
93
+ try {
94
+ return vitest_config_require.resolve(name, {
95
+ paths: [
96
+ rootContext
97
+ ]
98
+ });
99
+ } catch {
100
+ missingBabelPackages.push(name);
101
+ }
102
+ return '';
103
+ });
104
+ if (missingBabelPackages.length > 0) throw new Error(`With \`experimental_enableReactCompiler\` enabled, you need to install \`${missingBabelPackages.join('`, `')}\` in your project root to use React Compiler.`);
105
+ return {
106
+ babelPath,
107
+ babelPluginReactCompilerPath,
108
+ babelPluginSyntaxJsxPath,
109
+ babelPluginSyntaxTypescriptPath
110
+ };
111
+ }
112
+ return {
113
+ name: 'transformReactCompilerPlugin',
114
+ enforce: 'pre',
115
+ config (config) {
116
+ rootContext = config.root;
117
+ const reactCompilerRuntimeAlias = [];
118
+ try {
119
+ reactCompilerRuntimeAlias.push({
120
+ find: /^react-compiler-runtime$/,
121
+ replacement: path.join(path.dirname(vitest_config_require.resolve('react-compiler-runtime/package.json', {
122
+ paths: [
123
+ rootContext
124
+ ]
125
+ })), 'src', 'index.ts')
126
+ });
127
+ } catch (e) {}
128
+ config.test.alias.push(...reactCompilerRuntimeAlias);
129
+ compilerDeps = resolveCompilerDeps(rootContext);
130
+ const { babelPath } = compilerDeps;
131
+ babel = vitest_config_require(babelPath);
132
+ },
133
+ async transform (sourceText, sourcePath) {
134
+ if (/\.(?:jsx|tsx)$/.test(sourcePath)) {
135
+ const { babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath } = compilerDeps;
136
+ const isTSX = sourcePath.endsWith('.tsx');
137
+ try {
138
+ const result = babel.transformSync(sourceText, {
139
+ plugins: [
140
+ [
141
+ babelPluginReactCompilerPath,
142
+ {
143
+ target: '17'
144
+ }
145
+ ],
146
+ babelPluginSyntaxJsxPath,
147
+ isTSX ? [
148
+ babelPluginSyntaxTypescriptPath,
149
+ {
150
+ isTSX: true
151
+ }
152
+ ] : null
153
+ ].filter(Boolean),
154
+ filename: sourcePath,
155
+ ast: false,
156
+ sourceMaps: true
157
+ });
158
+ if (result?.code != null && result?.map != null) return {
159
+ code: result.code,
160
+ map: result.map
161
+ };
162
+ this.error(`babel-plugin-react-compiler transform failed for ${sourcePath}: ${result ? 'missing code or map' : 'no result'}`);
163
+ } catch (e) {
164
+ this.error(e);
165
+ }
166
+ }
167
+ return null;
168
+ }
169
+ };
170
+ }
54
171
  function transformReactLynxPlugin() {
55
172
  return {
56
173
  name: 'transformReactLynxPlugin',
@@ -109,6 +226,9 @@ const createVitestConfig = async (options)=>{
109
226
  }
110
227
  },
111
228
  plugins: [
229
+ ...options?.experimental_enableReactCompiler ? [
230
+ transformReactCompilerPlugin()
231
+ ] : [],
112
232
  transformReactLynxPlugin()
113
233
  ],
114
234
  test: {
@@ -120,7 +240,8 @@ const createVitestConfig = async (options)=>{
120
240
  alias: [
121
241
  ...runtimeOSSAlias,
122
242
  ...runtimeAlias,
123
- ...preactAlias
243
+ ...preactAlias,
244
+ ...reactAlias
124
245
  ],
125
246
  include: options?.include ?? [
126
247
  'src/**/*.test.{js,jsx,ts,tsx}'
@@ -4,9 +4,17 @@ export interface CreateVitestConfigOptions {
4
4
  /**
5
5
  * The package name of the ReactLynx runtime package.
6
6
  *
7
- * @default `@lynx-js/react`
7
+ * @defaultValue `@lynx-js/react`
8
8
  */
9
9
  runtimePkgName?: string;
10
+ /**
11
+ * Enable React Compiler for this build.
12
+ *
13
+ * @link https://react.dev/learn/react-compiler
14
+ *
15
+ * @defaultValue false
16
+ */
17
+ experimental_enableReactCompiler?: boolean;
10
18
  }
11
19
 
12
20
  export function createVitestConfig(options?: CreateVitestConfigOptions): Promise<ViteUserConfig>;