diff --git a/cordova-lib/spec-cordova/util.spec.js b/cordova-lib/spec-cordova/util.spec.js index b6577aed9..924e611a9 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')}})); diff --git a/cordova-lib/src/cordova/util.js b/cordova-lib/src/cordova/util.js index e77ea5622..6937e4dbc 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'); } diff --git a/cordova-lib/src/util/npm-helper.js b/cordova-lib/src/util/npm-helper.js index 4bd0ea1da..e1e5322a9 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')); }