Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.existsSync deprecated, replace with exists-sync #4316

Merged
merged 2 commits into from Jun 21, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions blueprints/addon/index.js
@@ -1,6 +1,7 @@
/*jshint node:true*/

var fs = require('fs');
var existsSync = require('exists-sync');
var path = require('path');
var walkSync = require('walk-sync');
var stringUtil = require('../../lib/utilities/string');
Expand Down Expand Up @@ -58,7 +59,7 @@ module.exports = {
var bowerPath = path.join(this.path, 'files', 'bower.json');

[packagePath, bowerPath].forEach(function(filePath) {
if (fs.existsSync(filePath)) {
if (existsSync(filePath)) {
fs.unlinkSync(filePath);
}
});
Expand Down Expand Up @@ -130,7 +131,7 @@ module.exports = {

srcPath: function(file) {
var filePath = path.resolve(this.path, 'files', file);
if (fs.existsSync(filePath)) {
if (existsSync(filePath)) {
return filePath;
} else {
return path.resolve(this._appBlueprint.path, 'files', file);
Expand Down
9 changes: 5 additions & 4 deletions lib/broccoli/broccoli-config-replace.js
@@ -1,8 +1,9 @@
'use strict';

var fs = require('fs-extra');
var path = require('path');
var Writer = require('broccoli-writer');
var fs = require('fs-extra');
var existsSync = require('exists-sync');
var path = require('path');
var Writer = require('broccoli-writer');

function CustomReplace (inputTree, configTree, options) {
if (!(this instanceof CustomReplace)) {
Expand Down Expand Up @@ -72,7 +73,7 @@ CustomReplace.prototype.processFile = function(config, filePath, destPath) {
contents = contents.replace(pattern.match, replacement);
}

if (!fs.existsSync(path.dirname(destPath))) {
if (!existsSync(path.dirname(destPath))) {
fs.mkdirsSync(path.dirname(destPath));
}
fs.writeFileSync(destPath, contents, { encoding: 'utf8' });
Expand Down
15 changes: 8 additions & 7 deletions lib/broccoli/ember-app.js
Expand Up @@ -5,6 +5,7 @@
@module ember-cli
*/
var fs = require('fs');
var existsSync = require('exists-sync');
var path = require('path');
var p = require('../preprocessors');
var chalk = require('chalk');
Expand Down Expand Up @@ -190,13 +191,13 @@ EmberApp.prototype._initOptions = function(options, isProduction) {

// these are contained within app/ no need to watch again
styles: unwatchedTree('app/styles'),
templates: fs.existsSync('app/templates') ? unwatchedTree('app/templates') : null,
templates: existsSync('app/templates') ? unwatchedTree('app/templates') : null,

// do not watch vendor/ or bower's default directory by default
bower: unwatchedTree(this.bowerDirectory),
vendor: fs.existsSync('vendor') ? unwatchedTree('vendor') : null,
vendor: existsSync('vendor') ? unwatchedTree('vendor') : null,

public: fs.existsSync('public') ? 'public' : null
public: existsSync('public') ? 'public' : null
}, defaults);

this.options.jshintrc = merge(this.options.jshintrc, {
Expand All @@ -213,7 +214,7 @@ EmberApp.prototype._initVendorFiles = function() {
// in Ember 1.10 and higher `ember.js` is deprecated in favor of
// the more aptly named `ember.debug.js`.
var defaultDevelopmentEmber = this.bowerDirectory + '/ember/ember.debug.js';
if (!fs.existsSync(path.join(this.project.root, defaultDevelopmentEmber))) {
if (!existsSync(path.join(this.project.root, defaultDevelopmentEmber))) {
defaultDevelopmentEmber = this.bowerDirectory + '/ember/ember.js';
}

Expand Down Expand Up @@ -266,7 +267,7 @@ EmberApp.prototype._initVendorFiles = function() {

// this is needed to support versions of Ember older than
// 1.8.0 (when ember-testing.js was added to the deployment)
if (!fs.existsSync(this.vendorFiles['ember-testing.js'][0])) {
if (!existsSync(this.vendorFiles['ember-testing.js'][0])) {
delete this.vendorFiles['ember-testing.js'];
}
};
Expand Down Expand Up @@ -1024,7 +1025,7 @@ EmberApp.prototype.javascript = function() {
@return {Tree} Merged tree for styles
*/
EmberApp.prototype.styles = function() {
if (fs.existsSync('app/styles/' + this.name + '.css')) {
if (existsSync('app/styles/' + this.name + '.css')) {
throw new SilentError('Style file cannot have the name of the application - ' + this.name);
}

Expand Down Expand Up @@ -1266,7 +1267,7 @@ EmberApp.prototype._import = function(assetPath, options, directory, subdirector
@param {String} subdirectory
*/
EmberApp.prototype._importAssetTree = function(directory, subdirectory) {
if (fs.existsSync(directory) && this._importTrees.indexOf(directory) === -1) {
if (existsSync(directory) && this._importTrees.indexOf(directory) === -1) {
var assetTree = new Funnel(directory, {
srcDir: '/',
destDir: subdirectory
Expand Down
4 changes: 2 additions & 2 deletions lib/models/addon-discovery.js
Expand Up @@ -6,7 +6,7 @@

var assign = require('lodash/object/assign');
var debug = require('debug')('ember-cli:addon-discovery');
var fs = require('fs');
var existsSync = require('exists-sync');
var path = require('path');
var CoreObject = require('core-object');
var resolve = require('resolve');
Expand Down Expand Up @@ -189,7 +189,7 @@ AddonDiscovery.prototype.discoverAtPath = function(addonPath) {
var pkgPath = path.join(addonPath, 'package.json');
debug('attemping to add: %s', addonPath);

if (fs.existsSync(pkgPath)) {
if (existsSync(pkgPath)) {
var addonPkg = require(pkgPath);
var keywords = addonPkg.keywords || [];
debug(' - module found: %s', addonPkg.name);
Expand Down
16 changes: 8 additions & 8 deletions lib/models/addon.js
Expand Up @@ -4,7 +4,7 @@
@module ember-cli
*/

var fs = require('fs');
var existsSync = require('exists-sync');
var path = require('path');
var deprecate = require('../utilities/deprecate');
var assign = require('lodash/object/assign');
Expand Down Expand Up @@ -311,7 +311,7 @@ Addon.prototype._treeFor = function _treeFor(name) {
var treeForMethod = this.treeForMethods[name];
var tree;

if (fs.existsSync(treePath)) {
if (existsSync(treePath)) {
tree = this.treeGenerator(treePath);
}

Expand Down Expand Up @@ -424,11 +424,11 @@ Addon.prototype.shouldCompileTemplates = function() {

var files = [];

if (fs.existsSync(addonTreePath)) {
if (existsSync(addonTreePath)) {
files = files.concat(walkSync(addonTreePath));
}

if (fs.existsSync(addonTemplatesTreePath)) {
if (existsSync(addonTemplatesTreePath)) {
files = files.concat(walkSync(addonTemplatesTreePath));
}

Expand Down Expand Up @@ -518,7 +518,7 @@ Addon.prototype.jshintAddonTree = function() {

var addonPath = path.join(this.root, this.treePaths['addon']);

if (!fs.existsSync(addonPath)) {
if (!existsSync(addonPath)) {
return;
}

Expand Down Expand Up @@ -603,7 +603,7 @@ Addon.prototype.moduleName = function() {
Addon.prototype.blueprintsPath = function() {
var blueprintPath = path.join(this.root, 'blueprints');

if (fs.existsSync(blueprintPath)) {
if (existsSync(blueprintPath)) {
return blueprintPath;
}
};
Expand Down Expand Up @@ -631,7 +631,7 @@ Addon.prototype.blueprintsPath = function() {
Addon.prototype.config = function (env, baseConfig) {
var configPath = path.join(this.root, 'config', 'environment.js');

if (fs.existsSync(configPath)) {
if (existsSync(configPath)) {
var configGenerator = require(configPath);

return configGenerator(env, baseConfig);
Expand Down Expand Up @@ -698,7 +698,7 @@ Addon.lookup = function(addon) {
modulePath = Addon.resolvePath(addon);
moduleDir = path.dirname(modulePath);

if (fs.existsSync(modulePath)) {
if (existsSync(modulePath)) {
addonModule = require(modulePath);

if (typeof addonModule === 'function') {
Expand Down
17 changes: 9 additions & 8 deletions lib/models/blueprint.js
Expand Up @@ -8,6 +8,7 @@ var Promise = require('../ext/promise');
var chalk = require('chalk');
var MarkdownColor = require('../../lib/utilities/markdown-color');
var fs = require('fs-extra');
var existsSync = require('exists-sync');
var inflector = require('inflection');
var minimatch = require('minimatch');
var path = require('path');
Expand Down Expand Up @@ -284,7 +285,7 @@ Blueprint.prototype.files = function() {
if (this._files) { return this._files; }

var filesPath = path.join(this.path, 'files');
if (fs.existsSync(filesPath)) {
if (existsSync(filesPath)) {
this._files = walkSync(path.join(this.path, 'files'));
} else {
this._files = [];
Expand Down Expand Up @@ -1106,7 +1107,7 @@ Blueprint.prototype.insertIntoFile = function(pathRelativeToProjectRoot, content
var fullPath = path.join(this.project.root, pathRelativeToProjectRoot);
var originalContents = '';

if (fs.existsSync(fullPath)) {
if (existsSync(fullPath)) {
originalContents = fs.readFileSync(fullPath, { encoding: 'utf8' });
}

Expand Down Expand Up @@ -1167,7 +1168,7 @@ Blueprint.prototype.printDetailedHelp = function() {
filePath = path.join(this.path, './HELP.md');
}

if (fs.existsSync(filePath)) {
if (existsSync(filePath)) {
return markdownColor.renderFile(filePath, {indent:' '});
}
return '';
Expand Down Expand Up @@ -1209,7 +1210,7 @@ Blueprint.lookup = function(name, options) {
for (var i = 0; lookupPath = lookupPaths[i]; i++) {
blueprintPath = path.resolve(lookupPath, name);

if (fs.existsSync(blueprintPath)) {
if (existsSync(blueprintPath)) {
return Blueprint.load(blueprintPath);
}
}
Expand All @@ -1234,7 +1235,7 @@ Blueprint.load = function(blueprintPath) {

if (fs.lstatSync(blueprintPath).isDirectory()) {

if (fs.existsSync(constructorPath)) {
if (existsSync(constructorPath)) {
blueprintModule = require(constructorPath);

if (typeof blueprintModule === 'function') {
Expand Down Expand Up @@ -1269,7 +1270,7 @@ Blueprint.list = function(options) {
var packagePath = path.join(lookupPath, '../package.json');
var source;

if (fs.existsSync(packagePath)) {
if (existsSync(packagePath)) {
source = require(packagePath).name;
} else {
source = path.basename(path.join(lookupPath, '..'));
Expand Down Expand Up @@ -1433,7 +1434,7 @@ function hasPathToken(files) {

function inRepoAddonExists(name, root) {
var addonPath = path.join(root, 'lib', name);
return fs.existsSync(addonPath);
return existsSync(addonPath);
}

function podDeprecations(config, ui){
Expand Down Expand Up @@ -1490,7 +1491,7 @@ function isFilePath(fileInfo) {
@returns {Array} list of files in the given directory or and empty array if no directory exists
*/
function dir(fullPath) {
if (fs.existsSync(fullPath)) {
if (existsSync(fullPath)) {
return fs.readdirSync(fullPath).map(function(fileName) {
return path.join(fullPath, fileName);
});
Expand Down
5 changes: 3 additions & 2 deletions lib/models/builder.js
@@ -1,6 +1,7 @@
'use strict';

var fs = require('fs-extra');
var existsSync = require('exists-sync');
var path = require('path');
var Promise = require('../ext/promise');
var remove = Promise.denodeify(fs.remove);
Expand Down Expand Up @@ -61,7 +62,7 @@ module.exports = Task.extend({
*/
clearOutputPath: function() {
var outputPath = this.outputPath;
if (!fs.existsSync(outputPath)) { return Promise.resolve();}
if (!existsSync(outputPath)) { return Promise.resolve();}

if(!this.canDeleteOutputPath(outputPath)) {
return Promise.reject(new SilentError('Using a build destination path of `' + outputPath + '` is not supported.'));
Expand All @@ -81,7 +82,7 @@ module.exports = Task.extend({
var outputPath = this.outputPath;

return new Promise(function(resolve) {
if (!fs.existsSync(outputPath)) {
if (!existsSync(outputPath)) {
fs.mkdirsSync(outputPath);
}

Expand Down
9 changes: 5 additions & 4 deletions lib/models/installation-checker.js
Expand Up @@ -2,6 +2,7 @@

var debug = require('debug')('ember-cli:installation-checker');
var fs = require('fs');
var existsSync = require('exists-sync');
var path = require('path');
var SilentError = require('silent-error');

Expand Down Expand Up @@ -54,21 +55,21 @@ InstallationChecker.prototype.hasBowerDeps = function() {
};

InstallationChecker.prototype.usingBower = function() {
return fs.existsSync(path.join(this.project.root, 'bower.json')) && this.hasBowerDeps();
return existsSync(path.join(this.project.root, 'bower.json')) && this.hasBowerDeps();
};

InstallationChecker.prototype.bowerDependenciesNotPresent = function() {
return !fs.existsSync(this.project.bowerDirectory);
return !existsSync(this.project.bowerDirectory);
};

InstallationChecker.prototype.hasNpmDeps = function() {
return hasDependencies(readJSON(path.join(this.project.root, 'package.json')));
};

InstallationChecker.prototype.usingNpm = function() {
return fs.existsSync(path.join(this.project.root, 'package.json')) && this.hasNpmDeps();
return existsSync(path.join(this.project.root, 'package.json')) && this.hasNpmDeps();
};

InstallationChecker.prototype.npmDependenciesNotPresent = function() {
return !fs.existsSync(this.project.nodeModulesPath);
return !existsSync(this.project.nodeModulesPath);
};
9 changes: 5 additions & 4 deletions lib/models/project.js
Expand Up @@ -8,6 +8,7 @@ var path = require('path');
var findup = Promise.denodeify(require('findup'));
var resolve = Promise.denodeify(require('resolve'));
var fs = require('fs');
var existsSync = require('exists-sync');
var find = require('lodash/collection/find');
var assign = require('lodash/object/assign');
var forOwn = require('lodash/object/forOwn');
Expand Down Expand Up @@ -58,7 +59,7 @@ Project.prototype.setupBowerDirectory = function() {

debug('bowerrc path: %s', bowerrcPath);

if (fs.existsSync(bowerrcPath)) {
if (existsSync(bowerrcPath)) {
var bowerrcContent = fs.readFileSync(bowerrcPath);
try {
this.bowerDirectory = JSON.parse(bowerrcContent).directory;
Expand Down Expand Up @@ -171,7 +172,7 @@ Project.prototype.configPath = function() {
Project.prototype.config = function(env) {
var configPath = this.configPath();

if (fs.existsSync(path.join(this.root, configPath + '.js'))) {
if (existsSync(path.join(this.root, configPath + '.js'))) {
var appConfig = this.require('./' + configPath)(env);
var addonsConfig = this.getAddonsConfig(env, appConfig);

Expand Down Expand Up @@ -213,7 +214,7 @@ Project.prototype.getAddonsConfig = function(env, appConfig) {
@return {Boolean} Whether or not the file is present
*/
Project.prototype.has = function(file) {
return fs.existsSync(path.join(this.root, file)) || fs.existsSync(path.join(this.root, file + '.js'));
return existsSync(path.join(this.root, file)) || existsSync(path.join(this.root, file + '.js'));
};

/**
Expand Down Expand Up @@ -280,7 +281,7 @@ Project.prototype.dependencies = function(pkg, excludeDevDeps) {
Project.prototype.bowerDependencies = function(bower) {
if (!bower) {
var bowerPath = path.join(this.root, 'bower.json');
bower = (fs.existsSync(bowerPath)) ? require(bowerPath) : {};
bower = (existsSync(bowerPath)) ? require(bowerPath) : {};
}
return assign({}, bower['devDependencies'], bower['dependencies']);
};
Expand Down
6 changes: 3 additions & 3 deletions lib/preprocessors/plugin.js
@@ -1,7 +1,7 @@
'use strict';

var path = require('path');
var fs = require('fs');
var path = require('path');
var existsSync = require('exists-sync');

function Plugin(name, ext, options) {
this.name = name;
Expand All @@ -24,7 +24,7 @@ Plugin.prototype.getExt = function(inputTreeRoot, inputPath, filename) {
var detect = require('lodash/collection/find');
return detect(this.ext, function(ext) {
var filenameAndExt = filename + '.' + ext;
return fs.existsSync(path.join(inputTreeRoot, inputPath, filenameAndExt));
return existsSync(path.join(inputTreeRoot, inputPath, filenameAndExt));
});
} else {
return this.ext;
Expand Down