• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var validate = require('aproba')
3var npm = require('../npm.js')
4
5module.exports = function (differences, decomposed, next) {
6  validate('AAF', arguments)
7  differences.forEach((action) => {
8    var cmd = action[0]
9    var pkg = action[1]
10    switch (cmd) {
11      case 'add':
12        addSteps(decomposed, pkg)
13        break
14      case 'update':
15        updateSteps(decomposed, pkg)
16        break
17      case 'move':
18        moveSteps(decomposed, pkg)
19        break
20      case 'remove':
21        removeSteps(decomposed, pkg)
22        break
23      default:
24        defaultSteps(decomposed, cmd, pkg)
25    }
26  })
27  next()
28}
29
30function addAction (decomposed, action, pkg) {
31  if (decomposed.some((_) => _[0] === action && _[1] === pkg)) return
32  decomposed.push([action, pkg])
33}
34
35function addSteps (decomposed, pkg) {
36  if (pkg.fromBundle) {
37    // make sure our source module exists to extract ourselves from
38    // if we're installing our source module anyway, the duplication
39    // of these steps will be elided by `addAction` automatically
40    addAction(decomposed, 'fetch', pkg.fromBundle)
41    addAction(decomposed, 'extract', pkg.fromBundle)
42  }
43  if (!pkg.fromBundle && !pkg.isLink) {
44    addAction(decomposed, 'fetch', pkg)
45    addAction(decomposed, 'extract', pkg)
46  }
47  if (!pkg.fromBundle || npm.config.get('rebuild-bundle')) {
48    addAction(decomposed, 'preinstall', pkg)
49    addAction(decomposed, 'build', pkg)
50    addAction(decomposed, 'install', pkg)
51    addAction(decomposed, 'postinstall', pkg)
52  }
53  if (!pkg.fromBundle || !pkg.isLink) {
54    addAction(decomposed, 'finalize', pkg)
55  }
56  addAction(decomposed, 'refresh-package-json', pkg)
57}
58
59function updateSteps (decomposed, pkg) {
60  removeSteps(decomposed, pkg.oldPkg)
61  addSteps(decomposed, pkg)
62}
63
64function removeSteps (decomposed, pkg) {
65  addAction(decomposed, 'unbuild', pkg)
66  addAction(decomposed, 'remove', pkg)
67}
68
69function moveSteps (decomposed, pkg) {
70  addAction(decomposed, 'move', pkg)
71  addAction(decomposed, 'build', pkg)
72  addAction(decomposed, 'install', pkg)
73  addAction(decomposed, 'postinstall', pkg)
74  addAction(decomposed, 'refresh-package-json', pkg)
75}
76
77function defaultSteps (decomposed, cmd, pkg) {
78  addAction(decomposed, cmd, pkg)
79}
80