1 | 'use strict'
|
2 |
|
3 | const fs = require('fs-extra')
|
4 | const path = require('path')
|
5 | const which = require('which')
|
6 | const execa = require('execa')
|
7 | const semver = require('semver')
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function getNpmLifecycleVersion () {
|
15 | const npmPath = which.sync('npm', {
|
16 | nothrow: true
|
17 | })
|
18 |
|
19 | if (!npmPath) {
|
20 | return ''
|
21 | }
|
22 |
|
23 | const pathSuffix = process.platform === 'win32'
|
24 | ? '../node_modules/npm/node_modules/npm-lifecycle/package.json'
|
25 | : '../../node_modules/npm-lifecycle/package.json'
|
26 |
|
27 | const lifecyclePkgPath = path.join(fs.realpathSync(npmPath), pathSuffix)
|
28 |
|
29 | if (!fs.existsSync(lifecyclePkgPath)) {
|
30 | return ''
|
31 | }
|
32 |
|
33 |
|
34 | return require(lifecyclePkgPath).version
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | const npmVersion = execa.sync('npm', ['-v']).stdout
|
47 | const npmLifecycleVersion = getNpmLifecycleVersion()
|
48 | let pass = true
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | if (npmLifecycleVersion) {
|
55 | pass = semver.gte(npmLifecycleVersion, '2.0.2')
|
56 | } else {
|
57 | pass = semver.satisfies(npmVersion, '<5.1.0 || >6.1.0')
|
58 | }
|
59 |
|
60 | module.exports = {
|
61 | npmVersion,
|
62 | npmLifecycleVersion,
|
63 | pass
|
64 | }
|