mirinjs 0.1.0-alpha.5 → 0.1.0-alpha.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/updater.ts +21 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mirinjs",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.6",
4
4
  "description": "Build desktop apps with Bun, TypeScript, and Chromium (CEF). The Bun-native Electron alternative.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/updater.ts CHANGED
@@ -13,7 +13,7 @@
13
13
  * packaged app with `release` set; in `mirin dev` the updater is idle.
14
14
  */
15
15
 
16
- import { homedir } from "node:os";
16
+ import { homedir, tmpdir } from "node:os";
17
17
  import { join } from "node:path";
18
18
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync } from "node:fs";
19
19
  import { $ } from "bun";
@@ -216,17 +216,29 @@ export class Updater {
216
216
  const exe = join(runningApp, `${this.#version()!.name}.exe`);
217
217
  const ps = [
218
218
  `$ErrorActionPreference='SilentlyContinue'`,
219
+ // Wait for the host process to exit (it locks the exe).
219
220
  `while (Get-Process -Id ${process.pid} -ErrorAction SilentlyContinue) { Start-Sleep -Milliseconds 200 }`,
220
- `Start-Sleep -Milliseconds 400`,
221
- `Remove-Item -Recurse -Force ${psq(runningApp)}`,
221
+ // Give CEF's helper subprocesses a beat to exit and release their file
222
+ // locks (libcef.dll etc.) — they go just after the host.
223
+ `Start-Sleep -Milliseconds 700`,
224
+ // Replace the app folder, retrying while any lingering lock clears
225
+ // (~10s max). Unlike Unix, Windows can't delete a dir that's still a
226
+ // process's cwd or holds an open handle — hence the neutral cwd below.
227
+ `for ($i=0; $i -lt 50; $i++) { Remove-Item -Recurse -Force ${psq(runningApp)}; if (-not (Test-Path ${psq(runningApp)})) { break }; Start-Sleep -Milliseconds 200 }`,
222
228
  `Move-Item -Force ${psq(this.#staged)} ${psq(runningApp)}`,
223
- `Start-Process ${psq(exe)}`,
229
+ `Start-Process -FilePath ${psq(exe)} -WorkingDirectory ${psq(runningApp)}`,
224
230
  ].join("; ");
225
- Bun.spawn(["powershell", "-NoProfile", "-NonInteractive", "-Command", ps], {
226
- stdin: "ignore",
227
- stdout: "ignore",
228
- stderr: "ignore",
229
- }).unref();
231
+ Bun.spawn(
232
+ ["powershell", "-NoProfile", "-NonInteractive", "-WindowStyle", "Hidden", "-Command", ps],
233
+ {
234
+ // Run from a neutral dir, NOT the inherited install dir — otherwise the
235
+ // app folder is this PowerShell's cwd and Windows refuses to delete it.
236
+ cwd: tmpdir(),
237
+ stdin: "ignore",
238
+ stdout: "ignore",
239
+ stderr: "ignore",
240
+ },
241
+ ).unref();
230
242
  } else {
231
243
  const runningApp = join(this.#resourcesDir()!, "..", "..");
232
244
  const script = [