Skip to content

Commit

Permalink
fix(core): increment update failed bug
Browse files Browse the repository at this point in the history
If you want to upgrade local npm packages in a folder whith package.json,
you need to fix package.json dependencies field first.
  • Loading branch information
lewischeng committed Mar 9, 2018
1 parent 4344fce commit e5333cd
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions lib/core/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,21 @@ class Upgrade {
table.cell('Update', version === ltsVersion ? 'N' : 'Y');
table.newRow();

return plugin;
return { plugin, ltsVersion };
}
});
});
}).filter((plugin) => {
return !!plugin;
}).then((needUpdatePlugins) => {
if (needUpdatePlugins.length) {
}).filter((obj) => {
return obj && !!obj.plugin;
}).then((pluginArr) => {
if (pluginArr.length) {
log.info('检测到您本地的部分插件需要更新才能继续使用,将采取 cli plugin 增量更新策略');

this.modifyDepsVersion(this.ctx.pkgPath, pluginArr);
console.log(table.toString());

const needUpdatePlugins = [];
pluginArr.map((obj) => {
needUpdatePlugins.push(obj.plugin);
});
const loading = new Loading('正在增量更新cli plugin,请稍等');
return self.execNpmCommand('install', needUpdatePlugins, false, baseDir).then(function (result) {
if (!result.code) {
Expand All @@ -98,6 +101,19 @@ class Upgrade {
});
}

/**
* Modify local package.json dependencies version, otherwise npm will not install success
*/
modifyDepsVersion(packagePath, arr) {
const obj = require(packagePath);

arr.map((item) => {
obj.dependencies[item.plugin] = item.ltsVersion;
});

fs.writeFileSync(packagePath, JSON.stringify(obj, null, 4));
}

getInstalledPlugins() {
const ctx = this.ctx;
const packagePath = pathFn.join(ctx.baseDir, 'package.json');
Expand Down Expand Up @@ -183,4 +199,4 @@ module.exports = function (ctx) {
upgrade.checkCore(),
upgrade.checkPlugin()
]);
};
};

0 comments on commit e5333cd

Please sign in to comment.