Skip to content

Commit

Permalink
Improve path resolution on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Aug 16, 2016
1 parent 343a36c commit f13bb77
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/hooks/moduleloader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ module.exports = function(sails) {
};

// Walk the /api and /config directories
walk.walkSync(localConfig.appPath+'/api', walkOpts);
walk.walkSync(localConfig.appPath+'/config', walkOpts);
walk.walkSync(path.resolve(localConfig.appPath,'api'), walkOpts);
walk.walkSync(path.resolve(localConfig.appPath, 'config'), walkOpts);

// ----------------------------------------------------------------------
// This slows down lift time **a lot** (~500ms on medium-sized app
Expand All @@ -157,11 +157,18 @@ module.exports = function(sails) {
var lang = _.find(supportedLangs, {module: moduleName});
detectedExtens = detectedExtens.concat(lang.extensions);

// Try to require the language extension module directly.
// (this only works if the dep is installed in the $HOME directory,
// or if we catch a lucky break)
try {
require(lang.require);
require(lang.require);
} catch(e0){

// If that doesn't work, then try to require the language extension module
// by building a path directly to where it _should_ be installed as one of
// this app's local dependencies.
try {
require(path.join(localConfig.appPath, 'node_modules/'+lang.require));
require(path.join(localConfig.appPath, 'node_modules', lang.require));
}
catch (e1) {
sails.log.error('Please run `npm install '+lang.module+'` to use '+lang.module+'!');
Expand Down Expand Up @@ -237,8 +244,8 @@ module.exports = function(sails) {
async.auto({
'config/*': function loadOtherConfigFiles (cb) {
buildDictionary.aggregate({
dirname : sails.config.paths.config || sails.config.appPath + '/config',
exclude : ['locales'].concat(_.map(sails.config.moduleloader.configExt, function(item){ return 'local.'+item; })),
dirname : sails.config.paths.config || path.resolve(sails.config.appPath, 'config'),
exclude : ['locales'].concat(_.map(sails.config.moduleloader.configExt, function (extension){ return 'local.'+extension; })),
excludeDirs: /(locales|env)$/,
filter : new RegExp('(.+)\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
flattenDirectories: !(sails.config.dontFlattenConfig),
Expand All @@ -248,7 +255,7 @@ module.exports = function(sails) {

'config/local' : function loadLocalOverrideFile (cb) {
buildDictionary.aggregate({
dirname : sails.config.paths.config || sails.config.appPath + '/config',
dirname : sails.config.paths.config || path.resolve(sails.config.appPath, 'config'),
filter : new RegExp('local\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
identity : false
}, cb);
Expand All @@ -261,7 +268,7 @@ module.exports = function(sails) {
// for an environment setting. Lastly, default to development.
var env = sails.config.environment || async_data['config/local'].environment || 'development';
buildDictionary.aggregate({
dirname : (sails.config.paths.config || sails.config.appPath + '/config') + '/env/' + env,
dirname : path.resolve( sails.config.paths.config || path.resolve(sails.config.appPath, 'config'), 'env', env ),
filter : new RegExp('(.+)\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
optional : true,
flattenDirectories: !(sails.config.dontFlattenConfig),
Expand All @@ -276,7 +283,7 @@ module.exports = function(sails) {
// for an environment setting. Lastly, default to development.
var env = sails.config.environment || async_data['config/local'].environment || 'development';
buildDictionary.aggregate({
dirname : (sails.config.paths.config || sails.config.appPath + '/config') + '/env',
dirname : path.resolve( sails.config.paths.config || path.resolve(sails.config.appPath, 'config'), 'env' ),
filter : new RegExp('^' + env + '\\.(' + sails.config.moduleloader.configExt.join('|') + ')$'),
optional : true,
flattenDirectories: !(sails.config.dontFlattenConfig),
Expand Down Expand Up @@ -481,7 +488,7 @@ module.exports = function(sails) {
// under node_modules or under a node_modules/@something (namespaced) folder
if ('object' === typeof modules[identity] && level === 0 || (level === 1 && currentPath[0] === '@')) {
var nextPath;
if (currentPath) { nextPath = currentPath + '/' + identity; }
if (currentPath) { nextPath = path.join(currentPath,identity); }
else { nextPath = identity; }

flattenDirectories(modules[identity], foundPackageJsons, nextPath, level + 1 );
Expand Down

0 comments on commit f13bb77

Please sign in to comment.