@@ -2,6 +2,9 @@ module.exports = function( grunt ) {
22
33 "use strict" ;
44
5+ // Integrate build task
6+ require ( "./build/build" ) ( grunt ) ;
7+
58 var distpaths = [
69 "dist/jquery.js" ,
710 "dist/jquery.min.map" ,
@@ -36,41 +39,19 @@ module.exports = function( grunt ) {
3639 cache : "dist/.sizecache.json"
3740 }
3841 } ,
39- selector : {
40- destFile : "src/selector-sizzle.js" ,
41- apiFile : "src/sizzle-jquery.js" ,
42- srcFile : "bower_components/sizzle/dist/sizzle.js"
43- } ,
4442 build : {
4543 all : {
4644 dest : "dist/jquery.js" ,
47- src : [
48- "src/intro.js" ,
49- "src/core.js" ,
50- { flag : "sizzle" , src : "src/selector-sizzle.js" , alt : "src/selector-native.js" } ,
51- "src/callbacks.js" ,
52- "src/deferred.js" ,
53- "src/support.js" ,
54- "src/data.js" ,
55- "src/queue.js" ,
56- "src/attributes.js" ,
57- "src/event.js" ,
58- "src/traversing.js" ,
59- "src/manipulation.js" ,
60- { flag : "wrap" , src : "src/wrap.js" } ,
61- { flag : "css" , src : "src/css.js" } ,
62- "src/serialize.js" ,
63- { flag : "event-alias" , src : "src/event-alias.js" } ,
64- { flag : "ajax" , src : "src/ajax.js" } ,
65- { flag : "ajax/script" , src : "src/ajax/script.js" , needs : [ "ajax" ] } ,
66- { flag : "ajax/jsonp" , src : "src/ajax/jsonp.js" , needs : [ "ajax" , "ajax/script" ] } ,
67- { flag : "ajax/xhr" , src : "src/ajax/xhr.js" , needs : [ "ajax" ] } ,
68- { flag : "effects" , src : "src/effects.js" , needs : [ "css" ] } ,
69- { flag : "offset" , src : "src/offset.js" , needs : [ "css" ] } ,
70- { flag : "dimensions" , src : "src/dimensions.js" , needs : [ "css" ] } ,
71- { flag : "deprecated" , src : "src/deprecated.js" } ,
72- "src/outro.js"
73- ]
45+ minimum : [
46+ "core" ,
47+ "selector"
48+ ] ,
49+ // Exclude specified modules if the module matching the key is removed
50+ removeWith : {
51+ callbacks : [ "deferred" ] ,
52+ css : [ "effects" , "dimensions" , "offset" ] ,
53+ sizzle : [ "css/hidden-visible-selectors" , "effects/animated-selector" ]
54+ }
7455 }
7556 } ,
7657 jsonlint : {
@@ -87,7 +68,7 @@ module.exports = function( grunt ) {
8768 options : srcHintOptions
8869 } ,
8970 grunt : {
90- src : [ "Gruntfile.js" ] ,
71+ src : [ "Gruntfile.js" , "build/build.js" ] ,
9172 options : {
9273 jshintrc : ".jshintrc"
9374 }
@@ -140,10 +121,6 @@ module.exports = function( grunt ) {
140121 join_vars : false ,
141122 loops : false ,
142123 unused : false
143- } ,
144- mangle : {
145- // saves some bytes when gzipped
146- except : [ "undefined" ]
147124 }
148125 }
149126 }
@@ -208,252 +185,6 @@ module.exports = function( grunt ) {
208185 ) ;
209186 } ) ;
210187
211- grunt . registerTask ( "selector" , "Build Sizzle-based selector module" , function ( ) {
212-
213- var cfg = grunt . config ( "selector" ) ,
214- name = cfg . destFile ,
215- sizzle = {
216- api : grunt . file . read ( cfg . apiFile ) ,
217- src : grunt . file . read ( cfg . srcFile )
218- } ,
219- compiled , parts ;
220-
221- /**
222-
223- sizzle-jquery.js -> sizzle between "EXPOSE" blocks,
224- replace define & window.Sizzle assignment
225-
226-
227- // EXPOSE
228- if ( typeof define === "function" && define.amd ) {
229- define(function() { return Sizzle; });
230- } else {
231- window.Sizzle = Sizzle;
232- }
233- // EXPOSE
234-
235- Becomes...
236-
237- Sizzle.attr = jQuery.attr;
238- jQuery.find = Sizzle;
239- jQuery.expr = Sizzle.selectors;
240- jQuery.expr[":"] = jQuery.expr.pseudos;
241- jQuery.unique = Sizzle.uniqueSort;
242- jQuery.text = Sizzle.getText;
243- jQuery.isXMLDoc = Sizzle.isXML;
244- jQuery.contains = Sizzle.contains;
245-
246- */
247-
248- // Break into 3 pieces
249- parts = sizzle . src . split ( "// EXPOSE" ) ;
250- // Replace the if/else block with api
251- parts [ 1 ] = sizzle . api ;
252- // Rejoin the pieces
253- compiled = parts . join ( "" ) ;
254-
255- grunt . verbose . writeln ( "Injected " + cfg . apiFile + " into " + cfg . srcFile ) ;
256-
257- // Write concatenated source to file, and ensure newline-only termination
258- grunt . file . write ( name , compiled . replace ( / \x0d \x0a / g, "\x0a" ) ) ;
259-
260- // Fail task if errors were logged.
261- if ( this . errorCount ) {
262- return false ;
263- }
264-
265- // Otherwise, print a success message.
266- grunt . log . writeln ( "File '" + name + "' created." ) ;
267- } ) ;
268-
269- // Special "alias" task to make custom build creation less grawlix-y
270- grunt . registerTask ( "custom" , function ( ) {
271- var done = this . async ( ) ,
272- args = [ ] . slice . call ( arguments ) ,
273- modules = args . length ? args [ 0 ] . replace ( / , / g, ":" ) : "" ;
274-
275-
276- // Translation example
277- //
278- // grunt custom:+ajax,-dimensions,-effects,-offset
279- //
280- // Becomes:
281- //
282- // grunt build:*:*:+ajax:-dimensions:-effects:-offset
283-
284- grunt . log . writeln ( "Creating custom build...\n" ) ;
285-
286- grunt . util . spawn ( {
287- grunt : true ,
288- args : [ "build:*:*:" + modules , "pre-uglify" , "uglify" , "dist" ]
289- } , function ( err , result ) {
290- if ( err ) {
291- grunt . verbose . error ( ) ;
292- done ( err ) ;
293- return ;
294- }
295-
296- grunt . log . writeln ( result . stdout . replace ( "Done, without errors." , "" ) ) ;
297-
298- done ( ) ;
299- } ) ;
300- } ) ;
301-
302- // Special concat/build task to handle various jQuery build requirements
303- grunt . registerMultiTask (
304- "build" ,
305- "Concatenate source (include/exclude modules with +/- flags), embed date/version" ,
306- function ( ) {
307-
308- // Concat specified files.
309- var compiled = "" ,
310- modules = this . flags ,
311- optIn = ! modules [ "*" ] ,
312- explicit = optIn || Object . keys ( modules ) . length > 1 ,
313- name = this . data . dest ,
314- src = this . data . src ,
315- deps = { } ,
316- excluded = { } ,
317- version = grunt . config ( "pkg.version" ) ,
318- excluder = function ( flag , needsFlag ) {
319- // optIn defaults implicit behavior to weak exclusion
320- if ( optIn && ! modules [ flag ] && ! modules [ "+" + flag ] ) {
321- excluded [ flag ] = false ;
322- }
323-
324- // explicit or inherited strong exclusion
325- if ( excluded [ needsFlag ] || modules [ "-" + flag ] ) {
326- excluded [ flag ] = true ;
327-
328- // explicit inclusion overrides weak exclusion
329- } else if ( excluded [ needsFlag ] === false &&
330- ( modules [ flag ] || modules [ "+" + flag ] ) ) {
331-
332- delete excluded [ needsFlag ] ;
333-
334- // ...all the way down
335- if ( deps [ needsFlag ] ) {
336- deps [ needsFlag ] . forEach ( function ( subDep ) {
337- modules [ needsFlag ] = true ;
338- excluder ( needsFlag , subDep ) ;
339- } ) ;
340- }
341- }
342- } ;
343-
344- // append commit id to version
345- if ( process . env . COMMIT ) {
346- version += " " + process . env . COMMIT ;
347- }
348-
349- // figure out which files to exclude based on these rules in this order:
350- // dependency explicit exclude
351- // > explicit exclude
352- // > explicit include
353- // > dependency implicit exclude
354- // > implicit exclude
355- // examples:
356- // * none (implicit exclude)
357- // *:* all (implicit include)
358- // *:*:-css all except css and dependents (explicit > implicit)
359- // *:*:-css:+effects same (excludes effects because explicit include is trumped by explicit exclude of dependency)
360- // *:+effects none except effects and its dependencies (explicit include trumps implicit exclude of dependency)
361- src . forEach ( function ( filepath ) {
362- var flag = filepath . flag ;
363-
364- if ( flag ) {
365-
366- excluder ( flag ) ;
367-
368- // check for dependencies
369- if ( filepath . needs ) {
370- deps [ flag ] = filepath . needs ;
371- filepath . needs . forEach ( function ( needsFlag ) {
372- excluder ( flag , needsFlag ) ;
373- } ) ;
374- }
375- }
376- } ) ;
377-
378- // append excluded modules to version
379- if ( Object . keys ( excluded ) . length ) {
380- version += " -" + Object . keys ( excluded ) . join ( ",-" ) ;
381- // set pkg.version to version with excludes, so minified file picks it up
382- grunt . config . set ( "pkg.version" , version ) ;
383- }
384-
385-
386- // conditionally concatenate source
387- src . forEach ( function ( filepath ) {
388- var flag = filepath . flag ,
389- specified = false ,
390- omit = false ,
391- messages = [ ] ;
392-
393- if ( flag ) {
394- if ( excluded [ flag ] !== undefined ) {
395- messages . push ( [
396- ( "Excluding " + flag ) . red ,
397- ( "(" + filepath . src + ")" ) . grey
398- ] ) ;
399- specified = true ;
400- omit = ! filepath . alt ;
401- if ( ! omit ) {
402- flag += " alternate" ;
403- filepath . src = filepath . alt ;
404- }
405- }
406- if ( excluded [ flag ] === undefined ) {
407- messages . push ( [
408- ( "Including " + flag ) . green ,
409- ( "(" + filepath . src + ")" ) . grey
410- ] ) ;
411-
412- // If this module was actually specified by the
413- // builder, then set the flag to include it in the
414- // output list
415- if ( modules [ "+" + flag ] ) {
416- specified = true ;
417- }
418- }
419-
420- filepath = filepath . src ;
421-
422- // Only display the inclusion/exclusion list when handling
423- // an explicit list.
424- //
425- // Additionally, only display modules that have been specified
426- // by the user
427- if ( explicit && specified ) {
428- messages . forEach ( function ( message ) {
429- grunt . log . writetableln ( [ 27 , 30 ] , message ) ;
430- } ) ;
431- }
432- }
433-
434- if ( ! omit ) {
435- compiled += grunt . file . read ( filepath ) ;
436- }
437- } ) ;
438-
439- // Embed Version
440- // Embed Date
441- compiled = compiled . replace ( / @ V E R S I O N / g, version )
442- // yyyy-mm-ddThh:mmZ
443- . replace ( / @ D A T E / g, ( new Date ( ) ) . toISOString ( ) . replace ( / : \d + \. \d + Z $ / , "Z" ) ) ;
444-
445- // Write concatenated source to file
446- grunt . file . write ( name , compiled ) ;
447-
448- // Fail task if errors were logged.
449- if ( this . errorCount ) {
450- return false ;
451- }
452-
453- // Otherwise, print a success message.
454- grunt . log . writeln ( "File '" + name + "' created." ) ;
455- } ) ;
456-
457188 // Process files for distribution
458189 grunt . registerTask ( "dist" , function ( ) {
459190 var stored , flags , paths , nonascii ;
@@ -545,7 +276,7 @@ module.exports = function( grunt ) {
545276 // Strip banners
546277 return contents
547278 // Remove the main jQuery banner, it'll be replaced by the new banner anyway.
548- . replace ( / ^ \/ \* ! (?: . | \n ) * ?\* \/ \n ? / g, "" )
279+ . replace ( / ^ \/ \* ! [ \W \w ] * ?\* \/ \n ? / g, "" )
549280 // Strip other banners preserving line count.
550281 . replace ( / ^ \/ \* ! (?: .| \n ) * ?\* \/ \n ? / gm, function ( match ) {
551282 return match . replace ( / [ ^ \n ] / gm, "" ) ;
@@ -590,7 +321,7 @@ module.exports = function( grunt ) {
590321 grunt . loadNpmTasks ( "grunt-jsonlint" ) ;
591322
592323 // Short list as a high frequency watch task
593- grunt . registerTask ( "dev" , [ "selector" , " build:*:*", "jshint" ] ) ;
324+ grunt . registerTask ( "dev" , [ "build:*:*" , "jshint" ] ) ;
594325
595326 // Default grunt
596327 grunt . registerTask ( "default" , [ "jsonlint" , "dev" , "pre-uglify" , "uglify" , "post-uglify" , "dist:*" , "compare_size" ] ) ;
0 commit comments