Wednesday, September 18, 2013

Needs More Dojo 0.5.1: Cyclic Dependency Detection

So 0.5.1 is a "minor" release. This means that it should be mostly bug-fixes and some minor enhancements. Well in this release I decided to add a pretty big feature (it was a feature request actually). The feature in question is cyclic dependency detection.

In dojo, cyclic dependencies present a problem. If you have a cyclic dependency, one of the modules involved will be resolved to {}, an empty object. Oops. This is to prevent further recursion as the AMD loader goes down the dependency graph. Unfortunately this can lead to subtle bugs and can be difficult to track down. I remember struggling when I was first learning dojo and ran into this problem, luckily a colleague was able to describe the issue.

Anyway, in Needs More Dojo I've added the ability to scan for cyclic dependencies. So now you can run a scan on your project sources, and you get a tool window like this:

Scanning for cyclic dependencies.
All it's doing is navigating the dependency graph and checking for cycles. It also counts the number of times a particular module has been involved in a cycle and displays the count next to it. In my simple example, all of the modules listed appear once. However, if you had one module appearing more than another one, it's more likely the culprit causing the cycle.

This appears as an action in the code menu that you can run. I've also added an inspection that will run in the background and highlight modules that are involved in cyclic dependency graphs like this:

Cyclic dependencies flagged as errors
In this example, the inspection has detected a cyclic dependency and displays it as an error. You can also see that the dependency in question (ProjectData) is flagged as unused. So there's an unnecessary cycle in this project.

The inspection is disabled by default. I did this because I didn't want large projects getting performance hits, as the inspection has to build a graph of dependencies for each file.

Expect 0.5.1 to be released in a couple of weeks.

Saturday, September 14, 2013

Needs More Dojo v0.5: Refactoring Support

For the past couple of months I've been working on an IntelliJ IDEA plugin called Needs More Dojo. It's basically a plugin that makes IntelliJ/WebStorm/etc. aware of conventions and structure of dojo applications. I use dojo at my day job, so it started out of things I noticed could be improved.

I'm very excited about the newest version, 0.5, that was released about a week ago. Although you might not do major refactoring every day, it's painful when you have to do it. Sadly, IntelliJ does not handle dojo's AMD system very well and so when moving files you still have to manually update them.

So Needs More Dojo complements IntelliJ's features by being aware of the AMD system and your project's package structure. Due to this, it will successfully update your import statements with the correct locations. It's taken awhile to build up the code necessary to support refactoring, but I'm glad it's here now.

The next release will be a minor release (0.5.1). For this release I have a few minor enhancements planned so far based on some user feedback and my own roadmap. I'm going to try to space the releases out on a more defined interval instead of sporadic (0.5 took forever to be released for example).

If you have any feature suggestions, head over to the issues page on github and add them.