diff --git a/.changeset/chilled-apricots-sit.md b/.changeset/chilled-apricots-sit.md new file mode 100644 index 00000000000..94da1d46c5f --- /dev/null +++ b/.changeset/chilled-apricots-sit.md @@ -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_ diff --git a/packages/app-builder-lib/package.json b/packages/app-builder-lib/package.json index 17070968526..d9a4f4460a6 100644 --- a/packages/app-builder-lib/package.json +++ b/packages/app-builder-lib/package.json @@ -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", diff --git a/packages/app-builder-lib/src/targets/FpmTarget.ts b/packages/app-builder-lib/src/targets/FpmTarget.ts index 9d848dbf40c..bdd83080ced 100644 --- a/packages/app-builder-lib/src/targets/FpmTarget.ts +++ b/packages/app-builder-lib/src/targets/FpmTarget.ts @@ -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" @@ -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 @@ -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", } diff --git a/packages/app-builder-lib/src/targets/archive.ts b/packages/app-builder-lib/src/targets/archive.ts index 086868a9de6..3bf60f82164 100644 --- a/packages/app-builder-lib/src/targets/archive.ts +++ b/packages/app-builder-lib/src/targets/archive.ts @@ -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( @@ -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), @@ -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), diff --git a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts index 7bda409453e..8b4d33cdd26 100644 --- a/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/app-builder-lib/src/targets/nsis/NsisTarget.ts @@ -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" @@ -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) diff --git a/packages/builder-util/package.json b/packages/builder-util/package.json index 6eb6763dc1d..da2264a8010 100644 --- a/packages/builder-util/package.json +++ b/packages/builder-util/package.json @@ -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:*", diff --git a/packages/builder-util/src/7za.ts b/packages/builder-util/src/7za.ts new file mode 100644 index 00000000000..b8fa1c59342 --- /dev/null +++ b/packages/builder-util/src/7za.ts @@ -0,0 +1,12 @@ +import { path7x, path7za } from "7zip-bin" +import { chmod } from "fs-extra" + +export async function getPath7za(): Promise { + await chmod(path7za, 0o755) + return path7za +} + +export async function getPath7x(): Promise { + await chmod(path7x, 0o755) + return path7x +} diff --git a/packages/builder-util/src/util.ts b/packages/builder-util/src/util.ts index a54cab954b1..9003a6504af 100644 --- a/packages/builder-util/src/util.ts +++ b/packages/builder-util/src/util.ts @@ -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" @@ -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() @@ -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) { @@ -357,10 +358,9 @@ export async function executeAppBuilder( maxRetries = 0 ): Promise { 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 diff --git a/packages/electron-builder-squirrel-windows/package.json b/packages/electron-builder-squirrel-windows/package.json index 34920d86575..1fe21cba53b 100644 --- a/packages/electron-builder-squirrel-windows/package.json +++ b/packages/electron-builder-squirrel-windows/package.json @@ -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" } diff --git a/packages/electron-builder-squirrel-windows/src/squirrelPack.ts b/packages/electron-builder-squirrel-windows/src/squirrelPack.ts index c7a920de206..6bc348aa944 100644 --- a/packages/electron-builder-squirrel-windows/src/squirrelPack.ts +++ b/packages/electron-builder-squirrel-windows/src/squirrelPack.ts @@ -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" @@ -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", { @@ -230,11 +229,10 @@ async function pack(options: SquirrelOptions, directory: string, updateFile: str } async function execSw(options: SquirrelOptions, args: Array) { - 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(), }, }) } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 23573c6e5eb..71dce96b222 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -101,9 +101,6 @@ importers: packages/app-builder-lib: dependencies: - 7zip-bin: - specifier: ~5.2.0 - version: 5.2.0 '@develar/schema-utils': specifier: ~2.6.5 version: 2.6.5 @@ -449,10 +446,6 @@ importers: fs-extra: specifier: ^10.1.0 version: 10.1.0 - optionalDependencies: - 7zip-bin: - specifier: ~5.2.0 - version: 5.2.0 devDependencies: '@types/archiver': specifier: 5.3.1 @@ -558,9 +551,6 @@ importers: test: dependencies: - 7zip-bin: - specifier: ~5.2.0 - version: 5.2.0 '@electron/osx-sign': specifier: ^1.0.4 version: 1.0.5 @@ -657,6 +647,7 @@ packages: /7zip-bin@5.2.0: resolution: {integrity: sha512-ukTPVhqG4jNzMro2qA9HSCSSVJN3aN7tlb+hfqYCt3ER0yWroeA2VR38MNrOHLQ/cVj+DaIMad0kFCtWWowh/A==} + requiresBuild: true dev: false /@aashutoshrathi/word-wrap@1.2.6: @@ -2746,7 +2737,7 @@ packages: /@types/fs-extra@9.0.13: resolution: {integrity: sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA==} dependencies: - '@types/node': 16.11.43 + '@types/node': 16.18.55 /@types/glob@8.1.0: resolution: {integrity: sha512-IO+MJPVhoqz+28h1qLAcBEH2+xHMK6MTyHJc7MTnnYb6wsoLR29POVGJ7LycmVXIqyy/4/2ShP5sUwTXuOwb/w==} diff --git a/test/package.json b/test/package.json index eb3f2d848bf..e158cb2c47a 100644 --- a/test/package.json +++ b/test/package.json @@ -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:*", diff --git a/test/src/helpers/packTester.ts b/test/src/helpers/packTester.ts index 36727635dbc..be636ab9554 100644 --- a/test/src/helpers/packTester.ts +++ b/test/src/helpers/packTester.ts @@ -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" @@ -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" @@ -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(), }, })