From ecec5a1ad03e58ef44aa3a39c00a5ef78bfe068c Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Fri, 17 Nov 2017 02:13:03 +0200 Subject: [PATCH] Ensure that Cordova is installed for `meteor [add |remove] cordova:*`. In the same spirit as the changes made in https://github.com/meteor/meteor/pull/8976. Fixes: https://github.com/meteor/meteor/issues/9257. --- tools/cli/commands-packages.js | 101 +++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 43 deletions(-) diff --git a/tools/cli/commands-packages.js b/tools/cli/commands-packages.js index 6b11f11b6e..bdf5f45e2b 100644 --- a/tools/cli/commands-packages.js +++ b/tools/cli/commands-packages.js @@ -23,7 +23,10 @@ var packageMapModule = require('../packaging/package-map.js'); var packageClient = require('../packaging/package-client.js'); var tropohouse = require('../packaging/tropohouse.js'); -import * as cordova from '../cordova'; +import { + newPluginId, + splitPluginsAndPackages, +} from '../cordova'; import { updateMeteorToolSymlink } from "../packaging/updater.js"; // For each release (or package), we store a meta-record with its name, @@ -1998,34 +2001,40 @@ main.registerCommand({ // Split arguments into Cordova plugins and packages const { plugins: pluginsToAdd, packages: packagesToAdd } = - cordova.splitPluginsAndPackages(options.args); + splitPluginsAndPackages(options.args); if (!_.isEmpty(pluginsToAdd)) { - let plugins = projectContext.cordovaPluginsFile.getPluginVersions(); - let changed = false; + function cordovaPluginAdd() { + let plugins = projectContext.cordovaPluginsFile.getPluginVersions(); + let changed = false; - for (target of pluginsToAdd) { - let { id, version } = - require('../cordova/package-id-version-parser.js').parse(target); - const newId = cordova.newPluginId(id); + for (target of pluginsToAdd) { + let { id, version } = + require('../cordova/package-id-version-parser.js').parse(target); + const newId = newPluginId(id); - if (!(version && utils.isValidVersion(version, {forCordova: true}))) { - Console.error(`${id}: Meteor requires either an exact version \ -(e.g. ${id}@1.0.0), a Git URL with a SHA reference, or a local path.`); - exitCode = 1; - } else if (newId) { - plugins[newId] = version; - Console.info(`Added Cordova plugin ${newId}@${version} \ -(plugin has been renamed as part of moving to npm).`); - changed = true; - } else { - plugins[id] = version; - Console.info(`Added Cordova plugin ${id}@${version}.`); - changed = true; + if (!(version && utils.isValidVersion(version, {forCordova: true}))) { + Console.error(`${id}: Meteor requires either an exact version \ + (e.g. ${id}@1.0.0), a Git URL with a SHA reference, or a local path.`); + exitCode = 1; + } else if (newId) { + plugins[newId] = version; + Console.info(`Added Cordova plugin ${newId}@${version} \ + (plugin has been renamed as part of moving to npm).`); + changed = true; + } else { + plugins[id] = version; + Console.info(`Added Cordova plugin ${id}@${version}.`); + changed = true; + } } + + changed && projectContext.cordovaPluginsFile.write(plugins); } - changed && projectContext.cordovaPluginsFile.write(plugins); + import { ensureDevBundleDependencies } from '../cordova'; + ensureDevBundleDependencies(); + cordovaPluginAdd(); } if (_.isEmpty(packagesToAdd)) { @@ -2191,34 +2200,40 @@ main.registerCommand({ // Split arguments into Cordova plugins and packages const { plugins: pluginsToRemove, packages } = - cordova.splitPluginsAndPackages(options.args); + splitPluginsAndPackages(options.args); if (!_.isEmpty(pluginsToRemove)) { - let plugins = projectContext.cordovaPluginsFile.getPluginVersions(); - let changed = false; + function cordovaPluginRemove() { + let plugins = projectContext.cordovaPluginsFile.getPluginVersions(); + let changed = false; - for (id of pluginsToRemove) { - const newId = cordova.newPluginId(id); + for (id of pluginsToRemove) { + const newId = newPluginId(id); - if (/@/.test(id)) { - Console.error(`${id}: do not specify version constraints.`); - exitCode = 1; - } else if (_.has(plugins, id)) { - delete plugins[id]; - Console.info(`Removed Cordova plugin ${id}.`); - changed = true; - } else if (newId && _.has(plugins, newId)) { - delete plugins[newId]; - Console.info(`Removed Cordova plugin ${newId} \ -(plugin has been renamed as part of moving to npm).`); - changed = true; - } else { - Console.error(`Cordova plugin ${id} is not in this project.`); - exitCode = 1; + if (/@/.test(id)) { + Console.error(`${id}: do not specify version constraints.`); + exitCode = 1; + } else if (_.has(plugins, id)) { + delete plugins[id]; + Console.info(`Removed Cordova plugin ${id}.`); + changed = true; + } else if (newId && _.has(plugins, newId)) { + delete plugins[newId]; + Console.info(`Removed Cordova plugin ${newId} \ + (plugin has been renamed as part of moving to npm).`); + changed = true; + } else { + Console.error(`Cordova plugin ${id} is not in this project.`); + exitCode = 1; + } } + + changed && projectContext.cordovaPluginsFile.write(plugins); } - changed && projectContext.cordovaPluginsFile.write(plugins); + import { ensureDevBundleDependencies } from '../cordova'; + ensureDevBundleDependencies(); + cordovaPluginRemove(); } if (_.isEmpty(packages)) {