forked from rockybars/atom-shell-packager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prune.js
45 lines (37 loc) · 1.35 KB
/
prune.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'
const child = require('mz/child_process')
const debug = require('debug')('electron-packager')
const Walker = require('pruner').Walker
const knownPackageManagers = ['npm', 'cnpm', 'yarn']
function pruneCommand (packageManager) {
switch (packageManager) {
case 'npm':
case 'cnpm':
return `${packageManager} prune --production`
case 'yarn':
return `${packageManager} install --production --no-bin-links --no-lockfile`
}
}
function pruneModules (opts, appPath) {
if (opts.packageManager === false) {
const walker = new Walker(appPath)
return walker.prune()
} else {
const packageManager = opts.packageManager || 'npm'
/* istanbul ignore if */
if (packageManager === 'cnpm' && process.platform === 'win32') {
return Promise.reject(new Error('cnpm support does not currently work with Windows, see: https://github.com/electron-userland/electron-packager/issues/515#issuecomment-297604044'))
}
const command = pruneCommand(packageManager)
if (command) {
debug(`Pruning modules via: ${command}`)
return child.exec(command, { cwd: appPath })
} else {
return Promise.reject(new Error(`Unknown package manager "${packageManager}". Known package managers: ${knownPackageManagers.join(', ')}`))
}
}
}
module.exports = {
pruneCommand: pruneCommand,
pruneModules: pruneModules
}