cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cordova-lib git commit: use fs instead of our own existsSync
Date Fri, 10 Mar 2017 06:44:04 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master 07040e7a2 -> d6f6a0e5c


use fs instead of our own existsSync

 This closes #524


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

Branch: refs/heads/master
Commit: d6f6a0e5cf8dd1bc78fa39908ce835a5334256bc
Parents: 07040e7
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Thu Mar 2 18:08:52 2017 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Thu Mar 9 22:43:56 2017 -0800

----------------------------------------------------------------------
 cordova-lib/spec-cordova/util.spec.js |  4 ++--
 cordova-lib/src/cordova/util.js       | 35 ++++++++++--------------------
 cordova-lib/src/util/npm-helper.js    |  3 ++-
 3 files changed, 16 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d6f6a0e5/cordova-lib/spec-cordova/util.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/util.spec.js b/cordova-lib/spec-cordova/util.spec.js
index b6577ae..924e611 100644
--- a/cordova-lib/spec-cordova/util.spec.js
+++ b/cordova-lib/spec-cordova/util.spec.js
@@ -38,7 +38,7 @@ describe('util module', function() {
             process.chdir(cwd);
         });
         function removeDir(directory) {
-            shell.rm('-rf', directory);            
+            shell.rm('-rf', directory);
         }
         it('Test 001 : should return false if it hits the home directory', function() {
             var somedir = path.join(home, 'somedir');
@@ -239,7 +239,7 @@ describe('util module', function() {
         });
 
         it('Test 020 : should pick buildConfig if no option is provided, but buildConfig.json
exists', function() {
-            spyOn(util, 'existsSync').and.returnValue(true);
+            spyOn(fs, 'existsSync').and.returnValue(true);
             // Using path.join below to normalize path separators
             expect(util.preProcessOptions())
                 .toEqual(jasmine.objectContaining({options: {buildConfig: path.join('/fake/path/build.json')}}));

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d6f6a0e5/cordova-lib/src/cordova/util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js
index e77ea56..6937e4d 100644
--- a/cordova-lib/src/cordova/util.js
+++ b/cordova-lib/src/cordova/util.js
@@ -43,7 +43,7 @@ var lib_path = path.join(global_config_path, 'lib');
 exports.binname = 'cordova';
 exports.globalConfig = global_config_path;
 
-// defer defining libDirectory on exports so we don't create it if 
+// defer defining libDirectory on exports so we don't create it if
 // someone simply requires this module
 Object.defineProperty(exports,'libDirectory', {
         configurable: true,
@@ -75,7 +75,7 @@ exports.isUrl = isUrl;
 exports.getLatestMatchingNpmVersion = getLatestMatchingNpmVersion;
 exports.getAvailableNpmVersions = getAvailableNpmVersions;
 exports.getInstalledPlatformsWithVersions = getInstalledPlatformsWithVersions;
-exports.existsSync = existsSync;
+
 
 function isUrl(value) {
     var u = value && url.parse(value);
@@ -83,34 +83,23 @@ function isUrl(value) {
 }
 
 function isRootDir(dir) {
-    if (exports.existsSync(path.join(dir, 'www'))) {
-        if (exports.existsSync(path.join(dir, 'config.xml'))) {
+    if (fs.existsSync(path.join(dir, 'www'))) {
+        if (fs.existsSync(path.join(dir, 'config.xml'))) {
             // For sure is.
-            if (exports.existsSync(path.join(dir, 'platforms'))) {
+            if (fs.existsSync(path.join(dir, 'platforms'))) {
                 return 2;
             } else {
                 return 1;
             }
         }
         // Might be (or may be under platforms/).
-        if (exports.existsSync(path.join(dir, 'www', 'config.xml'))) {
+        if (fs.existsSync(path.join(dir, 'www', 'config.xml'))) {
             return 1;
         }
     }
     return 0;
 }
 
-function existsSync(fileSpec) {
-    // Since fs.existsSync() is deprecated
-    try {
-        fs.statSync(fileSpec);
-        return true;
-    } catch (error) {
-        return false;
-    }
-}
-
-
 // Runs up the directory chain looking for a .cordova directory.
 // IF it is found we are in a Cordova project.
 // Omit argument to use CWD.
@@ -181,7 +170,7 @@ function fixRelativePath(value, /* optional */ cwd) {
 
 // Resolve any symlinks in order to avoid relative path issues. See https://issues.apache.org/jira/browse/CB-8757
 function convertToRealPathSafe(path) {
-    if (path && exports.existsSync(path)) {
+    if (path && fs.existsSync(path)) {
         return fs.realpathSync(path);
     }
 
@@ -204,7 +193,7 @@ function deleteSvnFolders(dir) {
 function listPlatforms(project_dir) {
     var core_platforms = require('../platforms/platforms');
     var platforms_dir = path.join(project_dir, 'platforms');
-    if ( !exports.existsSync(platforms_dir)) {
+    if ( !fs.existsSync(platforms_dir)) {
         return [];
     }
     var subdirs = fs.readdirSync(platforms_dir);
@@ -235,7 +224,7 @@ function findPlugins(pluginPath) {
     var plugins = [],
         stats;
 
-    if (exports.existsSync(pluginPath)) {
+    if (fs.existsSync(pluginPath)) {
         plugins = fs.readdirSync(pluginPath).filter(function (fileName) {
             stats = fs.statSync(path.join(pluginPath, fileName));
             return fileName != '.svn' && fileName != 'CVS' && stats.isDirectory();
@@ -256,9 +245,9 @@ function projectWww(projectDir) {
 function projectConfig(projectDir) {
     var rootPath = path.join(projectDir, 'config.xml');
     var wwwPath = path.join(projectDir, 'www', 'config.xml');
-    if (exports.existsSync(rootPath)) {
+    if (fs.existsSync(rootPath)) {
         return rootPath;
-    } else if (exports.existsSync(wwwPath)) {
+    } else if (fs.existsSync(wwwPath)) {
         return wwwPath;
     }
     return false;
@@ -295,7 +284,7 @@ function preProcessOptions (inputOptions) {
         result.platforms = projectPlatforms;
     }
 
-    if (!result.options.buildConfig && exports.existsSync(path.join(projectRoot,
'build.json'))) {
+    if (!result.options.buildConfig && fs.existsSync(path.join(projectRoot, 'build.json')))
{
         result.options.buildConfig = path.join(projectRoot, 'build.json');
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/d6f6a0e5/cordova-lib/src/util/npm-helper.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/util/npm-helper.js b/cordova-lib/src/util/npm-helper.js
index 4bd0ea1..e1e5322 100644
--- a/cordova-lib/src/util/npm-helper.js
+++ b/cordova-lib/src/util/npm-helper.js
@@ -21,6 +21,7 @@
 
 var npm = require('npm'),
     path = require('path'),
+    fs = require('fs'),
     Q = require('q'),
     unpack = require('./unpack'),
     util = require('../cordova/util'),
@@ -103,7 +104,7 @@ function cachePackage(packageName, packageVersion) {
         // If already cached, use that rather than calling 'npm cache add' again.
         var packageCacheDir = path.resolve(cacheDir, packageName, packageVersion);
         var packageTGZ = path.resolve(packageCacheDir, 'package.tgz');
-        if (util.existsSync(packageTGZ)) {
+        if (fs.existsSync(packageTGZ)) {
             return unpack.unpackTgz(packageTGZ, path.resolve(packageCacheDir, 'package'));
         }
 


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


Mime
View raw message