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

chore: consolidate 7zip-bin chmod logic #7930

Merged
merged 7 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/chilled-apricots-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"app-builder-lib": patch
"builder-util": patch
"electron-builder-squirrel-windows": patch
---

chore: consolidating usages of `7zip-bin` to builder-util-runtime so as to execute `chmod` logic _always_
1 change: 0 additions & 1 deletion packages/app-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "~5.2.0",
"@develar/schema-utils": "~2.6.5",
"@electron/notarize": "2.1.0",
"@electron/osx-sign": "1.0.5",
Expand Down
7 changes: 3 additions & 4 deletions packages/app-builder-lib/src/targets/FpmTarget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { path7za } from "7zip-bin"
import { Arch, executeAppBuilder, getArchSuffix, log, TmpDir, toLinuxArchString, use, serializeToYaml, asArray } from "builder-util"
import { unlinkIfExists } from "builder-util/out/fs"
import { chmod, outputFile, stat } from "fs-extra"
import { outputFile, stat } from "fs-extra"
import { mkdir, readFile } from "fs/promises"
import * as path from "path"
import { smarten } from "../appInfo"
Expand All @@ -18,6 +17,7 @@ import { getLinuxToolsPath } from "./tools"
import { hashFile } from "../util/hash"
import { ArtifactCreated } from "../packagerApi"
import { getAppUpdatePublishConfiguration } from "../publish/PublishManager"
import { getPath7za } from "builder-util"

