Skip to content

Commit e4d6be8

Browse files
authored
chore: consolidate 7zip-bin chmod logic into builder-util (#7930)
1 parent f7aacab commit e4d6be8

13 files changed

Lines changed: 45 additions & 49 deletions

File tree

.changeset/chilled-apricots-sit.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"app-builder-lib": patch
3+
"builder-util": patch
4+
"electron-builder-squirrel-windows": patch
5+
---
6+
7+
chore: consolidating usages of `7zip-bin` to builder-util-runtime so as to execute `chmod` logic _always_

packages/app-builder-lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"bugs": "https://github.com/electron-userland/electron-builder/issues",
4747
"homepage": "https://github.com/electron-userland/electron-builder",
4848
"dependencies": {
49-
"7zip-bin": "~5.2.0",
5049
"@develar/schema-utils": "~2.6.5",
5150
"@electron/notarize": "2.1.0",
5251
"@electron/osx-sign": "1.0.5",

packages/app-builder-lib/src/targets/FpmTarget.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { path7za } from "7zip-bin"
21
import { Arch, executeAppBuilder, getArchSuffix, log, TmpDir, toLinuxArchString, use, serializeToYaml, asArray } from "builder-util"
32
import { unlinkIfExists } from "builder-util/out/fs"
4-
import { chmod, outputFile, stat } from "fs-extra"
3+
import { outputFile, stat } from "fs-extra"
54
import { mkdir, readFile } from "fs/promises"
65
import * as path from "path"
76
import { smarten } from "../appInfo"
@@ -18,6 +17,7 @@ import { getLinuxToolsPath } from "./tools"
1817
import { hashFile } from "../util/hash"
1918
import { ArtifactCreated } from "../packagerApi"
2019
import { getAppUpdatePublishConfiguration } from "../publish/PublishManager"
20+
import { getPath7za } from "builder-util"
2121

2222
interface FpmOptions {
2323
name: string
@@ -234,10 +234,9 @@ export default class FpmTarget extends Target {
234234
return
235235
}
236236

237-
await chmod(path7za, 0o755)
238237
const env = {
239238
...process.env,
240-
SZA_PATH: path7za,
239+
SZA_PATH: await getPath7za(),
241240
SZA_COMPRESSION_LEVEL: packager.compression === "store" ? "0" : "9",
242241
}
243242

packages/app-builder-lib/src/targets/archive.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { path7za } from "7zip-bin"
21
import { debug7z, exec, log } from "builder-util"
32
import { exists, unlinkIfExists } from "builder-util/out/fs"
4-
import { chmod, move } from "fs-extra"
3+
import { move } from "fs-extra"
54
import * as path from "path"
65
import { create, CreateOptions, FileOptions } from "tar"
76
import { TmpDir } from "temp-file"
87
import { CompressionLevel } from "../core"
98
import { getLinuxToolsPath } from "./tools"
9+
import { getPath7za } from "builder-util"
1010

1111
/** @internal */
1212
export async function tar(
@@ -55,9 +55,8 @@ export async function tar(
5555
compression,
5656
})
5757
args.push(outFile, tarFile)
58-
await chmod(path7za, 0o755)
5958
await exec(
60-
path7za,
59+
await getPath7za(),
6160
args,
6261
{
6362
cwd: path.dirname(dirToArchive),
@@ -221,11 +220,9 @@ export async function archive(format: string, outFile: string, dirToArchive: str
221220
}
222221

223222
try {
224-
if (use7z) {
225-
await chmod(path7za, 0o755)
226-
}
223+
const binary = use7z ? await getPath7za() : "zip"
227224
await exec(
228-
use7z ? path7za : "zip",
225+
binary,
229226
args,
230227
{
231228
cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),

packages/app-builder-lib/src/targets/nsis/NsisTarget.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { path7za } from "7zip-bin"
21
import BluebirdPromise from "bluebird-lst"
3-
import { Arch, asArray, AsyncTaskManager, exec, executeAppBuilder, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use } from "builder-util"
2+
import { Arch, asArray, AsyncTaskManager, exec, executeAppBuilder, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use, getPath7za } from "builder-util"
43
import { CURRENT_APP_INSTALLER_FILE_NAME, CURRENT_APP_PACKAGE_FILE_NAME, PackageFileInfo, UUID } from "builder-util-runtime"
54
import { exists, statOrNull, walk } from "builder-util/out/fs"
65
import _debug from "debug"
76
import * as fs from "fs"
8-
import { chmod, readFile, stat, unlink } from "fs-extra"
7+
import { readFile, stat, unlink } from "fs-extra"
98
import * as path from "path"
109
import { getBinFromUrl } from "../../binDownload"
1110
import { Target } from "../../core"
@@ -250,7 +249,7 @@ export class NsisTarget extends Target {
250249
await packager.dispatchArtifactCreated(file, this, arch)
251250
packageFiles[Arch[arch]] = fileInfo
252251
}
253-
await chmod(path7za, 0o755)
252+
const path7za = await getPath7za()
254253
const archiveInfo = (await exec(path7za, ["l", file])).trim()
255254
// after adding blockmap data will be "Warnings: 1" in the end of output
256255
const match = /(\d+)\s+\d+\s+\d+\s+files/.exec(archiveInfo)

packages/builder-util/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"out"
1616
],
1717
"dependencies": {
18-
"@types/debug": "^4.1.6",
1918
"7zip-bin": "~5.2.0",
19+
"@types/debug": "^4.1.6",
2020
"app-builder-bin": "4.0.0",
2121
"bluebird-lst": "^1.0.9",
2222
"builder-util-runtime": "workspace:*",

packages/builder-util/src/7za.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { path7x, path7za } from "7zip-bin"
2+
import { chmod } from "fs-extra"
3+
4+
export async function getPath7za(): Promise<string> {
5+
await chmod(path7za, 0o755)
6+
return path7za
7+
}
8+
9+
export async function getPath7x(): Promise<string> {
10+
await chmod(path7x, 0o755)
11+
return path7x
12+
}

packages/builder-util/src/util.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { path7za } from "7zip-bin"
21
import { appBuilderPath } from "app-builder-bin"
32
import { safeStringifyJson } from "builder-util-runtime"
43
import * as chalk from "chalk"
@@ -7,10 +6,10 @@ import { spawn as _spawn } from "cross-spawn"
76
import { createHash } from "crypto"
87
import _debug from "debug"
98
import { dump } from "js-yaml"
10-
import { chmod } from "fs-extra"
119
import * as path from "path"
1210
import { debug, log } from "./log"
1311
import { install as installSourceMap } from "source-map-support"
12+
import { getPath7za } from "./7za"
1413

1514
if (process.env.JEST_WORKER_ID == null) {
1615
installSourceMap()
@@ -28,6 +27,8 @@ export { asArray } from "builder-util-runtime"
2827

2928
export { deepAssign } from "./deepAssign"
3029

30+
export { getPath7za, getPath7x } from "./7za"
31+
3132
export const debug7z = _debug("electron-builder:7z")
3233

3334
export function serializeToYaml(object: any, skipInvalid = false, noRefs = false) {
@@ -357,10 +358,9 @@ export async function executeAppBuilder(
357358
maxRetries = 0
358359
): Promise<string> {
359360
const command = appBuilderPath
360-
await chmod(path7za, 0o755)
361361
const env: any = {
362362
...process.env,
363-
SZA_PATH: path7za,
363+
SZA_PATH: await getPath7za(),
364364
FORCE_COLOR: chalk.level === 0 ? "0" : "1",
365365
}
366366
const cacheEnv = process.env.ELECTRON_BUILDER_CACHE

packages/electron-builder-squirrel-windows/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,5 @@
2424
"@types/archiver": "5.3.1",
2525
"@types/fs-extra": "9.0.13"
2626
},
27-
"optionalDependencies": {
28-
"7zip-bin": "~5.2.0"
29-
},
3027
"types": "./out/SquirrelWindowsTarget.d.ts"
3128
}

packages/electron-builder-squirrel-windows/src/squirrelPack.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { path7za } from "7zip-bin"
2-
import { Arch, debug, exec, log, spawn, isEmptyOrSpaces } from "builder-util"
1+
import { Arch, debug, exec, log, spawn, isEmptyOrSpaces, getPath7za } from "builder-util"
32
import { copyFile, walk } from "builder-util/out/fs"
43
import { compute7zCompressArgs } from "app-builder-lib/out/targets/archive"
54
import { execWine, prepareWindowsExecutableArgs as prepareArgs } from "app-builder-lib/out/wine"
65
import { WinPackager } from "app-builder-lib/out/winPackager"
7-
import { chmod, createWriteStream, stat, unlink, writeFile } from "fs-extra"
6+
import { createWriteStream, stat, unlink, writeFile } from "fs-extra"
87
import * as path from "path"
98
import * as archiver from "archiver"
109
import * as fs from "fs/promises"
@@ -126,7 +125,7 @@ export class SquirrelBuilder {
126125

127126
private async createEmbeddedArchiveFile(nupkgPath: string, dirToArchive: string) {
128127
const embeddedArchiveFile = await this.packager.getTempFile("setup.zip")
129-
await chmod(path7za, 0o755)
128+
const path7za = await getPath7za()
130129
await exec(
131130
path7za,
132131
compute7zCompressArgs("zip", {
@@ -230,11 +229,10 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
230229
}
231230

232231
async function execSw(options: SquirrelOptions, args: Array<string>) {
233-
await chmod(path7za, 0o755)
234232
return exec(process.platform === "win32" ? path.join(options.vendorPath, "Update.com") : "mono", prepareArgs(args, path.join(options.vendorPath, "Update-Mono.exe")), {
235233
env: {
236234
...process.env,
237-
SZA_PATH: path7za,
235+
SZA_PATH: await getPath7za(),
238236
},
239237
})
240238
}

0 commit comments

Comments
 (0)