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

Fixes #94 - modules walking code should check for the type correctly #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Fixes #94 - modules walking code should check for the type correctly #95

wants to merge 1 commit into from

Conversation

sometea
Copy link

@sometea sometea commented Feb 2, 2016

As described in #94, if the path of the app has the substring "model" in it, the app crashes. This was because when loading mean.io modules, the code walking through the directory and loading the modules just checked the type by searching for the substring in the path, causing controllers to be loaded before the modules. This PR fixes the issue by changing the way the type is checked.

See also linnovate/mean#1283

// if (!rgx.test(file)) console.log(' Consider updating filename:', newPath);
callback(newPath);
} else if (stat.isDirectory() && file !== excludeDir && ~newPath.indexOf(type)) {
} else if (stat.isDirectory() && file !== excludeDir &&
~newPath.split(path.sep).indexOf(type+'s')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected use of '~'.

@timelf123
Copy link
Contributor

timelf123 commented Mar 4, 2016

This fixes some of my model loading issues where before I had to move var Model declarations inside my express controller instead of defining them at the top of the file

edit: nvm

@ADSKLowenthal
Copy link
Contributor

I don't think that actually fixes that issue. That issue is just a matter of the order that modules load. If you load Module B before Module A, and B uses the model from A you'll get that error.

However, I'd have to dig a bit deeper into this. But my initial guess is that this is trying to add an 's' to 'model' when it's passed in as a type. This code looks like it's related to finding specific folders (Models and Routes) to process specially. Might be better to see if "model" is being passed and maybe change it to "models".

Though the error would possibly also occur if a folder was then named "models".

Again this is just from a cursory look, but I don't think it solves the larger problem of reserved words in a path. If someone knows that system better and can correct me that'd be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants