2012-04-18 20:07:35 +00:00
|
|
|
module.exports = function( grunt ) {
|
|
|
|
|
2012-10-16 14:10:17 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Integrate build task
|
|
|
|
require( "./build/build" )( grunt );
|
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
var distpaths = [
|
2012-10-16 16:21:17 +00:00
|
|
|
"dist/jquery.js",
|
2012-12-23 19:45:49 +00:00
|
|
|
"dist/jquery.min.map",
|
|
|
|
"dist/jquery.min.js"
|
2012-12-19 04:02:50 +00:00
|
|
|
],
|
2013-03-13 23:23:36 +00:00
|
|
|
gzip = require("gzip-js"),
|
2012-12-19 04:02:50 +00:00
|
|
|
readOptionalJSON = function( filepath ) {
|
|
|
|
var data = {};
|
|
|
|
try {
|
|
|
|
data = grunt.file.readJSON( filepath );
|
|
|
|
} catch(e) {}
|
|
|
|
return data;
|
2013-04-09 16:48:34 +00:00
|
|
|
},
|
2013-07-11 16:52:07 +00:00
|
|
|
fs = require( "fs" ),
|
|
|
|
srcHintOptions = readOptionalJSON( "src/.jshintrc" );
|
2013-04-09 16:48:34 +00:00
|
|
|
|
|
|
|
// The concatenated file won't pass onevar
|
|
|
|
// But our modules can
|
|
|
|
delete srcHintOptions.onevar;
|
2012-04-18 20:07:35 +00:00
|
|
|
|
|
|
|
grunt.initConfig({
|
2012-12-19 04:02:50 +00:00
|
|
|
pkg: grunt.file.readJSON("package.json"),
|
2012-06-05 17:10:01 +00:00
|
|
|
dst: readOptionalJSON("dist/.destination.json"),
|
2012-04-18 20:07:35 +00:00
|
|
|
compare_size: {
|
2013-03-25 04:47:46 +00:00
|
|
|
files: [ "dist/jquery.js", "dist/jquery.min.js" ],
|
|
|
|
options: {
|
|
|
|
compress: {
|
|
|
|
gz: function( contents ) {
|
|
|
|
return gzip.zip( contents, {} ).length;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cache: "dist/.sizecache.json"
|
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
|
|
|
build: {
|
2013-04-18 17:19:22 +00:00
|
|
|
all: {
|
2013-01-26 18:38:04 +00:00
|
|
|
dest: "dist/jquery.js",
|
2013-08-15 18:15:49 +00:00
|
|
|
minimum: [
|
|
|
|
"core",
|
|
|
|
"selector"
|
|
|
|
],
|
|
|
|
// Exclude specified modules if the module matching the key is removed
|
|
|
|
removeWith: {
|
|
|
|
callbacks: [ "deferred" ],
|
|
|
|
css: [ "effects", "dimensions", "offset" ],
|
|
|
|
sizzle: [ "css/hidden-visible-selectors", "effects/animated-selector" ]
|
|
|
|
}
|
2013-01-26 18:38:04 +00:00
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2013-07-19 13:53:57 +00:00
|
|
|
jsonlint: {
|
|
|
|
pkg: {
|
|
|
|
src: [ "package.json" ]
|
|
|
|
},
|
|
|
|
bower: {
|
|
|
|
src: [ "bower.json" ]
|
|
|
|
}
|
|
|
|
},
|
2012-12-19 04:02:50 +00:00
|
|
|
jshint: {
|
|
|
|
dist: {
|
|
|
|
src: [ "dist/jquery.js" ],
|
2013-04-09 16:48:34 +00:00
|
|
|
options: srcHintOptions
|
2012-12-19 04:02:50 +00:00
|
|
|
},
|
|
|
|
grunt: {
|
2013-08-15 18:15:49 +00:00
|
|
|
src: [ "Gruntfile.js", "build/build.js" ],
|
2012-12-19 04:02:50 +00:00
|
|
|
options: {
|
|
|
|
jshintrc: ".jshintrc"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
tests: {
|
2013-07-11 16:52:07 +00:00
|
|
|
src: [ "test/**/*.js" ],
|
2012-12-19 04:02:50 +00:00
|
|
|
options: {
|
|
|
|
jshintrc: "test/.jshintrc"
|
|
|
|
}
|
|
|
|
}
|
2012-05-09 07:34:00 +00:00
|
|
|
},
|
2012-12-13 01:19:18 +00:00
|
|
|
testswarm: {
|
|
|
|
tests: "ajax attributes callbacks core css data deferred dimensions effects event manipulation offset queue selector serialize support traversing Sizzle".split(" ")
|
|
|
|
},
|
2012-04-18 20:07:35 +00:00
|
|
|
watch: {
|
2012-12-19 04:02:50 +00:00
|
|
|
files: [ "<%= jshint.grunt.src %>", "<%= jshint.tests.src %>", "src/**/*.js" ],
|
2012-06-05 15:50:49 +00:00
|
|
|
tasks: "dev"
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2013-04-18 17:19:22 +00:00
|
|
|
"pre-uglify": {
|
|
|
|
all: {
|
|
|
|
files: {
|
|
|
|
"dist/jquery.pre-min.js": [ "dist/jquery.js" ]
|
|
|
|
},
|
|
|
|
options: {
|
2013-05-22 13:11:19 +00:00
|
|
|
banner: "\n\n\n\n\n\n\n\n\n\n" + // banner line size must be preserved
|
|
|
|
"/*! jQuery v<%= pkg.version %> | " +
|
2013-04-18 17:19:22 +00:00
|
|
|
"(c) 2005, 2013 jQuery Foundation, Inc. | " +
|
|
|
|
"jquery.org/license\n" +
|
2013-07-02 20:58:20 +00:00
|
|
|
"//@ sourceMappingURL=jquery.min.map\n" +
|
2013-05-22 13:11:19 +00:00
|
|
|
"*/\n"
|
2013-04-18 17:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-10-11 13:38:44 +00:00
|
|
|
uglify: {
|
2012-12-19 04:02:50 +00:00
|
|
|
all: {
|
|
|
|
files: {
|
2013-04-18 17:19:22 +00:00
|
|
|
"dist/jquery.min.js": [ "dist/jquery.pre-min.js" ]
|
2012-12-19 04:02:50 +00:00
|
|
|
},
|
|
|
|
options: {
|
2013-04-18 17:19:22 +00:00
|
|
|
// Keep our hard-coded banner
|
|
|
|
preserveComments: "some",
|
2012-12-22 21:23:27 +00:00
|
|
|
sourceMap: "dist/jquery.min.map",
|
2013-04-18 17:19:22 +00:00
|
|
|
sourceMappingURL: "jquery.min.map",
|
|
|
|
report: "min",
|
2012-12-19 04:02:50 +00:00
|
|
|
beautify: {
|
|
|
|
ascii_only: true
|
2013-04-10 18:46:31 +00:00
|
|
|
},
|
2013-04-18 13:16:59 +00:00
|
|
|
compress: {
|
|
|
|
hoist_funs: false,
|
|
|
|
join_vars: false,
|
|
|
|
loops: false,
|
|
|
|
unused: false
|
2012-12-19 04:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-11 13:38:44 +00:00
|
|
|
}
|
2013-05-22 13:11:19 +00:00
|
|
|
},
|
|
|
|
"post-uglify": {
|
|
|
|
all: {
|
|
|
|
files: {
|
|
|
|
"dist/jquery.min.map.tmp": [ "dist/jquery.min.map" ],
|
|
|
|
"dist/jquery.min.js.tmp": [ "dist/jquery.min.js" ]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
tempFiles: [ "dist/jquery.min.map.tmp", "dist/jquery.min.js.tmp", "dist/jquery.pre-min.js" ]
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 13:38:44 +00:00
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
});
|
|
|
|
|
2012-05-07 10:06:12 +00:00
|
|
|
grunt.registerTask( "testswarm", function( commit, configFile ) {
|
2012-11-24 23:59:56 +00:00
|
|
|
var jobName,
|
|
|
|
testswarm = require( "testswarm" ),
|
2013-06-05 13:58:33 +00:00
|
|
|
runs = {},
|
|
|
|
done = this.async(),
|
2012-11-24 23:59:56 +00:00
|
|
|
pull = /PR-(\d+)/.exec( commit ),
|
2012-07-11 13:54:01 +00:00
|
|
|
config = grunt.file.readJSON( configFile ).jquery,
|
2012-12-13 01:19:18 +00:00
|
|
|
tests = grunt.config([ this.name, "tests" ]);
|
2012-07-11 13:54:01 +00:00
|
|
|
|
2012-11-24 23:59:56 +00:00
|
|
|
if ( pull ) {
|
2012-11-25 18:50:49 +00:00
|
|
|
jobName = "jQuery pull <a href='https://github.com/jquery/jquery/pull/" +
|
2012-11-25 00:04:34 +00:00
|
|
|
pull[ 1 ] + "'>#" + pull[ 1 ] + "</a>";
|
2012-11-24 23:59:56 +00:00
|
|
|
} else {
|
|
|
|
jobName = "jQuery commit #<a href='https://github.com/jquery/jquery/commit/" +
|
|
|
|
commit + "'>" + commit.substr( 0, 10 ) + "</a>";
|
|
|
|
}
|
|
|
|
|
2012-05-07 10:06:12 +00:00
|
|
|
tests.forEach(function( test ) {
|
2013-06-05 13:58:33 +00:00
|
|
|
runs[test] = config.testUrl + commit + "/test/index.html?module=" + test;
|
2012-05-07 10:06:12 +00:00
|
|
|
});
|
2012-07-11 13:54:01 +00:00
|
|
|
|
2013-06-05 13:58:33 +00:00
|
|
|
// TODO: create separate job for git/git2 so we can do different browsersets
|
|
|
|
testswarm.createClient( {
|
2012-06-07 18:36:19 +00:00
|
|
|
url: config.swarmUrl,
|
2012-05-07 10:06:12 +00:00
|
|
|
pollInterval: 10000,
|
2013-06-05 13:58:33 +00:00
|
|
|
timeout: 1000 * 60 * 30
|
|
|
|
} )
|
|
|
|
.addReporter( testswarm.reporters.cli )
|
|
|
|
.auth( {
|
|
|
|
id: config.authUsername,
|
|
|
|
token: config.authToken
|
|
|
|
})
|
|
|
|
.addjob(
|
|
|
|
{
|
|
|
|
name: jobName,
|
|
|
|
runs: runs,
|
|
|
|
runMax: config.runMax,
|
|
|
|
browserSets: "popular-no-old-ie"
|
|
|
|
}, function( err, passed ) {
|
|
|
|
if ( err ) {
|
|
|
|
grunt.log.error( err );
|
|
|
|
}
|
|
|
|
done( passed );
|
|
|
|
}
|
|
|
|
);
|
2012-05-07 10:06:12 +00:00
|
|
|
});
|
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
// Process files for distribution
|
2012-06-04 16:48:18 +00:00
|
|
|
grunt.registerTask( "dist", function() {
|
2013-07-11 16:52:07 +00:00
|
|
|
var stored, flags, paths, nonascii;
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Check for stored destination paths
|
|
|
|
// ( set in dist/.destination.json )
|
2013-05-22 13:11:19 +00:00
|
|
|
stored = Object.keys( grunt.config( "dst" ) );
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Allow command line input as well
|
|
|
|
flags = Object.keys( this.flags );
|
2012-06-05 16:16:48 +00:00
|
|
|
|
2012-06-05 17:10:01 +00:00
|
|
|
// Combine all output target paths
|
|
|
|
paths = [].concat( stored, flags ).filter(function( path ) {
|
|
|
|
return path !== "*";
|
|
|
|
});
|
2012-06-05 16:16:48 +00:00
|
|
|
|
2012-10-11 14:17:24 +00:00
|
|
|
// Ensure the dist files are pure ASCII
|
2013-04-09 15:45:09 +00:00
|
|
|
nonascii = false;
|
2012-12-19 04:02:50 +00:00
|
|
|
|
2012-10-11 14:17:24 +00:00
|
|
|
distpaths.forEach(function( filename ) {
|
2013-04-18 17:19:22 +00:00
|
|
|
var i, c,
|
2013-01-05 18:11:01 +00:00
|
|
|
text = fs.readFileSync( filename, "utf8" );
|
|
|
|
|
|
|
|
// Ensure files use only \n for line endings, not \r\n
|
|
|
|
if ( /\x0d\x0a/.test( text ) ) {
|
|
|
|
grunt.log.writeln( filename + ": Incorrect line endings (\\r\\n)" );
|
|
|
|
nonascii = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure only ASCII chars so script tags don't need a charset attribute
|
2012-12-22 21:10:06 +00:00
|
|
|
if ( text.length !== Buffer.byteLength( text, "utf8" ) ) {
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( filename + ": Non-ASCII characters detected:" );
|
2012-12-22 21:10:06 +00:00
|
|
|
for ( i = 0; i < text.length; i++ ) {
|
|
|
|
c = text.charCodeAt( i );
|
2012-10-11 14:17:24 +00:00
|
|
|
if ( c > 127 ) {
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.log.writeln( "- position " + i + ": " + c );
|
2012-12-22 21:10:06 +00:00
|
|
|
grunt.log.writeln( "-- " + text.substring( i - 20, i + 20 ) );
|
|
|
|
break;
|
2012-10-11 14:17:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 18:11:01 +00:00
|
|
|
nonascii = true;
|
2012-10-11 14:17:24 +00:00
|
|
|
}
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2013-01-10 15:35:50 +00:00
|
|
|
// Modify map/min so that it points to files in the same folder;
|
2012-12-22 21:10:06 +00:00
|
|
|
// see https://github.com/mishoo/UglifyJS2/issues/47
|
|
|
|
if ( /\.map$/.test( filename ) ) {
|
|
|
|
text = text.replace( /"dist\//g, "\"" );
|
|
|
|
fs.writeFileSync( filename, text, "utf-8" );
|
2013-04-18 17:19:22 +00:00
|
|
|
|
|
|
|
// Use our hard-coded sourceMap directive instead of the autogenerated one (#13274; #13776)
|
2013-01-10 15:35:50 +00:00
|
|
|
} else if ( /\.min\.js$/.test( filename ) ) {
|
2013-04-18 17:19:22 +00:00
|
|
|
i = 0;
|
|
|
|
text = text.replace( /(?:\/\*|)\n?\/\/@\s*sourceMappingURL=.*(\n\*\/|)/g,
|
|
|
|
function( match ) {
|
|
|
|
if ( i++ ) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return match;
|
2013-01-23 22:42:28 +00:00
|
|
|
});
|
2013-01-10 15:35:50 +00:00
|
|
|
fs.writeFileSync( filename, text, "utf-8" );
|
2012-12-22 21:10:06 +00:00
|
|
|
}
|
2012-06-05 17:10:01 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
// Optionally copy dist files to other locations
|
|
|
|
paths.forEach(function( path ) {
|
|
|
|
var created;
|
2012-06-05 17:10:01 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
if ( !/\/$/.test( path ) ) {
|
|
|
|
path += "/";
|
|
|
|
}
|
2012-06-04 16:48:18 +00:00
|
|
|
|
2012-12-22 21:10:06 +00:00
|
|
|
created = path + filename.replace( "dist/", "" );
|
|
|
|
grunt.file.write( created, text );
|
|
|
|
grunt.log.writeln( "File '" + created + "' created." );
|
2012-06-04 16:48:18 +00:00
|
|
|
});
|
2012-12-22 21:10:06 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return !nonascii;
|
2012-06-04 16:48:18 +00:00
|
|
|
});
|
2012-12-19 04:02:50 +00:00
|
|
|
|
2013-04-18 17:19:22 +00:00
|
|
|
// Work around grunt-contrib-uglify sourceMap issues (jQuery #13776)
|
|
|
|
grunt.registerMultiTask( "pre-uglify", function() {
|
|
|
|
var banner = this.options().banner;
|
|
|
|
|
|
|
|
this.files.forEach(function( mapping ) {
|
|
|
|
// Join src
|
|
|
|
var input = mapping.src.map(function( file ) {
|
|
|
|
var contents = grunt.file.read( file );
|
|
|
|
|
|
|
|
// Strip banners
|
2013-05-22 13:11:19 +00:00
|
|
|
return contents
|
|
|
|
// Remove the main jQuery banner, it'll be replaced by the new banner anyway.
|
2013-08-15 18:15:49 +00:00
|
|
|
.replace( /^\/\*![\W\w]*?\*\/\n?/g, "" )
|
2013-05-22 13:11:19 +00:00
|
|
|
// Strip other banners preserving line count.
|
|
|
|
.replace( /^\/\*!(?:.|\n)*?\*\/\n?/gm, function ( match ) {
|
|
|
|
return match.replace( /[^\n]/gm, "" );
|
|
|
|
});
|
2013-04-18 17:19:22 +00:00
|
|
|
}).join("\n");
|
|
|
|
|
|
|
|
// Write temp file (with optional banner)
|
|
|
|
grunt.file.write( mapping.dest, ( banner || "" ) + input );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-05-22 13:11:19 +00:00
|
|
|
// Change the map file to point back to jquery.js instead of jquery.pre-min.js.
|
|
|
|
// The problem is caused by the pre-uglify task.
|
|
|
|
// Also, remove temporary files.
|
|
|
|
grunt.registerMultiTask( "post-uglify", function() {
|
|
|
|
this.files.forEach(function( mapping ) {
|
|
|
|
var mapFileName = mapping.src[ 0 ];
|
|
|
|
|
|
|
|
// Rename the file to a temporary name.
|
|
|
|
fs.renameSync( mapFileName, mapping.dest);
|
|
|
|
grunt.file.write( mapFileName, grunt.file.read( mapping.dest )
|
|
|
|
// The uglify task erroneously prepends dist/ to file names.
|
|
|
|
.replace( /"dist\//g, "\"" )
|
|
|
|
// Refer to the source jquery.js, not the temporary jquery.pre-min.js.
|
|
|
|
.replace( /\.pre-min\./g, "." )
|
|
|
|
// There's already a pragma at the beginning of the file, remove the one at the end.
|
|
|
|
.replace( /\/\/@ sourceMappingURL=jquery\.min\.map$/g, "" ));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Remove temporary files.
|
|
|
|
this.options().tempFiles.forEach(function( fileName ) {
|
|
|
|
fs.unlink( fileName );
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
// Load grunt tasks from NPM packages
|
2012-12-20 01:18:58 +00:00
|
|
|
grunt.loadNpmTasks("grunt-compare-size");
|
|
|
|
grunt.loadNpmTasks("grunt-git-authors");
|
2012-12-19 04:02:50 +00:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-jshint");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-uglify");
|
2013-07-19 13:53:57 +00:00
|
|
|
grunt.loadNpmTasks("grunt-jsonlint");
|
2012-12-19 04:02:50 +00:00
|
|
|
|
|
|
|
// Short list as a high frequency watch task
|
2013-08-15 18:15:49 +00:00
|
|
|
grunt.registerTask( "dev", [ "build:*:*", "jshint" ] );
|
2013-07-19 13:53:57 +00:00
|
|
|
|
|
|
|
// Default grunt
|
|
|
|
grunt.registerTask( "default", [ "jsonlint", "dev", "pre-uglify", "uglify", "post-uglify", "dist:*", "compare_size" ] );
|
2012-04-18 20:07:35 +00:00
|
|
|
};
|