Skip to content

Commit cc7483d

Browse files
committed
fix(build): 兼容不存在 npm_cache_share 的场景
1 parent 69884b5 commit cc7483d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/commands/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var fs = require('fs');
44
var path = require('path');
55
var shell = require('shelljs');
6+
var child_process = require('child_process');
67

78
exports.usage = '线上编译';
89

@@ -17,9 +18,14 @@ exports.run = function (options) {
1718
currentNpm = 'npm';
1819
log('指定 npm 进行模块安装');
1920
} else {
20-
currentNpm = 'npm_cache_share';
21-
log('指定 npm_cache_share 进行模块安装');
22-
process.stdout && process.stdout.write('npm_cache_share version: ') && run('npm_cache_share -V');
21+
try {
22+
child_process.execSync('npm_cache_share -h');
23+
currentNpm = 'npm_cache_share';
24+
log('指定 npm_cache_share 进行模块安装');
25+
} catch (e) {
26+
currentNpm = 'npm';
27+
log('npm_cache_share 不存在,将使用 npm 进行模块安装');
28+
}
2329
}
2430

2531
// 确定 node 版本

src/commands/build.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var fs = require('fs');
44
var path = require('path');
55
var shell = require('shelljs');
6+
var child_process = require('child_process');
67

78
exports.usage = '线上编译';
89

@@ -19,9 +20,14 @@ exports.run = function(options) {
1920
currentNpm = 'npm';
2021
log('指定 npm 进行模块安装');
2122
} else {
22-
currentNpm = 'npm_cache_share';
23-
log('指定 npm_cache_share 进行模块安装');
24-
process.stdout && process.stdout.write('npm_cache_share version: ') && run('npm_cache_share -V');
23+
try {
24+
child_process.execSync('npm_cache_share -h');
25+
currentNpm = 'npm_cache_share';
26+
log('指定 npm_cache_share 进行模块安装');
27+
} catch (e) {
28+
currentNpm = 'npm';
29+
log('npm_cache_share 不存在,将使用 npm 进行模块安装');
30+
}
2531
}
2632

2733
// 确定 node 版本

0 commit comments

Comments
 (0)