Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to electron/asar package #8570

Merged
merged 11 commits into from
Oct 12, 2024
5 changes: 5 additions & 0 deletions .changeset/ninety-candles-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": minor
---

feat: migrate to official `electron/asar` packaging
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest TEST_FILES",
"runtimeExecutable": "pnpm",
"program": "ci:test",
"console": "integratedTerminal",
"internalConsoleOptions": "openOnFirstSessionStart",
"env": {
"TEST_FILES": "BuildTest"
}
}
]
}
1 change: 1 addition & 0 deletions packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"@develar/schema-utils": "~2.6.5",
"@electron/asar": "^3.2.13",
"@electron/notarize": "2.5.0",
"@electron/osx-sign": "1.3.1",
"@electron/rebuild": "3.6.1",
Expand Down
35 changes: 10 additions & 25 deletions packages/app-builder-lib/src/asar/asarFileChecker.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
import { statOrNull } from "builder-util"
import { Node, readAsar } from "./asar"
import * as asar from "@electron/asar"
import { FilesystemEntry, FilesystemFileEntry } from "@electron/asar/lib/filesystem"

beyondkmp marked this conversation as resolved.
Show resolved Hide resolved
/** @internal */
export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
export function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
function error(text: string) {
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`)
}

let fs
let stat: FilesystemEntry
try {
fs = await readAsar(asarFile)
stat = asar.statFile(asarFile, relativeFile, false)
} catch (e: any) {
throw error(`is corrupted: ${e}`)
}

let stat: Node | null
try {
stat = fs.getFile(relativeFile)
} catch (_e: any) {
const fileStat = await statOrNull(asarFile)
if (fileStat == null) {
throw error(`does not exist. Seems like a wrong configuration.`)
if (e.message.includes("Cannot read properties of undefined (reading 'link')")) {
throw error("does not exist. Seems like a wrong configuration.")
}

// asar throws error on access to undefined object (info.link)
stat = null
}

if (stat == null) {
throw error(`does not exist. Seems like a wrong configuration.`)
throw error(`is corrupted: ${e}`)
}
if (stat.size === 0) {
if ((stat as FilesystemFileEntry).size === 0) {
throw error(`is corrupted: size 0`)
}
return stat
}
Loading
Loading