You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2017/03/09 20:39:07 UTC

[04/50] [abbrv] cordova-lib git commit: CB-11960: Added support to package.json for platform/plugin add/rm

CB-11960: Added support to package.json for platform/plugin add/rm


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/197cba97
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/197cba97
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/197cba97

Branch: refs/heads/common-2.0.x
Commit: 197cba977e38ffbb8783d6d3f5bec93e7e2a37f7
Parents: 9f704a7
Author: audreyso <au...@adobe.com>
Authored: Fri Oct 7 14:19:06 2016 -0700
Committer: Audrey So <au...@apache.org>
Committed: Thu Jan 26 17:36:50 2017 -0800

----------------------------------------------------------------------
 .../fixtures/basePkgJson/config.xml             |  14 +
 .../fixtures/basePkgJson/merges/.svn            |   0
 .../fixtures/basePkgJson/package.json           |  11 +
 .../fixtures/basePkgJson/plugins/.svn           |   0
 .../fixtures/basePkgJson/www/css/index.css      | 115 ++++++
 .../fixtures/basePkgJson/www/img/logo.png       | Bin 0 -> 21814 bytes
 .../fixtures/basePkgJson/www/index.html         |  43 ++
 .../fixtures/basePkgJson/www/js/index.js        |  49 +++
 .../fixtures/basePkgJson/www/spec.html          |  68 ++++
 .../fixtures/platforms/android/package.json     |  49 +++
 cordova-lib/spec-cordova/package.json.spec.js   | 389 +++++++++++++++++++
 .../spec-cordova/pkgJson-restore.spec.js        | 254 ++++++++++++
 cordova-lib/spec-cordova/pkgJson.spec.js        | 348 +++++++++++++++++
 cordova-lib/spec-cordova/platform.spec.js       |  37 +-
 cordova-lib/src/cordova/platform.js             |  63 ++-
 cordova-lib/src/cordova/plugin.js               |  53 ++-
 16 files changed, 1483 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/config.xml
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/config.xml b/cordova-lib/spec-cordova/fixtures/basePkgJson/config.xml
new file mode 100644
index 0000000..9e7b9e0
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/config.xml
@@ -0,0 +1,14 @@
+<?xml version='1.0' encoding='utf-8'?>
+<widget id="org.testing" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
+    <name>TestBase</name>
+    <description>
+        A sample Apache Cordova application that responds to the deviceready event.
+    </description>
+    <author email="dev@cordova.apache.org" href="http://cordova.io">
+        Apache Cordova Team
+    </author>
+    <content src="index.html" />
+    <access origin="*" />
+    <preference name="fullscreen" value="true" />
+    <preference name="webviewbounce" value="true" />
+</widget>

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/merges/.svn
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/merges/.svn b/cordova-lib/spec-cordova/fixtures/basePkgJson/merges/.svn
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/package.json
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/package.json b/cordova-lib/spec-cordova/fixtures/basePkgJson/package.json
new file mode 100644
index 0000000..eaf9d87
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/package.json
@@ -0,0 +1,11 @@
+{
+  "name": "testbase",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "author": "",
+  "license": "ISC"
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/plugins/.svn
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/plugins/.svn b/cordova-lib/spec-cordova/fixtures/basePkgJson/plugins/.svn
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/www/css/index.css
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/www/css/index.css b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/css/index.css
new file mode 100644
index 0000000..51daa79
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/css/index.css
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+* {
+    -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
+}
+
+body {
+    -webkit-touch-callout: none;                /* prevent callout to copy image, etc when tap to hold */
+    -webkit-text-size-adjust: none;             /* prevent webkit from resizing text to fit */
+    -webkit-user-select: none;                  /* prevent copy paste, to allow, change 'none' to 'text' */
+    background-color:#E4E4E4;
+    background-image:linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+    background-image:-webkit-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+    background-image:-ms-linear-gradient(top, #A7A7A7 0%, #E4E4E4 51%);
+    background-image:-webkit-gradient(
+        linear,
+        left top,
+        left bottom,
+        color-stop(0, #A7A7A7),
+        color-stop(0.51, #E4E4E4)
+    );
+    background-attachment:fixed;
+    font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
+    font-size:12px;
+    height:100%;
+    margin:0px;
+    padding:0px;
+    text-transform:uppercase;
+    width:100%;
+}
+
+/* Portrait layout (default) */
+.app {
+    background:url(../img/logo.png) no-repeat center top; /* 170px x 200px */
+    position:absolute;             /* position in the center of the screen */
+    left:50%;
+    top:50%;
+    height:50px;                   /* text area height */
+    width:225px;                   /* text area width */
+    text-align:center;
+    padding:180px 0px 0px 0px;     /* image height is 200px (bottom 20px are overlapped with text) */
+    margin:-115px 0px 0px -112px;  /* offset vertical: half of image height and text area height */
+                                   /* offset horizontal: half of text area width */
+}
+
+/* Landscape layout (with min-width) */
+@media screen and (min-aspect-ratio: 1/1) and (min-width:400px) {
+    .app {
+        background-position:left center;
+        padding:75px 0px 75px 170px;  /* padding-top + padding-bottom + text area = image height */
+        margin:-90px 0px 0px -198px;  /* offset vertical: half of image height */
+                                      /* offset horizontal: half of image width and text area width */
+    }
+}
+
+h1 {
+    font-size:24px;
+    font-weight:normal;
+    margin:0px;
+    overflow:visible;
+    padding:0px;
+    text-align:center;
+}
+
+.event {
+    border-radius:4px;
+    -webkit-border-radius:4px;
+    color:#FFFFFF;
+    font-size:12px;
+    margin:0px 30px;
+    padding:2px 0px;
+}
+
+.event.listening {
+    background-color:#333333;
+    display:block;
+}
+
+.event.received {
+    background-color:#4B946A;
+    display:none;
+}
+
+@keyframes fade {
+    from { opacity: 1.0; }
+    50% { opacity: 0.4; }
+    to { opacity: 1.0; }
+}
+ 
+@-webkit-keyframes fade {
+    from { opacity: 1.0; }
+    50% { opacity: 0.4; }
+    to { opacity: 1.0; }
+}
+ 
+.blink {
+    animation:fade 3000ms infinite;
+    -webkit-animation:fade 3000ms infinite;
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/www/img/logo.png
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/www/img/logo.png b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/img/logo.png
new file mode 100644
index 0000000..9519e7d
Binary files /dev/null and b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/img/logo.png differ

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/www/index.html
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/www/index.html b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/index.html
new file mode 100644
index 0000000..bde5741
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/index.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+     KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <meta name="format-detection" content="telephone=no" />
+        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
+        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
+        <link rel="stylesheet" type="text/css" href="css/index.css" />
+        <title>Hello World</title>
+    </head>
+    <body>
+        <div class="app">
+            <h1>Apache Cordova</h1>
+            <div id="deviceready" class="blink">
+                <p class="event listening">Connecting to Device</p>
+                <p class="event received">Device is Ready</p>
+            </div>
+        </div>
+        <script type="text/javascript" src="cordova.js"></script>
+        <script type="text/javascript" src="js/index.js"></script>
+        <script type="text/javascript">
+            app.initialize();
+        </script>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/www/js/index.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/www/js/index.js b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/js/index.js
new file mode 100644
index 0000000..31d9064
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/js/index.js
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+var app = {
+    // Application Constructor
+    initialize: function() {
+        this.bindEvents();
+    },
+    // Bind Event Listeners
+    //
+    // Bind any events that are required on startup. Common events are:
+    // 'load', 'deviceready', 'offline', and 'online'.
+    bindEvents: function() {
+        document.addEventListener('deviceready', this.onDeviceReady, false);
+    },
+    // deviceready Event Handler
+    //
+    // The scope of 'this' is the event. In order to call the 'receivedEvent'
+    // function, we must explicity call 'app.receivedEvent(...);'
+    onDeviceReady: function() {
+        app.receivedEvent('deviceready');
+    },
+    // Update DOM on a Received Event
+    receivedEvent: function(id) {
+        var parentElement = document.getElementById(id);
+        var listeningElement = parentElement.querySelector('.listening');
+        var receivedElement = parentElement.querySelector('.received');
+
+        listeningElement.setAttribute('style', 'display:none;');
+        receivedElement.setAttribute('style', 'display:block;');
+
+        console.log('Received Event: ' + id);
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/basePkgJson/www/spec.html
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/basePkgJson/www/spec.html b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/spec.html
new file mode 100644
index 0000000..71f00de
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/basePkgJson/www/spec.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+     KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<html>
+    <head>
+        <title>Jasmine Spec Runner</title>
+
+        <!-- jasmine source -->
+        <link rel="shortcut icon" type="image/png" href="spec/lib/jasmine-1.2.0/jasmine_favicon.png">
+        <link rel="stylesheet" type="text/css" href="spec/lib/jasmine-1.2.0/jasmine.css">
+        <script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine.js"></script>
+        <script type="text/javascript" src="spec/lib/jasmine-1.2.0/jasmine-html.js"></script>
+
+        <!-- include source files here... -->
+        <script type="text/javascript" src="js/index.js"></script>
+
+        <!-- include spec files here... -->
+        <script type="text/javascript" src="spec/helper.js"></script>
+        <script type="text/javascript" src="spec/index.js"></script>
+
+        <script type="text/javascript">
+            (function() {
+                var jasmineEnv = jasmine.getEnv();
+                jasmineEnv.updateInterval = 1000;
+
+                var htmlReporter = new jasmine.HtmlReporter();
+
+                jasmineEnv.addReporter(htmlReporter);
+
+                jasmineEnv.specFilter = function(spec) {
+                    return htmlReporter.specFilter(spec);
+                };
+
+                var currentWindowOnload = window.onload;
+
+                window.onload = function() {
+                    if (currentWindowOnload) {
+                        currentWindowOnload();
+                    }
+                    execJasmine();
+                };
+
+                function execJasmine() {
+                    jasmineEnv.execute();
+                }
+            })();
+        </script>
+    </head>
+    <body>
+        <div id="stage" style="display:none;"></div>
+    </body>
+</html>

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/fixtures/platforms/android/package.json
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/fixtures/platforms/android/package.json b/cordova-lib/spec-cordova/fixtures/platforms/android/package.json
new file mode 100644
index 0000000..6b81b07
--- /dev/null
+++ b/cordova-lib/spec-cordova/fixtures/platforms/android/package.json
@@ -0,0 +1,49 @@
+{
+  "name": "cordova-android",
+  "version": "5.2.2",
+  "description": "cordova-android release",
+  "bin": {
+    "create": "bin/create"
+  },
+  "main": "bin/templates/cordova/Api.js",
+  "repository": {
+    "type": "git",
+    "url": "https://git-wip-us.apache.org/repos/asf/cordova-android.git"
+  },
+  "keywords": [
+    "android",
+    "cordova",
+    "apache"
+  ],
+  "scripts": {
+    "test": "npm run jshint && jasmine-node --color spec/unit",
+    "cover": "istanbul cover --root bin/templates/cordova --print detail node_modules/jasmine-node/bin/jasmine-node -- spec/unit",
+    "test-build": "jasmine-node --captureExceptions --color spec/e2e",
+    "jshint": "node node_modules/jshint/bin/jshint bin && node node_modules/jshint/bin/jshint spec"
+  },
+  "author": "Apache Software Foundation",
+  "license": "Apache-2.0",
+  "dependencies": {
+    "cordova-common": "^1.4.0",
+    "elementtree": "^0.1.6",
+    "nopt": "^3.0.1",
+    "properties-parser": "^0.2.3",
+    "q": "^1.4.1",
+    "shelljs": "^0.5.3"
+  },
+  "bundledDependencies": [
+    "cordova-common",
+    "elementtree",
+    "nopt",
+    "properties-parser",
+    "q",
+    "shelljs"
+  ],
+  "devDependencies": {
+    "istanbul": "^0.4.2",
+    "jasmine-node": "^1.14.5",
+    "jshint": "^2.6.0",
+    "promise-matchers": "~0",
+    "rewire": "^2.1.3"
+  }
+}

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/package.json.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/package.json.spec.js b/cordova-lib/spec-cordova/package.json.spec.js
new file mode 100644
index 0000000..1755834
--- /dev/null
+++ b/cordova-lib/spec-cordova/package.json.spec.js
@@ -0,0 +1,389 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var helpers = require('./helpers'),
+    path = require('path'),
+    fs = require('fs'),
+    shell = require('shelljs'),
+    superspawn = require('cordova-common').superspawn,
+    Q = require('q'),
+    events = require('cordova-common').events,
+    cordova = require('../src/cordova/cordova'),
+    rewire = require('rewire'),
+    prepare = require('../src/cordova/prepare'),
+    platforms = require('../src/platforms/platforms'),
+    platform = rewire('../src/cordova/platform.js');
+
+var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker';
+var pluginsDir = path.join(__dirname, 'fixtures', 'plugins');
+
+function addPlugin(target, id, options) {
+    // Checks that there are no plugins yet.
+    return cordova.raw.plugin('list').then(function() {
+        expect(results).toMatch(/No plugins added/gi);
+    }).then(function() {
+        // Adds a fake plugin from fixtures.
+        return cordova.raw.plugin('add', target, options);
+    }).then(function() {
+        expect(path.join(project, 'plugins', id, 'plugin.xml')).toExist();
+    }).then(function() {
+        return cordova.raw.plugin('ls');
+    }).then(function() {
+        expect(results).toContain(id);
+    });
+}
+// Runs: remove, list.
+function removePlugin(id, options) {
+    return cordova.raw.plugin('rm', id)
+    .then(function() {
+        // The whole dir should be gone.
+        expect(path.join(project, 'plugins', id)).not.toExist();
+    }).then(function() {
+        return cordova.raw.plugin('ls');
+    }).then(function() {
+        expect(results).toMatch(/No plugins added/gi);
+    });
+}
+// Checks if plugin list is empty.
+function emptyPluginList() {
+    return cordova.raw.plugin('list').then(function() {
+        var installed = results.match(/Installed plugins:\n  (.*)/);
+        expect(installed).toBeDefined();
+        expect(installed[1].indexOf('fake-plugin')).toBe(-1);
+    });
+}
+// Checks if plugin list exists.
+function fullPluginList() {
+    return cordova.raw.plugin('list').then(function() {
+        var installed = results.match(/Installed plugins:\n  (.*)/);
+        expect(installed).toBeDefined();
+        expect(installed[1].indexOf('fake-plugin')).toBeGreaterThan(-1);
+    });
+}
+
+// This group of tests checks if plugins are added and removed as expected.
+describe('plugin end-to-end', function() {
+    var pluginId = 'cordova-plugin-device';
+    var tmpDir = helpers.tmpDir('platform_test_pkgjson');
+    var project = path.join(tmpDir, 'project');
+    var results;
+
+    events.on('results', function(res) { results = res; });
+
+    beforeEach(function() {
+        shell.rm('-rf', project);
+
+        // Copy then move because we need to copy everything, but that means it will copy the whole directory.
+        // Using /* doesn't work because of hidden files.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson'), tmpDir);
+        shell.mv(path.join(tmpDir, 'basePkgJson'), project);
+        // Copy some platform to avoid working on a project with no platforms.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform), path.join(project, 'platforms'));
+        process.chdir(project);
+
+        delete process.env.PWD;
+
+        spyOn(prepare, 'preparePlatforms').andCallThrough();
+    });
+
+    afterEach(function() {
+        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+        shell.rm('-rf', tmpDir);
+    });
+
+    it('Test#001 : should successfully add and remove a plugin with no options', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var retPromise;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save
+        return cordova.raw.plugin('add', pluginId, {'save':true})
+        .then(function() {
+            // Check that the plugin add was successful.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).then(function() {
+            // And now remove it with --save.
+            return cordova.raw.plugin('rm', pluginId, {'save':true})
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the plugin removed is in not in the platforms
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#002 : should successfully NOT add a plugin if save is not there', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', 'cordova-plugin-camera', {'save':true})
+        .then(function() {
+            // Add a second plugin without save
+            return cordova.raw.plugin('add', pluginId);
+        }).then(function() {
+            // Check the plugin add was successful for the first plugin that had --save.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toBeDefined();
+            // Expect that the second plugin is not added.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#003 : should NOT remove plugin if there is no --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var retPromise;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', pluginId, {'save':true})
+        .then(function() {
+            // Check the platform add was successful.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).then(function() {
+            // And now remove it, but without --save.
+            return cordova.raw.plugin('rm', 'cordova-plugin-device')
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // The plugin should still be in package.json.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#004 : should successfully add and remove a plugin with variables and save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var retPromise;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', pluginId, {'save':true, 'cli_variables': {'someKey':'someValue'}})
+        .then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Check the plugin add was successful and that variables have been added too.
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]['someKey']).toEqual('someValue');
+        }).then(function() {
+            // And now remove it with --save.
+            return cordova.raw.plugin('rm', pluginId, {'save':true})
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the plugin and variables were removed successfully.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+});
+
+// This group of tests checks if platforms are added and removed as expected.
+describe('platform end-to-end with --save', function () {
+    var tmpDir = helpers.tmpDir('platform_test_pkgjson');
+    var project = path.join(tmpDir, 'project');
+    var results;
+
+    beforeEach(function() {
+        shell.rm('-rf', tmpDir);
+
+        // cp then mv because we need to copy everything, but that means it'll copy the whole directory.
+        // Using /* doesn't work because of hidden files.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson'), tmpDir);
+        shell.mv(path.join(tmpDir, 'basePkgJson'), project);
+        process.chdir(project);
+
+        // The config.json in the fixture project points at fake "local" paths.
+        // Since it's not a URL, the lazy-loader will just return the junk path.
+        spyOn(superspawn, 'spawn').andCallFake(function(cmd, args) {
+            if (cmd.match(/create\b/)) {
+                // This is a call to the bin/create script, so do the copy ourselves.
+                shell.cp('-R', path.join(__dirname, 'fixtures', 'platforms', 'android'), path.join(project, 'platforms'));
+            } else if(cmd.match(/version\b/)) {
+                return Q('3.3.0');
+            } else if(cmd.match(/update\b/)) {
+                fs.writeFileSync(path.join(project, 'platforms', helpers.testPlatform, 'updated'), 'I was updated!', 'utf-8');
+            }
+            return Q();
+        });
+        events.on('results', function(res) { results = res; });
+    });
+
+    afterEach(function() {
+        delete require.cache[require.resolve(path.join(process.cwd(),'package.json'))];
+        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+        shell.rm('-rf', tmpDir);
+
+    });
+
+    // Factoring out some repeated checks.
+    function emptyPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBe(-1);
+        });
+    }
+    function fullPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        });
+    }
+
+    it('Test#006 : platform is added and removed correctly with --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        expect(pkgJsonPath).toExist();
+        var pkgJson = require(pkgJsonPath);
+
+        // Check there are no platforms yet.
+        emptyPlatformList().then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+        .then(function() {
+            // And now remove it with --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the platform removed is in not in the platforms key
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(-1);
+        }).then(emptyPlatformList) // platform ls should be empty too.
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#007 : should not remove platforms from package.json when removing without --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        expect(pkgJsonPath).toExist();
+        var pkgJson = require(pkgJsonPath);
+        emptyPlatformList().then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+        .then(function() {
+            // And now remove it without --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform]);
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+
+            // Check that the platform removed without --save is still in platforms key.
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        }).then(emptyPlatformList)
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#008 : should not add platform to package.json when adding without --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var platformToAdd = helpers.testPlatform;
+        expect(pkgJsonPath).toExist();
+
+        // Add platform without --save.
+        cordova.raw.platform('add',platformToAdd)
+        .then(function() {
+            // Check the platform add was successful, reload, skipping cache
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Beware empty/missing cordova object
+            var pckJsonCordova = pkgJson.cordova || {platforms:[]};
+            // Check that the platform has NOT been added.
+            expect(pckJsonCordova.platforms.indexOf(platformToAdd)).toEqual(-1);
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    });
+
+    it('Test#009 : should only add the platform to package.json with --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var platformToAdd = helpers.testPlatform;
+        var platformNotToAdd = 'ios';
+        expect(pkgJsonPath).toExist();
+
+        // Add a platform without --save.
+        cordova.raw.platform('add',platformNotToAdd)
+        .then(function() {
+            // And now add another platform with --save.
+            return cordova.raw.platform('add', platformToAdd, {'save':true});
+        }).then(function() {
+            // Check the platform add was successful, reload, skipping cache
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Beware empty/missing cordova object
+            var pckJsonCordova = pkgJson.cordova || {platforms:[]};
+            // Check that only the platform added with --save was added to package.json.
+            expect(pckJsonCordova.platforms.indexOf(platformToAdd)).toBeGreaterThan(-1);
+            expect(pckJsonCordova.platforms.indexOf(platformNotToAdd)).toEqual(-1);
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/pkgJson-restore.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/pkgJson-restore.spec.js b/cordova-lib/spec-cordova/pkgJson-restore.spec.js
new file mode 100644
index 0000000..1a1966d
--- /dev/null
+++ b/cordova-lib/spec-cordova/pkgJson-restore.spec.js
@@ -0,0 +1,254 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var helpers = require('./helpers'),
+    path = require('path'),
+    fs = require('fs'),
+    shell = require('shelljs'),
+    superspawn = require('cordova-common').superspawn,
+    Q = require('q'),
+    events = require('cordova-common').events,
+    cordova = require('../src/cordova/cordova'),
+    rewire = require('rewire'),
+    prepare = require('../src/cordova/prepare'),
+    platforms = require('../src/platforms/platforms'),
+    platform = rewire('../src/cordova/platform.js');
+
+var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker';
+var pluginsDir = path.join(__dirname, 'fixtures', 'plugins');
+
+// Testing will check if "cordova prepare" is restoring platforms as expected
+describe('platform end-to-end with --save', function () {
+    var tmpDir = helpers.tmpDir('platform_test_pkgjson');
+    var project = path.join(tmpDir, 'project'); // call it projectPath
+    var results;
+
+    beforeEach(function() {
+        shell.rm('-rf', tmpDir);
+        // cp then mv because we need to copy everything, but that means it'll copy the whole directory.
+        // Using /* doesn't work because of hidden files.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson2'), tmpDir);
+        shell.mv(path.join(tmpDir, 'basePkgJson2'), project);
+        process.chdir(project);
+        events.on('results', function(res) { results = res; });
+    });
+
+    afterEach(function() {
+        var cwd = process.cwd();
+        delete require.cache[require.resolve(path.join(process.cwd(),'package.json'))];
+        //delete require.cache[require.resolve(path.join(cwd,'platforms/platforms.json'))];
+        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+        shell.rm('-rf', tmpDir);
+    });
+
+    // Factoring out some repeated checks.
+    function emptyPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBe(-1);
+        });
+    }
+    function fullPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        });
+    }
+
+    it('Test#001 : should restore platform that has been removed from project', function(done) {
+        var cwd = process.cwd();
+        var pkgJsonPath = path.join(cwd,'package.json');
+        var pkgJson = require(pkgJsonPath);
+        var platformsFolderPath;
+
+        emptyPlatformList().then(function() {
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            platformsFolderPath = (path.join(cwd,'platforms/platforms.json'));
+            var platformsJson = require(platformsFolderPath);
+
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+            expect(platformsJson).toBeDefined();
+            // Expect that "helpers.testPlatform" in the installed platform list in platforms.json
+            expect(platformsJson[helpers.testPlatform]).toBeDefined();
+
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+        .then(function() {
+            // And now remove it without --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform]);
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+
+            // Check that the platform removed without --save is still in platforms key.
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+            // Check that the platform was removed from the platforms.json
+            expect(platformsJson[helpers.testPlatform]).toBeUndefined();
+        }).then(function() {
+            // Run cordova prepare
+            return cordova.raw.prepare();
+        })
+        .then(function() {
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            // Expect "helpers.testPlatform" to be in the installed platforms list
+            expect(platformsJson[helpers.testPlatform]).toBeDefined();
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    },30000);
+
+    it('Test#002 : should NOT restore platform that was removed with --save', function(done) {
+        var cwd = process.cwd();
+        var pkgJsonPath = path.join(cwd,'package.json');
+        var pkgJson = require(pkgJsonPath);
+        var platformsFolderPath;
+        var secondPlatformAdded = 'ios';
+
+        emptyPlatformList().then(function() {
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save': true});
+        }).then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            return cordova.raw.platform('add',secondPlatformAdded, {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            platformsFolderPath = (path.join(cwd,'platforms/platforms.json'));
+            var platformsJson = require(platformsFolderPath);
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(0);
+            expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(1);
+            expect(platformsJson).toBeDefined();
+            // Expect that "helpers.testPlatform" in the installed platform list in platforms.json
+            expect(platformsJson[helpers.testPlatform]).toBeDefined();
+
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+          .then(function() {
+            // And now remove it without --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            return cordova.raw.platform('rm', secondPlatformAdded);
+        }).then(function() {
+            // Delete any previous caches of require(package.json) and (platformsJson)
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Check that the platform removed without --save is still in platforms key.
+            expect(pkgJson.cordova.platforms.indexOf(secondPlatformAdded)).toEqual(0);
+            // Check that the platform was removed from the platforms.json
+            expect(platformsJson[helpers.testPlatform]).toBeUndefined();
+        }).then(function() {
+            // Run cordova prepare
+            return cordova.raw.prepare();
+        })
+        .then(function() {
+            // Delete any previous caches of platformsJson
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            // Expect "helpers.testPlatform" to be in the installed platforms list
+            expect(platformsJson[helpers.testPlatform]).toBeUndefined();
+            expect(platformsJson[secondPlatformAdded]).toBeDefined();
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    },30000);
+
+
+    it('Test#003 : should NOT restore platform that was not saved and removed', function(done) {
+        var cwd = process.cwd();
+        var pkgJsonPath = path.join(cwd,'package.json');
+        var pkgJson = require(pkgJsonPath);
+        var platformsFolderPath;
+        var secondPlatformAdded = 'ios';
+
+        emptyPlatformList().then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            return cordova.raw.platform('add', secondPlatformAdded);
+        }).then(function() {
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            platformsFolderPath = (path.join(cwd,'platforms/platforms.json'));
+            var platformsJson = require(platformsFolderPath);
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            //expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(-1);
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+            // Expect that "helpers.testPlatform" in the installed platform list in platforms.json
+            expect(platformsJson[helpers.testPlatform]).toBeDefined();
+
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+          .then(function() {
+            // And now remove it without --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform]);
+        }).then(function() {
+            return cordova.raw.platform('rm', secondPlatformAdded);
+        }).then(function() {
+            // Delete any previous caches of require(package.json) and (platformsJson)
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Check that the platform removed without --save is still in platforms key.
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+            // Check that the platform was removed from the platforms.json
+            expect(platformsJson[secondPlatformAdded]).toBeUndefined();
+            expect(platformsJson[helpers.testPlatform]).toBeUndefined();
+        }).then(function() {
+            // Run cordova prepare
+            return cordova.raw.prepare();
+        })
+        .then(function() {
+            // Delete any previous caches of platformsJson
+            delete require.cache[require.resolve(platformsFolderPath)];
+            platformsJson = require(platformsFolderPath);
+            // Expect "helpers.testPlatform" to be in the installed platforms list
+            expect(platformsJson[helpers.testPlatform]).toBeDefined();
+            expect(platformsJson[secondPlatformAdded]).toBeUndefined();
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    },30000);
+});
+
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/pkgJson.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/pkgJson.spec.js b/cordova-lib/spec-cordova/pkgJson.spec.js
new file mode 100644
index 0000000..93af1dc
--- /dev/null
+++ b/cordova-lib/spec-cordova/pkgJson.spec.js
@@ -0,0 +1,348 @@
+/**
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+*/
+var helpers = require('./helpers'),
+    path = require('path'),
+    fs = require('fs'),
+    shell = require('shelljs'),
+    superspawn = require('cordova-common').superspawn,
+    Q = require('q'),
+    events = require('cordova-common').events,
+    cordova = require('../src/cordova/cordova'),
+    rewire = require('rewire'),
+    prepare = require('../src/cordova/prepare'),
+    platforms = require('../src/platforms/platforms'),
+    platform = rewire('../src/cordova/platform.js');
+
+var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker';
+var pluginsDir = path.join(__dirname, 'fixtures', 'plugins');
+
+function addPlugin(target, id, options) {
+    // Checks that there are no plugins yet.
+    return cordova.raw.plugin('list').then(function() {
+        expect(results).toMatch(/No plugins added/gi);
+    }).then(function() {
+        // Adds a fake plugin from fixtures.
+        return cordova.raw.plugin('add', target, options);
+    }).then(function() {
+        expect(path.join(project, 'plugins', id, 'plugin.xml')).toExist();
+    }).then(function() {
+        return cordova.raw.plugin('ls');
+    }).then(function() {
+        expect(results).toContain(id);
+    });
+}
+// Runs: remove, list.
+function removePlugin(id, options) {
+    return cordova.raw.plugin('rm', id)
+    .then(function() {
+        // The whole dir should be gone.
+        expect(path.join(project, 'plugins', id)).not.toExist();
+    }).then(function() {
+        return cordova.raw.plugin('ls');
+    }).then(function() {
+        expect(results).toMatch(/No plugins added/gi);
+    });
+}
+// This group of tests checks if plugins are added and removed as expected from package.json.
+describe('plugin end-to-end', function() {
+    var pluginId = 'cordova-plugin-device';
+    var tmpDir = helpers.tmpDir('plugin_test_pkgjson');
+    var project = path.join(tmpDir, 'project');
+    var results;
+
+    events.on('results', function(res) { results = res; });
+
+    beforeEach(function() {
+        shell.rm('-rf', project);
+
+        // Copy then move because we need to copy everything, but that means it will copy the whole directory.
+        // Using /* doesn't work because of hidden files.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson'), tmpDir);
+        shell.mv(path.join(tmpDir, 'basePkgJson'), project);
+        // Copy some platform to avoid working on a project with no platforms.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'platforms', helpers.testPlatform), path.join(project, 'platforms'));
+        process.chdir(project);
+
+        delete process.env.PWD;
+    });
+
+    afterEach(function() {
+        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+        shell.rm('-rf', tmpDir);
+    });
+
+    it('Test#001 : should successfully add and remove a plugin with save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+    
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save
+        return cordova.raw.plugin('add', pluginId, {'save':true})
+        .then(function() {
+            // Check that the plugin add was successful.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).then(function() {
+            // And now remove it with --save.
+            return cordova.raw.plugin('rm', pluginId, {'save':true})
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the plugin removed is in not in the platforms
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#002 : should NOT add a plugin to package.json if --save is not used', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', 'cordova-plugin-camera', {'save':true})
+        .then(function() {
+            // Add a second plugin without save
+            return cordova.raw.plugin('add', pluginId);
+        }).then(function() {
+            // Check the plugin add was successful for the first plugin that had --save.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins['cordova-plugin-camera']).toBeDefined();
+            // Expect that the second plugin is not added.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#003 : should NOT remove plugin from package.json if there is no --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', pluginId, {'save':true})
+        .then(function() {
+            // Check the platform add was successful.
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).then(function() {
+            // And now remove it, but without --save.
+            return cordova.raw.plugin('rm', 'cordova-plugin-device')
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // The plugin should still be in package.json.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#004 : should successfully add and remove a plugin with variables and save to package.json', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+
+        expect(pkgJsonPath).toExist();
+
+        // Add the plugin with --save.
+        return cordova.raw.plugin('add', pluginId, {'save':true, 'cli_variables': {'someKey':'someValue'}})
+        .then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Check the plugin add was successful and that variables have been added too.
+            expect(pkgJson).not.toBeUndefined();
+            expect(pkgJson.cordova.plugins).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]).toBeDefined();
+            expect(pkgJson.cordova.plugins[pluginId]['someKey']).toEqual('someValue');
+        }).then(function() {
+            // And now remove it with --save.
+            return cordova.raw.plugin('rm', pluginId, {'save':true})
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the plugin and variables were removed successfully.
+            expect(pkgJson.cordova.plugins[pluginId]).toBeUndefined();
+        }).fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+});
+
+// This group of tests checks if platforms are added and removed as expected from package.json.
+describe('platform end-to-end with --save', function () {
+    var tmpDir = helpers.tmpDir('platform_test_pkgjson');
+    var project = path.join(tmpDir, 'project');
+    var results;
+
+    beforeEach(function() {
+        shell.rm('-rf', tmpDir);
+
+        // cp then mv because we need to copy everything, but that means it'll copy the whole directory.
+        // Using /* doesn't work because of hidden files.
+        shell.cp('-R', path.join(__dirname, 'fixtures', 'basePkgJson'), tmpDir);
+        shell.mv(path.join(tmpDir, 'basePkgJson'), project);
+        process.chdir(project);
+        events.on('results', function(res) { results = res; });
+    });
+
+    afterEach(function() {
+        delete require.cache[require.resolve(path.join(process.cwd(),'package.json'))];
+        process.chdir(path.join(__dirname, '..'));  // Needed to rm the dir on Windows.
+        shell.rm('-rf', tmpDir);
+    });
+
+    // Factoring out some repeated checks.
+    function emptyPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBe(-1);
+        });
+    }
+    function fullPlatformList() {
+        return cordova.raw.platform('list').then(function() {
+            var installed = results.match(/Installed platforms:\n  (.*)/);
+            expect(installed).toBeDefined();
+            expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        });
+    }
+
+    it('Test#006 : platform is added and removed correctly with --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        expect(pkgJsonPath).toExist();
+        var pkgJson;
+
+        // Check there are no platforms yet.
+        emptyPlatformList().then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+        .then(function() {
+            // And now remove it with --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Checking that the platform removed is in not in the platforms key
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toEqual(-1);
+        }).then(emptyPlatformList) // platform ls should be empty too.
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#007 : should not remove platforms from package.json when removing without --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        expect(pkgJsonPath).toExist();
+        var pkgJson;
+        emptyPlatformList().then(function() {
+            // Add the testing platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful.
+            pkgJson = require(pkgJsonPath);
+            expect(pkgJson.cordova.platforms).not.toBeUndefined();
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        }).then(fullPlatformList) // Platform should still be in platform ls.
+        .then(function() {
+            // And now remove it without --save.
+            return cordova.raw.platform('rm', [helpers.testPlatform]);
+        }).then(function() {
+            // Delete any previous caches of require(package.json)
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Check that the platform removed without --save is still in platforms key.
+            expect(pkgJson.cordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+        }).then(emptyPlatformList)
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        }).fin(done);
+    });
+
+    it('Test#008 : should not add platform to package.json when adding without --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        expect(pkgJsonPath).toExist();
+
+        // Add platform without --save.
+        cordova.raw.platform('add',[helpers.testPlatform])
+        .then(function() {
+            // Check the platform add was successful, reload, skipping cache
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Cordova key should not exist in package.json
+            expect(pkgJson.cordova).toBeUndefined();
+        }).then(fullPlatformList)
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    });
+
+    it('Test#009 : should only add the platform to package.json with --save', function(done) {
+        var pkgJsonPath = path.join(process.cwd(),'package.json');
+        var pkgJson;
+        var platformNotToAdd = 'ios';
+        expect(pkgJsonPath).toExist();
+
+        // Add a platform without --save.
+        cordova.raw.platform('add',platformNotToAdd)
+        .then(function() {
+            // And now add another platform with --save.
+            return cordova.raw.platform('add', [helpers.testPlatform], {'save':true});
+        }).then(function() {
+            // Check the platform add was successful, reload, skipping cache
+            delete require.cache[require.resolve(pkgJsonPath)];
+            pkgJson = require(pkgJsonPath);
+            // Beware empty/missing cordova object
+            var pckJsonCordova = pkgJson.cordova || {platforms:[]};
+            // Check that only the platform added with --save was added to package.json.
+            expect(pckJsonCordova.platforms.indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
+            expect(pckJsonCordova.platforms.indexOf(platformNotToAdd)).toEqual(-1);
+        })
+        .fail(function(err) {
+            expect(err).toBeUndefined();
+        })
+        .fin(done);
+    });
+});
+

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/spec-cordova/platform.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/platform.spec.js b/cordova-lib/spec-cordova/platform.spec.js
index 1a40130..4a3b2f1 100644
--- a/cordova-lib/spec-cordova/platform.spec.js
+++ b/cordova-lib/spec-cordova/platform.spec.js
@@ -28,6 +28,8 @@ var helpers = require('./helpers'),
     cordova = require('../src/cordova/cordova'),
     plugman = require('../src/plugman/plugman'),
     rewire = require('rewire'),
+    prepare = require('../src/cordova/prepare'),
+    platforms = require('../src/platforms/platforms'),
     platform = rewire('../src/cordova/platform.js');
 
 var projectRoot = 'C:\\Projects\\cordova-projects\\move-tracker';
@@ -92,6 +94,34 @@ describe('platform end-to-end', function () {
             expect(installed[1].indexOf(helpers.testPlatform)).toBeGreaterThan(-1);
         });
     }
+    // Runs: list, add, list
+    function addPlugin(target, id, options) {
+        // Check there are no plugins yet.
+        return cordova.raw.plugin('list').then(function() {
+            expect(results).toMatch(/No plugins added/gi);
+        }).then(function() {
+            // Add a fake plugin from fixtures.
+            return cordova.raw.plugin('add', target, options);
+        }).then(function() {
+            expect(path.join(project, 'plugins', id, 'plugin.xml')).toExist();
+        }).then(function() {
+            return cordova.raw.plugin('ls');
+        }).then(function() {
+            expect(results).toContain(id);
+        });
+    }
+    // Runs: remove, list
+    function removePlugin(id) {
+        return cordova.raw.plugin('rm', id)
+        .then(function() {
+            // The whole dir should be gone.
+            expect(path.join(project, 'plugins', id)).not.toExist();
+        }).then(function() {
+            return cordova.raw.plugin('ls');
+        }).then(function() {
+            expect(results).toMatch(/No plugins added/gi);
+        });
+    }        
 
     // The flows we want to test are add, rm, list, and upgrade.
     // They should run the appropriate hooks.
@@ -104,6 +134,7 @@ describe('platform end-to-end', function () {
             // Add the testing platform.
             return cordova.raw.platform('add', [helpers.testPlatform]);
         }).then(function() {
+            console.log("!!!");
             // Check the platform add was successful.
             expect(path.join(project, 'platforms', helpers.testPlatform)).toExist();
             expect(path.join(project, 'platforms', helpers.testPlatform, 'cordova')).toExist();
@@ -119,7 +150,6 @@ describe('platform end-to-end', function () {
             // And now remove it.
             return cordova.raw.platform('rm', [helpers.testPlatform]);
         }).then(function() {
-            // It should be gone.
             expect(path.join(project, 'platforms', helpers.testPlatform)).not.toExist();
         }).then(emptyPlatformList) // platform ls should be empty too.
         .fail(function(err) {
@@ -354,5 +384,8 @@ describe('plugin add and rm end-to-end --fetch', function () {
             expect(err).toBeUndefined();
         })
         .fin(done);
-    }, 100000);
+    }, 60000);
 });
+
+        // Runs: list, add, list
+    
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index 0d5f166..e34b4db 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -16,7 +16,6 @@
     specific language governing permissions and limitations
     under the License.
 */
-
 var config            = require('./config'),
     cordova           = require('./cordova'),
     prepare           = require('./prepare'),
@@ -38,9 +37,9 @@ var config            = require('./config'),
     _                 = require('underscore'),
     PlatformJson      = require('cordova-common').PlatformJson,
     fetch             = require('cordova-fetch'),
-    npmUninstall         = require('cordova-fetch').uninstall,
+    npmUninstall      = require('cordova-fetch').uninstall,
     platformMetadata  = require('./platform_metadata');
-
+ 
 // Expose the platform parsers on top of this command
 for (var p in platforms) {
     module.exports[p] = platforms[p];
@@ -84,6 +83,16 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
 
     return hooksRunner.fire('before_platform_' + cmd, opts)
     .then(function() {
+        var modifiedPkgJson = false;
+        var pkgJson;
+        var pkgJsonPath = path.join(projectRoot, 'package.json');
+        // If statement to see if pkgJsonPath exists in the filesystem
+        if(fs.existsSync(pkgJsonPath)) {
+            pkgJson = require(pkgJsonPath);
+        } else {
+            // Create package.json in cordova@7
+        }
+
         return promiseutil.Q_chainmap(targets, function(target) {
             // For each platform, download it and call its helper script.
             var parts = target.split('@');
@@ -217,6 +226,7 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                 .then(function() {
                     var saveVersion = !spec || semver.validRange(spec, true);
 
+
                     // Save platform@spec into platforms.json, where 'spec' is a version or a soure location. If a
                     // source location was specified, we always save that. Otherwise we save the version that was
                     // actually installed.
@@ -235,11 +245,34 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                         cfg.removeEngine(platform);
                         cfg.addEngine(platform, spec);
                         cfg.write();
+
+                        // If package.json exists, cordova key and platforms will be added to package.json if not
+                        // already there 
+                        if (pkgJson === undefined) {
+                            return;
+                        }
+                        if (pkgJson.cordova === undefined) {
+                            pkgJson.cordova = {};
+                        }
+                        if (pkgJson.cordova.platforms === undefined){
+                            pkgJson.cordova.platforms = [];
+                        }
+                        if (pkgJson.cordova.platforms.indexOf(platform) === -1) {
+                            events.emit('log','adding '+platform+' to cordova.platforms array in package.json');
+                            pkgJson.cordova.platforms.push(platform);
+                            modifiedPkgJson = true;
+                        } else {
+                            events.emit('verbose', platform + ' already added to platforms key');
+                        }
                     }
                 });
             });
+        }).then(function(){
+            if (modifiedPkgJson === true) {
+                fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+            }
         });
-    }).then(function() {
+    }).then(function(){
         return hooksRunner.fire('after_platform_' + cmd, opts);
     });
 }
@@ -379,6 +412,13 @@ function remove(hooksRunner, projectRoot, targets, opts) {
     }).then(function() {
         var config_json = config.read(projectRoot);
         var autosave =  config_json.auto_save_platforms || false;
+        var modifiedPkgJson = false;
+        var pkgJson;
+        var pkgJsonPath = path.join(projectRoot,'package.json');
+        // If statement to see if pkgJsonPath exists in the filesystem
+        if(fs.existsSync(pkgJsonPath)) {
+            pkgJson = require(pkgJsonPath);
+        }
         if(opts.save || autosave){
             targets.forEach(function(target) {
                 var platformName = target.split('@')[0];
@@ -387,7 +427,21 @@ function remove(hooksRunner, projectRoot, targets, opts) {
                 events.emit('log', 'Removing platform ' + target + ' from config.xml file...');
                 cfg.removeEngine(platformName);
                 cfg.write();
+                // If package.json exists and contains a specified platform in cordova.platforms, it will be removed
+                if(pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.platforms !== undefined) {
+                    var index = pkgJson.cordova.platforms.indexOf(platformName);
+                    //Check if platform exists in platforms array
+                    if (pkgJson.cordova.platforms !== undefined && index > -1) {
+                        events.emit('log', 'Removing ' + platformName + ' from cordova.platforms array in package.json');
+                        pkgJson.cordova.platforms.splice(index, 1);
+                        modifiedPkgJson = true;
+                    }
+                }
             });
+            //Write out new package.json if changes have been made
+            if(modifiedPkgJson === true) {
+                fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+            }
         }
     }).then(function() {
         // Remove targets from platforms.json
@@ -402,6 +456,7 @@ function remove(hooksRunner, projectRoot, targets, opts) {
                 if(target in platforms) {
                     target = 'cordova-'+target;
                 }
+                //edits package.json
                 return npmUninstall(target, projectRoot, opts);
             });
         }

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/197cba97/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 4ccf40e..4203ca3 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -235,6 +235,35 @@ module.exports = function plugin(command, targets, opts) {
                                 cfg.write();
 
                                 events.emit('results', 'Saved plugin info for "' + pluginInfo.id + '" to config.xml');
+
+                                var pkgJson;
+                                var pkgJsonPath = path.join(projectRoot,'package.json');
+
+                                // If statement to see if pkgJsonPath exists in the filesystem
+                                if(fs.existsSync(pkgJsonPath)) {
+                                    // Delete any previous caches of require(package.json)
+                                    delete require.cache[require.resolve(pkgJsonPath)];
+                                    pkgJson = require(pkgJsonPath);
+                                } else {
+                                    // Create package.json in cordova@7
+                                }
+                                // If package.json exists, the plugin object and plugin name will be added to package.json 
+                                // if not already there
+                                if (pkgJson === undefined) {
+                                    return;
+                                }
+                                if (pkgJson.cordova === undefined) {
+                                    pkgJson.cordova = {};
+                                }
+                                if (pkgJson.cordova.plugins === undefined) {
+                                    pkgJson.cordova.plugins = {};
+                                }
+                                if (pkgJson.cordova.plugins !== undefined) {
+                                    pkgJson.cordova.plugins[pluginInfo.id] = opts.cli_variables;
+                                    events.emit('log','Adding '+pluginInfo.id+ ' to package.json');
+                                    // Write to package.json
+                                    fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+                                }
                             }
                         });
                     }, Q());
@@ -243,7 +272,6 @@ module.exports = function plugin(command, targets, opts) {
                     if (!shouldRunPrepare) {
                         return Q();
                     }
-
                     // Need to require right here instead of doing this at the beginning of file
                     // otherwise tests are failing without any real reason.
                     return require('./prepare').preparePlatforms(platformList, projectRoot, opts);
@@ -299,9 +327,26 @@ module.exports = function plugin(command, targets, opts) {
                                     configXml.removePlugin(target);
                                     configXml.write();
                                 }
+                                var pkgJson;
+                                var pkgJsonPath = path.join(projectRoot,'package.json');
+                                // If statement to see if pkgJsonPath exists in the filesystem
+                                if(fs.existsSync(pkgJsonPath)) {
+                                    //delete any previous caches of require(package.json)
+                                    delete require.cache[require.resolve(pkgJsonPath)];
+                                    pkgJson = require(pkgJsonPath);
+                                } else {
+                                    // Create package.json in cordova@7
+                                }
+                                // If package.json exists and contains a specified plugin in cordova['plugins'], it will be removed    
+                                if(pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.plugins !== undefined) {
+                                    events.emit('log', 'Removing ' + target + ' from package.json');
+                                    delete pkgJson.cordova.plugins[target];
+                                    //Write out new package.json 
+                                    fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+                                }
                             }
-                        })
-                        .then(function(){
+                            
+                        }).then(function(){
                             // Remove plugin from fetch.json
                             events.emit('verbose', 'Removing plugin ' + target + ' from fetch.json');
                             metadata.remove_fetch_metadata(pluginPath, target);
@@ -311,7 +356,7 @@ module.exports = function plugin(command, targets, opts) {
                     // CB-11022 We do not need to run prepare after plugin install until shouldRunPrepare flag is set to true
                     if (!shouldRunPrepare) {
                         return Q();
-                    }
+                    }   
 
                     return require('./prepare').preparePlatforms(platformList, projectRoot, opts);
                 }).then(function() {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org