Skip to content

Commit

Permalink
fix(flat): don't use pkgbuild for MAS distributions (#340)
Browse files Browse the repository at this point in the history
* fix(flat): don't use pkgbuild for MAS distributions

* chore: additional validation and logging
  • Loading branch information
erickzhao authored Dec 31, 2024
1 parent a58646a commit a5bf4d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ async function validateFlatOpts (opts: FlatOptions): Promise<ValidatedFlatOption
install = '/Applications';
}

if (typeof opts.scripts === 'string' && opts.platform === 'mas') {
debugWarn('Mac App Store packages cannot have `scripts`, ignoring option.');
}

return {
...opts,
pkg,
Expand All @@ -49,27 +53,44 @@ async function validateFlatOpts (opts: FlatOptions): Promise<ValidatedFlatOption

/**
* This function returns a promise flattening the application.
* @function
* @param {Object} opts - Options.
* @returns {Promise} Promise.
* @param opts - Options for building the .pkg archive
*/
async function buildApplicationPkg (opts: ValidatedFlatOptions, identity: Identity) {
const componentPkgPath = path.join(path.dirname(opts.app), path.basename(opts.app, '.app') + '-component.pkg');
const pkgbuildArgs = ['--install-location', opts.install, '--component', opts.app, componentPkgPath];
if (opts.scripts) {
pkgbuildArgs.unshift('--scripts', opts.scripts);
}
debugLog('Building component package... ' + opts.app);
await execFileAsync('pkgbuild', pkgbuildArgs);
if (opts.platform === 'mas') {
const args = ['--component', opts.app, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}

const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}
debugLog('Flattening Mac App Store package... ' + opts.app);
await execFileAsync('productbuild', args);
} else {
const componentPkgPath = path.join(
path.dirname(opts.app),
path.basename(opts.app, '.app') + '-component.pkg'
);
const pkgbuildArgs = [
'--install-location',
opts.install,
'--component',
opts.app,
componentPkgPath
];
if (opts.scripts) {
pkgbuildArgs.unshift('--scripts', opts.scripts);
}
debugLog('Building component package... ' + opts.app);
await execFileAsync('pkgbuild', pkgbuildArgs);

const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
if (opts.keychain) {
args.unshift('--keychain', opts.keychain);
}

debugLog('Flattening... ' + opts.app);
await execFileAsync('productbuild', args);
await execFileAsync('rm', [componentPkgPath]);
debugLog('Flattening OS X Installer package... ' + opts.app);
await execFileAsync('productbuild', args);
await execFileAsync('rm', [componentPkgPath]);
}
}

/**
Expand Down Expand Up @@ -105,7 +126,10 @@ export async function buildPkg (_opts: FlatOptions) {
debugLog(
'Finding `Developer ID Application` certificate for distribution outside the Mac App Store...'
);
identities = await findIdentities(validatedOptions.keychain || null, 'Developer ID Installer:');
identities = await findIdentities(
validatedOptions.keychain || null,
'Developer ID Installer:'
);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ type OnlyFlatOptions = {
* Path to a directory containing `preinstall.sh` or `postinstall.sh` scripts.
* These must be executable and will run on pre/postinstall depending on the file
* name.
*
* This option is only valid if {@link FlatOptions.platform} is set to `darwin`.
*/
scripts?: string;
};
Expand Down

0 comments on commit a5bf4d4

Please sign in to comment.