embedded-react 0.7.0 → 0.8.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/build.mjs +10 -1
- package/cli.mjs +4 -1
- package/hotreload/pack-app.mjs +2 -1
- package/hotreload/pack-split.mjs +4 -3
- package/pack-container.mjs +10 -1
- package/package.json +1 -1
- package/qjsc-wasm.mjs +7 -1
- package/sim/embedded-react.wasm +0 -0
package/build.mjs
CHANGED
|
@@ -98,7 +98,16 @@ await build({
|
|
|
98
98
|
// them: map the bare `embedded-react` import to the library source and let the demo's bare deps
|
|
99
99
|
// (react, react-reconciler) resolve from this package's node_modules. (The library's own internal
|
|
100
100
|
// imports still resolve relatively / from node_modules as before.)
|
|
101
|
-
|
|
101
|
+
// Pin React to THIS package's copy: a demo/consumer project may carry its own node_modules
|
|
102
|
+
// (e.g., after `npm install` for device-dev deps), and esbuild resolving `react` from there while
|
|
103
|
+
// the library resolves its copy from here yields two React instances — the hook dispatcher is
|
|
104
|
+
// null and every component throws. One copy, always.
|
|
105
|
+
alias: {
|
|
106
|
+
'embedded-react': libEntry,
|
|
107
|
+
react: resolve(nodeModules, 'react'),
|
|
108
|
+
'react-reconciler': resolve(nodeModules, 'react-reconciler'),
|
|
109
|
+
scheduler: resolve(nodeModules, 'scheduler'),
|
|
110
|
+
},
|
|
102
111
|
nodePaths: [nodeModules],
|
|
103
112
|
plugins: [assetPlugin],
|
|
104
113
|
// Production React: smaller and avoids dev-only warning machinery that needs more shims.
|
package/cli.mjs
CHANGED
|
@@ -408,13 +408,16 @@ async function buildContainer(cwd, explicit, outDir) {
|
|
|
408
408
|
const lib = libSrc();
|
|
409
409
|
const paths = nodePaths(cwd);
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
// Release artifact: strip the embedded source text + debug tables from the bytecode (~8x smaller
|
|
412
|
+
// erpkg; stack traces lose line numbers). The dev loop (`embedded-react dev`) keeps them.
|
|
413
|
+
const vendor = await packVendor({libSrc: lib, nodePaths: paths, simDir, strip: true});
|
|
412
414
|
const app = await packApp({
|
|
413
415
|
entry,
|
|
414
416
|
projectRoot: cwd,
|
|
415
417
|
libSrc: lib,
|
|
416
418
|
nodePaths: paths,
|
|
417
419
|
simDir,
|
|
420
|
+
strip: true,
|
|
418
421
|
});
|
|
419
422
|
const container = await emitBootContainer({
|
|
420
423
|
vendorBytecode: vendor.bytecode,
|
package/hotreload/pack-app.mjs
CHANGED
|
@@ -52,6 +52,7 @@ export async function packAppContainer({
|
|
|
52
52
|
nodePaths,
|
|
53
53
|
simDir,
|
|
54
54
|
persist = false,
|
|
55
|
+
strip = false,
|
|
55
56
|
}) {
|
|
56
57
|
const esbuild = require('esbuild');
|
|
57
58
|
const {bakeImage} = await import('../assets/bake-image.mjs');
|
|
@@ -142,7 +143,7 @@ export async function packAppContainer({
|
|
|
142
143
|
});
|
|
143
144
|
const bundleSrc = readFileSync(bundlePath, 'utf8');
|
|
144
145
|
|
|
145
|
-
const bytecode = await compileToBytecode(bundleSrc, simDir);
|
|
146
|
+
const bytecode = await compileToBytecode(bundleSrc, simDir, {strip});
|
|
146
147
|
|
|
147
148
|
const discoveredSizes = [
|
|
148
149
|
...new Set(
|
package/hotreload/pack-split.mjs
CHANGED
|
@@ -247,10 +247,10 @@ async function bakeAssets({images, fonts, source, projectRoot}) {
|
|
|
247
247
|
*
|
|
248
248
|
* @returns {Promise<{bytecode: Buffer, bytecodeLen: number}>}
|
|
249
249
|
*/
|
|
250
|
-
export async function packVendor({libSrc, nodePaths, simDir}) {
|
|
250
|
+
export async function packVendor({libSrc, nodePaths, simDir, strip = false}) {
|
|
251
251
|
const {compileToBytecode} = await import('../qjsc-wasm.mjs');
|
|
252
252
|
const source = await bundleVendorSource({libSrc, nodePaths});
|
|
253
|
-
const bytecode = await compileToBytecode(source, simDir);
|
|
253
|
+
const bytecode = await compileToBytecode(source, simDir, {strip});
|
|
254
254
|
return {bytecode, bytecodeLen: bytecode.length};
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -267,6 +267,7 @@ export async function packApp({
|
|
|
267
267
|
nodePaths,
|
|
268
268
|
simDir,
|
|
269
269
|
persist = false,
|
|
270
|
+
strip = false,
|
|
270
271
|
}) {
|
|
271
272
|
const {compileToBytecode} = await import('../qjsc-wasm.mjs');
|
|
272
273
|
const {source, images, fonts} = await bundleAppSource({
|
|
@@ -275,7 +276,7 @@ export async function packApp({
|
|
|
275
276
|
nodePaths,
|
|
276
277
|
persist,
|
|
277
278
|
});
|
|
278
|
-
const bytecode = await compileToBytecode(source, simDir);
|
|
279
|
+
const bytecode = await compileToBytecode(source, simDir, {strip});
|
|
279
280
|
const assetPack = await bakeAssets({images, fonts, source, projectRoot});
|
|
280
281
|
return {
|
|
281
282
|
bytecode,
|
package/pack-container.mjs
CHANGED
|
@@ -141,7 +141,16 @@ await build({
|
|
|
141
141
|
platform: 'neutral',
|
|
142
142
|
target: 'es2020',
|
|
143
143
|
jsx: 'automatic',
|
|
144
|
-
|
|
144
|
+
// Pin React to THIS package's copy: a demo/consumer project may carry its own node_modules
|
|
145
|
+
// (e.g., after `npm install` for device-dev deps), and esbuild resolving `react` from there while
|
|
146
|
+
// the library resolves its copy from here yields two React instances — the hook dispatcher is
|
|
147
|
+
// null and every component throws. One copy, always.
|
|
148
|
+
alias: {
|
|
149
|
+
'embedded-react': libEntry,
|
|
150
|
+
react: resolve(nodeModules, 'react'),
|
|
151
|
+
'react-reconciler': resolve(nodeModules, 'react-reconciler'),
|
|
152
|
+
scheduler: resolve(nodeModules, 'scheduler'),
|
|
153
|
+
},
|
|
145
154
|
nodePaths: [nodeModules],
|
|
146
155
|
plugins: [assetPlugin],
|
|
147
156
|
define: {'process.env.NODE_ENV': '"production"'},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "embedded-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native-style component package + reconciler that drives the embedded-react C engine through the QuickJS NativeUI bridge (Flow A).",
|
|
6
6
|
"license": "Apache-2.0",
|
package/qjsc-wasm.mjs
CHANGED
|
@@ -31,11 +31,16 @@ const HERE = dirname(fileURLToPath(import.meta.url));
|
|
|
31
31
|
*
|
|
32
32
|
* @param {string} jsSource The bundled app (esbuild IIFE output).
|
|
33
33
|
* @param {string} [simDir] Dir holding embedded-react.{js,wasm} (defaults to the package's sim/).
|
|
34
|
+
* @param {{strip?: boolean}} [opts] strip: true drops the embedded source text + debug tables
|
|
35
|
+
* (release/device — ~8x smaller blob); default false keeps them so dev-loop stack traces have
|
|
36
|
+
* line numbers. (A sim .wasm built before the strip parameter existed ignores it and always
|
|
37
|
+
* keeps debug info.)
|
|
34
38
|
* @returns {Promise<Buffer>} The bytecode bytes.
|
|
35
39
|
*/
|
|
36
40
|
export async function compileToBytecode(
|
|
37
41
|
jsSource,
|
|
38
42
|
simDir = resolve(HERE, 'sim'),
|
|
43
|
+
{strip = false} = {},
|
|
39
44
|
) {
|
|
40
45
|
// The .cjs (not .js): this package is "type": "module", so Node would load the emscripten .js as ESM and
|
|
41
46
|
// its CommonJS factory export would never run. The .cjs is the same module forced to CommonJS for Node.
|
|
@@ -62,8 +67,9 @@ export async function compileToBytecode(
|
|
|
62
67
|
'number',
|
|
63
68
|
'number',
|
|
64
69
|
'number',
|
|
70
|
+
'number',
|
|
65
71
|
]);
|
|
66
|
-
const bcPtr = compile(srcPtr, bytes.length, outLenPtr);
|
|
72
|
+
const bcPtr = compile(srcPtr, bytes.length, outLenPtr, strip ? 1 : 0);
|
|
67
73
|
|
|
68
74
|
// ALLOW_MEMORY_GROWTH=1 can detach views across the malloc/compile calls — read through a FRESH buffer.
|
|
69
75
|
const heap = () => new Uint8Array(Module.HEAPU8.buffer);
|
package/sim/embedded-react.wasm
CHANGED
|
Binary file
|