Skip to content

Commit

Permalink
feat: migrate to electron/asar package (electron-userland#8570)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaietta authored Oct 12, 2024
1 parent 8cc2b42 commit c848430
Show file tree
Hide file tree
Showing 18 changed files with 2,602 additions and 1,764 deletions.
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.7.0",
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"

/** @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

0 comments on commit c848430

Please sign in to comment.