Permalink
Browse files

Actual initial commit

  • Loading branch information...
zship committed Jan 19, 2013
1 parent f65e787 commit d698c3df4e5241fd1f1bfd841c42b0d0211856c3
Showing with 20,190 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +47 −1 README.md
  3. +20 −0 package.json
  4. +21 −0 tasks/.jshintrc
  5. +73 −0 tasks/checkrequire.js
  6. +3,573 −0 tasks/lib/esprima.js
  7. +717 −0 tasks/lib/parse.js
  8. +15,586 −0 tasks/lib/r.js
  9. +152 −0 tasks/util.js
View
@@ -0,0 +1 @@
+node_modules/**
View
@@ -1,4 +1,50 @@
grunt-amd-checkrequire
======================
-Grunt task to check for broken AMD dependencies
+grunt-amd-checkrequire is a [grunt](http://gruntjs.com/) task to check for
+broken AMD dependencies in a project.
+
+
+Installataion
+-------------
+
+From the same directory as your Gruntfile, run
+
+```
+npm install grunt-amd-checkrequire
+```
+
+Then add the following line to your Gruntfile:
+
+```js
+grunt.loadNpmTasks('grunt-amd-checkrequire');
+```
+
+You can verify that the task is available by running `grunt --help` and
+checking that "checkrequire" is under "Available tasks".
+
+
+Usage
+-----
+
+grunt-amd-checkrequire reads two sections of your config: `checkrequire` and
+`requirejs`. `checkrequire` can contain these properties (example from
+[class.js](https://github.com/zship/class.js)):
+
+```js
+checkrequire: {
+ //String or Array of files for which to trace dependencies
+ include: ['src/**/*.js', 'test/spec/**/*.js']
+ //exclude files from the 'include' list. Useful to add specific
+ //exceptions to globbing.
+ exclude: []
+},
+```
+
+`requirejs` is a standard [r.js configuration
+object](https://github.com/jrburke/r.js/blob/master/build/example.build.js).
+grunt-amd-checkrequire uses `basePath`, `paths`, and `packages` (all optional)
+to transform AMD module names to absolute file names.
+
+Once these options are in place, `grunt checkrequire` will run
+grunt-amd-checkrequire and report any broken dependencies.
View
@@ -0,0 +1,20 @@
+{
+ "name": "grunt-amd-checkrequire",
+ "title": "grunt-amd-checkrequire",
+ "description": "Grunt task to check for broken AMD dependencies",
+ "version": "0.1.0",
+ "homepage": "https://github.com/zship/grunt-amd-checkrequire",
+ "author": "Zach Shipley <zach@zachshipley.com>",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/zship/grunt-amd-checkrequire"
+ },
+ "license": "MIT",
+ "dependencies": {
+ "grunt": "0.3.x"
+ },
+ "keywords": [
+ "gruntplugin",
+ "amd"
+ ]
+}
View
@@ -0,0 +1,21 @@
+{
+ "globals": {
+ "define": false,
+ "module": false
+ },
+
+ "es5": true,
+ "devel": true,
+ "node": true,
+
+ "undef": true,
+ "unused": true,
+ "smarttabs": true,
+ "laxbreak": true,
+ "curly": true,
+ "eqeqeq": true,
+ "nonew": true,
+ "latedef": true,
+ "sub": true
+
+}
View
@@ -0,0 +1,73 @@
+module.exports = function(grunt) {
+ 'use strict';
+
+ var path = require('path');
+ var parseDir = './lib/parse';
+ var libdir = path.resolve(__dirname + '/lib');
+ var util = require('./util.js');
+ var _ = grunt.utils._;
+
+
+ grunt.registerTask('checkrequire', 'Checks for broken AMD dependencies', function() {
+ var config = grunt.config.get(this.name);
+ var done = this.async();
+
+
+ config.include = util.expand(config.include);
+ config.exclude = util.expand(config.exclude);
+
+ var files = _.difference(config.include, config.exclude);
+
+ var requirejs = require(libdir + '/r.js');
+ requirejs.config({
+ baseUrl: __dirname,
+ nodeRequire: require
+ });
+
+ requirejs([parseDir], function(parse) {
+
+ var rjsconfig = grunt.config.get('requirejs');
+
+ _.each(files, function(file) {
+ file = path.resolve(process.cwd() + '/' + file);
+ var deps;
+ try {
+ deps = parse.findDependencies(file, grunt.file.read(file));
+ }
+ catch(e) {
+ deps = [];
+ }
+
+ deps = deps
+ .filter(function(depPath) {
+ //ignore special 'require' dependency
+ return depPath !== 'require';
+ })
+ .map(function(depPath) {
+ return {
+ declared: depPath,
+ resolved: util.moduleToFileName(depPath, path.dirname(file), rjsconfig)
+ };
+ })
+ .filter(function(dep) {
+ return !dep.resolved;
+ });
+
+ if (deps.length) {
+ grunt.log.writeln('');
+ grunt.log.error();
+ grunt.log.writeln('Unresolved dependencies in ' + file + ':');
+ deps.forEach(function(dep) {
+ grunt.log.writeln('\t' + dep.declared);
+ });
+ }
+ });
+
+ done();
+
+ });
+
+
+ });
+
+};
View

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit d698c3d

Please sign in to comment.