Skip to content

Commit 9dfcda0

Browse files
author
beyondkmp
committed
get file list by 7z
1 parent 5170902 commit 9dfcda0

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

test/src/helpers/packTester.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,28 @@ async function checkMacResult(packager: Packager, packagerOptions: PackagerOptio
376376
}
377377
}
378378

379+
async function listNupkgContents(nupkgPath: string) {
380+
const { exec } = require("child_process")
381+
const util = require("util")
382+
const execPromise = util.promisify(exec)
383+
try {
384+
const { stdout, stderr } = await execPromise(`7z l -slt "${nupkgPath}"`)
385+
if (stderr) {
386+
console.error("7z command error:", stderr)
387+
}
388+
389+
const files = stdout
390+
.split("\n")
391+
.filter((line: string) => line.startsWith("Path = "))
392+
.map((line: string) => line.replace("Path = ", "").trim())
393+
.filter((path: string) => path !== "")
394+
395+
return files
396+
} catch (err) {
397+
throw new Error(`run 7z fail `)
398+
}
399+
}
400+
379401
async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOptions, artifacts: Array<ArtifactCreated>, nameToTarget: Map<string, Target>) {
380402
const appInfo = packager.appInfo
381403
let squirrel = false
@@ -390,13 +412,10 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
390412
}
391413

392414
const packageFile = artifacts.find(it => it.file.endsWith("-full.nupkg"))!.file
393-
const unZipper = new DecompressZip(packageFile)
394-
const fileDescriptors = await unZipper.getFiles()
395-
396-
// we test app-update.yml separately, don't want to complicate general assert (yes, it is not good that we write app-update.yml for squirrel.windows if we build nsis and squirrel.windows in parallel, but as squirrel.windows is deprecated, it is ok)
415+
const rawFiles: string[] = await listNupkgContents(packageFile)
397416
const files = pathSorter(
398-
fileDescriptors
399-
.map(it => toSystemIndependentPath(it.path))
417+
rawFiles
418+
.map(it => toSystemIndependentPath(it))
400419
.filter(
401420
it =>
402421
(!it.startsWith("lib/net45/locales/") || it === "lib/net45/locales/en-US.pak") && !it.endsWith(".psmdcp") && !it.endsWith("app-update.yml") && !it.includes("/inspector/")
@@ -406,6 +425,8 @@ async function checkWindowsResult(packager: Packager, checkOptions: AssertPackOp
406425
expect(files).toMatchSnapshot()
407426

408427
if (checkOptions == null) {
428+
const unZipper = new DecompressZip(packageFile)
429+
const fileDescriptors = await unZipper.getFiles()
409430
await unZipper.extractFile(fileDescriptors.filter(it => it.path === "TestApp.nuspec")[0], {
410431
path: path.dirname(packageFile),
411432
})

0 commit comments

Comments
 (0)