@nativue/core 0.15.1 → 0.15.3
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/android/src/main/cpp/bridge.cpp +3 -1
- package/cli/hermes.mjs +38 -0
- package/cli/hot-prelude.mjs +29 -0
- package/cli/nativue.mjs +4 -46
- package/ios/Bridge.swift +3 -3
- package/ios/JavaScriptRuntime/JavaScriptRuntime.mm +3 -1
- package/ios/NativueView.swift +10 -5
- package/ios/ScreenStackView.swift +7 -1
- package/package.json +6 -6
|
@@ -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
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// What the dev server puts before the bundle: Vite's module runtime and nativue's hot client.
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { createRequire } from 'node:module'
|
|
4
|
+
|
|
5
|
+
const HOT_CLIENT_PATH = new URL('./hot-client.js', import.meta.url)
|
|
6
|
+
// The ESM syntax Hermes doesn't compile: the runtime's export list, and import() but not a method
|
|
7
|
+
// named import (`hooks.import(`).
|
|
8
|
+
export const EXPORT_LIST = /^export \{[^}]*\};?$/m
|
|
9
|
+
export const DYNAMIC_IMPORT = /(?<![.\w$])import\s*\(/g
|
|
10
|
+
|
|
11
|
+
export function hotPrelude(clientId, serverURL) {
|
|
12
|
+
const viteRequire = createRequire(createRequire(import.meta.url).resolve('vite'))
|
|
13
|
+
const runtime = readFileSync(viteRequire.resolve('rolldown/experimental/runtime'), 'utf8')
|
|
14
|
+
const client = readFileSync(HOT_CLIENT_PATH, 'utf8')
|
|
15
|
+
const options = JSON.stringify({ clientId, serverURL })
|
|
16
|
+
|
|
17
|
+
return `${hermesCompatible(runtime)}\nvar __NATIVUE_HOT__ = ${options};\n${client}\n`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Hermes compiles neither `export` nor `import()`. The runtime's import() loads lazy chunks, which
|
|
22
|
+
* nativue builds without, so it's never called.
|
|
23
|
+
*/
|
|
24
|
+
function hermesCompatible(runtime) {
|
|
25
|
+
return `function __nativueDynamicImport(specifier) {
|
|
26
|
+
return Promise.reject(new Error('nativue builds without lazy chunks: ' + specifier))
|
|
27
|
+
}
|
|
28
|
+
${runtime.replace(EXPORT_LIST, '').replace(DYNAMIC_IMPORT, '__nativueDynamicImport(')}`
|
|
29
|
+
}
|
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 {
|
|
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
|
-
import {
|
|
30
|
-
import { dirname, relative } from 'node:path'
|
|
20
|
+
import { relative } from 'node:path'
|
|
31
21
|
import { fileURLToPath } from 'node:url'
|
|
22
|
+
import { compileToBytecode } from './hermes.mjs'
|
|
23
|
+
import { hotPrelude } from './hot-prelude.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 {
|
|
@@ -271,15 +238,6 @@ function vueHotUpdates(sendToApps) {
|
|
|
271
238
|
}
|
|
272
239
|
}
|
|
273
240
|
|
|
274
|
-
function hotPrelude(clientId, serverURL) {
|
|
275
|
-
const viteRequire = createRequire(createRequire(import.meta.url).resolve('vite'))
|
|
276
|
-
const runtime = readFileSync(viteRequire.resolve('rolldown/experimental/runtime'), 'utf8')
|
|
277
|
-
const client = readFileSync(frameworkPath('cli/hot-client.js'), 'utf8')
|
|
278
|
-
const options = JSON.stringify({ clientId, serverURL })
|
|
279
|
-
|
|
280
|
-
return `${runtime.replace(/^export \{[^}]*\};?$/m, '')}\nvar __NATIVUE_HOT__ = ${options};\n${client}\n`
|
|
281
|
-
}
|
|
282
|
-
|
|
283
241
|
// Vite's full bundle mode builds the app and, on save, a patch with the changed modules. Each app
|
|
284
242
|
// runtime is a Vite client: the dev server speaks Vite's protocol for it and relays updates over SSE.
|
|
285
243
|
async function dev() {
|
package/ios/Bridge.swift
CHANGED
|
@@ -158,7 +158,7 @@ final class Bridge {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
private func modalTransitionInProgress() -> UIViewControllerTransitionCoordinator? {
|
|
161
|
-
guard let presentedViewController = rootView.
|
|
161
|
+
guard let presentedViewController = rootView.hostWindow?.rootViewController?.presentedViewController else {
|
|
162
162
|
return nil
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -440,7 +440,7 @@ final class Bridge {
|
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
define("dismissKeyboard") { [unowned self] _ in
|
|
443
|
-
enqueue { [unowned self] in rootView.
|
|
443
|
+
enqueue { [unowned self] in rootView.hostWindow?.endEditing(true) }
|
|
444
444
|
}
|
|
445
445
|
|
|
446
446
|
return JavaScriptRuntime(functions: functions) { [unowned self] message, stack in
|
|
@@ -492,7 +492,7 @@ final class Bridge {
|
|
|
492
492
|
|
|
493
493
|
private func resetNodeTree() {
|
|
494
494
|
// Sheets of the old tree's screen stacks too, which only their stack knows about.
|
|
495
|
-
rootView.
|
|
495
|
+
rootView.hostWindow?.rootViewController?.dismiss(animated: false)
|
|
496
496
|
rootView.subviews.forEach { $0.removeFromSuperview() }
|
|
497
497
|
contentRootsByNodeId.values.forEach { ($0 as? ModalController)?.setVisible(false) }
|
|
498
498
|
contentRootsByNodeId = [:]
|
|
@@ -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
|
-
|
|
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/ios/NativueView.swift
CHANGED
|
@@ -42,6 +42,8 @@ struct VueRoot: UIViewRepresentable {
|
|
|
42
42
|
final class RootView: UIView {
|
|
43
43
|
var onLayoutSubviews: (() -> Void)?
|
|
44
44
|
var onTraitCollectionChange: ((_ previous: UITraitCollection?) -> Void)?
|
|
45
|
+
/// `window` is nil under a full-screen modal: the bridge finds that modal through this one.
|
|
46
|
+
private(set) weak var hostWindow: UIWindow?
|
|
45
47
|
|
|
46
48
|
override func layoutSubviews() {
|
|
47
49
|
super.layoutSubviews()
|
|
@@ -53,6 +55,14 @@ final class RootView: UIView {
|
|
|
53
55
|
onTraitCollectionChange?(previous)
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
override func didMoveToWindow() {
|
|
59
|
+
super.didMoveToWindow()
|
|
60
|
+
if let window { hostWindow = window }
|
|
61
|
+
#if DEBUG
|
|
62
|
+
becomeFirstResponder()
|
|
63
|
+
#endif
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
#if DEBUG
|
|
57
67
|
var onReloadShortcut: (() -> Void)?
|
|
58
68
|
|
|
@@ -62,11 +72,6 @@ final class RootView: UIView {
|
|
|
62
72
|
[UIKeyCommand(input: "r", modifierFlags: .command, action: #selector(reloadShortcutPressed))]
|
|
63
73
|
}
|
|
64
74
|
|
|
65
|
-
override func didMoveToWindow() {
|
|
66
|
-
super.didMoveToWindow()
|
|
67
|
-
becomeFirstResponder()
|
|
68
|
-
}
|
|
69
|
-
|
|
70
75
|
@objc private func reloadShortcutPressed() {
|
|
71
76
|
onReloadShortcut?()
|
|
72
77
|
}
|
|
@@ -73,6 +73,7 @@ final class ScreenStackView: UIView, ScreenContainer, UINavigationControllerDele
|
|
|
73
73
|
super.didMoveToWindow()
|
|
74
74
|
|
|
75
75
|
embedInNearestViewController(navigationController)
|
|
76
|
+
if window != nil { scheduleSync() }
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
private func configure(_ navigationController: UINavigationController) {
|
|
@@ -185,9 +186,14 @@ final class ScreenStackView: UIView, ScreenContainer, UINavigationControllerDele
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
private func presentModal(_ group: [ScreenController]) {
|
|
188
|
-
let modalNavigationController = UINavigationController()
|
|
189
189
|
let presenter = modalNavigationControllers.last ?? navigationController
|
|
190
190
|
|
|
191
|
+
// Out of the window under a full-screen modal: UIKit would refuse without calling back. didMoveToWindow
|
|
192
|
+
// syncs again once it's back.
|
|
193
|
+
guard presenter.view.window != nil else { return }
|
|
194
|
+
|
|
195
|
+
let modalNavigationController = UINavigationController()
|
|
196
|
+
|
|
191
197
|
configure(modalNavigationController)
|
|
192
198
|
modalNavigationController.setViewControllers(group, animated: false)
|
|
193
199
|
modalNavigationController.modalPresentationStyle =
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativue/core",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
4
4
|
"description": "Vue rendering real native views on iOS and Android",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vue",
|
|
@@ -32,19 +32,19 @@
|
|
|
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": {
|
|
39
39
|
"@vitejs/plugin-vue": "^6.0.11",
|
|
40
|
-
"@vue/runtime-core": "^3.5.
|
|
40
|
+
"@vue/runtime-core": "^3.5.46",
|
|
41
41
|
"hermes-compiler": "260318099.0.8",
|
|
42
|
-
"vite": "^8.
|
|
43
|
-
"vue": "^3.5.
|
|
42
|
+
"vite": "^8.4.0",
|
|
43
|
+
"vue": "^3.5.46",
|
|
44
44
|
"whatwg-fetch": "^3.6.20"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"typescript": "^
|
|
47
|
+
"typescript": "^6.0.3",
|
|
48
48
|
"vue-tsc": "^3.3.14"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|