@lynx-js/external-bundle-rsbuild-plugin 0.1.1 → 0.3.0

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,5 +1,22 @@
1
1
  # @lynx-js/external-bundle-rsbuild-plugin
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Support Rsbuild v2 in the external bundle plugin by replacing the removed `dev.setupMiddlewares` integration with [`server.setup`](https://rsbuild.rs/guide/upgrade/v1-to-v2#others) and registering local external bundle asset middleware only during dev server startup. ([#2603](https://github.com/lynx-family/lynx-stack/pull/2603))
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - feat: support retrying `fetchBundle` on timeout via a new `retries` option (defaults to `0`). ([#2681](https://github.com/lynx-family/lynx-stack/pull/2681))
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [[`069af04`](https://github.com/lynx-family/lynx-stack/commit/069af04f7afd5fc9944f46f1f1488aed03f03b57)]:
18
+ - @lynx-js/externals-loading-webpack-plugin@0.2.0
19
+
3
20
  ## 0.1.1
4
21
 
5
22
  ### Patch Changes
package/lib/index.d.ts CHANGED
@@ -102,7 +102,7 @@ export declare const builtInExternalsPresetDefinitions: ExternalsPresetDefinitio
102
102
  *
103
103
  * @public
104
104
  */
105
- export interface PluginExternalBundleOptions extends Pick<ExternalsLoadingPluginOptions, 'globalObject' | 'timeout'> {
105
+ export interface PluginExternalBundleOptions extends Pick<ExternalsLoadingPluginOptions, 'globalObject' | 'timeout' | 'retries'> {
106
106
  /**
107
107
  * Root directory that stores project-owned external bundles referenced by
108
108
  * `bundlePath`.
package/lib/index.js CHANGED
@@ -395,24 +395,31 @@ export function pluginExternalBundle(options) {
395
395
  return config;
396
396
  }
397
397
  return mergeRsbuildConfig(config, {
398
- dev: {
399
- setupMiddlewares: [
400
- (middlewares) => {
401
- middlewares.unshift((req, res, next) => {
402
- const bundlePath = req.url
403
- ? localBundleAssets.get(req.url)
404
- : undefined;
405
- if (bundlePath && existsSync(bundlePath)) {
406
- res.setHeader('Content-Type', 'application/octet-stream');
407
- res.setHeader('Access-Control-Allow-Origin', '*');
408
- createReadStream(bundlePath).pipe(res);
409
- return;
410
- }
411
- next();
412
- });
413
- return middlewares;
414
- },
415
- ],
398
+ server: {
399
+ setup: ({ server, action }) => {
400
+ if (action !== 'dev') {
401
+ return;
402
+ }
403
+ server.middlewares.use((req, res, next) => {
404
+ const bundlePath = req.url
405
+ ? localBundleAssets.get(req.url)
406
+ : undefined;
407
+ if (bundlePath && existsSync(bundlePath)) {
408
+ res.setHeader('Content-Type', 'application/octet-stream');
409
+ res.setHeader('Access-Control-Allow-Origin', '*');
410
+ const stream = createReadStream(bundlePath);
411
+ stream.on('error', () => {
412
+ if (!res.headersSent) {
413
+ res.statusCode = 404;
414
+ }
415
+ res.end();
416
+ });
417
+ stream.pipe(res);
418
+ return;
419
+ }
420
+ next();
421
+ });
422
+ },
416
423
  },
417
424
  });
418
425
  });
@@ -437,6 +444,7 @@ export function pluginExternalBundle(options) {
437
444
  externals,
438
445
  globalObject: options.globalObject,
439
446
  timeout: options.timeout,
447
+ retries: options.retries,
440
448
  }));
441
449
  return config;
442
450
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/external-bundle-rsbuild-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "An rsbuild plugin for loading lynx external bundles.",
5
5
  "keywords": [
6
6
  "rsbuild",
@@ -34,12 +34,12 @@
34
34
  "README.md"
35
35
  ],
36
36
  "dependencies": {
37
- "@lynx-js/externals-loading-webpack-plugin": "0.1.1"
37
+ "@lynx-js/externals-loading-webpack-plugin": "0.2.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@microsoft/api-extractor": "7.58.2",
41
- "@rsbuild/core": "1.7.5",
42
- "@lynx-js/react-umd": "0.119.0"
41
+ "@rsbuild/core": "2.0.11",
42
+ "@lynx-js/react-umd": "0.121.2"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=18"