interface FpmOptions {
name: string
Expand Down Expand Up @@ -234,10 +234,9 @@ export default class FpmTarget extends Target {
return
}

await chmod(path7za, 0o755)
const env = {
...process.env,
SZA_PATH: path7za,
SZA_PATH: await getPath7za(),
SZA_COMPRESSION_LEVEL: packager.compression === "store" ? "0" : "9",
}

Expand Down
13 changes: 5 additions & 8 deletions packages/app-builder-lib/src/targets/archive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { path7za } from "7zip-bin"
import { debug7z, exec, log } from "builder-util"
import { exists, unlinkIfExists } from "builder-util/out/fs"
import { chmod, move } from "fs-extra"
import { move } from "fs-extra"
import * as path from "path"
import { create, CreateOptions, FileOptions } from "tar"
import { TmpDir } from "temp-file"
import { CompressionLevel } from "../core"
import { getLinuxToolsPath } from "./tools"
import { getPath7za } from "builder-util"

/** @internal */
export async function tar(
Expand Down Expand Up @@ -55,9 +55,8 @@ export async function tar(
compression,
})
args.push(outFile, tarFile)
await chmod(path7za, 0o755)
await exec(
path7za,
await getPath7za(),
args,
{
cwd: path.dirname(dirToArchive),
Expand Down Expand Up @@ -221,11 +220,9 @@ export async function archive(format: string, outFile: string, dirToArchive: str
}

try {
if (use7z) {
await chmod(path7za, 0o755)
}
const binary = use7z ? await getPath7za() : "zip"
await exec(
use7z ? path7za : "zip",
binary,
args,
{
cwd: options.withoutDir ? dirToArchive : path.dirname(dirToArchive),
Expand Down
7 changes: 3 additions & 4 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { path7za } from "7zip-bin"
import BluebirdPromise from "bluebird-lst"
import { Arch, asArray, AsyncTaskManager, exec, executeAppBuilder, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use } from "builder-util"
import { Arch, asArray, AsyncTaskManager, exec, executeAppBuilder, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use, getPath7za } from "builder-util"
import { CURRENT_APP_INSTALLER_FILE_NAME, CURRENT_APP_PACKAGE_FILE_NAME, PackageFileInfo, UUID } from "builder-util-runtime"
import { exists, statOrNull, walk } from "builder-util/out/fs"
import _debug from "debug"
import * as fs from "fs"
import { chmod, readFile, stat, unlink } from "fs-extra"
import { readFile, stat, unlink } from "fs-extra"
import * as path from "path"
import { getBinFromUrl } from "../../binDownload"
import { Target } from "../../core"
Expand Down Expand Up @@ -250,7 +249,7 @@ export class NsisTarget extends Target {
await packager.dispatchArtifactCreated(file, this, arch)
packageFiles[Arch[arch]] = fileInfo
}
await chmod(path7za, 0o755)
const path7za = await getPath7za()
const archiveInfo = (await exec(path7za, ["l", file])).trim()
// after adding blockmap data will be "Warnings: 1" in the end of output
const match = /(\d+)\s+\d+\s+\d+\s+files/.exec(archiveInfo)
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"out"
],
"dependencies": {
"@types/debug": "^4.1.6",
"7zip-bin": "~5.2.0",
"@types/debug": "^4.1.6",
"app-builder-bin": "4.0.0",
"bluebird-lst": "^1.0.9",
"builder-util-runtime": "workspace:*",
Expand Down
12 changes: 12 additions & 0 deletions packages/builder-util/src/7za.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { path7x, path7za } from "7zip-bin"
import { chmod } from "fs-extra"

export async function getPath7za(): Promise<string> {
await chmod(path7za, 0o755)
return path7za
}

export async function getPath7x(): Promise<string> {
await chmod(path7x, 0o755)
return path7x
}
8 changes: 4 additions & 4 deletions packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { path7za } from "7zip-bin"
import { appBuilderPath } from "app-builder-bin"
import { safeStringifyJson } from "builder-util-runtime"
import * as chalk from "chalk"
Expand All @@ -7,10 +6,10 @@ import { spawn as _spawn } from "cross-spawn"
import { createHash } from "crypto"
import _debug from "debug"
import { dump } from "js-yaml"
import { chmod } from "fs-extra"
import * as path from "path"
import { debug, log } from "./log"
import { install as installSourceMap } from "source-map-support"
import { getPath7za } from "./7za"

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

export { deepAssign } from "./deepAssign"

export { getPath7za, getPath7x } from "./7za"

export const debug7z = _debug("electron-builder:7z")

export function serializeToYaml(object: any, skipInvalid = false, noRefs = false) {
Expand Down Expand Up @@ -357,10 +358,9 @@ export async function executeAppBuilder(
maxRetries = 0
): Promise<string> {
const command = appBuilderPath
await chmod(path7za, 0o755)
const env: any = {
...process.env,
SZA_PATH: path7za,
SZA_PATH: await getPath7za(),
FORCE_COLOR: chalk.level === 0 ? "0" : "1",
}
const cacheEnv = process.env.ELECTRON_BUILDER_CACHE
Expand Down
3 changes: 0 additions & 3 deletions packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,5 @@
"@types/archiver": "5.3.1",
"@types/fs-extra": "9.0.13"
},
"optionalDependencies": {
"7zip-bin": "~5.2.0"
},
"types": "./out/SquirrelWindowsTarget.d.ts"
}
10 changes: 4 additions & 6 deletions packages/electron-builder-squirrel-windows/src/squirrelPack.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { path7za } from "7zip-bin"
import { Arch, debug, exec, log, spawn, isEmptyOrSpaces } from "builder-util"
import { Arch, debug, exec, log, spawn, isEmptyOrSpaces, getPath7za } from "builder-util"
import { copyFile, walk } from "builder-util/out/fs"
import { compute7zCompressArgs } from "app-builder-lib/out/targets/archive"
import { execWine, prepareWindowsExecutableArgs as prepareArgs } from "app-builder-lib/out/wine"
import { WinPackager } from "app-builder-lib/out/winPackager"
import { chmod, createWriteStream, stat, unlink, writeFile } from "fs-extra"
import { createWriteStream, stat, unlink, writeFile } from "fs-extra"
import * as path from "path"
import * as archiver from "archiver"
import * as fs from "fs/promises"
Expand Down Expand Up @@ -126,7 +125,7 @@ export class SquirrelBuilder {

private async createEmbeddedArchiveFile(nupkgPath: string, dirToArchive: string) {
const embeddedArchiveFile = await this.packager.getTempFile("setup.zip")
await chmod(path7za, 0o755)
const path7za = await getPath7za()
await exec(
path7za,
compute7zCompressArgs("zip", {
Expand Down Expand Up @@ -230,11 +229,10 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str
}

async function execSw(options: SquirrelOptions, args: Array<string>) {
await chmod(path7za, 0o755)
return exec(process.platform === "win32" ? path.join(options.vendorPath, "Update.com") : "mono", prepareArgs(args, path.join(options.vendorPath, "Update-Mono.exe")), {
env: {
...process.env,
SZA_PATH: path7za,
SZA_PATH: await getPath7za(),
},
})
}
Expand Down
13 changes: 2 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"7zip-bin": "~5.2.0",
"@electron/osx-sign": "^1.0.4",
"@jest/core": "^27.5.1",
"app-builder-lib": "workspace:*",
Expand Down
10 changes: 4 additions & 6 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { path7x, path7za } from "7zip-bin"
import { addValue, deepAssign, exec, log, spawn } from "builder-util"
import { addValue, deepAssign, exec, log, spawn, getPath7x, getPath7za } from "builder-util"
import { CancellationToken, UpdateFileInfo } from "builder-util-runtime"
import { copyDir, FileCopier, USE_HARD_LINKS, walk } from "builder-util/out/fs"
import { executeFinally } from "builder-util/out/promise"
Expand All @@ -10,7 +9,7 @@ import { computeArchToTargetNamesMap } from "app-builder-lib/out/targets/targetF
import { getLinuxToolsPath } from "app-builder-lib/out/targets/tools"
import { convertVersion } from "electron-builder-squirrel-windows/out/squirrelPack"
import { PublishPolicy } from "electron-publish"
import { chmod, emptyDir, writeJson } from "fs-extra"
import { emptyDir, writeJson } from "fs-extra"
import * as fs from "fs/promises"
import { load } from "js-yaml"
import * as path from "path"
Expand Down Expand Up @@ -438,12 +437,11 @@ export async function getTarExecutable() {
}

async function getContents(packageFile: string) {
await chmod(path7x, 0o755)
const result = await execShell(`ar p '${packageFile}' data.tar.xz | ${await getTarExecutable()} -t -I'${path7x}'`, {
const result = await execShell(`ar p '${packageFile}' data.tar.xz | ${await getTarExecutable()} -t -I'${await getPath7x()}'`, {
maxBuffer: 10 * 1024 * 1024,
env: {
...process.env,
SZA_PATH: path7za,
SZA_PATH: await getPath7za(),
},
})

Expand Down
Loading