@nativescript/windows-hermes 1.0.0-beta.14 → 1.0.0-beta.18
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__/Package.appxmanifest +0 -1
- package/framework/__PROJECT_NAME__/RuntimeHost.cs +11 -5
- package/framework/__PROJECT_NAME__/__PROJECT_NAME__.csproj +24 -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
|
@@ -32,11 +32,7 @@ namespace __PROJECT_NAME__
|
|
|
32
32
|
[DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_set_local_folder))]
|
|
33
33
|
private static extern void runtime_set_local_folder([MarshalAs(UnmanagedType.LPUTF8Str)] string localFolder);
|
|
34
34
|
|
|
35
|
-
//
|
|
36
|
-
// app.nsbundle containers). Must be called before runtime_init if used at all: apps
|
|
37
|
-
// packed with the default pepper (no --key-hex) never need to call this. Not wired to a
|
|
38
|
-
// default call site here; an app author supplies their own key material and calls this
|
|
39
|
-
// from Initialize() before runtime_init(...).
|
|
35
|
+
// Must be called before runtime_init, which opens app.nsbundle.
|
|
40
36
|
[DllImport(NativeScriptLibrary, EntryPoint = nameof(runtime_set_bundle_key))]
|
|
41
37
|
private static extern int runtime_set_bundle_key([MarshalAs(UnmanagedType.LPUTF8Str)] string keyHex);
|
|
42
38
|
|
|
@@ -252,6 +248,15 @@ namespace __PROJECT_NAME__
|
|
|
252
248
|
}
|
|
253
249
|
}
|
|
254
250
|
|
|
251
|
+
private static void ApplyBundleKey()
|
|
252
|
+
{
|
|
253
|
+
using var stream = typeof(RuntimeHost).Assembly.GetManifestResourceStream("NSBundleKey");
|
|
254
|
+
if (stream == null) return;
|
|
255
|
+
using var reader = new StreamReader(stream);
|
|
256
|
+
try { runtime_set_bundle_key(reader.ReadToEnd().Trim()); }
|
|
257
|
+
catch (EntryPointNotFoundException) { }
|
|
258
|
+
}
|
|
259
|
+
|
|
255
260
|
public void Initialize()
|
|
256
261
|
{
|
|
257
262
|
if (_initialized) return;
|
|
@@ -259,6 +264,7 @@ namespace __PROJECT_NAME__
|
|
|
259
264
|
try { attached = AttachConsole(ATTACH_PARENT_PROCESS); } catch { }
|
|
260
265
|
runtime_install_ctrlc_handler(0);
|
|
261
266
|
runtime_set_local_folder(LocalFolderPath);
|
|
267
|
+
ApplyBundleKey();
|
|
262
268
|
_runtime = runtime_init(AppContext.BaseDirectory);
|
|
263
269
|
#if DEBUG
|
|
264
270
|
TrySetDebugBuild();
|
|
@@ -87,6 +87,9 @@
|
|
|
87
87
|
<Content Include="app.nsbundle" Condition="Exists('app.nsbundle')">
|
|
88
88
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
89
89
|
</Content>
|
|
90
|
+
<!-- app.nsbundle's per-build key; RuntimeHost passes it to the runtime. -->
|
|
91
|
+
<EmbeddedResource Include="nsbundle.key" LogicalName="NSBundleKey"
|
|
92
|
+
Condition="Exists('app.nsbundle') and Exists('nsbundle.key')" />
|
|
90
93
|
<Content Include="app\**\*" Condition="!Exists('app.nsbundle')">
|
|
91
94
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
92
95
|
</Content>
|
|
@@ -154,12 +157,31 @@
|
|
|
154
157
|
<!--
|
|
155
158
|
Publishes DotNetBridge.dll before the app build.
|
|
156
159
|
Inputs/Outputs make this incremental: MSBuild skips the Exec when DotNetBridge.dll
|
|
157
|
-
is already newer than
|
|
160
|
+
is already newer than the project and every bridge source file.
|
|
158
161
|
-->
|
|
162
|
+
<ItemGroup>
|
|
163
|
+
<_DotNetBridgeSources Include="$(NSWindowsRoot)\dotnet-bridge\*.cs" />
|
|
164
|
+
</ItemGroup>
|
|
165
|
+
|
|
166
|
+
<!--
|
|
167
|
+
@nativescript/windows-hermes: Release builds compile the app's JavaScript to Hermes bytecode
|
|
168
|
+
(tools\hermes-precompile.ps1), so a launch doesn't compile the bundle again. Only that
|
|
169
|
+
framework ships tools\hermesc.exe.
|
|
170
|
+
-->
|
|
171
|
+
<Target Name="PrecompileHermesBytecode"
|
|
172
|
+
BeforeTargets="AssignTargetPaths"
|
|
173
|
+
Condition="'$(Configuration)' == 'Release' and Exists('$(NSWindowsRoot)\tools\hermesc.exe') and Exists('app') and !Exists('app.nsbundle')">
|
|
174
|
+
<Exec Command="powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(NSWindowsRoot)\tools\hermes-precompile.ps1" -AppDir "$(MSBuildProjectDirectory)\app" -Hermesc "$(NSWindowsRoot)\tools\hermesc.exe" -Optimize" />
|
|
175
|
+
<ItemGroup>
|
|
176
|
+
<Content Include="app\**\*.hbc" Exclude="@(Content)">
|
|
177
|
+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
|
178
|
+
</Content>
|
|
179
|
+
</ItemGroup>
|
|
180
|
+
</Target>
|
|
159
181
|
<Target Name="PublishDotNetBridge"
|
|
160
182
|
BeforeTargets="Build"
|
|
161
183
|
Inputs="$(NSWindowsRoot)\dotnet-bridge\DotNetBridge.csproj;
|
|
162
|
-
|
|
184
|
+
@(_DotNetBridgeSources)"
|
|
163
185
|
Outputs="$(NSWindowsRoot)\dotnet-bridge\publish\DotNetBridge.dll"
|
|
164
186
|
Condition="Exists('$(NSWindowsRoot)\dotnet-bridge\DotNetBridge.csproj')">
|
|
165
187
|
<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
|