Skip to content

Commit c848430

Browse files
authored
feat: migrate to electron/asar package (#8570)
1 parent 8cc2b42 commit c848430

18 files changed

+2602
-1764
lines changed

.changeset/ninety-candles-laugh.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": minor
3+
---
4+
5+
feat: migrate to official `electron/asar` packaging

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Jest TEST_FILES",
8+
"runtimeExecutable": "pnpm",
9+
"program": "ci:test",
10+
"console": "integratedTerminal",
11+
"internalConsoleOptions": "openOnFirstSessionStart",
12+
"env": {
13+
"TEST_FILES": "BuildTest"
14+
}
15+
}
16+
]
17+
}

packages/app-builder-lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"homepage": "https://github.com/electron-userland/electron-builder",
4848
"dependencies": {
4949
"@develar/schema-utils": "~2.6.5",
50+
"@electron/asar": "^3.2.13",
5051
"@electron/notarize": "2.5.0",
5152
"@electron/osx-sign": "1.3.1",
5253
"@electron/rebuild": "3.7.0",
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
import { statOrNull } from "builder-util"
2-
import { Node, readAsar } from "./asar"
1+
import * as asar from "@electron/asar"
2+
import { FilesystemEntry, FilesystemFileEntry } from "@electron/asar/lib/filesystem"
33

4-
/** @internal */
5-
export async function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
4+
export function checkFileInArchive(asarFile: string, relativeFile: string, messagePrefix: string) {
65
function error(text: string) {
76
return new Error(`${messagePrefix} "${relativeFile}" in the "${asarFile}" ${text}`)
87
}
9-
10-
let fs
8+
let stat: FilesystemEntry
119
try {
12-
fs = await readAsar(asarFile)
10+
stat = asar.statFile(asarFile, relativeFile, false)
1311
} catch (e: any) {
14-
throw error(`is corrupted: ${e}`)
15-
}
16-
17-
let stat: Node | null
18-
try {
19-
stat = fs.getFile(relativeFile)
20-
} catch (_e: any) {
21-
const fileStat = await statOrNull(asarFile)
22-
if (fileStat == null) {
23-
throw error(`does not exist. Seems like a wrong configuration.`)
12+
if (e.message.includes("Cannot read properties of undefined (reading 'link')")) {
13+
throw error("does not exist. Seems like a wrong configuration.")
2414
}
25-
26-
// asar throws error on access to undefined object (info.link)
27-
stat = null
28-
}
29-
30-
if (stat == null) {
31-
throw error(`does not exist. Seems like a wrong configuration.`)
15+
throw error(`is corrupted: ${e}`)
3216
}
33-
if (stat.size === 0) {
17+
if ((stat as FilesystemFileEntry).size === 0) {
3418
throw error(`is corrupted: size 0`)
3519
}
20+
return stat
3621
}

0 commit comments

Comments
 (0)