aboutsummaryrefslogtreecommitdiffstats
path: root/grunt.js
diff options
context:
space:
mode:
authorRichard Gibson <richard.gibson@gmail.com>2012-05-28 22:25:04 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-05-28 22:36:23 -0400
commit7f2cc46955b35dc3d5a0526d0cb038d4a50b936b (patch)
treee2a4e841e16f90c93118130ec93319013eb3f08f /grunt.js
parent82d4c72fb15edd91869afa01a5bca3af678852fb (diff)
downloadjquery-7f2cc46955b35dc3d5a0526d0cb038d4a50b936b.tar.gz
jquery-7f2cc46955b35dc3d5a0526d0cb038d4a50b936b.zip
Fix #11767. Modularize build and unit tests for exluding effects.
Closes gh-785. To build a version of jQuery without effects, use `grunt build:*:*:-effects`. The unit tests feature-check for the interfaces and skip the unit tests for effects if they don't detect it.
Diffstat (limited to 'grunt.js')
-rw-r--r--grunt.js69
1 files changed, 44 insertions, 25 deletions
diff --git a/grunt.js b/grunt.js
index 2313bb27a..bdc6e8a1d 100644
--- a/grunt.js
+++ b/grunt.js
@@ -50,7 +50,7 @@ module.exports = function( grunt ) {
"src/ajax/jsonp.js",
"src/ajax/script.js",
"src/ajax/xhr.js",
- "src/effects.js",
+ { flag: "effects", src: "src/effects.js" },
"src/offset.js",
"src/dimensions.js",
"src/exports.js",
@@ -103,7 +103,7 @@ module.exports = function( grunt ) {
});
// Default grunt.
- grunt.registerTask( "default", "selector build lint min compare_size" );
+ grunt.registerTask( "default", "selector build:*:* lint min compare_size" );
grunt.loadNpmTasks("grunt-compare-size");
@@ -159,29 +159,48 @@ module.exports = function( grunt ) {
// Special concat/build task to handle various jQuery build requirements
- grunt.registerMultiTask( "build", "Concatenate source, embed date/version", function() {
- // Concat specified files.
- var compiled = "",
- name = this.file.dest;
+ grunt.registerMultiTask(
+ "build",
+ "Concatenate source (include/exclude modules with +/- flags), embed date/version",
+ function() {
+ // Concat specified files.
+ var compiled = "",
+ modules = this.flags,
+ optIn = !modules["*"],
+ name = this.file.dest;
+
+ this.file.src.forEach(function( filepath ) {
+ // Include optional modules per build flags; exclusion trumps inclusion
+ var flag = filepath.flag;
+ if ( flag ) {
+ if ( modules[ "-" + flag ] ||
+ optIn && !modules[ flag ] && !modules[ "+" + flag ] ) {
+
+ log.writeln( "Excluding " + filepath.flag + ": '" + filepath.src + "'." );
+ return;
+ }
+ log.writeln( "Including " + filepath.flag + ": '" + filepath.src + "'." );
+ filepath = filepath.src;
+ }
+
+ // Unwrap redundant IIFEs
+ compiled += file.read( filepath ).replace( /^\(function\( jQuery \) \{|\}\)\( jQuery \);\s*$/g, "" );
+ });
+
+ // Embed Date
+ // Embed Version
+ compiled = compiled.replace( "@DATE", new Date() )
+ .replace( "@VERSION", config("pkg.version") );
+
+ // Write concatenated source to file
+ file.write( name, compiled );
+
+ // Fail task if errors were logged.
+ if ( this.errorCount ) {
+ return false;
+ }
- this.file.src.forEach(function( filepath ) {
- compiled += file.read( filepath ).replace( /.function..jQuery...\{/g, "" ).replace( /\}...jQuery..;/g, "" );
+ // Otherwise, print a success message.
+ log.writeln( "File '" + name + "' created." );
});
-
- // Embed Date
- // Embed Version
- compiled = compiled.replace( "@DATE", new Date() )
- .replace( "@VERSION", config("pkg.version") );
-
- // Write concatenated source to file
- file.write( name, compiled );
-
- // Fail task if errors were logged.
- if ( this.errorCount ) {
- return false;
- }
-
- // Otherwise, print a success message.
- log.writeln( "File '" + name + "' created." );
- });
};