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.
Files changed (140) hide show
  1. package/NOTICE +5 -0
  2. package/README.md +3 -2
  3. package/aot/app-file-loader.mjs +116 -0
  4. package/aot/compile.mjs +17 -47
  5. package/aot/compiler/alerts.mjs +604 -0
  6. package/aot/compiler/animations.mjs +299 -57
  7. package/aot/compiler/boot.mjs +27 -2
  8. package/aot/compiler/check.mjs +62 -10
  9. package/aot/compiler/collect.mjs +517 -137
  10. package/aot/compiler/contexts.mjs +391 -0
  11. package/aot/compiler/control-flow.mjs +276 -117
  12. package/aot/compiler/custom-hooks.mjs +686 -0
  13. package/aot/compiler/elements/button.mjs +182 -0
  14. package/aot/compiler/elements/image-background.mjs +76 -0
  15. package/aot/compiler/elements/image.mjs +2 -1
  16. package/aot/compiler/elements/props.mjs +47 -8
  17. package/aot/compiler/elements/rewrite.mjs +118 -0
  18. package/aot/compiler/elements/section-list.mjs +370 -0
  19. package/aot/compiler/expressions.mjs +1378 -97
  20. package/aot/compiler/handlers.mjs +1807 -354
  21. package/aot/compiler/helper-values.mjs +312 -0
  22. package/aot/compiler/ir/nodes.mjs +40 -1
  23. package/aot/compiler/ir/reads.mjs +206 -5
  24. package/aot/compiler/ir/text.mjs +5 -1
  25. package/aot/compiler/ir/types.mjs +12 -0
  26. package/aot/compiler/kept-states.mjs +177 -0
  27. package/aot/compiler/keyboard-dismiss.mjs +99 -0
  28. package/aot/compiler/keyboard.mjs +1 -1
  29. package/aot/compiler/list-items.mjs +226 -0
  30. package/aot/compiler/list-order.mjs +586 -0
  31. package/aot/compiler/list-split.mjs +259 -0
  32. package/aot/compiler/loops.mjs +582 -0
  33. package/aot/compiler/lower.mjs +203 -53
  34. package/aot/compiler/native-files.mjs +439 -0
  35. package/aot/compiler/native-header.mjs +335 -0
  36. package/aot/compiler/native-modules.mjs +1173 -0
  37. package/aot/compiler/nodes.mjs +45 -31
  38. package/aot/compiler/options.mjs +3 -2
  39. package/aot/compiler/out.mjs +18 -1
  40. package/aot/compiler/package/animations.mjs +133 -23
  41. package/aot/compiler/package/assemble.mjs +2 -4
  42. package/aot/compiler/package/bytecode.mjs +37 -8
  43. package/aot/compiler/package/checks.mjs +4 -0
  44. package/aot/compiler/package/codegen.mjs +906 -33
  45. package/aot/compiler/package/enums.mjs +10 -0
  46. package/aot/compiler/package/format.mjs +16 -3
  47. package/aot/compiler/package/lower.mjs +707 -176
  48. package/aot/compiler/package/string-caps.mjs +515 -0
  49. package/aot/compiler/package/tables.mjs +24 -0
  50. package/aot/compiler/package/writer.mjs +22 -0
  51. package/aot/compiler/parse.mjs +3 -1
  52. package/aot/compiler/record-shapes.mjs +246 -0
  53. package/aot/compiler/records.mjs +654 -0
  54. package/aot/compiler/reducers.mjs +272 -0
  55. package/aot/compiler/scroll-to.mjs +112 -0
  56. package/aot/compiler/static-eval.mjs +315 -7
  57. package/aot/compiler/style-text.mjs +20 -5
  58. package/aot/compiler/svg.mjs +13 -7
  59. package/aot/compiler/switch-cases.mjs +198 -0
  60. package/aot/compiler/tagged-records.mjs +450 -0
  61. package/aot/compiler/typing.mjs +307 -0
  62. package/aot/compiler/updaters.mjs +321 -0
  63. package/aot/compiler/window-dimensions.mjs +94 -0
  64. package/aot/compiler/worked-values.mjs +319 -0
  65. package/aot/demo-file.mjs +30 -0
  66. package/aot/style-map.mjs +94 -3
  67. package/assets/bake-font.mjs +187 -244
  68. package/assets/bake-image.mjs +47 -71
  69. package/assets/bake-svg.mjs +465 -533
  70. package/assets/build-builtin-font.mjs +14 -27
  71. package/assets/emit-c.mjs +124 -204
  72. package/assets/emit-container.mjs +129 -197
  73. package/assets/emit-pack.mjs +92 -136
  74. package/assets/font-config.mjs +19 -27
  75. package/assets/font-sizes.mjs +432 -507
  76. package/assets/glyph-coverage.mjs +170 -214
  77. package/assets/index.mjs +52 -97
  78. package/assets/rasterize.mjs +173 -194
  79. package/assets/svg-loader.mjs +42 -48
  80. package/build.mjs +85 -94
  81. package/cli.mjs +490 -586
  82. package/compile-bin.mjs +24 -36
  83. package/flash.mjs +297 -401
  84. package/hotreload/dev-device.mjs +229 -270
  85. package/hotreload/pack-app.mjs +118 -159
  86. package/hotreload/pack-split.mjs +146 -213
  87. package/hotreload/package-transfer.mjs +128 -131
  88. package/hotreload/protocol.mjs +118 -118
  89. package/hotreload/uploader.mjs +132 -159
  90. package/hotreload/watch-tree.mjs +56 -65
  91. package/pack-container.mjs +94 -116
  92. package/package.json +19 -16
  93. package/persist-transform.mjs +89 -105
  94. package/qjsc-wasm.mjs +47 -72
  95. package/sim/embedded-react.wasm +0 -0
  96. package/sim/index.html +1 -1
  97. package/sim-server.mjs +260 -354
  98. package/src/embedded-react/Alert.mjs +112 -0
  99. package/src/embedded-react/Animated.mjs +412 -0
  100. package/src/embedded-react/{AppRegistry.js → AppRegistry.mjs} +26 -25
  101. package/src/embedded-react/{Button.js → Button.mjs} +29 -53
  102. package/src/embedded-react/Dimensions.mjs +32 -0
  103. package/src/embedded-react/Easing.mjs +34 -0
  104. package/src/embedded-react/{FlatList.js → FlatList.mjs} +25 -42
  105. package/src/embedded-react/{ImageBackground.js → ImageBackground.mjs} +11 -22
  106. package/src/embedded-react/Keyboard.mjs +82 -0
  107. package/src/embedded-react/{LayoutAnimation.js → LayoutAnimation.mjs} +17 -28
  108. package/src/embedded-react/PanResponder.mjs +256 -0
  109. package/src/embedded-react/{Platform.js → Platform.mjs} +8 -9
  110. package/src/embedded-react/{Pressable.js → Pressable.mjs} +12 -25
  111. package/src/embedded-react/SectionList.mjs +103 -0
  112. package/src/embedded-react/{StyleSheet.js → StyleSheet.mjs} +16 -20
  113. package/src/embedded-react/{TouchableOpacity.js → TouchableOpacity.mjs} +47 -83
  114. package/src/embedded-react/background-image.mjs +321 -0
  115. package/src/embedded-react/{components.js → components.mjs} +1 -3
  116. package/src/embedded-react/{imperative.js → imperative.mjs} +27 -38
  117. package/src/embedded-react/index.d.ts +238 -5
  118. package/src/embedded-react/index.js +26 -17
  119. package/src/embedded-react/layout-anim-config.mjs +85 -0
  120. package/src/embedded-react/{list-child.js → list-child.mjs} +11 -20
  121. package/src/embedded-react/{named-colors.js → named-colors.mjs} +2 -6
  122. package/src/embedded-react/nativeModule.mjs +371 -0
  123. package/src/embedded-react/split-style.mjs +57 -0
  124. package/src/embedded-react/svg-ops.mjs +1075 -0
  125. package/src/embedded-react/{useHostValue.js → useHostValue.mjs} +2 -4
  126. package/src/embedded-react/{usePersistentState.js → usePersistentState.mjs} +34 -38
  127. package/src/embedded-react/{warn-props.js → warn-props.mjs} +32 -39
  128. package/src/host-config.mjs +512 -0
  129. package/src/{native-ui.js → native-ui.mjs} +1 -8
  130. package/src/props.mjs +341 -0
  131. package/src/{renderer.js → renderer.mjs} +30 -44
  132. package/src/embedded-react/Animated.js +0 -440
  133. package/src/embedded-react/Easing.js +0 -39
  134. package/src/embedded-react/PanResponder.js +0 -330
  135. package/src/embedded-react/SectionList.js +0 -148
  136. package/src/embedded-react/layout-anim-config.js +0 -101
  137. package/src/embedded-react/split-style.js +0 -58
  138. package/src/embedded-react/svg-ops.js +0 -1295
  139. package/src/host-config.js +0 -548
  140. package/src/props.js +0 -306
