parent
e68502a4f5
commit
974fb8b9f7
|
@ -9,6 +9,7 @@ var fs = require('fs');
|
|||
var path = require('path');
|
||||
var toposort = require('toposort');
|
||||
var ConfigLoader = require('./config-loader');
|
||||
var utils = require('./utils');
|
||||
var debug = require('debug')('loopback:boot:compiler');
|
||||
var Module = require('module');
|
||||
var _ = require('lodash');
|
||||
|
@ -391,7 +392,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
|
|||
|
||||
if (fullPath) {
|
||||
// This check is needed to support paths pointing to a directory
|
||||
if (fs.existsSync(fullPath)) {
|
||||
if (utils.fileExists(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
|
@ -429,7 +430,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
|
|||
}
|
||||
})
|
||||
.filter(function(candidate) {
|
||||
return fs.existsSync(candidate.toString());
|
||||
return utils.fileExists(candidate.toString());
|
||||
})
|
||||
[0];
|
||||
|
||||
|
@ -755,7 +756,7 @@ function loadMixins(sourceFiles, options) {
|
|||
name = normalizeMixinName(name, options);
|
||||
var meta = {};
|
||||
meta.name = name;
|
||||
if (fs.existsSync(metafile)) {
|
||||
if (utils.fileExists(metafile)) {
|
||||
// May overwrite name, not sourceFile
|
||||
_.extend(meta, require(metafile));
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
var cloneDeep = require('lodash').cloneDeep;
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var utils = require('./utils.js');
|
||||
var debug = require('debug')('loopback:boot:config-loader');
|
||||
var assert = require('assert');
|
||||
var g = require('strong-globalize')();
|
||||
|
@ -111,7 +111,7 @@ function findConfigFiles(appRootDir, env, name) {
|
|||
|
||||
function ifExists(fileName) {
|
||||
var filepath = path.resolve(appRootDir, fileName);
|
||||
return fs.existsSync(filepath) ? filepath : undefined;
|
||||
return utils.fileExists(filepath) ? filepath : undefined;
|
||||
}
|
||||
|
||||
function ifExistsWithAnyExt(fileName) {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright IBM Corp. 2014,2016. All Rights Reserved.
|
||||
// Node module: loopback-boot
|
||||
// This file is licensed under the MIT License.
|
||||
// License text available at https://opensource.org/licenses/MIT
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
exports.fileExists = fileExists;
|
||||
|
||||
/**
|
||||
* Check synchronously if a filepath points to an existing file.
|
||||
* Replaces calls to fs.existsSync, which is deprecated (see:
|
||||
* https://github.com/nodejs/node/pull/166).
|
||||
*
|
||||
* @param {String} filepath The absolute path to check
|
||||
* @returns {Boolean} True if the file exists
|
||||
*/
|
||||
function fileExists(filepath) {
|
||||
try {
|
||||
fs.statSync(filepath);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue