You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by au...@apache.org on 2017/10/02 18:33:19 UTC

cordova-fetch git commit: CB-13303 : setting production flag to default during npm install and test

Repository: cordova-fetch
Updated Branches:
  refs/heads/master 06441bb53 -> 086ca2999


CB-13303 : setting production flag to default during npm install and test


Project: http://git-wip-us.apache.org/repos/asf/cordova-fetch/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-fetch/commit/086ca299
Tree: http://git-wip-us.apache.org/repos/asf/cordova-fetch/tree/086ca299
Diff: http://git-wip-us.apache.org/repos/asf/cordova-fetch/diff/086ca299

Branch: refs/heads/master
Commit: 086ca2999d1e2bd9a08b057e90d973269f094736
Parents: 06441bb
Author: Audrey So <au...@apache.org>
Authored: Thu Sep 21 11:45:53 2017 -0700
Committer: Audrey So <au...@apache.org>
Committed: Mon Oct 2 09:56:58 2017 -0700

----------------------------------------------------------------------
 index.js                | 11 +++++++++--
 package.json            |  2 +-
 spec/fetch-unit.spec.js | 47 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/086ca299/index.js
----------------------------------------------------------------------
diff --git a/index.js b/index.js
index fd4c583..60a3176 100644
--- a/index.js
+++ b/index.js
@@ -40,9 +40,10 @@ module.exports = function (target, dest, opts) {
     var fetchArgs = opts.link ? ['link'] : ['install'];
     opts = opts || {};
     var tree1;
+    opts.production = opts.production || true;
 
     // check if npm is installed
-    return isNpmInstalled()
+    return module.exports.isNpmInstalled()
         .then(function () {
             if (dest && target) {
                 // add target to fetchArgs Array
@@ -60,6 +61,10 @@ module.exports = function (target, dest, opts) {
 
             // set the directory where npm install will be run
             opts.cwd = dest;
+            // npm should use production by default when install is npm run
+            if (opts.production) {
+                fetchArgs.push('--production');
+            }
 
             // if user added --save flag, pass it to npm install command
             if (opts.save) {
@@ -88,7 +93,7 @@ module.exports = function (target, dest, opts) {
             // This could happen on a platform update.
             var id = getJsonDiff(tree1, tree2) || trimID(target);
 
-            return getPath(id, dest, target);
+            return module.exports.getPath(id, dest, target);
         })
         .fail(function (err) {
             return Q.reject(new CordovaError(err));
@@ -194,6 +199,7 @@ function getPath (id, dest, target) {
     return finalDest;
 }
 
+module.exports.getPath = getPath;
 /*
  * Make an additional search in destination folder using repository.url property from package.json
  *
@@ -235,6 +241,7 @@ function isNpmInstalled () {
     return Q();
 }
 
+module.exports.isNpmInstalled = isNpmInstalled;
 /*
  * A function that deletes the target from node_modules and runs npm uninstall
  *

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/086ca299/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 3b9d8bf..f82ad1b 100644
--- a/package.json
+++ b/package.json
@@ -40,7 +40,7 @@
   "scripts": {
     "test": "npm run eslint && npm run jasmine",
     "eslint": "eslint index.js spec/fetch.spec.js",
-    "jasmine": "jasmine spec/fetch.spec.js"
+    "jasmine": "jasmine spec/fetch.spec.js spec/fetch-unit.spec.js"
   },
   "engines": {
     "node": ">=4.0.0",

http://git-wip-us.apache.org/repos/asf/cordova-fetch/blob/086ca299/spec/fetch-unit.spec.js
----------------------------------------------------------------------
diff --git a/spec/fetch-unit.spec.js b/spec/fetch-unit.spec.js
new file mode 100644
index 0000000..faf53c7
--- /dev/null
+++ b/spec/fetch-unit.spec.js
@@ -0,0 +1,47 @@
+/**
+    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.
+*/
+
+/* eslint-env jasmine */
+var fetch = require('../index.js');
+var shell = require('shelljs');
+var fs = require('fs');
+var Q = require('q');
+var superspawn = require('cordova-common').superspawn;
+
+describe('unit tests for index.js', function () {
+    beforeEach(function () {
+        spyOn(superspawn, 'spawn').and.returnValue(true);
+        spyOn(shell, 'mkdir').and.returnValue(true);
+        spyOn(shell, 'which').and.returnValue(Q());
+        spyOn(fetch, 'isNpmInstalled').and.returnValue(Q());
+        spyOn(fetch, 'getPath').and.returnValue('some/path');
+        spyOn(fs, 'existsSync').and.returnValue(false);
+    });
+
+    it('npm install should be called with production flag (default)', function (done) {
+        var opts = { cwd: 'some/path', production: true };
+        fetch('platform', 'tmpDir', opts)
+            .then(function (result) {
+                expect(superspawn.spawn).toHaveBeenCalledWith('npm', [ 'install', 'platform', '--production' ], jasmine.any(Object));
+            })
+            .fail(function (err) {
+                console.error(err);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+    }, 600000);
+});


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