@@ -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.mjs) inlines react + react-reconciler + the embedded-react library
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 {createRequire} from 'node:module';
37
- import {pathToFileURL} from 'node:url';
38
- import {basename, dirname, resolve, relative} from 'node:path';
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.mjs's QJS_TAG, pack-app.mjs, and the
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
- 'react',
50
- 'react/jsx-runtime',
51
- 'embedded-react',
45
+ 'react',
46
+ 'react/jsx-runtime',
47
+ 'embedded-react',
52
48
  ];
53
-
54
- const esbuildCommon = nodePaths => ({
55
- bundle: true,
56
- format: 'iife',
57
- platform: 'neutral',
58
- target: 'es2020',
59
- jsx: 'automatic',
60
- nodePaths,
61
- define: {'process.env.NODE_ENV': '"production"'},
62
- legalComments: 'none',
63
- logLevel: 'silent',
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
- return `import * as React from 'react';
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
- * @param {object} options
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
- const esbuild = require('esbuild');
98
- const result = await esbuild.build({
99
- ...esbuildCommon(nodePaths),
100
- stdin: {
101
- contents: vendorEntrySource(),
102
- resolveDir: dirname(libSrc),
103
- sourcefile: 'vendor-entry.js',
104
- loader: 'js',
105
- },
106
- alias: {'embedded-react': libSrc},
107
- });
108
- return result.outputFiles[0].text;
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), and — when persist is on — the app's
114
- * own source gets the useState→persist transform so state survives a live reload.
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, persistHooks, projectRoot}) {
117
- const assetName = filePath => basename(filePath).replace(/\.[^.]+$/, '');
118
- return {
119
- name: 'embedded-react-assets',
120
- async setup(build) {
121
- const {registerSvgVectorLoader} =
122
- await import('../assets/svg-loader.mjs');
123
- if (persistHooks) {
124
- build.onLoad({filter: /\.(jsx?|tsx?)$/}, args => {
125
- const {transformPersist, shouldPersist, normalizedProjectRoot} =
126
- persistHooks;
127
- if (!shouldPersist(args.path, normalizedProjectRoot))
128
- return undefined;
129
- try {
130
- const loader = args.path.endsWith('.tsx')
131
- ? 'tsx'
132
- : args.path.endsWith('.ts')
133
- ? 'ts'
134
- : 'jsx';
135
- return {
136
- contents: transformPersist(
137
- readFileSync(args.path, 'utf8'),
138
- relative(projectRoot, args.path).replace(/\\/g, '/'),
139
- ),
140
- loader,
141
- };
142
- } catch (error) {
143
- return {errors: [{text: `persist transform: ${error.message}`}]};
144
- }
145
- });
146
- }
147
- build.onLoad({filter: /\.(png|jpe?g|webp|gif|bmp)$/i}, args => {
148
- const name = assetName(args.path);
149
- images.set(name, args.path);
150
- return {
151
- contents: `module.exports = ${JSON.stringify(name)};`,
152
- loader: 'js',
153
- };
154
- });
155
- build.onLoad({filter: /\.(ttf|otf)$/i}, args => {
156
- const family = assetName(args.path);
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
- entry,
176
- projectRoot,
177
- nodePaths,
178
- persist = false,
179
- }) {
180
- const esbuild = require('esbuild');
181
- const images = new Map();
182
- const fonts = new Map();
183
-
184
- let persistHooks = null;
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
- const {bakeImage} = await import('../assets/bake-image.mjs');
207
- const {bakeFont} = await import('../assets/bake-font.mjs');
208
- const {resolveFontJobs} = await import('../assets/font-config.mjs');
209
- const {analyzeFontSizes, warnFontSizes} =
210
- await import('../assets/font-sizes.mjs');
211
- const {warnMissingGlyphs} = await import('../assets/glyph-coverage.mjs');
212
- const {emitAssetPack} = await import('../assets/emit-pack.mjs');
213
-
214
- const usedSizes = analyzeFontSizes(source);
215
-
216
- let config = {};
217
- const configPath = resolve(projectRoot, 'assets.config.js');
218
- if (existsSync(configPath))
219
- config =
220
- (
221
- await import(
222
- `${pathToFileURL(configPath).href}?t=${statSync(configPath).mtimeMs}`
223
- )
224
- ).default || {};
225
- const fontConfig = config.fonts || {};
226
- const imageConfig = config.images || {};
227
-
228
- const fontJobs = resolveFontJobs(fonts, fontConfig, usedSizes.sizes);
229
- const imageJobs = [...images.entries()].map(([name, path]) => ({
230
- path,
231
- name,
232
- format: imageConfig[name]?.format,
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
- const {compileToBytecode} = await import('../qjsc-wasm.mjs');
251
- const source = await bundleVendorSource({libSrc, nodePaths});
252
- const bytecode = await compileToBytecode(source, simDir, {strip});
253
- return {bytecode, bytecodeLen: bytecode.length};
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
- entry,
264
- projectRoot,
265
- libSrc,
266
- nodePaths,
267
- simDir,
268
- persist = false,
269
- strip = false,
270
- }) {
271
- const {compileToBytecode} = await import('../qjsc-wasm.mjs');
272
- const {source, images, fonts} = await bundleAppSource({
273
- entry,
274
- projectRoot,
275
- nodePaths,
276
- persist,
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
- return emit({bytecode: appBytecode, vendorBytecode, assetPack});
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
- return emit({bytecode: appBytecode, assetPack});
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
- const {emitContainer} = await import('../assets/emit-container.mjs');
308
- return emitContainer({...options, qjsTag: QJS_TAG});
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 };