@nativescript/windows-hermes 1.0.0-beta.14 → 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.
@@ -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 both source files.
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 &quot;$(NSWindowsRoot)\tools\hermes-precompile.ps1&quot; -AppDir &quot;$(MSBuildProjectDirectory)\app&quot; -Hermesc &quot;$(NSWindowsRoot)\tools\hermesc.exe&quot; -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
- $(NSWindowsRoot)\dotnet-bridge\Bridge.cs"
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/windows-hermes",
3
- "version": "1.0.0-beta.14",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "NativeScript Windows runtime (Hermes engine) with a WinUI 3 app template",
5
5
  "keywords": [
6
6
  "NativeScript",