|
1 | 1 | import { Arch, log } from "builder-util"
|
2 | 2 | import { PackageFileInfo } from "builder-util-runtime"
|
3 | 3 | import { getBinFromUrl, getBinFromCustomLoc } from "../../binDownload"
|
4 |
| -import { copyFile } from "builder-util/out/fs" |
| 4 | +import { copyFile, dirSize } from "builder-util/out/fs" |
5 | 5 | import * as path from "path"
|
6 | 6 | import { getTemplatePath } from "../../util/pathManager"
|
7 | 7 | import { NsisTarget } from "./NsisTarget"
|
@@ -39,30 +39,42 @@ export const NSIS_PATH = () => {
|
39 | 39 | })
|
40 | 40 | }
|
41 | 41 |
|
| 42 | +export interface PackArchResult { |
| 43 | + fileInfo: PackageFileInfo |
| 44 | + unpackedSize: number |
| 45 | +} |
| 46 | + |
42 | 47 | export class AppPackageHelper {
|
43 |
| - private readonly archToFileInfo = new Map<Arch, Promise<PackageFileInfo>>() |
| 48 | + private readonly archToResult = new Map<Arch, Promise<PackArchResult>>() |
44 | 49 | private readonly infoToIsDelete = new Map<PackageFileInfo, boolean>()
|
45 | 50 |
|
46 | 51 | /** @private */
|
47 | 52 | refCount = 0
|
48 | 53 |
|
49 | 54 | constructor(private readonly elevateHelper: CopyElevateHelper) {}
|
50 | 55 |
|
51 |
| - async packArch(arch: Arch, target: NsisTarget): Promise<PackageFileInfo> { |
52 |
| - let infoPromise = this.archToFileInfo.get(arch) |
53 |
| - if (infoPromise == null) { |
| 56 | + async packArch(arch: Arch, target: NsisTarget): Promise<PackArchResult> { |
| 57 | + let resultPromise = this.archToResult.get(arch) |
| 58 | + if (resultPromise == null) { |
54 | 59 | const appOutDir = target.archs.get(arch)!
|
55 |
| - infoPromise = this.elevateHelper.copy(appOutDir, target).then(() => target.buildAppPackage(appOutDir, arch)) |
56 |
| - this.archToFileInfo.set(arch, infoPromise) |
| 60 | + resultPromise = this.elevateHelper |
| 61 | + .copy(appOutDir, target) |
| 62 | + .then(() => target.buildAppPackage(appOutDir, arch)) |
| 63 | + .then(async fileInfo => ({ |
| 64 | + fileInfo, |
| 65 | + unpackedSize: await dirSize(appOutDir), |
| 66 | + })) |
| 67 | + this.archToResult.set(arch, resultPromise) |
57 | 68 | }
|
58 | 69 |
|
59 |
| - const info = await infoPromise |
| 70 | + const result = await resultPromise |
| 71 | + const { fileInfo: info } = result |
60 | 72 | if (target.isWebInstaller) {
|
61 | 73 | this.infoToIsDelete.set(info, false)
|
62 | 74 | } else if (!this.infoToIsDelete.has(info)) {
|
63 | 75 | this.infoToIsDelete.set(info, true)
|
64 | 76 | }
|
65 |
| - return info |
| 77 | + return result |
66 | 78 | }
|
67 | 79 |
|
68 | 80 | async finishBuild(): Promise<any> {
|
|
0 commit comments