@lynx-js/react 0.114.2 → 0.114.4
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 +52 -0
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +2 -2
- package/refresh/dist/index.js +34 -45
- package/runtime/lib/backgroundSnapshot.js +3 -1
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/hydrate.d.ts +3 -1
- package/runtime/lib/hydrate.js +24 -5
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/listUpdateInfo.js +15 -1
- package/runtime/lib/listUpdateInfo.js.map +1 -1
- package/testing-library/dist/vitest-global-setup.js +3 -4
- package/testing-library/dist/vitest.config.js +126 -1
- package/testing-library/types/vitest-config.d.ts +9 -1
- package/transform/dist/wasm.cjs +1 -1
- package/transform/index.d.ts +2 -0
- package/worklet-runtime/dist/dev.js +2 -3
- package/worklet-runtime/dist/main.js +1 -1
- package/worklet-runtime/lib/hydrate.js +1 -2
- package/worklet-runtime/lib/hydrate.js.map +1 -1
|
@@ -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',
|
|
@@ -74,6 +191,7 @@ const createVitestConfig = async (options)=>{
|
|
|
74
191
|
filename: relativePath,
|
|
75
192
|
target: 'MIXED'
|
|
76
193
|
},
|
|
194
|
+
engineVersion: options?.engineVersion ?? '',
|
|
77
195
|
directiveDCE: false,
|
|
78
196
|
defineDCE: false,
|
|
79
197
|
shake: false,
|
|
@@ -108,6 +226,9 @@ const createVitestConfig = async (options)=>{
|
|
|
108
226
|
}
|
|
109
227
|
},
|
|
110
228
|
plugins: [
|
|
229
|
+
...options?.experimental_enableReactCompiler ? [
|
|
230
|
+
transformReactCompilerPlugin()
|
|
231
|
+
] : [],
|
|
111
232
|
transformReactLynxPlugin()
|
|
112
233
|
],
|
|
113
234
|
test: {
|
|
@@ -119,7 +240,11 @@ const createVitestConfig = async (options)=>{
|
|
|
119
240
|
alias: [
|
|
120
241
|
...runtimeOSSAlias,
|
|
121
242
|
...runtimeAlias,
|
|
122
|
-
...preactAlias
|
|
243
|
+
...preactAlias,
|
|
244
|
+
...reactAlias
|
|
245
|
+
],
|
|
246
|
+
include: options?.include ?? [
|
|
247
|
+
'src/**/*.test.{js,jsx,ts,tsx}'
|
|
123
248
|
]
|
|
124
249
|
}
|
|
125
250
|
});
|
|
@@ -4,9 +4,17 @@ export interface CreateVitestConfigOptions {
|
|
|
4
4
|
/**
|
|
5
5
|
* The package name of the ReactLynx runtime package.
|
|
6
6
|
*
|
|
7
|
-
* @
|
|
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>;
|