Created
May 19, 2014 12:49
-
-
Save olov/eedc1788d221ac579868 to your computer and use it in GitHub Desktop.
ng-annotate + assetgraph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Process (almost) all files with ng-annotate options {add: true, regexp: "^$"} | |
I say almost because there should be no risk that already minified files (i.e. matching the filename pattern *.min.* or something similar) need processing by ng-annotate. So we're saving the nature and build times by excluding them. | |
Add means "add annotations but don't remove or rebuild those already existing, if any". That's what you want. The weird-looking regexp-option really just means disable the support for short declaration forms. | |
This is a short declaration form: | |
myMod.controller("MyCtrl", function($scope, $timeout) { | |
}); | |
And this is a long declaration form (which is officially recommended by the angular team): | |
angular.module("MyMod").controller("MyCtrl", function($scope, $timeout) { | |
}); | |
As you can see, executed on tens of millions of non-angular-app-code, having short form support enabled (with no limitations) will eventuelly probably cause a false positive (thus breaking the build). So I think that assetgraph should disable that by default, and then let the user opt-in on enabling it by overriding the regexp-option through an assetgraph configuration. The user would be able to enable it for everything with {regexp: ".*"}, or only enable it for modules called myMod with {regexp: "^myMod$"}. I want to stress here that this regexp is only there for optionally limiting matching of the short form module identifier name. All of the heavy lifting matching happens on the AST level. | |
You did mention that assetgraph doesn't process a project unless it found ng-app in an html file. Perhaps that, together with not processing already minified files (which I assume should mean most major third party libraries in most real world builds), could mean that you'd be able to keep short declaration forms enabled by default. It seems quite unlikely (although not impossible) to stuble upon false positive trigging code that looks like it (but isn't) in an angularjs application codebase. |
Great. If so then I would actually try it with ng-annotate's default options (just pass {add: true}) and then only if real-world issues arise, make short declarations opt-in.
Tracking it here: assetgraph/assetgraph-builder#121
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good suggestions.
I can certainly skip all filenames matching
.min
and hide the short declarations form behind a configuration switch.Further more I can limit the collection of javascript files to only the ones actually in the immediate dependency graph of the html-file having the
ng-app
attribute. In that way I won't have to run annotation on dependencies of non-app pages that are in the graph, like 404 pages, login pages etc.