@astralsight/astroforge-rsbuild-plugin 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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.d.mts +229 -0
- package/dist/index.mjs +1538 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AstroForge contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @astralsight/astroforge-rsbuild-plugin
|
|
2
|
+
|
|
3
|
+
AstroForge 的 [Rsbuild](https://rsbuild.dev/) 插件:在 TSX 源码与厂商 quick-app runtime(小米 Vela / vivo BlueOS 等)之间生成跨进程 IR 契约(`docs/ir-document.schema.json`)。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @astralsight/astroforge-rsbuild-plugin @rsbuild/core
|
|
9
|
+
pnpm add @astralsight/astroforge-core
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 使用
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
// rsbuild.config.ts
|
|
16
|
+
import { defineConfig } from "@rsbuild/core";
|
|
17
|
+
import { pluginAstroForge } from "@astralsight/astroforge-rsbuild-plugin";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [pluginAstroForge({ target: "vela" })],
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
插件会在 `onBeforeBuild` / `onBeforeDevCompile` 阶段:
|
|
25
|
+
|
|
26
|
+
1. 扫描 `src/pages/**` 发现页面入口;
|
|
27
|
+
2. 解析 TSX,把节点 / 属性 / 事件 / 列表 / 条件 / 生命周期 / `useState` / `useEffect` 等下沉到 IR;
|
|
28
|
+
3. BFS 加载相对路径 import 的子组件;
|
|
29
|
+
4. 收集图片 / 字体等静态资源;
|
|
30
|
+
5. 在 `node_modules/.cache/astroforge/ir-document.json` 写出统一 IR,供下游 `astroforge` Rust CLI 消费。
|
|
31
|
+
|
|
32
|
+
## 配置
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
pluginAstroForge({
|
|
36
|
+
target: "vela", // 仅支持 "vela"
|
|
37
|
+
cacheDir: "node_modules/.cache/astroforge",
|
|
38
|
+
root: undefined, // 默认取 Rsbuild context.rootPath
|
|
39
|
+
configFile: "astroforge.config.ts",
|
|
40
|
+
outFile: undefined, // 显式 IR 输出路径,优先级高于 cacheDir
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { PlatformId } from "@astralsight/astroforge-core/platform";
|
|
2
|
+
import { RsbuildPlugin } from "@rsbuild/core";
|
|
3
|
+
|
|
4
|
+
//#region src/ir.d.ts
|
|
5
|
+
declare const IR_VERSION = 1;
|
|
6
|
+
type JsonValue = null | boolean | number | string | JsonValue[] | {
|
|
7
|
+
[key: string]: JsonValue;
|
|
8
|
+
};
|
|
9
|
+
interface IrDocument {
|
|
10
|
+
ir_version: number;
|
|
11
|
+
manifest: Manifest;
|
|
12
|
+
app: AppModule;
|
|
13
|
+
pages: Record<string, Page>;
|
|
14
|
+
components: Record<string, Component>;
|
|
15
|
+
assets: AssetRef[];
|
|
16
|
+
}
|
|
17
|
+
interface Manifest {
|
|
18
|
+
package: string;
|
|
19
|
+
name: string;
|
|
20
|
+
version_name: string;
|
|
21
|
+
version_code: number;
|
|
22
|
+
min_platform_version: number;
|
|
23
|
+
icon: string;
|
|
24
|
+
simulation_version?: string;
|
|
25
|
+
device_type_list: string[];
|
|
26
|
+
features: Feature[];
|
|
27
|
+
config: AppConfig;
|
|
28
|
+
router: Router;
|
|
29
|
+
source?: Record<string, JsonValue>;
|
|
30
|
+
}
|
|
31
|
+
interface Feature {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
interface AppConfig {
|
|
35
|
+
log_level?: string;
|
|
36
|
+
design_width?: string;
|
|
37
|
+
}
|
|
38
|
+
interface Router {
|
|
39
|
+
entry: string;
|
|
40
|
+
pages: Record<string, RoutePage>;
|
|
41
|
+
}
|
|
42
|
+
interface RoutePage {
|
|
43
|
+
component: string;
|
|
44
|
+
}
|
|
45
|
+
interface AppModule {
|
|
46
|
+
lifecycle: Record<string, string>;
|
|
47
|
+
}
|
|
48
|
+
interface Page {
|
|
49
|
+
route: string;
|
|
50
|
+
imports: Record<string, string>;
|
|
51
|
+
template: Node[];
|
|
52
|
+
script: Script;
|
|
53
|
+
style: StyleTable;
|
|
54
|
+
}
|
|
55
|
+
interface Component {
|
|
56
|
+
name: string;
|
|
57
|
+
template: Node[];
|
|
58
|
+
script: Script;
|
|
59
|
+
style: StyleTable;
|
|
60
|
+
}
|
|
61
|
+
interface Script {
|
|
62
|
+
props: Record<string, Prop>;
|
|
63
|
+
private_data: Record<string, JsonValue>;
|
|
64
|
+
methods: Record<string, string>;
|
|
65
|
+
lifecycle: Record<string, string>;
|
|
66
|
+
}
|
|
67
|
+
interface Prop {
|
|
68
|
+
type: string;
|
|
69
|
+
default?: JsonValue;
|
|
70
|
+
}
|
|
71
|
+
interface StyleTable {
|
|
72
|
+
rules: StyleRule[];
|
|
73
|
+
}
|
|
74
|
+
interface StyleRule {
|
|
75
|
+
selectors: Selector[];
|
|
76
|
+
declarations: Record<string, string>;
|
|
77
|
+
}
|
|
78
|
+
interface Selector {
|
|
79
|
+
kind: SelectorKind;
|
|
80
|
+
name: string;
|
|
81
|
+
}
|
|
82
|
+
type SelectorKind = "class" | "id" | "tag" | "keyframes" | "font_face";
|
|
83
|
+
interface AssetRef {
|
|
84
|
+
path: string;
|
|
85
|
+
source_path: string;
|
|
86
|
+
digest: string;
|
|
87
|
+
}
|
|
88
|
+
type Node = {
|
|
89
|
+
kind: "element";
|
|
90
|
+
value: Element;
|
|
91
|
+
} | {
|
|
92
|
+
kind: "text";
|
|
93
|
+
value: string;
|
|
94
|
+
} | {
|
|
95
|
+
kind: "expression";
|
|
96
|
+
value: Binding;
|
|
97
|
+
} | {
|
|
98
|
+
kind: "conditional";
|
|
99
|
+
value: Conditional;
|
|
100
|
+
} | {
|
|
101
|
+
kind: "list";
|
|
102
|
+
value: List;
|
|
103
|
+
} | {
|
|
104
|
+
kind: "fragment";
|
|
105
|
+
value: Node[];
|
|
106
|
+
};
|
|
107
|
+
interface Element {
|
|
108
|
+
tag: string;
|
|
109
|
+
is_component: boolean;
|
|
110
|
+
attrs: Record<string, Attr>;
|
|
111
|
+
events: Record<string, Binding>;
|
|
112
|
+
children: Node[];
|
|
113
|
+
}
|
|
114
|
+
type Attr = {
|
|
115
|
+
kind: "static";
|
|
116
|
+
value: JsonValue;
|
|
117
|
+
} | {
|
|
118
|
+
kind: "dynamic";
|
|
119
|
+
value: Binding;
|
|
120
|
+
} | {
|
|
121
|
+
kind: "style_object";
|
|
122
|
+
value: StyleSlot[];
|
|
123
|
+
};
|
|
124
|
+
interface StyleSlot {
|
|
125
|
+
name: string;
|
|
126
|
+
value: StyleSlotValue;
|
|
127
|
+
}
|
|
128
|
+
type StyleSlotValue = {
|
|
129
|
+
kind: "static";
|
|
130
|
+
value: JsonValue;
|
|
131
|
+
} | {
|
|
132
|
+
kind: "dynamic";
|
|
133
|
+
value: Binding;
|
|
134
|
+
};
|
|
135
|
+
interface Binding {
|
|
136
|
+
path: string;
|
|
137
|
+
is_callable: boolean;
|
|
138
|
+
}
|
|
139
|
+
interface Conditional {
|
|
140
|
+
branches: ConditionalBranch[];
|
|
141
|
+
}
|
|
142
|
+
interface ConditionalBranch {
|
|
143
|
+
guard: Binding | null;
|
|
144
|
+
body: Node[];
|
|
145
|
+
}
|
|
146
|
+
interface List {
|
|
147
|
+
source: Binding;
|
|
148
|
+
item_var: string;
|
|
149
|
+
index_var?: string;
|
|
150
|
+
key?: Binding;
|
|
151
|
+
body: Node[];
|
|
152
|
+
}
|
|
153
|
+
declare function createEmptyScript(): Script;
|
|
154
|
+
declare function createEmptyStyleTable(): StyleTable;
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/config.d.ts
|
|
157
|
+
interface AstroForgeManifestInput {
|
|
158
|
+
package: string;
|
|
159
|
+
name: string;
|
|
160
|
+
versionName: string;
|
|
161
|
+
versionCode: number;
|
|
162
|
+
minPlatformVersion: number;
|
|
163
|
+
icon: string;
|
|
164
|
+
simulationVersion?: string;
|
|
165
|
+
deviceTypeList: string[];
|
|
166
|
+
features?: Array<{
|
|
167
|
+
name: string;
|
|
168
|
+
}>;
|
|
169
|
+
config?: {
|
|
170
|
+
logLevel?: string;
|
|
171
|
+
designWidth?: string;
|
|
172
|
+
};
|
|
173
|
+
[extra: string]: JsonValue | undefined;
|
|
174
|
+
}
|
|
175
|
+
interface AstroForgeProjectConfig {
|
|
176
|
+
manifest: AstroForgeManifestInput;
|
|
177
|
+
plugin?: AstroForgePluginConfig;
|
|
178
|
+
}
|
|
179
|
+
interface AstroForgePluginConfig {
|
|
180
|
+
target?: PlatformId;
|
|
181
|
+
cacheDir?: string;
|
|
182
|
+
}
|
|
183
|
+
declare function readAstroForgeConfig(root: string, configFile?: string): AstroForgeProjectConfig;
|
|
184
|
+
declare function parseAstroForgeConfig(source: string, filename?: string): JsonValue & AstroForgeProjectConfig;
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/project.d.ts
|
|
187
|
+
interface CompileProjectOptions {
|
|
188
|
+
root: string;
|
|
189
|
+
configFile?: string;
|
|
190
|
+
cacheDir?: string;
|
|
191
|
+
outFile?: string;
|
|
192
|
+
config?: AstroForgeProjectConfig;
|
|
193
|
+
}
|
|
194
|
+
interface CompileProjectResult {
|
|
195
|
+
document: IrDocument;
|
|
196
|
+
outFile?: string;
|
|
197
|
+
pages: PageModule[];
|
|
198
|
+
}
|
|
199
|
+
interface PageModule {
|
|
200
|
+
route: string;
|
|
201
|
+
component: string;
|
|
202
|
+
file: string;
|
|
203
|
+
}
|
|
204
|
+
declare function compileAstroForgeProject(options: CompileProjectOptions): CompileProjectResult;
|
|
205
|
+
declare function discoverPages(root: string): PageModule[];
|
|
206
|
+
declare function createRsbuildEntries(root: string): Record<string, string>;
|
|
207
|
+
declare function defaultIrOutFile(root: string, cacheDir?: string): string;
|
|
208
|
+
//#endregion
|
|
209
|
+
//#region src/tsx.d.ts
|
|
210
|
+
interface ExtractPageOptions {
|
|
211
|
+
route: string;
|
|
212
|
+
filename?: string;
|
|
213
|
+
loadStyle?: StyleImportLoader;
|
|
214
|
+
}
|
|
215
|
+
declare function extractPageFromTsx(source: string, options: ExtractPageOptions): Page;
|
|
216
|
+
type StyleImportLoader = (specifier: string, importer?: string) => string | undefined;
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/index.d.ts
|
|
219
|
+
interface AstroForgePluginOptions {
|
|
220
|
+
target?: PlatformId;
|
|
221
|
+
cacheDir?: string;
|
|
222
|
+
root?: string;
|
|
223
|
+
configFile?: string;
|
|
224
|
+
manifest?: AstroForgeManifestInput;
|
|
225
|
+
outFile?: string;
|
|
226
|
+
}
|
|
227
|
+
declare function pluginAstroForge(options?: AstroForgePluginOptions): RsbuildPlugin;
|
|
228
|
+
//#endregion
|
|
229
|
+
export { type AppConfig, type AppModule, type AssetRef, type AstroForgeManifestInput, type AstroForgePluginConfig, AstroForgePluginOptions, type AstroForgeProjectConfig, type Attr, type Binding, type CompileProjectOptions, type CompileProjectResult, type Component, type Conditional, type ConditionalBranch, type Element, type Feature, type IR_VERSION, type IrDocument, type JsonValue, type List, type Manifest, type Node, type Page, type PageModule, type Prop, type RoutePage, type Router, type Script, type Selector, type SelectorKind, type StyleRule, type StyleSlot, type StyleSlotValue, type StyleTable, compileAstroForgeProject, type createEmptyScript, type createEmptyStyleTable, createRsbuildEntries, defaultIrOutFile, discoverPages, extractPageFromTsx, parseAstroForgeConfig, pluginAstroForge, readAstroForgeConfig };
|