@nativescript/windows-hermes 1.0.0-beta.13 → 1.0.0-beta.17
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/framework/__PROJECT_NAME__/App.xaml.cs +3 -0
- package/framework/__PROJECT_NAME__/RuntimeHost.cs +56 -0
- package/framework/__PROJECT_NAME__/__PROJECT_NAME__.csproj +21 -2
- package/framework/libs/x64/nativescript.dll +0 -0
- package/framework/tools/hermes-precompile.ps1 +62 -0
- package/framework/tools/hermesc.exe +0 -0
- package/package.json +1 -1
|
@@ -123,8 +123,60 @@ namespace __PROJECT_NAME__
|
|
|
123
123
|
private const string InspectorMarker = "ns-inspector";
|
|
124
124
|
private const string DebugBreakMarker = "ns-debugbreak";
|
|
125
125
|
private const string DebuggerStartedMarker = "ns-debugger-started";
|
|
126
|
+
// The CLI writes LiveSyncMarker after syncing files into app\ (webpack HMR), but only
|
|
127
|
+
// while LiveSyncReadyMarker says this host is watching for it.
|
|
128
|
+
private const string LiveSyncMarker = "ns-livesync";
|
|
129
|
+
private const string LiveSyncReadyMarker = "ns-livesync-ready";
|
|
126
130
|
|
|
127
131
|
private bool _waitForDebugger;
|
|
132
|
+
private FileSystemWatcher _liveSyncWatcher;
|
|
133
|
+
|
|
134
|
+
/// Applies CLI file syncs while the app runs, by calling global.__onLiveSync() on the UI
|
|
135
|
+
/// thread, as the Android and iOS runtimes do after a LiveSync.
|
|
136
|
+
public void WatchLiveSync(Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue)
|
|
137
|
+
{
|
|
138
|
+
if (!_initialized || _liveSyncWatcher != null || dispatcherQueue == null) return;
|
|
139
|
+
try
|
|
140
|
+
{
|
|
141
|
+
DeleteMarker(LiveSyncMarker);
|
|
142
|
+
var watcher = new FileSystemWatcher(LocalFolderPath, LiveSyncMarker)
|
|
143
|
+
{
|
|
144
|
+
NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite,
|
|
145
|
+
};
|
|
146
|
+
FileSystemEventHandler onMarker = (_, _) => dispatcherQueue.TryEnqueue(ApplyLiveSync);
|
|
147
|
+
watcher.Created += onMarker;
|
|
148
|
+
watcher.Changed += onMarker;
|
|
149
|
+
watcher.EnableRaisingEvents = true;
|
|
150
|
+
_liveSyncWatcher = watcher;
|
|
151
|
+
WriteMarker(LiveSyncReadyMarker, "");
|
|
152
|
+
}
|
|
153
|
+
catch (Exception ex)
|
|
154
|
+
{
|
|
155
|
+
System.Diagnostics.Debug.WriteLine($"[NativeScript LiveSync] Watch failed: {ex.Message}");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private void ApplyLiveSync()
|
|
160
|
+
{
|
|
161
|
+
// One write raises several events; the first one consumes the marker.
|
|
162
|
+
if (!_initialized || !ConsumeMarker(LiveSyncMarker)) return;
|
|
163
|
+
try
|
|
164
|
+
{
|
|
165
|
+
runtime_runscript(_runtime, "typeof __onLiveSync === 'function' && __onLiveSync();", "ns-livesync.js");
|
|
166
|
+
}
|
|
167
|
+
catch (Exception ex)
|
|
168
|
+
{
|
|
169
|
+
System.Diagnostics.Debug.WriteLine($"[NativeScript LiveSync] Apply failed: {ex.Message}");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private void StopWatchingLiveSync()
|
|
174
|
+
{
|
|
175
|
+
if (_liveSyncWatcher == null) return;
|
|
176
|
+
_liveSyncWatcher.Dispose();
|
|
177
|
+
_liveSyncWatcher = null;
|
|
178
|
+
DeleteMarker(LiveSyncReadyMarker);
|
|
179
|
+
}
|
|
128
180
|
|
|
129
181
|
public string DevtoolsFrontendUrl { get; private set; }
|
|
130
182
|
|
|
@@ -235,6 +287,7 @@ namespace __PROJECT_NAME__
|
|
|
235
287
|
}
|
|
236
288
|
catch { }
|
|
237
289
|
DeleteMarker(DebuggerStartedMarker);
|
|
290
|
+
DeleteMarker(LiveSyncReadyMarker);
|
|
238
291
|
var debugBreak = ConsumeMarker(DebugBreakMarker);
|
|
239
292
|
if (ConsumeMarker(InspectorMarker) || debugBreak)
|
|
240
293
|
{
|
|
@@ -476,6 +529,9 @@ namespace __PROJECT_NAME__
|
|
|
476
529
|
public void Dispose()
|
|
477
530
|
{
|
|
478
531
|
if (!_initialized) return;
|
|
532
|
+
#if DEBUG
|
|
533
|
+
StopWatchingLiveSync();
|
|
534
|
+
#endif
|
|
479
535
|
runtime_deinit(_runtime);
|
|
480
536
|
_runtime = 0;
|
|
481
537
|
_initialized = false;
|
|
@@ -154,12 +154,31 @@
|
|
|
154
154
|
<!--
|
|
155
155
|
Publishes DotNetBridge.dll before the app build.
|
|
156
156
|
Inputs/Outputs make this incremental: MSBuild skips the Exec when DotNetBridge.dll
|
|
157
|
-
is already newer than
|
|
157
|
+
is already newer than the project and every bridge source file.
|
|
158
158
|
-->
|
|
159
|
+
<ItemGroup>
|
|
160
|
+
<_DotNetBridgeSources Include="$(NSWindowsRoot)\dotnet-bridge\*.cs" />
|
|
161
|
+
</ItemGroup>
|
|
162
|
+
|
|
163
|
+
<!--
|
|
164
|
+
@nativescript/windows-hermes: Release builds compile the app's JavaScript to Hermes bytecode
|
|
165
|
+
(tools\hermes-precompile.ps1), so a launch doesn't compile the bundle again. Only that
|
|
166
|
+
framework ships tools\hermesc.exe.
|
|
167
|
+
-->
|
|
168
|
+
<Target Name="PrecompileHermesBytecode"
|
|
169
|
+
BeforeTargets="AssignTargetPaths"
|
|
170
|
+
Condition="'$(Configuration)' == 'Release' and Exists('$(NSWindowsRoot)\tools\hermesc.exe') and Exists('app') and !Exists('app.nsbundle')">
|
|
171
|
+
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(NSWindowsRoot)\tools\hermes-precompile.ps1" -AppDir "$(MSBuildProjectDirectory)\app" -Hermesc "$(NSWindowsRoot)\tools\hermesc.exe" -Optimize" />
|
|
172
|
+
<ItemGroup>
|
|
173
|
+
<Content Include="app\**\*.hbc" Exclude="@(Content)">
|
|
174
|
+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
175
|
+
</Content>
|
|
176
|
+
</ItemGroup>
|
|
177
|
+
</Target>
|
|
159
178
|
<Target Name="PublishDotNetBridge"
|
|
160
179
|
BeforeTargets="Build"
|
|
161
180
|
Inputs="$(NSWindowsRoot)\dotnet-bridge\DotNetBridge.csproj;
|
|
162
|
-
|
|
181
|
+
@(_DotNetBridgeSources)"
|
|
163
182
|
Outputs="$(NSWindowsRoot)\dotnet-bridge\publish\DotNetBridge.dll"
|
|
164
183
|
Condition="Exists('$(NSWindowsRoot)\dotnet-bridge\DotNetBridge.csproj')">
|
|
165
184
|
<Message Text="[NativeScript] Publishing DotNetBridge..." Importance="low" />
|
|
Binary file
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Compiles the app's JavaScript to Hermes bytecode beside each file, for Release builds of
|
|
2
|
+
# @nativescript/windows-hermes apps: <file>.hbc for scripts the host runs as is (runtime.js,
|
|
3
|
+
# vendor.js, bundle.js, the package.json "main"), <file>.cjs.hbc for modules, compiled inside the
|
|
4
|
+
# runtime's CommonJS wrapper. Up-to-date files are skipped; the runtime ignores bytecode older
|
|
5
|
+
# than its source. Runs on Windows PowerShell 5.1.
|
|
6
|
+
param(
|
|
7
|
+
[Parameter(Mandatory = $true)][string]$AppDir,
|
|
8
|
+
[Parameter(Mandatory = $true)][string]$Hermesc,
|
|
9
|
+
[switch]$Optimize
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
$ErrorActionPreference = 'Stop'
|
|
13
|
+
if (-not (Test-Path $AppDir)) { return }
|
|
14
|
+
$AppDir = (Resolve-Path $AppDir).Path
|
|
15
|
+
|
|
16
|
+
$entries = @('runtime.js', 'vendor.js', 'bundle.js')
|
|
17
|
+
$packageJson = Join-Path $AppDir 'package.json'
|
|
18
|
+
if (Test-Path $packageJson) {
|
|
19
|
+
try {
|
|
20
|
+
$package = Get-Content -Raw $packageJson | ConvertFrom-Json
|
|
21
|
+
if ($package.main) { $entries += [IO.Path]::GetFileName([string]$package.main) }
|
|
22
|
+
} catch { }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
$wrapperHead = '(function (module, exports, require, __filename, __dirname) {'
|
|
26
|
+
$utf8 = New-Object System.Text.UTF8Encoding($false)
|
|
27
|
+
$scratch = Join-Path ([IO.Path]::GetTempPath()) ("ns-hermes-" + [Guid]::NewGuid().ToString('N'))
|
|
28
|
+
$compiled = 0
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
Get-ChildItem -Path $AppDir -Recurse -File -Filter *.js |
|
|
32
|
+
Where-Object { $_.FullName -notmatch '\\node_modules\\' } |
|
|
33
|
+
ForEach-Object {
|
|
34
|
+
$isEntry = ($_.DirectoryName -eq $AppDir) -and ($entries -contains $_.Name)
|
|
35
|
+
$out = $_.FullName + $(if ($isEntry) { '.hbc' } else { '.cjs.hbc' })
|
|
36
|
+
if ((Test-Path $out) -and ((Get-Item $out).LastWriteTimeUtc -ge $_.LastWriteTimeUtc)) { return }
|
|
37
|
+
|
|
38
|
+
$source = $_.FullName
|
|
39
|
+
if (-not $isEntry) {
|
|
40
|
+
# Same file name in a scratch folder, so the bytecode's debug info names the module.
|
|
41
|
+
$dir = Join-Path $scratch ([Guid]::NewGuid().ToString('N'))
|
|
42
|
+
$null = New-Item -ItemType Directory -Force -Path $dir
|
|
43
|
+
$source = Join-Path $dir $_.Name
|
|
44
|
+
$text = [IO.File]::ReadAllText($_.FullName)
|
|
45
|
+
[IO.File]::WriteAllText($source, $wrapperHead + $text + "`n})", $utf8)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
$hermescArgs = @('-emit-binary', '-w', '-out', $out, $source)
|
|
49
|
+
if ($Optimize) { $hermescArgs = @('-O') + $hermescArgs }
|
|
50
|
+
& $Hermesc @hermescArgs
|
|
51
|
+
if ($LASTEXITCODE -ne 0) {
|
|
52
|
+
Remove-Item -Force -ErrorAction SilentlyContinue $out
|
|
53
|
+
Write-Warning "hermesc could not compile $($_.FullName); it will be compiled at run time"
|
|
54
|
+
} else {
|
|
55
|
+
$compiled++
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} finally {
|
|
59
|
+
if (Test-Path $scratch) { Remove-Item -Recurse -Force $scratch }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Write-Host "[NativeScript] Hermes bytecode: $compiled file(s) compiled"
|
|
Binary file
|