@nativue/core 0.15.1 → 0.15.2

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.
@@ -463,7 +463,9 @@ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
463
463
 
464
464
  extern "C" JNIEXPORT jlong JNICALL
465
465
  Java_dev_nativue_JavaScriptRuntime_create(JNIEnv* env, jobject owner, jobjectArray functionNames) {
466
- auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).build();
466
+ // Off by default: a let in a loop would be one variable for every iteration, so callbacks made
467
+ // in the loop would all see its last value. Bytecode gets the same from hermesc's -Xes6-block-scoping.
468
+ auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).withES6BlockScoping(true).build();
467
469
  auto runtime = new Runtime{facebook::hermes::makeHermesRuntime(config), env->NewGlobalRef(owner)};
468
470
  installNativeModule(*runtime, env, functionNames);
469
471
 
package/cli/hermes.mjs ADDED
@@ -0,0 +1,38 @@
1
+ // Hermes bytecode for production bundles.
2
+ import { execFileSync } from 'node:child_process'
3
+ import { renameSync } from 'node:fs'
4
+ import { createRequire } from 'node:module'
5
+ import { dirname } from 'node:path'
6
+
7
+ const HERMESC_BY_PLATFORM = {
8
+ darwin: 'osx-bin/hermesc',
9
+ linux: 'linux64-bin/hermesc',
10
+ win32: 'win64-bin/hermesc.exe',
11
+ }
12
+
13
+ // -Xes6-block-scoping: a let in a loop is a variable per iteration, as when the runtime compiles source
14
+ // in development. Without it, callbacks made in the loop all see its last value.
15
+ export const HERMESC_OPTIONS = ['-O', '-w', '-Xes6-block-scoping']
16
+
17
+ export function hermescPath() {
18
+ const packageDirectory = dirname(
19
+ createRequire(import.meta.url).resolve('hermes-compiler/package.json'),
20
+ )
21
+
22
+ return `${packageDirectory}/hermesc/${HERMESC_BY_PLATFORM[process.platform]}`
23
+ }
24
+
25
+ // Hermes bytecode starts faster: no parsing when the app opens. The runtime tells bytecode from
26
+ // source on its own, so the file keeps its name.
27
+ export function compileToBytecode(bundlePath) {
28
+ const bytecodePath = `${bundlePath}.hbc`
29
+
30
+ execFileSync(
31
+ hermescPath(),
32
+ ['-emit-binary', ...HERMESC_OPTIONS, '-out', bytecodePath, bundlePath],
33
+ {
34
+ stdio: 'inherit',
35
+ },
36
+ )
37
+ renameSync(bytecodePath, bundlePath)
38
+ }
package/cli/nativue.mjs CHANGED
@@ -15,20 +15,12 @@ import { build, createServer, loadConfigFromFile, transformWithOxc } from 'vite'
15
15
  import vue from '@vitejs/plugin-vue'
16
16
  import http from 'node:http'
17
17
  import net from 'node:net'
18
- import { execFileSync } from 'node:child_process'
19
- import {
20
- copyFileSync,
21
- existsSync,
22
- mkdirSync,
23
- readdirSync,
24
- readFileSync,
25
- renameSync,
26
- watch,
27
- } from 'node:fs'
18
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, watch } from 'node:fs'
28
19
  import { randomUUID } from 'node:crypto'
29
20
  import { createRequire } from 'node:module'
30
- import { dirname, relative } from 'node:path'
21
+ import { relative } from 'node:path'
31
22
  import { fileURLToPath } from 'node:url'
23
+ import { compileToBytecode } from './hermes.mjs'
32
24
  import { resolvePlugins } from './plugins.mjs'
33
25
  import { linkNativePackages, PLATFORMS, prebuild } from './prebuild.mjs'
34
26
  import { runOnAndroid, runOnIOS } from './run.mjs'
@@ -62,31 +54,6 @@ function frameworkPath(relativePath) {
62
54
  }
63
55
 
64
56
  // hermesc ships with the hermes-compiler package, one binary per host system.
65
- const HERMESC_BY_PLATFORM = {
66
- darwin: 'osx-bin/hermesc',
67
- linux: 'linux64-bin/hermesc',
68
- win32: 'win64-bin/hermesc.exe',
69
- }
70
-
71
- function hermescPath() {
72
- const packageDirectory = dirname(
73
- createRequire(import.meta.url).resolve('hermes-compiler/package.json'),
74
- )
75
-
76
- return `${packageDirectory}/hermesc/${HERMESC_BY_PLATFORM[process.platform]}`
77
- }
78
-
79
- // Hermes bytecode starts faster: no parsing when the app opens. The runtime tells bytecode from
80
- // source on its own, so the file keeps its name.
81
- function compileToBytecode(bundlePath) {
82
- const bytecodePath = `${bundlePath}.hbc`
83
-
84
- execFileSync(hermescPath(), ['-emit-binary', '-O', '-w', '-out', bytecodePath, bundlePath], {
85
- stdio: 'inherit',
86
- })
87
- renameSync(bytecodePath, bundlePath)
88
- }
89
-
90
57
  // A production bundle becomes bytecode; the Android app packages its assets folder, so it gets a copy.
91
58
  function finishBundle(mode) {
92
59
  return {
@@ -239,7 +239,9 @@ void installBlobCollector(jsi::Runtime &runtime, NativueNativeFunction release)
239
239
  self = [super init];
240
240
  if (self == nil) return nil;
241
241
 
242
- auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).build();
242
+ // Off by default: a let in a loop would be one variable for every iteration, so callbacks made
243
+ // in the loop would all see its last value. Bytecode gets the same from hermesc's -Xes6-block-scoping.
244
+ auto config = ::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(true).withES6BlockScoping(true).build();
243
245
  _hermes = facebook::hermes::makeHermesRuntime(config);
244
246
  _onError = onError;
245
247
  [self installNativeModule:functions];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativue/core",
3
- "version": "0.15.1",
3
+ "version": "0.15.2",
4
4
  "description": "Vue rendering real native views on iOS and Android",
5
5
  "keywords": [
6
6
  "vue",
@@ -32,7 +32,7 @@
32
32
  }
33
33
  },
34
34
  "scripts": {
35
- "test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/prebuild.test.mjs",
35
+ "test": "(cd ../../examples/demo && nativue build) && node test/test.mjs && node test/native-events.test.mjs && node test/hermes.test.mjs && node test/prebuild.test.mjs",
36
36
  "typecheck": "vue-tsc"
37
37
  },
38
38
  "dependencies": {