@lynx-js/react-webpack-plugin 0.9.3 → 0.9.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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @lynx-js/react-webpack-plugin
2
2
 
3
+ ## 0.9.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Support the unified `debug-metadata.json` format and depend on `@lynx-js/debug-metadata`. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
8
+
9
+ - Prefix Lynx runtime module names with `webpack/runtime/` (e.g. `Lynx async chunks` → `webpack/runtime/lynx async chunks`), matching the path-structured naming of the bundler's built-in runtime modules. The previous bare names had no path segment, so when they appear as a source-map `sources` entry under a `file://` module-filename template they collapsed into an invalid URL authority (the space-containing name became the host) and broke `SourceMapConsumer` parsing. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
10
+
11
+ - Widen peer ranges to admit the new minor versions of `@lynx-js/template-webpack-plugin` (^0.12.0) and `@lynx-js/rspeedy` (^0.15.0) shipping with the unified `debug-metadata.json` feature. ([#2642](https://github.com/lynx-family/lynx-stack/pull/2642))
12
+
13
+ - Updated dependencies [[`a839d59`](https://github.com/lynx-family/lynx-stack/commit/a839d59b7f477a86f2cd10215d0b754264e54425), [`d3201df`](https://github.com/lynx-family/lynx-stack/commit/d3201dfa57964bfe6c8c52a803aeeb0fca1f2d27), [`409594b`](https://github.com/lynx-family/lynx-stack/commit/409594b9c51bb0c13f01c7d3f16949b27ebfdced), [`353363e`](https://github.com/lynx-family/lynx-stack/commit/353363e52dca3b252b39b34a3a87ce840dd308f3)]:
14
+ - @lynx-js/debug-metadata@0.1.0
15
+
3
16
  ## 0.9.3
4
17
 
5
18
  ### Patch Changes
@@ -2,7 +2,7 @@ import { RuntimeGlobals as LynxRuntimeGlobals } from '@lynx-js/webpack-runtime-g
2
2
  export function createLynxProcessEvalResultRuntimeModule(webpack) {
3
3
  return class LynxProcessEvalResultRuntimeModule extends webpack.RuntimeModule {
4
4
  constructor() {
5
- super('Lynx process eval result', webpack.RuntimeModule.STAGE_ATTACH);
5
+ super('webpack/runtime/lynx process eval result', webpack.RuntimeModule.STAGE_ATTACH);
6
6
  }
7
7
  generate() {
8
8
  const chunk = this.chunk;
@@ -10,6 +10,8 @@ export interface ModuleWithElementTemplateBuildInfo {
10
10
  modules?: Iterable<ModuleWithElementTemplateBuildInfo>;
11
11
  }
12
12
  export declare function collectElementTemplatesFromModule(module: ModuleWithElementTemplateBuildInfo): ElementTemplateBuildInfo[];
13
+ export declare function mergeElementTemplate(elementTemplates: Record<string, Record<string, unknown>>, templateId: string, compiledTemplate: Record<string, unknown>): void;
14
+ export declare function mergeElementTemplatesFromModule(elementTemplates: Record<string, Record<string, unknown>>, module: ModuleWithElementTemplateBuildInfo): void;
13
15
  /**
14
16
  * The options for ReactWebpackPlugin
15
17
  *
@@ -23,6 +23,51 @@ export function collectElementTemplatesFromModule(module) {
23
23
  }
24
24
  return elementTemplates;
25
25
  }
26
+ function isPlainRecord(value) {
27
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
28
+ }
29
+ function areCompiledTemplateValuesEqual(left, right) {
30
+ if (Object.is(left, right)) {
31
+ return true;
32
+ }
33
+ if (Array.isArray(left) || Array.isArray(right)) {
34
+ if (!Array.isArray(left)
35
+ || !Array.isArray(right)
36
+ || left.length !== right.length) {
37
+ return false;
38
+ }
39
+ return left.every((value, index) => areCompiledTemplateValuesEqual(value, right[index]));
40
+ }
41
+ if (isPlainRecord(left) || isPlainRecord(right)) {
42
+ if (!isPlainRecord(left) || !isPlainRecord(right)) {
43
+ return false;
44
+ }
45
+ const leftKeys = Object.keys(left).sort();
46
+ const rightKeys = Object.keys(right).sort();
47
+ if (leftKeys.length !== rightKeys.length) {
48
+ return false;
49
+ }
50
+ return leftKeys.every((key, index) => key === rightKeys[index]
51
+ && areCompiledTemplateValuesEqual(left[key], right[key]));
52
+ }
53
+ return false;
54
+ }
55
+ export function mergeElementTemplate(elementTemplates, templateId, compiledTemplate) {
56
+ const existingTemplate = elementTemplates[templateId];
57
+ if (!existingTemplate) {
58
+ elementTemplates[templateId] = compiledTemplate;
59
+ return;
60
+ }
61
+ if (areCompiledTemplateValuesEqual(existingTemplate, compiledTemplate)) {
62
+ return;
63
+ }
64
+ throw new Error(`Element Template id collision for ${templateId}: same template id has different compiledTemplate content.`);
65
+ }
66
+ export function mergeElementTemplatesFromModule(elementTemplates, module) {
67
+ for (const { templateId, compiledTemplate } of collectElementTemplatesFromModule(module)) {
68
+ mergeElementTemplate(elementTemplates, templateId, compiledTemplate);
69
+ }
70
+ }
26
71
  /**
27
72
  * ReactWebpackPlugin allows using ReactLynx with webpack
28
73
  *
@@ -172,8 +217,6 @@ class ReactWebpackPlugin {
172
217
  .forEach(name => this.#updateMainThreadInfo(compilation, name));
173
218
  });
174
219
  });
175
- // TODO: replace LynxTemplatePlugin types with Rspack
176
- // @ts-expect-error Rspack x Webpack compilation not match
177
220
  const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
178
221
  const { RawSource, ConcatSource } = compiler.webpack.sources;
179
222
  hooks.beforeEncode.tap(this.constructor.name, (args) => {
@@ -242,10 +285,10 @@ class ReactWebpackPlugin {
242
285
  hooks.beforeEncode.tap(`${this.constructor.name}.ElementTemplate`, (args) => {
243
286
  const elementTemplates = {};
244
287
  for (const module of compilation.modules) {
245
- for (const { templateId, compiledTemplate } of collectElementTemplatesFromModule(module)) {
246
- elementTemplates[templateId] = compiledTemplate;
247
- }
288
+ mergeElementTemplatesFromModule(elementTemplates, module);
248
289
  }
290
+ args.encodeData.sourceContent.config['enableUnifyFixedBehavior'] =
291
+ true;
249
292
  args.encodeData.elementTemplate = elementTemplates;
250
293
  return args;
251
294
  });
@@ -2,7 +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
+ import { UI_SOURCE_MAP_RECORDS_BUILD_INFO } from '@lynx-js/debug-metadata';
6
6
  import { getMainThreadTransformOptions } from './options.js';
7
7
  export const ELEMENT_TEMPLATE_BUILD_INFO = 'lynx:element-templates';
8
8
  const mainThreadLoader = function (content, sourceMap) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/react-webpack-plugin",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "A webpack plugin for ReactLynx",
5
5
  "keywords": [
6
6
  "webpack",
@@ -34,22 +34,23 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "tiny-invariant": "^1.3.3",
37
+ "@lynx-js/debug-metadata": "^0.1.0",
37
38
  "@lynx-js/webpack-runtime-globals": "0.0.6"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@microsoft/api-extractor": "7.58.2",
41
- "@rspack/core": "1.7.9",
42
+ "@rspack/core": "2.0.8",
43
+ "@rspack/lite-tapable": "1.1.0",
44
+ "@rstest/core": "0.10.5",
42
45
  "css-loader": "^7.1.4",
43
46
  "swc-loader": "^0.2.7",
44
- "webpack": "^5.105.2",
45
- "@lynx-js/css-extract-webpack-plugin": "0.7.1",
46
- "@lynx-js/react": "0.121.1",
47
- "@lynx-js/template-webpack-plugin": "0.11.2",
47
+ "@lynx-js/css-extract-webpack-plugin": "0.8.0",
48
+ "@lynx-js/react": "0.121.2",
48
49
  "@lynx-js/test-tools": "0.0.0",
49
- "@lynx-js/vitest-setup": "0.0.0"
50
+ "@lynx-js/template-webpack-plugin": "0.12.0"
50
51
  },
51
52
  "peerDependencies": {
52
- "@lynx-js/template-webpack-plugin": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0"
53
+ "@lynx-js/template-webpack-plugin": "^0.4.0 || ^0.5.0 || ^0.6.0 || ^0.7.0 || ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0"
53
54
  },
54
55
  "peerDependenciesMeta": {
55
56
  "@lynx-js/react": {
@@ -61,6 +62,6 @@
61
62
  },
62
63
  "scripts": {
63
64
  "api-extractor": "api-extractor run --verbose",
64
- "test": "pnpm -w run test --project webpack/react"
65
+ "test": "rstest"
65
66
  }
66
67
  }