You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/10/31 07:10:24 UTC
[cordova-lib] branch master updated: Do not spawn child process to
get platform version (#815)
This is an automated email from the ASF dual-hosted git repository.
raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git
The following commit(s) were added to refs/heads/master by this push:
new 97d65e8 Do not spawn child process to get platform version (#815)
97d65e8 is described below
commit 97d65e827a9db779c5b1fbf37e322124615ea5c3
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Thu Oct 31 08:10:18 2019 +0100
Do not spawn child process to get platform version (#815)
---
src/cordova/util.js | 35 ++++++++++++++++++++++-------------
src/plugman/install.js | 2 +-
src/plugman/uninstall.js | 3 +--
3 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/src/cordova/util.js b/src/cordova/util.js
index 9e00d81..31ceaa1 100644
--- a/src/cordova/util.js
+++ b/src/cordova/util.js
@@ -45,6 +45,7 @@ exports.getInstalledPlatformsWithVersions = getInstalledPlatformsWithVersions;
exports.requireNoCache = requireNoCache;
exports.getPlatformApiFunction = getPlatformApiFunction;
exports.removePlatformPluginsJson = removePlatformPluginsJson;
+exports.getPlatformVersion = getPlatformVersionOrNull;
// Remove <platform>.json file from plugins directory.
function removePlatformPluginsJson (projectRoot, target) {
@@ -186,20 +187,28 @@ function listPlatforms (project_dir) {
}
function getInstalledPlatformsWithVersions (project_dir) {
- var result = {};
- var platforms_on_fs = listPlatforms(project_dir);
-
- return Promise.all(platforms_on_fs.map(function (p) {
- var superspawn = require('cordova-common').superspawn;
- return superspawn.maybeSpawn(path.join(project_dir, 'platforms', p, 'cordova', 'version'), [], { chmod: true })
- .then(function (v) {
- result[p] = v || null;
- }, function (v) {
- result[p] = 'broken';
- });
- })).then(function () {
+ return Promise.resolve(listPlatforms(project_dir).reduce((result, p) => {
+ try {
+ const platformPath = path.join(project_dir, 'platforms', p);
+ result[p] = getPlatformVersion(platformPath) || null;
+ } catch (e) {
+ result[p] = 'broken';
+ }
return result;
- });
+ }, {}));
+}
+
+function getPlatformVersion (platformPath) {
+ const versionPath = path.join(platformPath, 'cordova/version');
+ return requireNoCache(versionPath).version;
+}
+
+function getPlatformVersionOrNull (platformPath) {
+ try {
+ return getPlatformVersion(platformPath);
+ } catch (e) {
+ return null;
+ }
}
// list the directories in the path, ignoring any files
diff --git a/src/plugman/install.js b/src/plugman/install.js
index 6bb075c..89b8575 100644
--- a/src/plugman/install.js
+++ b/src/plugman/install.js
@@ -296,7 +296,7 @@ function runInstall (actions, platform, project_dir, plugin_dir, plugins_dir, op
if (options.platformVersion) {
return Promise.resolve(options.platformVersion);
}
- return Promise.resolve(superspawn.maybeSpawn(path.join(project_dir, 'cordova', 'version'), [], { chmod: true }));
+ return Promise.resolve(cordovaUtil.getPlatformVersion(project_dir));
}).then(function (platformVersion) {
options.platformVersion = platformVersion;
return callEngineScripts(theEngines, path.resolve(plugins_dir, '..'));
diff --git a/src/plugman/uninstall.js b/src/plugman/uninstall.js
index ce5391e..19108a4 100644
--- a/src/plugman/uninstall.js
+++ b/src/plugman/uninstall.js
@@ -29,7 +29,6 @@ var HooksRunner = require('../hooks/HooksRunner');
var cordovaUtil = require('../cordova/util');
var npmUninstall = require('cordova-fetch').uninstall;
-var superspawn = require('cordova-common').superspawn;
var PlatformJson = require('cordova-common').PlatformJson;
var PluginInfoProvider = require('cordova-common').PluginInfoProvider;
var variableMerge = require('../plugman/variable-merge');
@@ -83,7 +82,7 @@ module.exports.uninstallPlatform = function (platform, project_dir, id, plugins_
if (options.platformVersion) {
return Promise.resolve(options.platformVersion);
}
- return Promise.resolve(superspawn.maybeSpawn(path.join(project_dir, 'cordova', 'version'), [], { chmod: true }));
+ return Promise.resolve(cordovaUtil.getPlatformVersion(project_dir));
}).then(function (platformVersion) {
options.platformVersion = platformVersion;
return runUninstallPlatform(current_stack, platform, project_dir, plugin_dir, plugins_dir, options);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org