From d84423bbef6ef527d9e6ba72ee03aadbdc774ddf Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Thu, 6 Nov 2025 13:50:06 -0800 Subject: [PATCH 1/2] fix: correctly log `MakeAppx` errors --- src/bin.ts | 208 ++++++++++++++++++++++++++--------------------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 8f26757..6550caa 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -1,104 +1,104 @@ -import { sign as windowsSign, SignOptions } from "@electron/windows-sign"; -import { spawn } from 'child_process'; - -import { log } from "./logger"; -import { ProgramOptions } from "./types"; - -const run = async (executable: string, args: Array) => { - return new Promise((resolve, reject) => { - const proc = spawn(executable, args, {}); - log.debug(`Calling ${executable} with args`, args); - - const cleanOutData = (data: any) => { - return data - .toString() - .replace(/\r/g, '') - .replace(/\\\\/g, '\\') - .split('\n') - } - - let stdout = ""; - proc.stdout.on('data', (data) => { - stdout += data; - }); - - let stderr = ""; - proc.stderr.on('data', (data) => { - stderr += data; - }); - - proc.on('exit', (code: number) => { - log.debug(`stdout of ${executable}`, cleanOutData(stdout)); - if (code !== 0) { - log.error(`stderr of ${executable}`, false, cleanOutData(stderr)) - return reject(new Error(`Failed running ${executable} Exit Code: ${code} See previous errors for details`)) - } - return resolve(stdout); - }); - - proc.stdin.end(); - }) -} - -export const getCertPublisher = async (cert: string, cert_pass: string) => { - const args = []; - args.push('-p', cert_pass); - args.push('-dump', cert); - const certDump = await run('certutil', args); - const subjectRegex = /Subject:\s*(.*)/; - const match = certDump.match(subjectRegex); - const publisher = match ? match[1].trim() : null; - if(!publisher) { - log.error('Unable to find publisher in Cert'); - } - return publisher; -} - -export const priConfig = async (program: ProgramOptions) => { - const { makePri, priConfig, createPri } = program; - if(createPri) { - const args = ['createconfig', '/cf', priConfig, '/dq', 'en-US']; - log.debug('Creating pri config.') - await run(makePri, args); - } else { - log.debug('Skipping making pri config.'); - } -} - -export const pri = async (program: ProgramOptions) => { - const { makePri, priConfig, layoutDir, priFile, appManifestLayout, createPri } = program; - if(createPri) { - log.debug('Making pri.') - const args = ['new', '/pr', layoutDir, '/cf', priConfig, '/mn', appManifestLayout, '/of', priFile, '/v']; - await run(makePri, args); - } else { - log.debug('Skipping making pri.'); - } -} - -export const make = async (program: ProgramOptions) => { - const { makeMsix, layoutDir, msix, isSparsePackage} = program; - const args = [ - 'pack', - '/d', - layoutDir, - '/p', - msix, - '/o', - ]; - - if(isSparsePackage) { - args.push('/nv'); - } - await run(makeMsix, args); -} - -export const sign = async (program: ProgramOptions) => { - if(program.sign) { - const signOptions = program.windowsSignOptions; - log.debug('Signing with options', signOptions); - await windowsSign(signOptions as SignOptions); - } else { - log.debug('Skipping signing.'); - } -} +import { sign as windowsSign, SignOptions } from "@electron/windows-sign"; +import { spawn } from 'child_process'; + +import { log } from "./logger"; +import { ProgramOptions } from "./types"; + +const run = async (executable: string, args: Array) => { + return new Promise((resolve, reject) => { + const proc = spawn(executable, args, {}); + log.debug(`Calling ${executable} with args`, args); + + const cleanOutData = (data: any) => { + return data + .toString() + .replace(/\r/g, '') + .replace(/\\\\/g, '\\') + .split('\n') + } + + let stdout = ""; + proc.stdout.on('data', (data) => { + stdout += data; + }); + + let stderr = ""; + proc.stderr.on('data', (data) => { + stderr += data; + }); + + proc.on('exit', (code: number) => { + log.debug(`Output from ${executable}:`, cleanOutData(stdout)); + if (code !== 0) { + log.error(`Output from ${executable}:`, false, cleanOutData(stdout)) + return reject(new Error(`Failed running ${executable} Exit Code: ${code} See previous errors for details`)) + } + return resolve(stdout); + }); + + proc.stdin.end(); + }) +} + +export const getCertPublisher = async (cert: string, cert_pass: string) => { + const args = []; + args.push('-p', cert_pass); + args.push('-dump', cert); + const certDump = await run('certutil', args); + const subjectRegex = /Subject:\s*(.*)/; + const match = certDump.match(subjectRegex); + const publisher = match ? match[1].trim() : null; + if(!publisher) { + log.error('Unable to find publisher in Cert'); + } + return publisher; +} + +export const priConfig = async (program: ProgramOptions) => { + const { makePri, priConfig, createPri } = program; + if(createPri) { + const args = ['createconfig', '/cf', priConfig, '/dq', 'en-US']; + log.debug('Creating pri config.') + await run(makePri, args); + } else { + log.debug('Skipping making pri config.'); + } +} + +export const pri = async (program: ProgramOptions) => { + const { makePri, priConfig, layoutDir, priFile, appManifestLayout, createPri } = program; + if(createPri) { + log.debug('Making pri.') + const args = ['new', '/pr', layoutDir, '/cf', priConfig, '/mn', appManifestLayout, '/of', priFile, '/v']; + await run(makePri, args); + } else { + log.debug('Skipping making pri.'); + } +} + +export const make = async (program: ProgramOptions) => { + const { makeMsix, layoutDir, msix, isSparsePackage} = program; + const args = [ + 'pack', + '/d', + layoutDir, + '/p', + msix, + '/o', + ]; + + if(isSparsePackage) { + args.push('/nv'); + } + await run(makeMsix, args); +} + +export const sign = async (program: ProgramOptions) => { + if(program.sign) { + const signOptions = program.windowsSignOptions; + log.debug('Signing with options', signOptions); + await windowsSign(signOptions as SignOptions); + } else { + log.debug('Skipping signing.'); + } +} From 72f226975510700988c65395fa4616158bb06edf Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Thu, 6 Nov 2025 18:07:11 -0800 Subject: [PATCH 2/2] fixes --- src/bin.ts | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/bin.ts b/src/bin.ts index 6550caa..839031b 100644 --- a/src/bin.ts +++ b/src/bin.ts @@ -28,12 +28,24 @@ const run = async (executable: string, args: Array) => { }); proc.on('exit', (code: number) => { - log.debug(`Output from ${executable}:`, cleanOutData(stdout)); - if (code !== 0) { - log.error(`Output from ${executable}:`, false, cleanOutData(stdout)) - return reject(new Error(`Failed running ${executable} Exit Code: ${code} See previous errors for details`)) + if (code === 0) { + log.debug(`stdout of ${executable}`, cleanOutData(stdout)); + return resolve(stdout); + } else { + if (stderr !== '') { + log.error(`stderr of ${executable}`, false, cleanOutData(stderr)); + } + + if (stdout !== '') { + log.error(`stdout of ${executable}`, false, cleanOutData(stdout)); + } + return reject( + new Error( + `Failed running ${executable} Exit Code: ${code} See previous errors for details` + ) + ); + } - return resolve(stdout); }); proc.stdin.end();