embedded-react 0.20.0 → 0.22.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/NOTICE +5 -0
- package/README.md +3 -2
- package/aot/app-file-loader.mjs +116 -0
- package/aot/compile.mjs +17 -47
- package/aot/compiler/alerts.mjs +604 -0
- package/aot/compiler/animations.mjs +299 -57
- package/aot/compiler/boot.mjs +27 -2
- package/aot/compiler/check.mjs +62 -10
- package/aot/compiler/collect.mjs +517 -137
- package/aot/compiler/contexts.mjs +391 -0
- package/aot/compiler/control-flow.mjs +276 -117
- package/aot/compiler/custom-hooks.mjs +686 -0
- package/aot/compiler/elements/button.mjs +182 -0
- package/aot/compiler/elements/image-background.mjs +76 -0
- package/aot/compiler/elements/image.mjs +2 -1
- package/aot/compiler/elements/props.mjs +47 -8
- package/aot/compiler/elements/rewrite.mjs +118 -0
- package/aot/compiler/elements/section-list.mjs +370 -0
- package/aot/compiler/expressions.mjs +1378 -97
- package/aot/compiler/handlers.mjs +1807 -354
- package/aot/compiler/helper-values.mjs +312 -0
- package/aot/compiler/ir/nodes.mjs +40 -1
- package/aot/compiler/ir/reads.mjs +206 -5
- package/aot/compiler/ir/text.mjs +5 -1
- package/aot/compiler/ir/types.mjs +12 -0
- package/aot/compiler/kept-states.mjs +177 -0
- package/aot/compiler/keyboard-dismiss.mjs +99 -0
- package/aot/compiler/keyboard.mjs +1 -1
- package/aot/compiler/list-items.mjs +226 -0
- package/aot/compiler/list-order.mjs +586 -0
- package/aot/compiler/list-split.mjs +259 -0
- package/aot/compiler/loops.mjs +582 -0
- package/aot/compiler/lower.mjs +203 -53
- package/aot/compiler/native-files.mjs +439 -0
- package/aot/compiler/native-header.mjs +335 -0
- package/aot/compiler/native-modules.mjs +1173 -0
- package/aot/compiler/nodes.mjs +45 -31
- package/aot/compiler/options.mjs +3 -2
- package/aot/compiler/out.mjs +18 -1
- package/aot/compiler/package/animations.mjs +133 -23
- package/aot/compiler/package/assemble.mjs +2 -4
- package/aot/compiler/package/bytecode.mjs +37 -8
- package/aot/compiler/package/checks.mjs +4 -0
- package/aot/compiler/package/codegen.mjs +906 -33
- package/aot/compiler/package/enums.mjs +10 -0
- package/aot/compiler/package/format.mjs +16 -3
- package/aot/compiler/package/lower.mjs +707 -176
- package/aot/compiler/package/string-caps.mjs +515 -0
- package/aot/compiler/package/tables.mjs +24 -0
- package/aot/compiler/package/writer.mjs +22 -0
- package/aot/compiler/parse.mjs +3 -1
- package/aot/compiler/record-shapes.mjs +246 -0
- package/aot/compiler/records.mjs +654 -0
- package/aot/compiler/reducers.mjs +272 -0
- package/aot/compiler/scroll-to.mjs +112 -0
- package/aot/compiler/static-eval.mjs +315 -7
- package/aot/compiler/style-text.mjs +20 -5
- package/aot/compiler/svg.mjs +13 -7
- package/aot/compiler/switch-cases.mjs +198 -0
- package/aot/compiler/tagged-records.mjs +450 -0
- package/aot/compiler/typing.mjs +307 -0
- package/aot/compiler/updaters.mjs +321 -0
- package/aot/compiler/window-dimensions.mjs +94 -0
- package/aot/compiler/worked-values.mjs +319 -0
- package/aot/demo-file.mjs +30 -0
- package/aot/style-map.mjs +94 -3
- package/assets/bake-font.mjs +187 -244
- package/assets/bake-image.mjs +47 -71
- package/assets/bake-svg.mjs +465 -533
- package/assets/build-builtin-font.mjs +14 -27
- package/assets/emit-c.mjs +124 -204
- package/assets/emit-container.mjs +129 -197
- package/assets/emit-pack.mjs +92 -136
- package/assets/font-config.mjs +19 -27
- package/assets/font-sizes.mjs +432 -507
- package/assets/glyph-coverage.mjs +170 -214
- package/assets/index.mjs +52 -97
- package/assets/rasterize.mjs +173 -194
- package/assets/svg-loader.mjs +42 -48
- package/build.mjs +85 -94
- package/cli.mjs +490 -586
- package/compile-bin.mjs +24 -36
- package/flash.mjs +297 -401
- package/hotreload/dev-device.mjs +229 -270
- package/hotreload/pack-app.mjs +118 -159
- package/hotreload/pack-split.mjs +146 -213
- package/hotreload/package-transfer.mjs +128 -131
- package/hotreload/protocol.mjs +118 -118
- package/hotreload/uploader.mjs +132 -159
- package/hotreload/watch-tree.mjs +56 -65
- package/pack-container.mjs +94 -116
- package/package.json +19 -16
- package/persist-transform.mjs +89 -105
- package/qjsc-wasm.mjs +47 -72
- package/sim/embedded-react.wasm +0 -0
- package/sim/index.html +1 -1
- package/sim-server.mjs +260 -354
- package/src/embedded-react/Alert.mjs +112 -0
- package/src/embedded-react/Animated.mjs +412 -0
- package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
- package/src/embedded-react/{Button.js → Button.mjs} +29 -53
- package/src/embedded-react/Dimensions.mjs +32 -0
- package/src/embedded-react/Easing.mjs +34 -0
- package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
- package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
- package/src/embedded-react/Keyboard.mjs +82 -0
- package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
- package/src/embedded-react/PanResponder.mjs +256 -0
- package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
- package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
- package/src/embedded-react/SectionList.mjs +103 -0
- package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
- package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
- package/src/embedded-react/background-image.mjs +321 -0
- package/src/embedded-react/{components.js → components.mjs} +1 -3
- package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
- package/src/embedded-react/index.d.ts +238 -5
- package/src/embedded-react/index.js +26 -17
- package/src/embedded-react/layout-anim-config.mjs +85 -0
- package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
- package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
- package/src/embedded-react/nativeModule.mjs +371 -0
- package/src/embedded-react/split-style.mjs +57 -0
- package/src/embedded-react/svg-ops.mjs +1075 -0
- package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
- package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
- package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
- package/src/host-config.mjs +512 -0
- package/src/{native-ui.js → native-ui.mjs} +1 -8
- package/src/props.mjs +341 -0
- package/src/{renderer.js → renderer.mjs} +30 -44
- package/src/embedded-react/Animated.js +0 -440
- package/src/embedded-react/Easing.js +0 -39
- package/src/embedded-react/PanResponder.js +0 -330
- package/src/embedded-react/SectionList.js +0 -148
- package/src/embedded-react/layout-anim-config.js +0 -101
- package/src/embedded-react/split-style.js +0 -58
- package/src/embedded-react/svg-ops.js +0 -1295
- package/src/host-config.js +0 -548
- package/src/props.js +0 -306
package/hotreload/pack-split.mjs
CHANGED
|
@@ -13,10 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
|
|
17
16
|
// pack-split — build the vendor/app SPLIT of a Flow A app, for incremental hot reload.
|
|
18
17
|
//
|
|
19
|
-
// The monolithic packer (pack-app.
|
|
18
|
+
// The monolithic packer (pack-app.mts) inlines react + react-reconciler + the embedded-react library
|
|
20
19
|
// together with the user's source into one ~1 MB bytecode blob. But the framework half never changes
|
|
21
20
|
// when you edit your app, so re-shipping and re-parsing it on every save is pure waste. pack-split cuts
|
|
22
21
|
// the bundle along the one seam that matters:
|
|
@@ -32,45 +31,40 @@
|
|
|
32
31
|
// then the app. A hot-reload frame carries only the app chunk — the device keeps the resident vendor and
|
|
33
32
|
// swaps just the app (a "soft reset"). Old monolithic containers still boot unchanged (emit-container's
|
|
34
33
|
// vendor section is optional), so this is backwards-compatible, and production behavior is identical.
|
|
35
|
-
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {existsSync, readFileSync, statSync} from 'node:fs';
|
|
40
|
-
|
|
34
|
+
import { createRequire } from 'node:module';
|
|
35
|
+
import { pathToFileURL } from 'node:url';
|
|
36
|
+
import { basename, dirname, resolve, relative } from 'node:path';
|
|
37
|
+
import { existsSync, statSync } from 'node:fs';
|
|
41
38
|
const require = createRequire(import.meta.url);
|
|
42
|
-
|
|
43
|
-
// QuickJS release the bytecode container targets — MUST match cli.
|
|
39
|
+
const loadEsbuild = () => require('esbuild');
|
|
40
|
+
// QuickJS release the bytecode container targets — MUST match cli.mts's QJS_TAG, pack-app.mts, and the
|
|
44
41
|
// device loader.
|
|
45
42
|
const QJS_TAG = 'v0.15.0';
|
|
46
|
-
|
|
47
43
|
// The shared deps the app chunk resolve through the vendor registry instead of inlining.
|
|
48
44
|
export const VENDOR_EXTERNALS = [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
45
|
+
'react',
|
|
46
|
+
'react/jsx-runtime',
|
|
47
|
+
'embedded-react',
|
|
52
48
|
];
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
write: false,
|
|
49
|
+
const esbuildCommon = (nodePaths) => ({
|
|
50
|
+
bundle: true,
|
|
51
|
+
format: 'iife',
|
|
52
|
+
platform: 'neutral',
|
|
53
|
+
target: 'es2020',
|
|
54
|
+
jsx: 'automatic',
|
|
55
|
+
nodePaths,
|
|
56
|
+
define: { 'process.env.NODE_ENV': '"production"' },
|
|
57
|
+
legalComments: 'none',
|
|
58
|
+
logLevel: 'silent',
|
|
59
|
+
write: false,
|
|
65
60
|
});
|
|
66
|
-
|
|
67
61
|
/**
|
|
68
62
|
* The vendor chunk's synthetic entry source: import the shared deps, register them in a runtime module
|
|
69
63
|
* registry, and install the `require()` shim the app chunk resolves through. esbuild's `__require` helper
|
|
70
64
|
* (emitted for the app chunk's external imports) finds this global `require` at runtime.
|
|
71
65
|
*/
|
|
72
66
|
function vendorEntrySource() {
|
|
73
|
-
|
|
67
|
+
return `import * as React from 'react';
|
|
74
68
|
import * as JsxRuntime from 'react/jsx-runtime';
|
|
75
69
|
import * as EmbeddedReact from 'embedded-react';
|
|
76
70
|
const reg = (globalThis.__er_modules = globalThis.__er_modules || {});
|
|
@@ -84,228 +78,167 @@ globalThis.require = function (id) {
|
|
|
84
78
|
};
|
|
85
79
|
`;
|
|
86
80
|
}
|
|
87
|
-
|
|
88
81
|
/**
|
|
89
82
|
* Bundle the vendor chunk (react + reconciler + embedded-react lib) to a self-contained IIFE source.
|
|
90
83
|
*
|
|
91
|
-
* @
|
|
92
|
-
* @param {string} options.libSrc embedded-react library entry (aliased as 'embedded-react').
|
|
93
|
-
* @param {string[]} options.nodePaths esbuild nodePaths (package + project node_modules).
|
|
94
|
-
* @returns {Promise<string>} The bundled JS source.
|
|
84
|
+
* @returns The bundled JS source.
|
|
95
85
|
*/
|
|
96
|
-
export async function bundleVendorSource({libSrc, nodePaths}) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
86
|
+
export async function bundleVendorSource({ libSrc, nodePaths, }) {
|
|
87
|
+
const esbuild = loadEsbuild();
|
|
88
|
+
const result = await esbuild.build({
|
|
89
|
+
...esbuildCommon(nodePaths),
|
|
90
|
+
stdin: {
|
|
91
|
+
contents: vendorEntrySource(),
|
|
92
|
+
resolveDir: dirname(libSrc),
|
|
93
|
+
sourcefile: 'vendor-entry.js',
|
|
94
|
+
loader: 'js',
|
|
95
|
+
},
|
|
96
|
+
alias: { 'embedded-react': libSrc },
|
|
97
|
+
});
|
|
98
|
+
return result.outputFiles[0].text;
|
|
109
99
|
}
|
|
110
|
-
|
|
111
100
|
/**
|
|
112
101
|
* Build an asset-discovering esbuild plugin shared with the monolithic packer's behavior: image/font/svg
|
|
113
|
-
* imports become bare string names (the bytes live in the ERPK pack)
|
|
114
|
-
*
|
|
102
|
+
* imports become bare string names (the bytes live in the ERPK pack). The app's own source gives its native modules
|
|
103
|
+
* their signatures and, when persist is on, gets the useState→persist transform so state survives a live reload.
|
|
115
104
|
*/
|
|
116
|
-
function makeAssetPlugin({images, fonts,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
fonts.set(family, args.path);
|
|
158
|
-
return {
|
|
159
|
-
contents: `module.exports = ${JSON.stringify(family)};`,
|
|
160
|
-
loader: 'js',
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
registerSvgVectorLoader(build, (name, pngPath) =>
|
|
164
|
-
images.set(name, pngPath),
|
|
165
|
-
);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
105
|
+
function makeAssetPlugin({ images, fonts, persist, projectRoot, }) {
|
|
106
|
+
const assetName = (filePath) => basename(filePath).replace(/\.[^.]+$/, '');
|
|
107
|
+
return {
|
|
108
|
+
name: 'embedded-react-assets',
|
|
109
|
+
async setup(build) {
|
|
110
|
+
const { registerSvgVectorLoader } = await import('../assets/svg-loader.mjs');
|
|
111
|
+
const { shouldPersist, transformPersist } = await import('../persist-transform.mjs');
|
|
112
|
+
const { loadAppFile, loadDependencyFile } = await import('../aot/app-file-loader.mjs');
|
|
113
|
+
const normalizedProjectRoot = projectRoot.replace(/\\/g, '/');
|
|
114
|
+
build.onLoad({ filter: /\.(jsx?|tsx?)$/ }, async (args) => {
|
|
115
|
+
if (!shouldPersist(args.path, normalizedProjectRoot)) {
|
|
116
|
+
return loadDependencyFile(args.path);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
return await loadAppFile(args.path, persist
|
|
120
|
+
? (source) => transformPersist(source, relative(projectRoot, args.path).replace(/\\/g, '/'))
|
|
121
|
+
: undefined);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
return { errors: [{ text: `persist transform: ${error.message}` }] };
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
build.onLoad({ filter: /\.(png|jpe?g|webp|gif|bmp)$/i }, args => {
|
|
128
|
+
const name = assetName(args.path);
|
|
129
|
+
images.set(name, args.path);
|
|
130
|
+
return {
|
|
131
|
+
contents: `module.exports = ${JSON.stringify(name)};`,
|
|
132
|
+
loader: 'js',
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
build.onLoad({ filter: /\.(ttf|otf)$/i }, args => {
|
|
136
|
+
const family = assetName(args.path);
|
|
137
|
+
fonts.set(family, args.path);
|
|
138
|
+
return {
|
|
139
|
+
contents: `module.exports = ${JSON.stringify(family)};`,
|
|
140
|
+
loader: 'js',
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
registerSvgVectorLoader(build, (name, pngPath) => images.set(name, pngPath));
|
|
144
|
+
},
|
|
145
|
+
};
|
|
168
146
|
}
|
|
169
|
-
|
|
170
147
|
/**
|
|
171
148
|
* Bundle the app chunk: the user's entry with the shared deps marked external (resolved at runtime through
|
|
172
149
|
* the vendor registry). Returns the bundled source plus the discovered image/font maps for baking.
|
|
173
150
|
*/
|
|
174
|
-
export async function bundleAppSource({
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (persist) {
|
|
186
|
-
const {transformPersist, shouldPersist} =
|
|
187
|
-
await import('../persist-transform.mjs');
|
|
188
|
-
persistHooks = {
|
|
189
|
-
transformPersist,
|
|
190
|
-
shouldPersist,
|
|
191
|
-
normalizedProjectRoot: projectRoot.replace(/\\/g, '/'),
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const result = await esbuild.build({
|
|
196
|
-
...esbuildCommon(nodePaths),
|
|
197
|
-
entryPoints: [entry],
|
|
198
|
-
external: VENDOR_EXTERNALS,
|
|
199
|
-
plugins: [makeAssetPlugin({images, fonts, persistHooks, projectRoot})],
|
|
200
|
-
});
|
|
201
|
-
return {source: result.outputFiles[0].text, images, fonts};
|
|
151
|
+
export async function bundleAppSource({ entry, projectRoot, nodePaths, persist = false, }) {
|
|
152
|
+
const esbuild = loadEsbuild();
|
|
153
|
+
const images = new Map();
|
|
154
|
+
const fonts = new Map();
|
|
155
|
+
const result = await esbuild.build({
|
|
156
|
+
...esbuildCommon(nodePaths),
|
|
157
|
+
entryPoints: [entry],
|
|
158
|
+
external: VENDOR_EXTERNALS,
|
|
159
|
+
plugins: [makeAssetPlugin({ images, fonts, persist, projectRoot })],
|
|
160
|
+
});
|
|
161
|
+
return { source: result.outputFiles[0].text, images, fonts };
|
|
202
162
|
}
|
|
203
|
-
|
|
204
163
|
/** Bake the discovered images/fonts into an ERPK asset pack (or null if there are none). */
|
|
205
|
-
async function bakeAssets({images, fonts, source, projectRoot}) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
await import('../assets/
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
config
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}));
|
|
234
|
-
const bakedImages = imageJobs.map(bakeImage);
|
|
235
|
-
const bakedFonts = fontJobs.map(bakeFont);
|
|
236
|
-
warnMissingGlyphs({source, fonts: bakedFonts});
|
|
237
|
-
warnFontSizes({used: usedSizes, fonts: bakedFonts});
|
|
238
|
-
return bakedImages.length || bakedFonts.length
|
|
239
|
-
? emitAssetPack({images: bakedImages, fonts: bakedFonts})
|
|
240
|
-
: null;
|
|
164
|
+
async function bakeAssets({ images, fonts, source, projectRoot, }) {
|
|
165
|
+
const { bakeImage } = await import('../assets/bake-image.mjs');
|
|
166
|
+
const { bakeFont } = await import('../assets/bake-font.mjs');
|
|
167
|
+
const { resolveFontJobs } = await import('../assets/font-config.mjs');
|
|
168
|
+
const { analyzeFontSizes, warnFontSizes } = await import('../assets/font-sizes.mjs');
|
|
169
|
+
const { warnMissingGlyphs } = await import('../assets/glyph-coverage.mjs');
|
|
170
|
+
const { emitAssetPack } = await import('../assets/emit-pack.mjs');
|
|
171
|
+
const usedSizes = analyzeFontSizes(source);
|
|
172
|
+
let config = {};
|
|
173
|
+
const configPath = resolve(projectRoot, 'assets.config.js');
|
|
174
|
+
if (existsSync(configPath))
|
|
175
|
+
config =
|
|
176
|
+
(await import(`${pathToFileURL(configPath).href}?t=${statSync(configPath).mtimeMs}`)).default || {};
|
|
177
|
+
const fontConfig = config.fonts || {};
|
|
178
|
+
const imageConfig = config.images || {};
|
|
179
|
+
const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
|
|
180
|
+
const imageJobs = [...images.entries()].map(([name, path]) => ({
|
|
181
|
+
path,
|
|
182
|
+
name,
|
|
183
|
+
format: imageConfig[name]?.format,
|
|
184
|
+
}));
|
|
185
|
+
const bakedImages = imageJobs.map(bakeImage);
|
|
186
|
+
const bakedFonts = fontJobs.map(bakeFont);
|
|
187
|
+
warnMissingGlyphs({ source, fonts: bakedFonts });
|
|
188
|
+
warnFontSizes({ used: usedSizes, fonts: bakedFonts });
|
|
189
|
+
return bakedImages.length || bakedFonts.length
|
|
190
|
+
? emitAssetPack({ images: bakedImages, fonts: bakedFonts })
|
|
191
|
+
: null;
|
|
241
192
|
}
|
|
242
|
-
|
|
243
193
|
/**
|
|
244
194
|
* Compile the vendor chunk to a QuickJS bytecode blob. Built once per dev session (it changes only when a
|
|
245
195
|
* dependency changes), so the per-edit reload never re-ships it.
|
|
246
|
-
*
|
|
247
|
-
* @returns {Promise<{bytecode: Buffer, bytecodeLen: number}>}
|
|
248
196
|
*/
|
|
249
|
-
export async function packVendor({libSrc, nodePaths, simDir, strip = false}) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
197
|
+
export async function packVendor({ libSrc, nodePaths, simDir, strip = false, }) {
|
|
198
|
+
const { compileToBytecode } = await import('../qjsc-wasm.mjs');
|
|
199
|
+
const source = await bundleVendorSource({ libSrc, nodePaths });
|
|
200
|
+
const bytecode = await compileToBytecode(source, simDir, { strip });
|
|
201
|
+
return { bytecode, bytecodeLen: bytecode.length };
|
|
254
202
|
}
|
|
255
|
-
|
|
256
203
|
/**
|
|
257
204
|
* Compile the app chunk to a QuickJS bytecode blob and bake its assets. This is the only thing rebuilt on
|
|
258
205
|
* each save — and the only thing a hot-reload frame carries.
|
|
259
|
-
*
|
|
260
|
-
* @returns {Promise<{bytecode: Buffer, assetPack: Buffer|null, bytecodeLen: number, assetsLen: number}>}
|
|
261
206
|
*/
|
|
262
|
-
export async function packApp({
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const bytecode = await compileToBytecode(source, simDir, {strip});
|
|
279
|
-
const assetPack = await bakeAssets({images, fonts, source, projectRoot});
|
|
280
|
-
return {
|
|
281
|
-
bytecode,
|
|
282
|
-
assetPack,
|
|
283
|
-
bytecodeLen: bytecode.length,
|
|
284
|
-
assetsLen: assetPack ? assetPack.length : 0,
|
|
285
|
-
};
|
|
207
|
+
export async function packApp({ entry, projectRoot, nodePaths, simDir, persist = false, strip = false, }) {
|
|
208
|
+
const { compileToBytecode } = await import('../qjsc-wasm.mjs');
|
|
209
|
+
const { source, images, fonts } = await bundleAppSource({
|
|
210
|
+
entry,
|
|
211
|
+
projectRoot,
|
|
212
|
+
nodePaths,
|
|
213
|
+
persist,
|
|
214
|
+
});
|
|
215
|
+
const bytecode = await compileToBytecode(source, simDir, { strip });
|
|
216
|
+
const assetPack = await bakeAssets({ images, fonts, source, projectRoot });
|
|
217
|
+
return {
|
|
218
|
+
bytecode,
|
|
219
|
+
assetPack,
|
|
220
|
+
bytecodeLen: bytecode.length,
|
|
221
|
+
assetsLen: assetPack ? assetPack.length : 0,
|
|
222
|
+
};
|
|
286
223
|
}
|
|
287
|
-
|
|
288
224
|
/**
|
|
289
225
|
* Assemble the flashed BOOT container: vendor + app + assets in one ERCF. The device runs vendor first
|
|
290
226
|
* (installs the registry + require shim), registers assets, then runs the app. Used by `embedded-react
|
|
291
227
|
* build` so the same firmware/artifact serves both production and hot reload.
|
|
292
228
|
*/
|
|
293
|
-
export function emitBootContainer({vendorBytecode, appBytecode, assetPack}) {
|
|
294
|
-
|
|
229
|
+
export function emitBootContainer({ vendorBytecode, appBytecode, assetPack, }) {
|
|
230
|
+
return emit({ bytecode: appBytecode, vendorBytecode, assetPack });
|
|
295
231
|
}
|
|
296
|
-
|
|
297
232
|
/**
|
|
298
233
|
* Assemble a hot-reload APP frame: the app chunk + its assets, NO vendor. The device keeps the resident
|
|
299
234
|
* vendor and swaps just the app (soft reset). This is the ~64 KB that travels on each save.
|
|
300
235
|
*/
|
|
301
|
-
export function emitAppFrame({appBytecode, assetPack}) {
|
|
302
|
-
|
|
236
|
+
export function emitAppFrame({ appBytecode, assetPack, }) {
|
|
237
|
+
return emit({ bytecode: appBytecode, assetPack });
|
|
303
238
|
}
|
|
304
|
-
|
|
305
239
|
// emitBootContainer/emitAppFrame are async (emit() dynamically imports the emitter) — callers await them.
|
|
306
240
|
async function emit(options) {
|
|
307
|
-
|
|
308
|
-
|
|
241
|
+
const { emitContainer } = await import('../assets/emit-container.mjs');
|
|
242
|
+
return emitContainer({ ...options, qjsTag: QJS_TAG });
|
|
309
243
|
}
|
|
310
|
-
|
|
311
|
-
export {QJS_TAG};
|
|
244
|
+
export { QJS_TAG };
|