Skip to content

Commit

Permalink
use adm-zip to decode
Browse files Browse the repository at this point in the history
  • Loading branch information
beyondkmp committed Nov 3, 2024
1 parent 10931d5 commit 7733641
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 66 deletions.
2 changes: 2 additions & 0 deletions docker/wine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ARG IMAGE_VERSION=latest
FROM electronuserland/builder:$IMAGE_VERSION

ENV WINEARCH=win64
ENV WINEPREFIX=/root/.wine64
RUN dpkg --add-architecture i386 && \
curl -Lo /usr/share/keyrings/winehq.asc https://dl.winehq.org/wine-builds/winehq.key && \
echo 'deb [signed-by=/usr/share/keyrings/winehq.asc] https://dl.winehq.org/wine-builds/ubuntu/ focal main' > /etc/apt/sources.list.d/winehq.list && \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { sanitizeFileName } from "builder-util/out/filename"
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"
import { getBin } from "app-builder-lib/out/binDownload"
import { WinPackager } from "app-builder-lib/out/winPackager"
import * as path from "path"
import * as fs from "fs"
Expand Down Expand Up @@ -110,13 +109,7 @@ export default class SquirrelWindowsTarget extends Target {
const appInfo = packager.appInfo
const projectUrl = await appInfo.computePackageUrl()
const appName = this.appName
const vendorDirectory =
this.options.vendorDirectory ||
(await getBin(
"Squirrel.Windows-2.0.1",
"https://github.com/beyondkmp/electron-builder-binaries/releases/download/Squirrel.Windows-2.0.1/Squirrel.Windows-2.0.1.7z",
"IGIosfkJ25mhpGS6LREBbaSq4uysb3lwXUzt0psM9UBeaVvpOfDz0ZUqat6WAaji35n0oXJqw63WXT24/7ksLA=="
))
const vendorDirectory = this.options.vendorDirectory
const options: SquirrelOptions = {
name: appName,
appId: this.options.useAppIdAsId ? appInfo.id : appName,
Expand All @@ -133,11 +126,11 @@ export default class SquirrelWindowsTarget extends Target {
...(this.options as any),
}

options.windowsSign = {
hookFunction: async (file: string) => {
await packager.sign(file)
},
}
// options.windowsSign = {
// hookFunction: async (file: string) => {
// await packager.sign(file)
// },
// }

if (isEmptyOrSpaces(options.description)) {
options.description = this.options.name || appInfo.productName
Expand Down
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

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

5 changes: 4 additions & 1 deletion test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"stat-mode": "^1.0.0",
"temp-file": "^3.4.0",
"yargs": "^17.6.2",
"electron-winstaller": "5.4.0"
"electron-winstaller": "5.4.0",
"adm-zip": "0.5.16",
"iconv-lite": "0.6.3"
},
"devDependencies": {
"@babel/core": "7.24.9",
Expand All @@ -37,6 +39,7 @@
"@types/jest": "^26.0.23",
"@types/js-yaml": "^4.0.1",
"@types/semver": "^7.3.13",
"@types/adm-zip": "0.5.6",
"babel-jest": "^29.7.0",
"esbuild": "^0.12.14",
"esbuild-jest": "^0.5.0",
Expand Down
64 changes: 12 additions & 52 deletions test/src/helpers/packTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { emptyDir, writeJson } from "fs-extra"
import * as fs from "fs/promises"
import { load } from "js-yaml"
import * as path from "path"
import AdmZip from "adm-zip"
import { decode } from "iconv-lite"
import { promisify } from "util"
import pathSorter from "path-sort"
import { TmpDir } from "temp-file"
Expand Down Expand Up @@ -375,55 +377,6 @@ async function checkMacResult(packager: Packager, packagerOptions: PackagerOptio
}
}

async function listNupkgContents(nupkgPath: string) {
try {
const { exec } = require("child_process")
const util = require("util")
const execPromise = util.promisify(exec)
let zPath = await getPath7za()
const { stdout, stderr } = await execPromise(`${zPath} l -slt "${nupkgPath}"`)
if (stderr) {
console.error("7z command error:", stderr)
}

const lines = stdout.split("\n")
const files = []

for (let i = 0; i < lines.length; i++) {
if (lines[i].startsWith("Path = ")) {
const path = lines[i].replace("Path = ", "").trim()
const nextLine = lines[i + 1]
if (nextLine && nextLine.startsWith("Folder = -")) {
files.push(path)
}
}
}

return files
} catch (error) {
throw new Error(`run 7z failed: ${error}`)
}
}

async function getFileContentFrom7Zip(zipFilePath: string, fileToRead: string): Promise<string> {
try {
const { exec } = require("child_process")
const util = require("util")
const execPromise = util.promisify(exec)
let zPath = await getPath7za()
const command = `${zPath} e -so "${zipFilePath}" "${fileToRead}"`

const { stdout, stderr } = await execPromise(command, { encoding: "utf8", maxBuffer: 50 * 1024 * 1024 })

if (stderr) {
throw new Error(`Stderr: ${stderr}`)
}
return stdout
} catch (error) {
throw new Error(`Error: ${error}`)
}
}

async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>, nameToTarget: Map<string, Target>) {
const appInfo = packager.appInfo
let squirrel = false
Expand All @@ -438,7 +391,15 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
}

const packageFile = artifacts.find(it => it.file.endsWith("-full.nupkg"))!.file
const allFiles: string[] = await listNupkgContents(packageFile)
const zip = new AdmZip(packageFile)
const zipEntries = zip.getEntries()
const allFiles: string[] = []
zipEntries.forEach(function (zipEntry) {
let name = decode(zipEntry.rawEntryName, "cp437")
if (!name.endsWith("/")) {
allFiles.push(name)
}
})
const files = pathSorter(
allFiles
.map((it: string) => toSystemIndependentPath(it))
Expand All @@ -451,9 +412,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
expect(files).toMatchSnapshot()

if (checkOptions == null) {
const expectedSpec = (await getFileContentFrom7Zip(packageFile, "TestApp.nuspec")).replace(/\r\n/g, "\n")
const expectedSpec = zip.readAsText("TestApp.nuspec").replace(/\r\n/g, "\n")

// console.log(expectedSpec)
expect(expectedSpec).toEqual(`<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
Expand Down
Binary file added wine-stable-amd64_6.0.4~focal-1_amd64.deb
Binary file not shown.

0 comments on commit 7733641

Please sign in to comment.