You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ge...@apache.org on 2019/11/13 06:50:26 UTC

[cordova-fetch] branch master updated: Save platforms and plugins to devDependencies

This is an automated email from the ASF dual-hosted git repository.

gedasga pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-fetch.git


The following commit(s) were added to refs/heads/master by this push:
     new b3a1806  Save platforms and plugins to devDependencies
     new 11105d1  Merge pull request #65 from GedasGa/install-to-devdeps
b3a1806 is described below

commit b3a1806ae6c44a291c04bbf7521c069c0187a9b6
Author: Gedas Gardauskas <ge...@gmail.com>
AuthorDate: Tue May 14 19:15:35 2019 +0900

    Save platforms and plugins to devDependencies
---
 index.js                | 14 +++++---------
 spec/fetch-unit.spec.js | 17 ++++++-----------
 spec/fetch.spec.js      | 18 +++++++++---------
 3 files changed, 20 insertions(+), 29 deletions(-)

diff --git a/index.js b/index.js
index c5c03ad..b17d3dc 100644
--- a/index.js
+++ b/index.js
@@ -72,18 +72,14 @@ function installPackage (target, dest, opts) {
         .then(spec => pathToInstalledPackage(spec, dest));
 }
 
-function npmArgs (target, userOptions) {
-    const opts = Object.assign({ production: true }, userOptions);
-
+function npmArgs (target, opts) {
     const args = ['install', target];
+    opts = opts || {};
 
-    if (opts.production) {
-        args.push('--production');
-    }
     if (opts.save_exact) {
         args.push('--save-exact');
     } else if (opts.save) {
-        args.push('--save');
+        args.push('--save-dev');
     } else {
         args.push('--no-save');
     }
@@ -171,9 +167,9 @@ module.exports.uninstall = function (target, dest, opts) {
             // set the directory where npm uninstall will be run
             opts.cwd = dest;
 
-            // if user added --save flag, pass it to npm uninstall command
+            // if user added --save flag, pass --save-dev flag to npm uninstall command
             if (opts.save) {
-                fetchArgs.push('--save');
+                fetchArgs.push('--save-dev');
             } else {
                 fetchArgs.push('--no-save');
             }
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
index fff3981..3e26821 100644
--- a/spec/fetch-unit.spec.js
+++ b/spec/fetch-unit.spec.js
@@ -57,23 +57,18 @@ describe('npmArgs', function () {
         npmArgs('platform');
     });
 
-    it('npm install should be called with production flag (default)', function () {
-        var opts = { cwd: 'some/path', production: true, save: true };
-        expect(npmArgs('platform', opts)).toContain('--production');
-    });
-
-    it('save-exact should be true if passed in', function () {
+    it('when save_exact is true, save-exact flag should be passed through to npm', function () {
         var opts = { cwd: 'some/path', save_exact: true };
         expect(npmArgs('platform', opts)).toContain('--save-exact');
     });
 
-    it('noprod should turn production off', function () {
-        var opts = { cwd: 'some/path', production: false };
-        expect(npmArgs('platform', opts)).not.toContain('--production');
+    it('when save is true, save-dev flag should be passed through to npm', function () {
+        var opts = { cwd: 'some/path', save: true };
+        expect(npmArgs('platform', opts)).toContain('--save-dev');
     });
 
-    it('when save is false, no-save flag should be passed through', function () {
-        var opts = { cwd: 'some/path', production: true, save: false };
+    it('when save is false, no-save flag should be passed through to npm', function () {
+        var opts = { cwd: 'some/path', save: false };
         expect(npmArgs('platform', opts)).toContain('--no-save');
     });
 });
diff --git a/spec/fetch.spec.js b/spec/fetch.spec.js
index 2dfa087..6cb7846 100644
--- a/spec/fetch.spec.js
+++ b/spec/fetch.spec.js
@@ -55,9 +55,9 @@ function expectNotToBeInstalled (pkgName) {
     expect(fs.existsSync(path.join(tmpDir, 'node_modules', pkgName))).toBe(false);
 }
 
-function expectDependenciesToBe (deps) {
+function expectDevDependenciesToBe (deps) {
     const rootPJ = fs.readJsonSync(path.join(tmpDir, 'package.json'));
-    expect(rootPJ.dependencies).toEqual(deps);
+    expect(rootPJ.devDependencies).toEqual(deps);
 }
 
 describe('fetch/uninstall tests via npm & git', function () {
@@ -93,9 +93,9 @@ describe('fetch/uninstall with --save', function () {
                 name: 'cordova-android',
                 version: '8.1.0'
             }))
-            .then(_ => expectDependenciesToBe({ 'cordova-android': '^8.1.0' }))
+            .then(_ => expectDevDependenciesToBe({ 'cordova-android': '^8.1.0' }))
             .then(_ => uninstall('cordova-android', tmpDir, opts))
-            .then(_ => expectDependenciesToBe({}))
+            .then(_ => expectDevDependenciesToBe({}))
             .then(_ => expectNotToBeInstalled('cordova-android'))
 
             // git tag
@@ -103,9 +103,9 @@ describe('fetch/uninstall with --save', function () {
                 name: 'cordova-ios',
                 version: '5.0.1'
             }))
-            .then(_ => expectDependenciesToBe({ 'cordova-ios': 'git+https://github.com/apache/cordova-ios.git#rel/5.0.1' }))
+            .then(_ => expectDevDependenciesToBe({ 'cordova-ios': 'git+https://github.com/apache/cordova-ios.git#rel/5.0.1' }))
             .then(_ => uninstall('cordova-ios', tmpDir, opts))
-            .then(_ => expectDependenciesToBe({}))
+            .then(_ => expectDevDependenciesToBe({}))
             .then(_ => expectNotToBeInstalled('cordova-ios'))
 
             // git branch
@@ -113,7 +113,7 @@ describe('fetch/uninstall with --save', function () {
                 name: 'cordova-android',
                 version: '4.1.1'
             }))
-            .then(_ => expectDependenciesToBe({ 'cordova-android': 'git+https://github.com/apache/cordova-android.git#4.1.x' }))
+            .then(_ => expectDevDependenciesToBe({ 'cordova-android': 'git+https://github.com/apache/cordova-android.git#4.1.x' }))
             .then(_ => uninstall('cordova-android', tmpDir, opts));
     }, 150000);
 
@@ -124,9 +124,9 @@ describe('fetch/uninstall with --save', function () {
                 name: 'cordova-plugin-contacts',
                 version: '2.0.2-dev'
             }))
-            .then(_ => expectDependenciesToBe({ 'cordova-plugin-contacts': `git+${URL}` }))
+            .then(_ => expectDevDependenciesToBe({ 'cordova-plugin-contacts': `git+${URL}` }))
             .then(_ => uninstall('cordova-plugin-contacts', tmpDir, opts))
-            .then(_ => expectDependenciesToBe({}))
+            .then(_ => expectDevDependenciesToBe({}))
             .then(_ => expectNotToBeInstalled('cordova-plugin-contacts'));
     }, 30000);
 });


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