Skip to content

Commit a5bf4d4

Browse files
authored
fix(flat): don't use pkgbuild for MAS distributions (#340)
* fix(flat): don't use pkgbuild for MAS distributions * chore: additional validation and logging
1 parent a58646a commit a5bf4d4

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/flat.ts

+42-18
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ async function validateFlatOpts (opts: FlatOptions): Promise<ValidatedFlatOption
3939
install = '/Applications';
4040
}
4141

42+
if (typeof opts.scripts === 'string' && opts.platform === 'mas') {
43+
debugWarn('Mac App Store packages cannot have `scripts`, ignoring option.');
44+
}
45+
4246
return {
4347
...opts,
4448
pkg,
@@ -49,27 +53,44 @@ async function validateFlatOpts (opts: FlatOptions): Promise<ValidatedFlatOption
4953

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

65-
const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
66-
if (opts.keychain) {
67-
args.unshift('--keychain', opts.keychain);
68-
}
65+
debugLog('Flattening Mac App Store package... ' + opts.app);
66+
await execFileAsync('productbuild', args);
67+
} else {
68+
const componentPkgPath = path.join(
69+
path.dirname(opts.app),
70+
path.basename(opts.app, '.app') + '-component.pkg'
71+
);
72+
const pkgbuildArgs = [
73+
'--install-location',
74+
opts.install,
75+
'--component',
76+
opts.app,
77+
componentPkgPath
78+
];
79+
if (opts.scripts) {
80+
pkgbuildArgs.unshift('--scripts', opts.scripts);
81+
}
82+
debugLog('Building component package... ' + opts.app);
83+
await execFileAsync('pkgbuild', pkgbuildArgs);
84+
85+
const args = ['--package', componentPkgPath, opts.install, '--sign', identity.name, opts.pkg];
86+
if (opts.keychain) {
87+
args.unshift('--keychain', opts.keychain);
88+
}
6989

70-
debugLog('Flattening... ' + opts.app);
71-
await execFileAsync('productbuild', args);
72-
await execFileAsync('rm', [componentPkgPath]);
90+
debugLog('Flattening OS X Installer package... ' + opts.app);
91+
await execFileAsync('productbuild', args);
92+
await execFileAsync('rm', [componentPkgPath]);
93+
}
7394
}
7495

7596
/**
@@ -105,7 +126,10 @@ export async function buildPkg (_opts: FlatOptions) {
105126
debugLog(
106127
'Finding `Developer ID Application` certificate for distribution outside the Mac App Store...'
107128
);
108-
identities = await findIdentities(validatedOptions.keychain || null, 'Developer ID Installer:');
129+
identities = await findIdentities(
130+
validatedOptions.keychain || null,
131+
'Developer ID Installer:'
132+
);
109133
}
110134
}
111135

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ type OnlyFlatOptions = {
220220
* Path to a directory containing `preinstall.sh` or `postinstall.sh` scripts.
221221
* These must be executable and will run on pre/postinstall depending on the file
222222
* name.
223+
*
224+
* This option is only valid if {@link FlatOptions.platform} is set to `darwin`.
223225
*/
224226
scripts?: string;
225227
};

0 commit comments

Comments
 (0)