执行过npm install命令的vue-element-admin源码
康凯
2022-05-20 aa4c235a8ca67ea8b731f90c951a465e92c0a865
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
"use strict"
 
var test = require('tape')
 
var path = require('path')
var join = path.join
 
var npmWhich = require('../')
 
var level0 = join(__dirname, 'fixtures', 'level0')
var level1 = join(level0, 'node_modules', 'level1')
var level2 = join(level1, 'node_modules', 'level2')
 
var LEVEL = [level0, level1, level2]
 
var BINPATH_FOR_LEVEL = LEVEL.map(function(levelPath) {
  return join(levelPath, "node_modules", ".bin")
})
 
var before = process.env.PATH
 
test('includes all .bin dirs in all parent node_modules folders', function(t) {
  t.test('no nesting', function(t) {
    var level1Bin = npmWhich(LEVEL[0]).sync('level1')
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
    t.end()
  })
 
  t.test('nesting', function(t) {
    var which = npmWhich(LEVEL[1])
    var level1Bin = which.sync('level1')
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
    var level2Bin = which.sync('level2')
    t.equal(level2Bin, join(BINPATH_FOR_LEVEL[1], 'level2'), 'got level2 path')
    t.end()
  })
 
  t.test('more nesting', function(t) {
    var which = npmWhich(LEVEL[1])
    var level1Bin = which.sync('level1')
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
    var level2Bin = which.sync('level2')
    t.equal(level2Bin, join(BINPATH_FOR_LEVEL[1], 'level2'), 'got level2 path')
    t.end()
  })
 
  t.end()
})
 
test('which.sync requires a cwd', function(t) {
  t.throws(function() {
    npmWhich().sync('level1')
  })
  t.end()
})
 
test('which.sync requires a cwd, can be supplied in options', function(t) {
  var level1Bin = npmWhich().sync('level1', {cwd: LEVEL[0]})
  t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
  t.end()
})
 
test('which requires a cwd', function(t) {
  npmWhich()('level1', function(err) {
    t.ok(err)
    t.end()
  })
})
 
test('which can be curried', function(t) {
  var which = npmWhich(LEVEL[0])('level1')
  which(function(err, level1Bin) {
    t.ifError(err)
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
    t.end()
  })
})
 
test('which can be curried, options overridden', function(t) {
  var which = npmWhich(LEVEL[1])('level1')
  which({cwd: LEVEL[0]}, function(err, level1Bin) {
    t.ifError(err)
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
  })
  t.end()
})
 
test('which can be curried with sync', function(t) {
  var which = npmWhich(LEVEL[0])('level1')
  var level1Bin = which.sync()
  t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
  t.end()
})
 
test('which can be curried with sync, options overridden', function(t) {
  var which = npmWhich(LEVEL[1])('level1')
  var level1Bin = which.sync({cwd: LEVEL[0]})
  t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
  t.end()
})
 
test('which requires a cwd, can be supplied in options', function(t) {
  npmWhich()('level1', {cwd: LEVEL[0]}, function(err, level1Bin) {
    t.ifError(err)
    t.equal(level1Bin, join(BINPATH_FOR_LEVEL[0], 'level1'), 'got level1 path')
    t.end()
  })
})
 
test('cwd can be overridden in options', function(t) {
  npmWhich(LEVEL[0])('level2', {cwd: LEVEL[1]}, function(err, level2Bin) {
    t.ifError(err)
    t.equal(level2Bin, join(BINPATH_FOR_LEVEL[1], 'level2'), 'got level2 path')
    t.end()
  })
})
 
test('which.sync does not mutate PATH', function(t) {
  npmWhich(__dirname).sync('level1', {env: {PATH: BINPATH_FOR_LEVEL[0]}})
  var after = process.env.PATH
  t.deepEqual(after, before, 'PATH unmodified')
  t.end()
})
 
test('which.sync does not mutate PATH after failed find', function(t) {
  t.throws(function() {
    npmWhich(__dirname).sync('asdasd', {env: {PATH: BINPATH_FOR_LEVEL[0]}})
  })
  var after = process.env.PATH
  t.deepEqual(after, before, 'PATH unmodified')
  t.end()
})
 
test('which does not mutate PATH', function(t) {
  var level1Bin = npmWhich(__dirname)('level1', {env: {PATH: BINPATH_FOR_LEVEL[0]}}, function(err) {
    t.ifError(err)
    var after = process.env.PATH
    t.deepEqual(after, before, 'PATH unmodified')
    t.end()
  })
})
 
test('which does not mutate PATH after failed find', function(t) {
  npmWhich('asdasdb/jhbhj')('asdasd', function(err) {
    t.ok(err)
    var after = process.env.PATH
    t.deepEqual(after, before, 'PATH unmodified')
    t.end()
  })
})
 
test('can find path with bad cwd', function(t) {
  npmWhich('/asdasdb/jhbhj')('node', function(err, path) {
    t.ifError(err)
    t.ok(path)
    t.equal(path.split('/').pop(), 'node')
    var after = process.env.PATH
    t.deepEqual(after, before, 'PATH unmodified')
    t.end()
  })
})
 
test('which does not mutate PATH with bad cmd & cwd', function(t) {
  npmWhich('asdasdb/jhbhj')('asdasd', function(err) {
    t.ok(err)
    var after = process.env.PATH
    t.deepEqual(after, before, 'PATH unmodified')
    t.end()
  })
})
 
test('which.sync on default export will error without cwd', function(t) {
  t.throws(function() {
    npmWhich.sync('level1')
  })
  t.end()
})
 
if (process.version.indexOf('v0.10') !== -1) {
  // can't test this on 0.11 as process.platform is (rightfully) read-only
  test('which does not mutate PATH with bad cwd/cmd on "windows"', function(t) {
    var actualPlatform = process.platform
    process.platform = "win32"
    npmWhich('asdasdb/jhbhj')('asdasd', function(err) {
      process.platform = actualPlatform
      t.ok(err)
      var after = process.env.PATH
      t.deepEqual(after, before, 'PATH unmodified')
      t.end()
    })
  })
}
 
 
 
// Ensure old 1.0.0 tests function, except for the breakages.
require('./1.0.0-interface')