@lynx-js/react-webpack-plugin-canary 0.9.0 → 0.9.1-canary-20260414-a9f8d054
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 +26 -18
- package/lib/ReactWebpackPlugin.d.ts +1 -1
- package/lib/ReactWebpackPlugin.js +1 -0
- package/lib/loaders/main-thread.js +6 -0
- package/lib/loaders/options.d.ts +9 -0
- package/lib/loaders/options.js +4 -3
- package/lib/loaders/testing.d.ts +4 -0
- package/lib/loaders/testing.js +102 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @lynx-js/react-webpack-plugin
|
|
2
2
|
|
|
3
|
+
## 0.9.1-canary-20260414031205-a9f8d0548664ea32ebae2072c13f2cf6fee676eb
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Support rstest for testing library using a dedicated testing loader. ([#2328](https://github.com/lynx-family/lynx-stack/pull/2328))
|
|
8
|
+
|
|
9
|
+
- Add `enableUiSourceMap` option to enable UI source map generation and debug-metadata asset emission. ([#2402](https://github.com/lynx-family/lynx-stack/pull/2402))
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`a9f8d05`](https://github.com/lynx-family/lynx-stack/commit/a9f8d0548664ea32ebae2072c13f2cf6fee676eb)]:
|
|
12
|
+
- @lynx-js/template-webpack-plugin@0.10.9-canary-20260414031205-a9f8d0548664ea32ebae2072c13f2cf6fee676eb
|
|
13
|
+
|
|
3
14
|
## 0.9.0
|
|
4
15
|
|
|
5
16
|
### Minor Changes
|
|
@@ -13,7 +24,6 @@
|
|
|
13
24
|
### Minor Changes
|
|
14
25
|
|
|
15
26
|
- feat: add `globalPropsMode` option to `PluginReactLynxOptions` ([#2346](https://github.com/lynx-family/lynx-stack/pull/2346))
|
|
16
|
-
|
|
17
27
|
- When configured to `"event"`, `updateGlobalProps` will only trigger a global event and skip the `runWithForce` flow.
|
|
18
28
|
- Defaults to `"reactive"`, which means `updateGlobalProps` will trigger re-render automatically.
|
|
19
29
|
|
|
@@ -22,7 +32,6 @@
|
|
|
22
32
|
- Fix sourcemap misalignment when wrapping lazy bundle main-thread chunks. ([#2361](https://github.com/lynx-family/lynx-stack/pull/2361))
|
|
23
33
|
|
|
24
34
|
The lazy bundle IIFE wrapper is now injected in `processAssets` at `PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1` by walking chunk groups instead of patching assets in `beforeEncode`.
|
|
25
|
-
|
|
26
35
|
- With `experimental_isLazyBundle: true`, the wrapper is applied to lazy-bundle chunk groups.
|
|
27
36
|
- Without lazy bundle mode, the wrapper is applied to async main-thread chunk groups generated by dynamic import.
|
|
28
37
|
|
|
@@ -102,16 +111,16 @@
|
|
|
102
111
|
type InlineChunkConfig =
|
|
103
112
|
| boolean
|
|
104
113
|
| InlineChunkTest
|
|
105
|
-
| { enable?: boolean |
|
|
114
|
+
| { enable?: boolean | "auto"; test: InlineChunkTest };
|
|
106
115
|
```
|
|
107
116
|
|
|
108
117
|
```ts
|
|
109
|
-
import { defineConfig } from
|
|
118
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
110
119
|
|
|
111
120
|
export default defineConfig({
|
|
112
121
|
output: {
|
|
113
122
|
inlineScripts: ({ name, size }) => {
|
|
114
|
-
return name.includes(
|
|
123
|
+
return name.includes("foo") && size < 1000;
|
|
115
124
|
},
|
|
116
125
|
},
|
|
117
126
|
});
|
|
@@ -166,7 +175,6 @@
|
|
|
166
175
|
- feat: fully support MTS ([#569](https://github.com/lynx-family/lynx-stack/pull/569))
|
|
167
176
|
|
|
168
177
|
Now use support the following usage
|
|
169
|
-
|
|
170
178
|
- mainthread event
|
|
171
179
|
- mainthread ref
|
|
172
180
|
- runOnMainThread/runOnBackground
|
|
@@ -195,7 +203,7 @@
|
|
|
195
203
|
- Shake `useImperativeHandle` on the main-thread by default. ([#153](https://github.com/lynx-family/lynx-stack/pull/153))
|
|
196
204
|
|
|
197
205
|
```js
|
|
198
|
-
import { forwardRef, useImperativeHandle } from
|
|
206
|
+
import { forwardRef, useImperativeHandle } from "@lynx-js/react";
|
|
199
207
|
|
|
200
208
|
export default forwardRef(function App(_, ref) {
|
|
201
209
|
useImperativeHandle(ref, () => {
|
|
@@ -203,7 +211,7 @@
|
|
|
203
211
|
return {
|
|
204
212
|
name() {
|
|
205
213
|
// This should be considered as background only
|
|
206
|
-
console.info(
|
|
214
|
+
console.info("This should not exist in main-thread");
|
|
207
215
|
},
|
|
208
216
|
};
|
|
209
217
|
});
|
|
@@ -263,14 +271,14 @@
|
|
|
263
271
|
- e8039f2: Add `defineDCE` in plugin options. Often used to define custom macros.
|
|
264
272
|
|
|
265
273
|
```js
|
|
266
|
-
import { pluginReactLynx } from
|
|
267
|
-
import { defineConfig } from
|
|
274
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
275
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
268
276
|
|
|
269
277
|
export default defineConfig({
|
|
270
278
|
plugins: [
|
|
271
279
|
pluginReactLynx({
|
|
272
280
|
defineDCE: {
|
|
273
|
-
__SOME_FALSE_DEFINE__:
|
|
281
|
+
__SOME_FALSE_DEFINE__: "false",
|
|
274
282
|
},
|
|
275
283
|
}),
|
|
276
284
|
],
|
|
@@ -282,20 +290,20 @@
|
|
|
282
290
|
For example, `import` initialized by dead code will be removed:
|
|
283
291
|
|
|
284
292
|
```js
|
|
285
|
-
import { foo } from
|
|
293
|
+
import { foo } from "bar";
|
|
286
294
|
|
|
287
295
|
if (__SOME_FALSE_DEFINE__) {
|
|
288
296
|
foo();
|
|
289
|
-
console.log(
|
|
297
|
+
console.log("dead code");
|
|
290
298
|
} else {
|
|
291
|
-
console.log(
|
|
299
|
+
console.log("reachable code");
|
|
292
300
|
}
|
|
293
301
|
```
|
|
294
302
|
|
|
295
303
|
will be transformed to:
|
|
296
304
|
|
|
297
305
|
```js
|
|
298
|
-
console.log(
|
|
306
|
+
console.log("reachable code");
|
|
299
307
|
```
|
|
300
308
|
|
|
301
309
|
## 0.6.0
|
|
@@ -305,14 +313,14 @@
|
|
|
305
313
|
- a30c83d: Add `compat.removeComponentAttrRegex`.
|
|
306
314
|
|
|
307
315
|
```js
|
|
308
|
-
import { pluginReactLynx } from
|
|
309
|
-
import { defineConfig } from
|
|
316
|
+
import { pluginReactLynx } from "@lynx-js/react-rsbuild-plugin";
|
|
317
|
+
import { defineConfig } from "@lynx-js/rspeedy";
|
|
310
318
|
|
|
311
319
|
export default defineConfig({
|
|
312
320
|
plugins: [
|
|
313
321
|
pluginReactLynx({
|
|
314
322
|
compat: {
|
|
315
|
-
removeComponentAttrRegex:
|
|
323
|
+
removeComponentAttrRegex: "YOUR REGEX",
|
|
316
324
|
},
|
|
317
325
|
}),
|
|
318
326
|
],
|
|
@@ -101,7 +101,7 @@ declare class ReactWebpackPlugin {
|
|
|
101
101
|
*
|
|
102
102
|
* @public
|
|
103
103
|
*/
|
|
104
|
-
static loaders: Record<keyof typeof LAYERS, string>;
|
|
104
|
+
static loaders: Record<keyof typeof LAYERS | 'TESTING', string>;
|
|
105
105
|
constructor(options?: ReactWebpackPluginOptions | undefined);
|
|
106
106
|
/**
|
|
107
107
|
* `defaultOptions` is the default options that the {@link ReactWebpackPlugin} uses.
|
|
@@ -60,6 +60,7 @@ class ReactWebpackPlugin {
|
|
|
60
60
|
static { this.loaders = {
|
|
61
61
|
BACKGROUND: require.resolve('../lib/loaders/background.js'),
|
|
62
62
|
MAIN_THREAD: require.resolve('../lib/loaders/main-thread.js'),
|
|
63
|
+
TESTING: require.resolve('../lib/loaders/testing.js'),
|
|
63
64
|
}; }
|
|
64
65
|
constructor(options) {
|
|
65
66
|
this.options = options;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
|
+
import { UI_SOURCE_MAP_RECORDS_BUILD_INFO } from '@lynx-js/template-webpack-plugin';
|
|
5
6
|
import { getMainThreadTransformOptions } from './options.js';
|
|
6
7
|
const mainThreadLoader = function (content, sourceMap) {
|
|
7
8
|
const require = createRequire(import.meta.url);
|
|
@@ -75,6 +76,11 @@ const mainThreadLoader = function (content, sourceMap) {
|
|
|
75
76
|
this.emitWarning(new Error(warning.text));
|
|
76
77
|
}
|
|
77
78
|
}
|
|
79
|
+
const currentModule = this._module;
|
|
80
|
+
const buildInfo = currentModule?.buildInfo;
|
|
81
|
+
if (buildInfo) {
|
|
82
|
+
buildInfo[UI_SOURCE_MAP_RECORDS_BUILD_INFO] = result.uiSourceMapRecords;
|
|
83
|
+
}
|
|
78
84
|
this.callback(null, result.code + (this.hot
|
|
79
85
|
// TODO: temporary fix LEPUS error `$RefreshReg$ is not defined`
|
|
80
86
|
// should make react-refresh transform in `react-transform`.
|
package/lib/loaders/options.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { LoaderContext } from '@rspack/core';
|
|
2
2
|
import type { CompatVisitorConfig, DefineDceVisitorConfig, JsxTransformerConfig, ShakeVisitorConfig, TransformNodiffOptions } from '@lynx-js/react/transform';
|
|
3
|
+
export declare const JSX_IMPORT_SOURCE: {
|
|
4
|
+
MAIN_THREAD: string;
|
|
5
|
+
BACKGROUND: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const RUNTIME_PKG = "@lynx-js/react/internal";
|
|
3
8
|
/**
|
|
4
9
|
* The options of the ReactLynx plugin.
|
|
5
10
|
* @public
|
|
@@ -17,6 +22,10 @@ export interface ReactLoaderOptions {
|
|
|
17
22
|
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.jsx}
|
|
18
23
|
*/
|
|
19
24
|
jsx?: JsxTransformerConfig | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* {@inheritdoc @lynx-js/react-rsbuild-plugin#PluginReactLynxOptions.enableUiSourceMap}
|
|
27
|
+
*/
|
|
28
|
+
enableUiSourceMap?: boolean | undefined;
|
|
20
29
|
/**
|
|
21
30
|
* Enable the Fast Refresh for ReactLynx.
|
|
22
31
|
*/
|
package/lib/loaders/options.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
const PLUGIN_NAME = 'react:webpack';
|
|
6
|
-
const JSX_IMPORT_SOURCE = {
|
|
6
|
+
export const JSX_IMPORT_SOURCE = {
|
|
7
7
|
MAIN_THREAD: '@lynx-js/react/lepus',
|
|
8
8
|
BACKGROUND: '@lynx-js/react',
|
|
9
9
|
};
|
|
10
10
|
const PUBLIC_RUNTIME_PKG = '@lynx-js/react';
|
|
11
|
-
const RUNTIME_PKG = '@lynx-js/react/internal';
|
|
11
|
+
export const RUNTIME_PKG = '@lynx-js/react/internal';
|
|
12
12
|
const OLD_RUNTIME_PKG = '@lynx-js/react-runtime';
|
|
13
13
|
const COMPONENT_PKG = '@lynx-js/react-components';
|
|
14
14
|
function normalizeSlashes(file) {
|
|
@@ -16,7 +16,7 @@ function normalizeSlashes(file) {
|
|
|
16
16
|
}
|
|
17
17
|
function getCommonOptions(inputSourceMap) {
|
|
18
18
|
const filename = normalizeSlashes(path.relative(this.rootContext, this.resourcePath));
|
|
19
|
-
const { compat, enableRemoveCSSScope, inlineSourcesContent, isDynamicComponent, engineVersion, defineDCE = { define: {} }, } = this.getOptions();
|
|
19
|
+
const { compat, enableRemoveCSSScope, enableUiSourceMap, inlineSourcesContent, isDynamicComponent, engineVersion, defineDCE = { define: {} }, } = this.getOptions();
|
|
20
20
|
const syntax = (/\.[mc]?tsx?$/.exec(this.resourcePath))
|
|
21
21
|
? 'typescript'
|
|
22
22
|
: 'ecmascript';
|
|
@@ -70,6 +70,7 @@ function getCommonOptions(inputSourceMap) {
|
|
|
70
70
|
// This allows serializing the updated runtime code to Lepus using `Function.prototype.toString`.
|
|
71
71
|
? 'MIXED'
|
|
72
72
|
: 'JS',
|
|
73
|
+
enableUiSourceMap: enableUiSourceMap ?? false,
|
|
73
74
|
runtimePkg: RUNTIME_PKG,
|
|
74
75
|
filename,
|
|
75
76
|
isDynamicComponent: isDynamicComponent ?? false,
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
|
+
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
import { createRequire } from 'node:module';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { JSX_IMPORT_SOURCE, RUNTIME_PKG } from './options.js';
|
|
7
|
+
function normalizeSlashes(file) {
|
|
8
|
+
return file.replaceAll(path.win32.sep, '/');
|
|
9
|
+
}
|
|
10
|
+
function testingLoader(content) {
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const { compat = false, defineDCE = { define: {} }, engineVersion = '', shake = false, transformPath = '@lynx-js/react/transform', } = this.getOptions();
|
|
13
|
+
const { transformReactLynxSync } = require(transformPath);
|
|
14
|
+
const filename = normalizeSlashes(path.relative(this.rootContext, this.resourcePath));
|
|
15
|
+
const result = transformReactLynxSync(content, {
|
|
16
|
+
mode: 'test',
|
|
17
|
+
pluginName: '',
|
|
18
|
+
filename: this.resourcePath,
|
|
19
|
+
sourcemap: true,
|
|
20
|
+
snapshot: {
|
|
21
|
+
preserveJsx: false,
|
|
22
|
+
runtimePkg: RUNTIME_PKG,
|
|
23
|
+
jsxImportSource: JSX_IMPORT_SOURCE.BACKGROUND,
|
|
24
|
+
filename,
|
|
25
|
+
target: 'MIXED',
|
|
26
|
+
},
|
|
27
|
+
// snapshot: true,
|
|
28
|
+
directiveDCE: false,
|
|
29
|
+
defineDCE,
|
|
30
|
+
shake,
|
|
31
|
+
compat,
|
|
32
|
+
engineVersion,
|
|
33
|
+
worklet: {
|
|
34
|
+
filename,
|
|
35
|
+
runtimePkg: RUNTIME_PKG,
|
|
36
|
+
target: 'MIXED',
|
|
37
|
+
},
|
|
38
|
+
refresh: false,
|
|
39
|
+
cssScope: false,
|
|
40
|
+
});
|
|
41
|
+
if (result.errors.length > 0) {
|
|
42
|
+
for (const error of result.errors) {
|
|
43
|
+
if (this.experiments?.emitDiagnostic) {
|
|
44
|
+
// Rspack with `emitDiagnostic` API
|
|
45
|
+
try {
|
|
46
|
+
this.experiments.emitDiagnostic({
|
|
47
|
+
message: error.text,
|
|
48
|
+
sourceCode: content,
|
|
49
|
+
location: {
|
|
50
|
+
line: error.location?.line ?? 1,
|
|
51
|
+
column: error.location?.column ?? 0,
|
|
52
|
+
length: error.location?.length ?? 0,
|
|
53
|
+
text: error.text ?? '',
|
|
54
|
+
},
|
|
55
|
+
severity: 'error',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Rspack may throw on invalid line & column when containing UTF-8.
|
|
60
|
+
// We catch it up here.
|
|
61
|
+
this.emitError(new Error(error.text));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
// Webpack or legacy Rspack
|
|
66
|
+
this.emitError(new Error(error.text));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
this.callback(new Error('react-transform failed'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const warning of result.warnings) {
|
|
73
|
+
if (this.experiments?.emitDiagnostic) {
|
|
74
|
+
// Rspack with `emitDiagnostic` API
|
|
75
|
+
try {
|
|
76
|
+
this.experiments.emitDiagnostic({
|
|
77
|
+
message: warning.text,
|
|
78
|
+
sourceCode: content,
|
|
79
|
+
location: {
|
|
80
|
+
line: warning.location?.line ?? 1,
|
|
81
|
+
column: warning.location?.column ?? 0,
|
|
82
|
+
length: warning.location?.length ?? 0,
|
|
83
|
+
text: warning.text ?? '',
|
|
84
|
+
},
|
|
85
|
+
severity: 'warning',
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// Rspack may throw on invalid line & column when containing UTF-8.
|
|
90
|
+
// We catch it up here.
|
|
91
|
+
this.emitWarning(new Error(warning.text));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// Webpack or legacy Rspack
|
|
96
|
+
this.emitWarning(new Error(warning.text));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.callback(null, result.code, result.map);
|
|
100
|
+
}
|
|
101
|
+
export default testingLoader;
|
|
102
|
+
//# sourceMappingURL=testing.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/react-webpack-plugin-canary",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1-canary-20260414-a9f8d054",
|
|
4
4
|
"description": "A webpack plugin for ReactLynx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"webpack",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"swc-loader": "^0.2.7",
|
|
44
44
|
"webpack": "^5.105.2",
|
|
45
45
|
"@lynx-js/css-extract-webpack-plugin": "npm:@lynx-js/css-extract-webpack-plugin-canary@0.7.0",
|
|
46
|
-
"@lynx-js/react": "npm:@lynx-js/react-canary@0.118.
|
|
47
|
-
"@lynx-js/template-webpack-plugin": "npm:@lynx-js/template-webpack-plugin-canary@0.10.8",
|
|
46
|
+
"@lynx-js/react": "npm:@lynx-js/react-canary@0.118.1-canary-20260414-a9f8d054",
|
|
48
47
|
"@lynx-js/test-tools": "0.0.0",
|
|
48
|
+
"@lynx-js/template-webpack-plugin": "npm:@lynx-js/template-webpack-plugin-canary@0.10.9-canary-20260414-a9f8d054",
|
|
49
49
|
"@lynx-js/vitest-setup": "0.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|