@lynx-js/vanilla-rsbuild-plugin 0.0.0-rc.0 → 0.0.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.
- package/CHANGELOG.md +9 -0
- package/LICENSE +202 -0
- package/README.md +77 -0
- package/dist/index.d.ts +130 -0
- package/dist/index.js +234 -0
- package/package.json +52 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# `@lynx-js/vanilla-rsbuild-plugin`
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add `pluginVanillaLynx` for building native and web Vanilla Lynx Element PAPI applications with Rsbuild and Rspeedy. ([#3441](https://github.com/lynx-family/lynx-stack/pull/3441))
|
|
8
|
+
- Updated dependencies [[`6cc9624`](https://github.com/lynx-family/lynx-stack/commit/6cc9624fb54dc7f73b6e68e49e2322b8136d3418)]:
|
|
9
|
+
- @lynx-js/template-webpack-plugin@0.15.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# `@lynx-js/vanilla-rsbuild-plugin`
|
|
2
|
+
|
|
3
|
+
An Rsbuild plugin for building Vanilla Lynx applications directly with Element PAPI.
|
|
4
|
+
|
|
5
|
+
## Usage with Rspeedy
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineConfig } from '@lynx-js/rspeedy'
|
|
9
|
+
import { pluginVanillaLynx } from '@lynx-js/vanilla-rsbuild-plugin'
|
|
10
|
+
|
|
11
|
+
export default defineConfig({
|
|
12
|
+
plugins: [
|
|
13
|
+
pluginVanillaLynx({
|
|
14
|
+
entries: {
|
|
15
|
+
card: {
|
|
16
|
+
mainThread: './src/card/main-thread.ts',
|
|
17
|
+
background: './src/card/background.ts',
|
|
18
|
+
css: './src/card/style.css',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
],
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For a convention-based entry, `source.entry` points to the main-thread source:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
source: {
|
|
31
|
+
entry: {
|
|
32
|
+
card: './src/card/main-thread.ts',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
plugins: [pluginVanillaLynx()],
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The plugin discovers these optional sibling files:
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
src/card/
|
|
43
|
+
main-thread.ts
|
|
44
|
+
background.ts
|
|
45
|
+
style.css
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`background.ts` runs in the background JavaScript thread. Element PAPI tree creation and mutation must stay in `main-thread.ts`.
|
|
49
|
+
|
|
50
|
+
Use an explicit `entries` item when the two thread sources are in different directories. Set `background: false` for a main-thread-only card. Explicit entries take precedence over `source.entry`.
|
|
51
|
+
|
|
52
|
+
Entry sources are module requests and use Rspeedy or Rsbuild resolution,
|
|
53
|
+
including aliases and configured extensions. Automatic sibling discovery is a
|
|
54
|
+
filesystem convention: it runs only when `mainThread` names an existing local
|
|
55
|
+
file. When `mainThread` is an alias or package request, configure `background`
|
|
56
|
+
and `css` explicitly when they are needed.
|
|
57
|
+
|
|
58
|
+
The plugin emits one `.bundle` per logical entry, marks the main-thread asset for Lepus encoding, wraps only the native background asset, and enables the event-handler config required by Element PAPI listeners. HMR and live reload are disabled because Vanilla Lynx does not currently install a compatible hot-update runtime.
|
|
59
|
+
|
|
60
|
+
When Rspeedy configures both `web` and `lynx` environments, the plugin emits a web-encoded `[name].web.bundle` and a native `[name].lynx.bundle`. Background JavaScript is runtime-wrapped only for native Lynx; the web encoder embeds the unwrapped background chunk for the web runtime.
|
|
61
|
+
|
|
62
|
+
## Options
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
pluginVanillaLynx({
|
|
66
|
+
entries: {
|
|
67
|
+
card: {
|
|
68
|
+
mainThread: './src/card/main-thread.ts',
|
|
69
|
+
background: './src/card/background.ts',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
engineVersion: '3.5',
|
|
73
|
+
bundleFilename: '[name].bundle',
|
|
74
|
+
})
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
When `bundleFilename` is omitted, the plugin uses Rspeedy's `output.filename.bundle`. Outside Rspeedy it defaults to `[name].[platform].bundle`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* An Rsbuild plugin that integrates Vanilla Lynx applications with Rspeedy.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { LynxTemplatePlugin as LynxTemplatePlugin_2 } from '@lynx-js/template-webpack-plugin';
|
|
8
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
9
|
+
import type { TemplateHooks } from '@lynx-js/template-webpack-plugin';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Rspack layers used by Vanilla Lynx entries.
|
|
13
|
+
*
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare const LAYERS: Readonly<{
|
|
17
|
+
BACKGROUND: 'vanilla:background';
|
|
18
|
+
MAIN_THREAD: 'vanilla:main-thread';
|
|
19
|
+
}>;
|
|
20
|
+
|
|
21
|
+
export declare interface LynxTemplatePlugin {
|
|
22
|
+
getLynxTemplatePluginHooks: typeof LynxTemplatePlugin_2.getLynxTemplatePluginHooks;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create the Vanilla Lynx DSL integration for Rsbuild or Rspeedy.
|
|
27
|
+
*
|
|
28
|
+
* A logical entry can explicitly declare its main-thread and background-thread
|
|
29
|
+
* sources. As a shorthand, an Rsbuild entry is treated as the main-thread
|
|
30
|
+
* source and optional sibling `background.ts` and `style.css` files are
|
|
31
|
+
* discovered by convention.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export declare function pluginVanillaLynx(options?: PluginVanillaLynxOptions): RsbuildPlugin;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options for {@link pluginVanillaLynx}.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare interface PluginVanillaLynxOptions {
|
|
43
|
+
/**
|
|
44
|
+
* Explicit two-thread entries.
|
|
45
|
+
*
|
|
46
|
+
* @remarks
|
|
47
|
+
* When omitted, every Rsbuild `source.entry` is treated as a main-thread
|
|
48
|
+
* entry and optional sibling `background.ts` and `style.css` files are
|
|
49
|
+
* discovered by convention.
|
|
50
|
+
*/
|
|
51
|
+
entries?: Record<string, VanillaLynxEntry> | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Override the final `.bundle` filename.
|
|
54
|
+
*
|
|
55
|
+
* @remarks
|
|
56
|
+
* When omitted under Rspeedy, `output.filename.bundle` is used.
|
|
57
|
+
* The default outside Rspeedy is `[name].[platform].bundle`.
|
|
58
|
+
*/
|
|
59
|
+
bundleFilename?: VanillaBundleFilename | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* The minimum Lynx Engine version required by the emitted bundle.
|
|
62
|
+
*
|
|
63
|
+
* @defaultValue `'3.5'`
|
|
64
|
+
*/
|
|
65
|
+
engineVersion?: string | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Alias of {@link PluginVanillaLynxOptions.engineVersion}.
|
|
68
|
+
*
|
|
69
|
+
* @deprecated Use `engineVersion` instead.
|
|
70
|
+
*/
|
|
71
|
+
targetSdkVersion?: string | undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { TemplateHooks }
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The final Vanilla Lynx bundle filename.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare type VanillaBundleFilename = string | ((context: VanillaBundleFilenameContext) => string);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Context passed to a Vanilla Lynx bundle filename function.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export declare interface VanillaBundleFilenameContext {
|
|
89
|
+
/** The logical Rsbuild entry name. */
|
|
90
|
+
entryName: string;
|
|
91
|
+
/** Vanilla Lynx currently emits only the main card bundle. */
|
|
92
|
+
lazyBundle: false;
|
|
93
|
+
/** The Rsbuild environment name. */
|
|
94
|
+
platform: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The two thread source files of a logical Vanilla Lynx entry.
|
|
99
|
+
*
|
|
100
|
+
* @public
|
|
101
|
+
*/
|
|
102
|
+
export declare interface VanillaLynxEntry {
|
|
103
|
+
/**
|
|
104
|
+
* Module request executed on the Lynx main thread with Element PAPI globals.
|
|
105
|
+
*
|
|
106
|
+
* @remarks
|
|
107
|
+
* The request is resolved by Rspeedy or Rsbuild. When it names an existing
|
|
108
|
+
* local file, optional sibling `background.ts` and `style.css` files are
|
|
109
|
+
* discovered by convention.
|
|
110
|
+
*/
|
|
111
|
+
mainThread: string;
|
|
112
|
+
/**
|
|
113
|
+
* Source executed in the background JavaScript thread.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* When omitted, a sibling `background.ts` is used when it exists. Set this
|
|
117
|
+
* to `false` to explicitly create a main-thread-only bundle.
|
|
118
|
+
*/
|
|
119
|
+
background?: string | false | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* CSS source encoded into the Lynx template.
|
|
122
|
+
*
|
|
123
|
+
* @remarks
|
|
124
|
+
* When omitted, a sibling `style.css` is used when it exists. Set this to
|
|
125
|
+
* `false` to disable the convention.
|
|
126
|
+
*/
|
|
127
|
+
css?: string | false | undefined;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { RuntimeWrapperWebpackPlugin } from "@lynx-js/runtime-wrapper-webpack-plugin";
|
|
4
|
+
import { LynxEncodePlugin, LynxTemplatePlugin, WebEncodePlugin } from "@lynx-js/template-webpack-plugin";
|
|
5
|
+
const PLUGIN_NAME = 'lynx:vanilla';
|
|
6
|
+
const VANILLA_WEBPACK_PLUGIN_NAME = 'VanillaLynxWebpackPlugin';
|
|
7
|
+
const DEFAULT_ENGINE_VERSION = '3.5';
|
|
8
|
+
const DEFAULT_BUNDLE_FILENAME = '[name].[platform].bundle';
|
|
9
|
+
const INTERMEDIATE_DIR = '.rspeedy';
|
|
10
|
+
const LAYERS = Object.freeze({
|
|
11
|
+
BACKGROUND: 'vanilla:background',
|
|
12
|
+
MAIN_THREAD: 'vanilla:main-thread'
|
|
13
|
+
});
|
|
14
|
+
function pluginVanillaLynx(options = {}) {
|
|
15
|
+
return {
|
|
16
|
+
name: PLUGIN_NAME,
|
|
17
|
+
pre: [
|
|
18
|
+
'lynx:rsbuild:plugin-api',
|
|
19
|
+
'lynx:config'
|
|
20
|
+
],
|
|
21
|
+
setup (api) {
|
|
22
|
+
const resolvedOptions = resolvePluginOptions(api, options);
|
|
23
|
+
exposeVanillaCapabilities(api);
|
|
24
|
+
disableVanillaHotUpdates(api);
|
|
25
|
+
setupVanillaBundler(api, resolvedOptions);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function resolvePluginOptions(api, options) {
|
|
30
|
+
const lynxConfig = api.useExposed(Symbol.for('lynx.config'))?.config;
|
|
31
|
+
return {
|
|
32
|
+
bundleFilename: options.bundleFilename,
|
|
33
|
+
engineVersion: options.engineVersion ?? options.targetSdkVersion ?? lynxConfig?.targetSdkVersion ?? DEFAULT_ENGINE_VERSION,
|
|
34
|
+
entries: options.entries
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function exposeVanillaCapabilities(api) {
|
|
38
|
+
api.expose(Symbol.for('LAYERS'), LAYERS);
|
|
39
|
+
api.expose(Symbol.for('LynxTemplatePlugin'), {
|
|
40
|
+
LynxTemplatePlugin: {
|
|
41
|
+
getLynxTemplatePluginHooks: LynxTemplatePlugin.getLynxTemplatePluginHooks.bind(LynxTemplatePlugin)
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function disableVanillaHotUpdates(api) {
|
|
46
|
+
api.modifyRsbuildConfig((config, { mergeRsbuildConfig })=>mergeRsbuildConfig(config, {
|
|
47
|
+
dev: {
|
|
48
|
+
hmr: false,
|
|
49
|
+
liveReload: false
|
|
50
|
+
}
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
function setupVanillaBundler(api, options) {
|
|
54
|
+
api.modifyBundlerChain((chain, { environment })=>{
|
|
55
|
+
const rspeedyFilename = api.useExposed(Symbol.for('rspeedy.api'))?.config?.output?.filename;
|
|
56
|
+
const platform = getVanillaPlatform(environment.name);
|
|
57
|
+
if (!platform) return;
|
|
58
|
+
const entries = resolveVanillaEntries(api, chain.entryPoints.entries() ?? {}, options.entries);
|
|
59
|
+
const entryContext = {
|
|
60
|
+
bundleFilename: options.bundleFilename,
|
|
61
|
+
engineVersion: options.engineVersion,
|
|
62
|
+
platform: environment.name,
|
|
63
|
+
rspeedyFilename
|
|
64
|
+
};
|
|
65
|
+
chain.entryPoints.clear();
|
|
66
|
+
const artifacts = entries.map(([entryName, entry])=>addVanillaEntry(chain, entryName, entry, entryContext));
|
|
67
|
+
addVanillaBundlerPlugins(chain, artifacts, options.engineVersion, platform);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function addVanillaEntry(chain, entryName, entry, context) {
|
|
71
|
+
const { backgroundSource, styleSource } = entry;
|
|
72
|
+
const hasBackground = void 0 !== backgroundSource;
|
|
73
|
+
const backgroundEntry = `${entryName}__background`;
|
|
74
|
+
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');
|
|
77
|
+
if (hasBackground) chain.entry(backgroundEntry).add({
|
|
78
|
+
layer: LAYERS.BACKGROUND,
|
|
79
|
+
import: backgroundSource,
|
|
80
|
+
filename: backgroundAsset
|
|
81
|
+
});
|
|
82
|
+
chain.entry(mainThreadEntry).add({
|
|
83
|
+
layer: LAYERS.MAIN_THREAD,
|
|
84
|
+
import: styleSource ? [
|
|
85
|
+
...entry.mainThreadImports,
|
|
86
|
+
styleSource
|
|
87
|
+
] : entry.mainThreadImports,
|
|
88
|
+
filename: mainThreadAsset
|
|
89
|
+
});
|
|
90
|
+
chain.plugin(`${PLUGIN_NAME}:template:${entryName}`).use(LynxTemplatePlugin, [
|
|
91
|
+
{
|
|
92
|
+
...LynxTemplatePlugin.defaultOptions,
|
|
93
|
+
chunks: hasBackground ? [
|
|
94
|
+
backgroundEntry,
|
|
95
|
+
mainThreadEntry
|
|
96
|
+
] : [
|
|
97
|
+
mainThreadEntry
|
|
98
|
+
],
|
|
99
|
+
dsl: 'react_nodiff',
|
|
100
|
+
filename: resolveBundleFilename(context.rspeedyFilename, context.bundleFilename, entryName, context.platform),
|
|
101
|
+
intermediate: node_path.posix.join(INTERMEDIATE_DIR, entryName),
|
|
102
|
+
targetSdkVersion: context.engineVersion
|
|
103
|
+
}
|
|
104
|
+
]);
|
|
105
|
+
return {
|
|
106
|
+
hasBackground,
|
|
107
|
+
mainThreadAsset
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function addVanillaBundlerPlugins(chain, artifacts, engineVersion, platform) {
|
|
111
|
+
chain.plugin(VANILLA_WEBPACK_PLUGIN_NAME).use(createVanillaWebpackPlugin(artifacts.map((artifact)=>artifact.mainThreadAsset)));
|
|
112
|
+
if ('lynx' === platform && artifacts.some((artifact)=>artifact.hasBackground)) chain.plugin(`${PLUGIN_NAME}:runtime-wrapper`).use(RuntimeWrapperWebpackPlugin, [
|
|
113
|
+
{
|
|
114
|
+
targetSdkVersion: engineVersion,
|
|
115
|
+
test: /^\.rspeedy\/.+\/background\.js$/
|
|
116
|
+
}
|
|
117
|
+
]);
|
|
118
|
+
if ('lynx' === platform) chain.plugin(LynxEncodePlugin.name).use(LynxEncodePlugin, []);
|
|
119
|
+
else chain.plugin(WebEncodePlugin.name).use(WebEncodePlugin, []);
|
|
120
|
+
}
|
|
121
|
+
function resolveVanillaEntries(api, rawEntries, configuredEntries) {
|
|
122
|
+
if (configuredEntries) return Object.entries(configuredEntries).map(([entryName, entry])=>{
|
|
123
|
+
const mainThreadSource = locateLocalSource(api.context.rootPath, entry.mainThread);
|
|
124
|
+
const entryDir = mainThreadSource ? node_path.dirname(mainThreadSource) : void 0;
|
|
125
|
+
return [
|
|
126
|
+
entryName,
|
|
127
|
+
{
|
|
128
|
+
backgroundSource: resolveOptionalSource(entry.background, entryDir ? node_path.join(entryDir, 'background.ts') : void 0),
|
|
129
|
+
mainThreadImports: [
|
|
130
|
+
entry.mainThread
|
|
131
|
+
],
|
|
132
|
+
styleSource: resolveOptionalSource(entry.css, entryDir ? node_path.join(entryDir, 'style.css') : void 0)
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
});
|
|
136
|
+
return Object.entries(rawEntries).map(([entryName, entryPoint])=>{
|
|
137
|
+
const imports = getEntryImports(entryPoint.values());
|
|
138
|
+
const mainThreadRequest = getMainThreadRequest(entryName, imports);
|
|
139
|
+
const mainThreadSource = locateLocalSource(api.context.rootPath, mainThreadRequest);
|
|
140
|
+
const entryDir = mainThreadSource ? node_path.dirname(mainThreadSource) : void 0;
|
|
141
|
+
return [
|
|
142
|
+
entryName,
|
|
143
|
+
{
|
|
144
|
+
backgroundSource: resolveOptionalSource(void 0, entryDir ? node_path.join(entryDir, 'background.ts') : void 0),
|
|
145
|
+
mainThreadImports: imports,
|
|
146
|
+
styleSource: resolveOptionalSource(void 0, entryDir ? node_path.join(entryDir, 'style.css') : void 0)
|
|
147
|
+
}
|
|
148
|
+
];
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function getVanillaPlatform(name) {
|
|
152
|
+
if ('lynx' === name || name.startsWith('lynx-')) return 'lynx';
|
|
153
|
+
if ('web' === name || name.startsWith('web-')) return 'web';
|
|
154
|
+
}
|
|
155
|
+
function getEntryImports(values) {
|
|
156
|
+
const imports = [];
|
|
157
|
+
for (const value of values){
|
|
158
|
+
if ('string' == typeof value) {
|
|
159
|
+
imports.push(value);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(value)) {
|
|
163
|
+
for (const item of value)if ('string' == typeof item) imports.push(item);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if ('object' != typeof value || null === value || !('import' in value)) continue;
|
|
167
|
+
const entryImport = value.import;
|
|
168
|
+
if ('string' == typeof entryImport) imports.push(entryImport);
|
|
169
|
+
else if (Array.isArray(entryImport)) {
|
|
170
|
+
for (const item of entryImport)if ('string' == typeof item) imports.push(item);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return imports;
|
|
174
|
+
}
|
|
175
|
+
function getMainThreadRequest(entryName, imports) {
|
|
176
|
+
const source = imports.find((value)=>/(?:^|\/)main-thread\.[cm]?[jt]sx?(?:\?.*)?$/.test(value.replaceAll('\\', '/'))) ?? (1 === imports.length ? imports[0] : void 0);
|
|
177
|
+
if (!source) throw new Error(`[pluginVanillaLynx] Entry \`${entryName}\` must contain exactly one \`main-thread.ts\` source.`);
|
|
178
|
+
return source;
|
|
179
|
+
}
|
|
180
|
+
function locateLocalSource(rootPath, request) {
|
|
181
|
+
const source = request.split(/[?#]/, 1)[0];
|
|
182
|
+
if (!source) return;
|
|
183
|
+
const candidate = node_path.isAbsolute(source) ? source : node_path.resolve(rootPath, source);
|
|
184
|
+
return isFile(candidate) ? candidate : void 0;
|
|
185
|
+
}
|
|
186
|
+
function isFile(candidate) {
|
|
187
|
+
try {
|
|
188
|
+
return statSync(candidate).isFile();
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function resolveOptionalSource(source, conventionSource) {
|
|
194
|
+
if (false === source) return;
|
|
195
|
+
if (source) return source;
|
|
196
|
+
return conventionSource && isFile(conventionSource) ? conventionSource : void 0;
|
|
197
|
+
}
|
|
198
|
+
function resolveBundleFilename(rspeedyFilename, option, entryName, platform) {
|
|
199
|
+
const configured = option ?? ('object' == typeof rspeedyFilename ? rspeedyFilename.bundle ?? rspeedyFilename.template : rspeedyFilename) ?? DEFAULT_BUNDLE_FILENAME;
|
|
200
|
+
const context = {
|
|
201
|
+
entryName,
|
|
202
|
+
lazyBundle: false,
|
|
203
|
+
platform
|
|
204
|
+
};
|
|
205
|
+
const filename = 'function' == typeof configured ? configured(context) : configured;
|
|
206
|
+
return filename.replaceAll('[name]', entryName).replaceAll('[platform]', platform);
|
|
207
|
+
}
|
|
208
|
+
function createVanillaWebpackPlugin(mainThreadAssets) {
|
|
209
|
+
return {
|
|
210
|
+
apply (compiler) {
|
|
211
|
+
compiler.hooks.thisCompilation.tap(VANILLA_WEBPACK_PLUGIN_NAME, (compilation)=>{
|
|
212
|
+
compilation.hooks.processAssets.tap({
|
|
213
|
+
name: VANILLA_WEBPACK_PLUGIN_NAME,
|
|
214
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
215
|
+
}, ()=>{
|
|
216
|
+
for (const name of mainThreadAssets){
|
|
217
|
+
const asset = compilation.getAsset(name);
|
|
218
|
+
if (!asset) throw new Error(`[pluginVanillaLynx] Main-thread asset was not emitted: ${name}`);
|
|
219
|
+
compilation.updateAsset(asset.name, asset.source, {
|
|
220
|
+
...asset.info,
|
|
221
|
+
'lynx:main-thread': true
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const hooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation);
|
|
226
|
+
hooks.beforeEncode.tap(VANILLA_WEBPACK_PLUGIN_NAME, (args)=>{
|
|
227
|
+
args.encodeData.sourceContent.config['enableEventHandleRefactor'] = true;
|
|
228
|
+
return args;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
export { LAYERS, pluginVanillaLynx };
|
package/package.json
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/vanilla-rsbuild-plugin",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "An Rsbuild plugin for building Vanilla Lynx applications with Element PAPI.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rsbuild",
|
|
7
|
+
"Lynx",
|
|
8
|
+
"Vanilla Lynx",
|
|
9
|
+
"Element PAPI"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/lynx-family/lynx-stack.git",
|
|
14
|
+
"directory": "packages/rspeedy/plugin-vanilla"
|
|
15
|
+
},
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "Lynx Authors"
|
|
19
|
+
},
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"CHANGELOG.md",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@lynx-js/runtime-wrapper-webpack-plugin": "0.2.3",
|
|
36
|
+
"@lynx-js/template-webpack-plugin": "0.15.1"
|
|
8
37
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@rsbuild/core": "2.1.10",
|
|
40
|
+
"@rstest/core": "0.11.6",
|
|
41
|
+
"@lynx-js/rspeedy": "0.16.4",
|
|
42
|
+
"@lynx-js/test-tools": "0.0.0"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "rslib build",
|
|
52
|
+
"test": "rstest",
|
|
53
|
+
"test:type": "tsc6 --noEmit"
|
|
54
|
+
}
|
|
55
|
+
}
|