codekingpro/portable-devtools
114k
1const getBinFromManifest = (mani) => {
2 // if we have a bin matching (unscoped portion of) packagename, use that
3 // otherwise if there's 1 bin or all bin value is the same (alias), use
4 // that; otherwise, fail
5 const bin = mani.bin || {}
6 if (new Set(Object.values(bin)).size === 1) {
7 return Object.keys(bin)[0]
8 }
9
10 // XXX probably a util to parse this better?
11 const name = mani.name.replace(/^@[^/]+\//, '')
12 if (bin[name]) {
13 return name
14 }
15
16 // XXX need better error message
17 throw Object.assign(new Error('could not determine executable to run'), {
18 pkgid: mani._id,
19 })
20}
21
22module.exports = getBinFromManifest
23 