@lynx-js/vanilla-rsbuild-plugin 0.0.2 → 0.1.1

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/index.js +21 -17
  3. package/package.json +20 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # `@lynx-js/vanilla-rsbuild-plugin`
2
2
 
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`b900a78`](https://github.com/lynx-family/lynx-stack/commit/b900a78a43914adf2aae60849e2d6433be5eb797)]:
8
+ - @lynx-js/template-webpack-plugin@0.16.1
9
+
10
+ ## 0.1.0
11
+
12
+ ### Minor Changes
13
+
14
+ - **BREAKING CHANGE**: Require `@lynx-js/rspeedy` `^0.17.0` in the plugins that read the build engine config through `Symbol.for('@lynx-js/rsbuild-plugin:config')`, since the engine that ships with `0.16` does not expose it. The plugins that do not touch the engine keep their existing range and add `^0.17.0` to it. ([#3682](https://github.com/lynx-family/lynx-stack/pull/3682))
15
+
16
+ ### Patch Changes
17
+
18
+ - Declare the build host as an optional peer dependency. `@rsbuild/core` covers a plain Rsbuild build, and `@lynx-js/rspeedy` covers an Rspeedy one, so whichever host is installed is version-checked. ([#3678](https://github.com/lynx-family/lynx-stack/pull/3678))
19
+
20
+ - Honor `output.distPath.intermediate`. The Lynx build engine now resolves the intermediate directory, so the option is no longer ignored by the plugins that emit a Lynx bundle. ([#3676](https://github.com/lynx-family/lynx-stack/pull/3676))
21
+
22
+ - Resolve the bundle filename through `getLynxConfig(api).resolveBundleFilename()` instead of reading `output.filename` out of the Rspeedy config. A configured filename is now honored when the plugins are used with Rsbuild directly. ([#3651](https://github.com/lynx-family/lynx-stack/pull/3651))
23
+
24
+ - Expose `Symbol.for('LynxTemplatePlugin')` from `pluginLynx` instead of from each DSL plugin, so the plugins that tap the template hooks work with the build engine alone. ([#3675](https://github.com/lynx-family/lynx-stack/pull/3675))
25
+
26
+ - Wrap the background chunk again. The runtime wrapper only matched assets under `.rspeedy/`, so once the intermediate directory moved to `.lynx/` the background chunk shipped without the wrapper and failed on load with `ReferenceError: lynx is not defined`. The wrapper now targets the background asset the plugin emits, wherever the intermediate directory lives. ([#3745](https://github.com/lynx-family/lynx-stack/pull/3745))
27
+ - Updated dependencies [[`c21cddd`](https://github.com/lynx-family/lynx-stack/commit/c21cddd0b75290330b6891f041db63ee5b28f492), [`f743e12`](https://github.com/lynx-family/lynx-stack/commit/f743e123e058d8f97720b1ce8c4a3d6601c8f7be), [`5637926`](https://github.com/lynx-family/lynx-stack/commit/5637926c579bac5e9b78a02b982b1110cf4421d4), [`cdceffc`](https://github.com/lynx-family/lynx-stack/commit/cdceffc6f3fb9ac7b5ce1f48b7edb53c7788c057), [`6da3e18`](https://github.com/lynx-family/lynx-stack/commit/6da3e189f58637e14318782c176ed5970b59f75d), [`5637926`](https://github.com/lynx-family/lynx-stack/commit/5637926c579bac5e9b78a02b982b1110cf4421d4), [`eaefef6`](https://github.com/lynx-family/lynx-stack/commit/eaefef64d9874a8236d99b8abe17978d803a02da), [`0be26e9`](https://github.com/lynx-family/lynx-stack/commit/0be26e91d362041d1b0f568d15828d92f0ed2a6d), [`32ba734`](https://github.com/lynx-family/lynx-stack/commit/32ba7347d1733eb4b2e19e95d7b7415ae78e23d2)]:
28
+ - @lynx-js/template-webpack-plugin@0.16.0
29
+ - @lynx-js/runtime-wrapper-webpack-plugin@0.2.4
30
+
3
31
  ## 0.0.2
4
32
 
5
33
  ### Patch Changes
package/dist/index.js CHANGED
@@ -2,11 +2,10 @@ import { statSync } from "node:fs";
2
2
  import node_path from "node:path";
3
3
  import { RuntimeWrapperWebpackPlugin } from "@lynx-js/runtime-wrapper-webpack-plugin";
4
4
  import { LynxEncodePlugin, LynxTemplatePlugin, WebEncodePlugin } from "@lynx-js/template-webpack-plugin";
5
+ const S_LYNX_CONFIG = Symbol.for('@lynx-js/rsbuild-plugin:config');
5
6
  const PLUGIN_NAME = 'lynx:vanilla';
6
7
  const VANILLA_WEBPACK_PLUGIN_NAME = 'VanillaLynxWebpackPlugin';
7
8
  const DEFAULT_ENGINE_VERSION = '3.5';
8
- const DEFAULT_BUNDLE_FILENAME = '[name].[platform].bundle';
9
- const INTERMEDIATE_DIR = '.rspeedy';
10
9
  const LAYERS = Object.freeze({
11
10
  BACKGROUND: 'vanilla:background',
12
11
  MAIN_THREAD: 'vanilla:main-thread'
@@ -36,11 +35,6 @@ function resolvePluginOptions(api, options) {
36
35
  }
37
36
  function exposeVanillaCapabilities(api) {
38
37
  api.expose(Symbol.for('LAYERS'), LAYERS);
39
- api.expose(Symbol.for('LynxTemplatePlugin'), {
40
- LynxTemplatePlugin: {
41
- getLynxTemplatePluginHooks: LynxTemplatePlugin.getLynxTemplatePluginHooks.bind(LynxTemplatePlugin)
42
- }
43
- });
44
38
  }
45
39
  function disableVanillaHotUpdates(api) {
46
40
  api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>mergeRsbuildConfig(config, {
@@ -52,7 +46,8 @@ function disableVanillaHotUpdates(api) {
52
46
  }
53
47
  function setupVanillaBundler(api, options) {
54
48
  api.modifyBundlerChain((chain, { environment })=>{
55
- const rspeedyFilename = api.useExposed(Symbol.for('rspeedy.api'))?.config?.output?.filename;
49
+ const lynxConfig = api.useExposed(S_LYNX_CONFIG);
50
+ if (!lynxConfig) throw new Error('No Lynx config exposed. `pluginLynx` has to be applied for the Lynx build engine to be configured.');
56
51
  const platform = getVanillaPlatform(environment.name);
57
52
  if (!platform) return;
58
53
  const entries = resolveVanillaEntries(api, chain.entryPoints.entries() ?? {}, options.entries);
@@ -60,7 +55,7 @@ function setupVanillaBundler(api, options) {
60
55
  bundleFilename: options.bundleFilename,
61
56
  engineVersion: options.engineVersion,
62
57
  platform: environment.name,
63
- rspeedyFilename
58
+ lynxConfig
64
59
  };
65
60
  chain.entryPoints.clear();
66
61
  const artifacts = entries.map(([entryName, entry])=>addVanillaEntry(chain, entryName, entry, entryContext));
@@ -72,8 +67,11 @@ function addVanillaEntry(chain, entryName, entry, context) {
72
67
  const hasBackground = void 0 !== backgroundSource;
73
68
  const backgroundEntry = `${entryName}__background`;
74
69
  const mainThreadEntry = `${entryName}__main-thread`;
75
- const backgroundAsset = node_path.posix.join(INTERMEDIATE_DIR, entryName, 'background.js');
76
- const mainThreadAsset = node_path.posix.join(INTERMEDIATE_DIR, entryName, 'main-thread.js');
70
+ const intermediateDir = context.lynxConfig.resolveIntermediateDir({
71
+ entryName
72
+ });
73
+ const backgroundAsset = node_path.posix.join(intermediateDir, 'background.js');
74
+ const mainThreadAsset = node_path.posix.join(intermediateDir, 'main-thread.js');
77
75
  if (hasBackground) chain.entry(backgroundEntry).add({
78
76
  layer: LAYERS.BACKGROUND,
79
77
  import: backgroundSource,
@@ -97,12 +95,13 @@ function addVanillaEntry(chain, entryName, entry, context) {
97
95
  mainThreadEntry
98
96
  ],
99
97
  dsl: 'react_nodiff',
100
- filename: resolveBundleFilename(context.rspeedyFilename, context.bundleFilename, entryName, context.platform),
101
- intermediate: node_path.posix.join(INTERMEDIATE_DIR, entryName),
98
+ filename: resolveVanillaBundleFilename(context.lynxConfig, context.bundleFilename, entryName, context.platform),
99
+ intermediate: intermediateDir,
102
100
  targetSdkVersion: context.engineVersion
103
101
  }
104
102
  ]);
105
103
  return {
104
+ backgroundAsset: hasBackground ? backgroundAsset : void 0,
106
105
  hasBackground,
107
106
  mainThreadAsset
108
107
  };
@@ -112,7 +111,9 @@ function addVanillaBundlerPlugins(chain, artifacts, engineVersion, platform) {
112
111
  if ('lynx' === platform && artifacts.some((artifact)=>artifact.hasBackground)) chain.plugin(`${PLUGIN_NAME}:runtime-wrapper`).use(RuntimeWrapperWebpackPlugin, [
113
112
  {
114
113
  targetSdkVersion: engineVersion,
115
- test: /^\.rspeedy\/.+\/background\.js$/
114
+ test: artifacts.flatMap((artifact)=>void 0 === artifact.backgroundAsset ? [] : [
115
+ artifact.backgroundAsset
116
+ ])
116
117
  }
117
118
  ]);
118
119
  if ('lynx' === platform) chain.plugin(LynxEncodePlugin.name).use(LynxEncodePlugin, []);
@@ -195,14 +196,17 @@ function resolveOptionalSource(source, conventionSource) {
195
196
  if (source) return source;
196
197
  return conventionSource && isFile(conventionSource) ? conventionSource : void 0;
197
198
  }
198
- function resolveBundleFilename(rspeedyFilename, option, entryName, platform) {
199
- const configured = option ?? ('object' == typeof rspeedyFilename ? rspeedyFilename.bundle ?? rspeedyFilename.template : rspeedyFilename) ?? DEFAULT_BUNDLE_FILENAME;
199
+ function resolveVanillaBundleFilename(lynxConfig, option, entryName, platform) {
200
200
  const context = {
201
201
  entryName,
202
202
  lazyBundle: false,
203
203
  platform
204
204
  };
205
- const filename = 'function' == typeof configured ? configured(context) : configured;
205
+ if (void 0 === option) return lynxConfig.resolveBundleFilename({
206
+ entryName,
207
+ platform
208
+ });
209
+ const filename = 'function' == typeof option ? option(context) : option;
206
210
  return filename.replaceAll('[name]', entryName).replaceAll('[platform]', platform);
207
211
  }
208
212
  function createVanillaWebpackPlugin(mainThreadAssets) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/vanilla-rsbuild-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "An Rsbuild plugin for building Vanilla Lynx applications with Element PAPI.",
5
5
  "keywords": [
6
6
  "rsbuild",
@@ -32,14 +32,27 @@
32
32
  "README.md"
33
33
  ],
34
34
  "dependencies": {
35
- "@lynx-js/runtime-wrapper-webpack-plugin": "0.2.3",
36
- "@lynx-js/template-webpack-plugin": "0.15.2"
35
+ "@lynx-js/runtime-wrapper-webpack-plugin": "0.2.4",
36
+ "@lynx-js/template-webpack-plugin": "0.16.1"
37
37
  },
38
38
  "devDependencies": {
39
- "@rsbuild/core": "2.1.10",
40
- "@rstest/core": "0.11.6",
41
- "@lynx-js/rspeedy": "0.16.5",
42
- "@lynx-js/test-tools": "0.0.0"
39
+ "@lynx-js/rsbuild-plugin": "0.1.2",
40
+ "@lynx-js/rspeedy": "0.17.2",
41
+ "@lynx-js/test-tools": "0.0.0",
42
+ "@rsbuild/core": "2.2.4",
43
+ "@rstest/core": "0.11.12"
44
+ },
45
+ "peerDependencies": {
46
+ "@lynx-js/rspeedy": "^0.17.0",
47
+ "@rsbuild/core": "^2.0.0"
48
+ },
49
+ "peerDependenciesMeta": {
50
+ "@lynx-js/rspeedy": {
51
+ "optional": true
52
+ },
53
+ "@rsbuild/core": {
54
+ "optional": true
55
+ }
43
56
  },
44
57
  "engines": {
45
58
  "node": ">=18"