Skip to content

Commit 1acd5b3

Browse files
committed
fix(mas): Cannot create MAS build
Close #4048
1 parent 0ee226b commit 1acd5b3

19 files changed

+1237
-55
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
"chromium-pickle-js": "^0.2.0",
4343
"debug": "^4.1.1",
4444
"ejs": "^2.6.2",
45-
"electron-osx-sign": "0.4.11",
4645
"fs-extra": "^8.1.0",
4746
"hosted-git-info": "^2.7.1",
4847
"iconv-lite": "^0.5.0",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Copyright (c) 2015-2016 Zhuo Lu, Jason Hinkle, et al.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
14+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
</dict>
6+
</plist>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
</dict>
6+
</plist>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
<key>com.apple.security.inherit</key>
8+
<true/>
9+
</dict>
10+
</plist>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.app-sandbox</key>
6+
<true/>
7+
</dict>
8+
</plist>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/**
2+
* @module flat
3+
*/
4+
5+
'use strict'
6+
7+
const path = require('path')
8+
9+
const util = require('./util')
10+
const debuglog = util.debuglog
11+
const debugwarn = util.debugwarn
12+
const execFileAsync = util.execFileAsync
13+
const validateOptsAppAsync = util.validateOptsAppAsync
14+
const validateOptsPlatformAsync = util.validateOptsPlatformAsync
15+
const Identity = require('./util-identities').findIdentitiesAsync
16+
const findIdentitiesAsync = require('./util-identities').findIdentitiesAsync
17+
18+
/**
19+
* This function returns a promise validating all options passed in opts.
20+
* @function
21+
* @param {Object} opts - Options.
22+
* @returns {Promise} Promise.
23+
*/
24+
function validateFlatOptsAsync (opts) {
25+
if (opts.pkg) {
26+
if (typeof opts.pkg !== 'string') return Promise.reject(new Error('`pkg` must be a string.'))
27+
if (path.extname(opts.pkg) !== '.pkg') return Promise.reject(new Error('Extension of output package must be `.pkg`.'))
28+
} else {
29+
debugwarn('No `pkg` passed in arguments, will fallback to default inferred from the given application.')
30+
opts.pkg = path.join(path.dirname(opts.app), path.basename(opts.app, '.app') + '.pkg')
31+
}
32+
33+
if (opts.install) {
34+
if (typeof opts.install !== 'string') return Promise.reject(new Error('`install` must be a string.'))
35+
} else {
36+
debugwarn('No `install` passed in arguments, will fallback to default `/Applications`.')
37+
opts.install = '/Applications'
38+
}
39+
40+
return Promise.all([
41+
validateOptsAppAsync(opts),
42+
validateOptsPlatformAsync(opts),
43+
])
44+
}
45+
46+
/**
47+
* This function returns a promise flattening the application.
48+
* @function
49+
* @param {Object} opts - Options.
50+
* @returns {Promise} Promise.
51+
*/
52+
function flatApplicationAsync (opts) {
53+
const args = [
54+
'--component', opts.app, opts.install,
55+
'--sign', opts.identity.name,
56+
opts.pkg
57+
]
58+
if (opts.keychain) {
59+
args.unshift('--keychain', opts.keychain)
60+
}
61+
if (opts.scripts) {
62+
args.unshift('--scripts', opts.scripts)
63+
}
64+
65+
debuglog('Flattening... ' + opts.app)
66+
return execFileAsync('productbuild', args)
67+
.thenReturn(undefined)
68+
}
69+
70+
/**
71+
* This function is exported and returns a promise flattening the application.
72+
* @function
73+
* @param {Object} opts - Options.
74+
* @returns {Promise} Promise.
75+
*/
76+
module.exports.flatAsync = function (opts) {
77+
return validateFlatOptsAsync(opts)
78+
.then(function () {
79+
let promise
80+
if (opts.identity) {
81+
debuglog('`identity` passed in arguments.')
82+
if (opts['identity-validation'] === false || opts.identity instanceof Identity) {
83+
return Promise.resolve()
84+
}
85+
promise = findIdentitiesAsync(opts, opts.identity)
86+
} else {
87+
debugwarn('No `identity` passed in arguments...')
88+
if (opts.platform === 'mas') {
89+
debuglog('Finding `3rd Party Mac Developer Installer` certificate for flattening app distribution in the Mac App Store...')
90+
promise = findIdentitiesAsync(opts, '3rd Party Mac Developer Installer:')
91+
} else {
92+
debuglog('Finding `Developer ID Application` certificate for distribution outside the Mac App Store...')
93+
promise = findIdentitiesAsync(opts, 'Developer ID Installer:')
94+
}
95+
}
96+
return promise
97+
.then(function (identities) {
98+
if (identities.length > 0) {
99+
// Provisioning profile(s) found
100+
if (identities.length > 1) {
101+
debugwarn('Multiple identities found, will use the first discovered.')
102+
} else {
103+
debuglog('Found 1 identity.')
104+
}
105+
opts.identity = identities[0]
106+
} else {
107+
// No identity found
108+
return Promise.reject(new Error('No identity found for signing.'))
109+
}
110+
})
111+
})
112+
.then(function () {
113+
// Pre-flat operations
114+
})
115+
.then(function () {
116+
debuglog('Flattening application...', '\n',
117+
'> Application:', opts.app, '\n',
118+
'> Package output:', opts.pkg, '\n',
119+
'> Install path:', opts.install, '\n',
120+
'> Identity:', opts.identity, '\n',
121+
'> Scripts:', opts.scripts)
122+
return flatApplicationAsync(opts)
123+
})
124+
.then(function () {
125+
// Post-flat operations
126+
debuglog('Application flattened.')
127+
})
128+
}
129+
130+
/**
131+
* This function is exported with normal callback implementation.
132+
* @function
133+
* @param {Object} opts - Options.
134+
* @param {RequestCallback} cb - Callback.
135+
*/
136+
module.exports.flat = function (opts, cb) {
137+
module.exports.flatAsync(opts)
138+
.then(function () {
139+
debuglog('Application flattened, saved to: ' + opts.app)
140+
if (cb) cb()
141+
})
142+
.catch(function (err) {
143+
debuglog('Flat failed:')
144+
if (err.message) debuglog(err.message)
145+
else if (err.stack) debuglog(err.stack)
146+
else debuglog(err)
147+
if (cb) cb(err)
148+
})
149+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
interface BaseSignOptions {
2+
app: string
3+
identity?: string
4+
platform?: string
5+
keychain?: string
6+
}
7+
8+
interface SignOptions extends BaseSignOptions {
9+
binaries?: Array<string>
10+
entitlements?: string
11+
"entitlements-inherit"?: string
12+
"gatekeeper-assess"?: boolean
13+
ignore?: string
14+
"pre-auto-entitlements"?: boolean
15+
"pre-embed-provisioning-profile"?: boolean
16+
"provisioning-profile"?: string
17+
"requirements"?: string
18+
"type"?: string
19+
version?: string
20+
"identity-validation"?: boolean
21+
}
22+
23+
export function sign(opts: SignOptions, callback: (error: Error) => void): void
24+
25+
export function signAsync(opts: SignOptions): Promise<any>
26+
27+
interface FlatOptions extends BaseSignOptions {
28+
install?: string
29+
pkg?: string
30+
scripts?: string
31+
}
32+
33+
export function flat(opts: FlatOptions, callback: (error: Error) => void): void
34+
35+
export function flatAsync(opts: FlatOptions): Promise<any>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @module electron-osx-sign
3+
*/
4+
5+
'use strict'
6+
7+
const sign = require('./sign')
8+
const flat = require('./flat')
9+
10+
/**
11+
* This function is a normal callback implementation.
12+
* @param {Object} opts - Options.
13+
* @param {RequestCallback} cb - Callback.
14+
*/
15+
module.exports = sign.sign // Aliasing
16+
17+
/**
18+
* This function is a normal callback implementation.
19+
* @function
20+
* @param {Object} opts - Options.
21+
* @param {RequestCallback} cb - Callback.
22+
*/
23+
module.exports.sign = sign.sign
24+
25+
/**
26+
* This function returns a promise signing the application.
27+
* @function
28+
* @param {mixed} opts - Options.
29+
* @returns {Promise} Promise.
30+
*/
31+
module.exports.signAsync = sign.signAsync
32+
33+
/**
34+
* This function is exported with normal callback implementation.
35+
* @function
36+
* @param {Object} opts - Options.
37+
* @param {RequestCallback} cb - Callback.
38+
*/
39+
module.exports.flat = flat.flat
40+
41+
/**
42+
* This function is exported and returns a promise flattening the application.
43+
* @function
44+
* @param {Object} opts - Options.
45+
* @returns {Promise} Promise.
46+
*/
47+
module.exports.flatAsync = flat.flatAsync

0 commit comments

Comments
 (0)