Skip to content

Commit 960dad3

Browse files
committed
feat(build): 检测 ykit 配置文件及 node_modules
1 parent cd37e67 commit 960dad3

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

lib/commands/build.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,34 @@ exports.setOptions = function (optimist) {};
2020
exports.npmInstall = function () {
2121
var currentNpm = null;
2222

23+
// 检测是否存在 ykit.*.js
24+
var configFile = globby.sync(['ykit.*.js', 'ykit.js'], { cwd: process.cwd() })[0];
25+
if (!configFile) {
26+
log('未发现存在 ykit 配置文件,编译退出.');
27+
process.exit(1);
28+
}
29+
30+
// 检测是否存在 node_modules
31+
var isNodeModulesExists = fs.existsSync(sysPath.join(process.cwd(), 'node_modules'));
32+
if (isNodeModulesExists) {
33+
log('发现仓库中已存在 node_modules,这会导致由于 npm 包系统版本不兼容而编译失败,请从仓库中删除并重新编译.');
34+
process.exit(1);
35+
}
36+
2337
try {
2438
child_process.execSync('npm_cache_share -h');
2539

2640
if (UtilFs.fileExists(sysPath.join(process.cwd(), 'npm-shrinkwrap.json'))) {
2741
currentNpm = 'npm_cache_share';
28-
log('将使用 npm_cache_share 进行模块安装');
42+
log('将使用 npm_cache_share 进行模块安装.');
2943
} else {
3044
currentNpm = 'npm';
31-
log('npm-shrinkwrap.json 不存在,将使用 npm 进行模块安装');
45+
log('npm-shrinkwrap.json 不存在,将使用 npm 进行模块安装.');
46+
log('建议使用 shrinkwrap 固定模块版本,否则构建存在风险。文档请参考:http://ued.qunar.com/ykit/docs-npm%20shrinkwrap.html');
3247
}
3348
} catch (e) {
3449
currentNpm = 'npm';
35-
log('npm_cache_share 不存在,将使用 npm 进行模块安装');
50+
log('npm_cache_share 不存在,将使用 npm 进行模块安装.');
3651
}
3752

3853
// cache clean

src/commands/build.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,34 @@ exports.setOptions = (optimist) => {
2222
exports.npmInstall = function() {
2323
let currentNpm = null;
2424

25+
// 检测是否存在 ykit.*.js
26+
const configFile = globby.sync(['ykit.*.js', 'ykit.js'], { cwd: process.cwd() })[0];
27+
if(!configFile) {
28+
log('未发现存在 ykit 配置文件,编译退出.');
29+
process.exit(1);
30+
}
31+
32+
// 检测是否存在 node_modules
33+
const isNodeModulesExists = fs.existsSync(sysPath.join(process.cwd(), 'node_modules'));
34+
if(isNodeModulesExists) {
35+
log('发现仓库中已存在 node_modules,这会导致由于 npm 包系统版本不兼容而编译失败,请从仓库中删除并重新编译.');
36+
process.exit(1);
37+
}
38+
2539
try {
2640
child_process.execSync('npm_cache_share -h');
2741

2842
if(UtilFs.fileExists(sysPath.join(process.cwd(), 'npm-shrinkwrap.json'))) {
2943
currentNpm = 'npm_cache_share';
30-
log('将使用 npm_cache_share 进行模块安装');
44+
log('将使用 npm_cache_share 进行模块安装.');
3145
} else {
3246
currentNpm = 'npm';
33-
log('npm-shrinkwrap.json 不存在,将使用 npm 进行模块安装');
47+
log('npm-shrinkwrap.json 不存在,将使用 npm 进行模块安装.');
48+
log('建议使用 shrinkwrap 固定模块版本,否则构建存在风险。文档请参考:http://ued.qunar.com/ykit/docs-npm%20shrinkwrap.html');
3449
}
3550
} catch (e) {
3651
currentNpm = 'npm';
37-
log('npm_cache_share 不存在,将使用 npm 进行模块安装');
52+
log('npm_cache_share 不存在,将使用 npm 进行模块安装.');
3853
}
3954

4055
// cache clean

0 commit comments

Comments
 (0)