Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(flat): don't use pkgbuild for MAS distributions #340

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading