@@ -16,12 +16,16 @@ module.exports = function( grunt ) {
1616 baseUrl : "src" ,
1717 name : "jquery" ,
1818 out : "dist/jquery.js" ,
19+
1920 // We have multiple minify steps
2021 optimize : "none" ,
22+
2123 // Include dependencies loaded with require
2224 findNestedDependencies : true ,
25+
2326 // Avoid inserting define() placeholder
2427 skipModuleInsertion : true ,
28+
2529 // Avoid breaking semicolons inserted by r.js
2630 skipSemiColonInsertion : true ,
2731 wrap : {
@@ -47,22 +51,25 @@ module.exports = function( grunt ) {
4751 */
4852 function convert ( name , path , contents ) {
4953 var amdName ;
54+
5055 // Convert var modules
5156 if ( / .\/ v a r \/ / . test ( path ) ) {
5257 contents = contents
53- . replace ( / d e f i n e \( [ \w \W ] * ?r e t u r n / , "var " + ( / v a r \/ ( [ \w - ] + ) / . exec ( name ) [ 1 ] ) + " =" )
58+ . replace ( / d e f i n e \( [ \w \W ] * ?r e t u r n / , "var " + ( / v a r \/ ( [ \w - ] + ) / . exec ( name ) [ 1 ] ) + " =" )
5459 . replace ( rdefineEnd , "" ) ;
5560
5661 // Sizzle treatment
5762 } else if ( / ^ s i z z l e $ / . test ( name ) ) {
5863 contents = "var Sizzle =\n" + contents
64+
5965 // Remove EXPOSE lines from Sizzle
6066 . replace ( / \/ \/ \s * E X P O S E [ \w \W ] * \/ \/ \s * E X P O S E / , "return Sizzle;" ) ;
6167
6268 } else {
6369
6470 contents = contents
6571 . replace ( / \s * r e t u r n \s + [ ^ \} ] + ( \} \s * ?\) ; [ ^ \w \} ] * ) $ / , "$1" )
72+
6673 // Multiple exports
6774 . replace ( / \s * e x p o r t s \. \w + \s * = \s * \w + ; / g, "" ) ;
6875
@@ -82,13 +89,15 @@ module.exports = function( grunt ) {
8289 contents = contents
8390 . replace ( / d e f i n e \( \[ [ ^ \] ] * \] \) [ \W \n ] + $ / , "" ) ;
8491 }
92+
8593 // AMD Name
86- if ( ( amdName = grunt . option ( "amd" ) ) != null && / ^ e x p o r t s \/ a m d $ / . test ( name ) ) {
87- if ( amdName ) {
94+ if ( ( amdName = grunt . option ( "amd" ) ) != null && / ^ e x p o r t s \/ a m d $ / . test ( name ) ) {
95+ if ( amdName ) {
8896 grunt . log . writeln ( "Naming jQuery with AMD name: " + amdName ) ;
8997 } else {
9098 grunt . log . writeln ( "AMD name now anonymous" ) ;
9199 }
100+
92101 // Remove the comma for anonymous defines
93102 contents = contents
94103 . replace ( / ( \s * ) " j q u e r y " ( \, \s * ) / , amdName ? "$1\"" + amdName + "\"$2" : "" ) ;
@@ -121,7 +130,8 @@ module.exports = function( grunt ) {
121130 excludeList = function ( list , prepend ) {
122131 if ( list ) {
123132 prepend = prepend ? prepend + "/" : "" ;
124- list . forEach ( function ( module ) {
133+ list . forEach ( function ( module ) {
134+
125135 // Exclude var modules as well
126136 if ( module === "var" ) {
127137 excludeList (
@@ -130,20 +140,22 @@ module.exports = function( grunt ) {
130140 return ;
131141 }
132142 if ( prepend ) {
143+
133144 // Skip if this is not a js file and we're walking files in a dir
134- if ( ! ( module = / ( [ \w -\/ ] + ) \. j s $ / . exec ( module ) ) ) {
145+ if ( ! ( module = / ( [ \w -\/ ] + ) \. j s $ / . exec ( module ) ) ) {
135146 return ;
136147 }
148+
137149 // Prepend folder name if passed
138150 // Remove .js extension
139- module = prepend + module [ 1 ] ;
151+ module = prepend + module [ 1 ] ;
140152 }
141153
142154 // Avoid infinite recursion
143155 if ( excluded . indexOf ( module ) === - 1 ) {
144156 excluder ( "-" + module ) ;
145157 }
146- } ) ;
158+ } ) ;
147159 }
148160 } ,
149161 /**
@@ -158,12 +170,15 @@ module.exports = function( grunt ) {
158170 module = m [ 2 ] ;
159171
160172 if ( exclude ) {
173+
161174 // Can't exclude certain modules
162175 if ( minimum . indexOf ( module ) === - 1 ) {
176+
163177 // Add to excluded
164178 if ( excluded . indexOf ( module ) === - 1 ) {
165179 grunt . log . writeln ( flag ) ;
166180 excluded . push ( module ) ;
181+
167182 // Exclude all files in the folder of the same name
168183 // These are the removable dependencies
169184 // It's fine if the directory is not there
@@ -173,10 +188,11 @@ module.exports = function( grunt ) {
173188 grunt . verbose . writeln ( e ) ;
174189 }
175190 }
191+
176192 // Check removeWith list
177193 excludeList ( removeWith [ module ] ) ;
178194 } else {
179- grunt . log . error ( "Module \"" + module + "\" is a minimum requirement." ) ;
195+ grunt . log . error ( "Module \"" + module + "\" is a minimum requirement." ) ;
180196 if ( module === "selector" ) {
181197 grunt . log . error (
182198 "If you meant to replace Sizzle, use -sizzle instead."
@@ -215,13 +231,13 @@ module.exports = function( grunt ) {
215231
216232 // Handle Sizzle exclusion
217233 // Replace with selector-native
218- if ( ( index = excluded . indexOf ( "sizzle" ) ) > - 1 ) {
234+ if ( ( index = excluded . indexOf ( "sizzle" ) ) > - 1 ) {
219235 config . rawText . selector = "define(['./selector-native']);" ;
220236 excluded . splice ( index , 1 ) ;
221237 }
222238
223239 // Replace exports/global with a noop noConflict
224- if ( ( index = excluded . indexOf ( "exports/global" ) ) > - 1 ) {
240+ if ( ( index = excluded . indexOf ( "exports/global" ) ) > - 1 ) {
225241 config . rawText [ "exports/global" ] = "define(['../core']," +
226242 "function( jQuery ) {\njQuery.noConflict = function() {};\n});" ;
227243 excluded . splice ( index , 1 ) ;
@@ -233,9 +249,11 @@ module.exports = function( grunt ) {
233249 // append excluded modules to version
234250 if ( excluded . length ) {
235251 version += " -" + excluded . join ( ",-" ) ;
252+
236253 // set pkg.version to version with excludes, so minified file picks it up
237254 grunt . config . set ( "pkg.version" , version ) ;
238255 grunt . verbose . writeln ( "Version changed to " + version ) ;
256+
239257 // Have to use shallow or core will get excluded since it is a dependency
240258 config . excludeShallow = excluded ;
241259 }
@@ -247,8 +265,10 @@ module.exports = function( grunt ) {
247265 */
248266 config . out = function ( compiled ) {
249267 compiled = compiled
268+
250269 // Embed Version
251270 . replace ( / @ V E R S I O N / g, version )
271+
252272 // Embed Date
253273 // yyyy-mm-ddThh:mmZ
254274 . replace ( / @ D A T E / g, ( new Date ( ) ) . toISOString ( ) . replace ( / : \d + \. \d + Z $ / , "Z" ) ) ;
@@ -259,9 +279,10 @@ module.exports = function( grunt ) {
259279
260280 // Turn off opt-in if necessary
261281 if ( ! optIn ) {
282+
262283 // Overwrite the default inclusions with the explicit ones provided
263284 config . rawText . jquery = "define([" +
264- ( included . length ? included . join ( "," ) : "" ) +
285+ ( included . length ? included . join ( "," ) : "" ) +
265286 "]);" ;
266287 }
267288
@@ -272,8 +293,8 @@ module.exports = function( grunt ) {
272293 done ( ) ;
273294 } , function ( err ) {
274295 done ( err ) ;
275- } ) ;
276- } ) ;
296+ } ) ;
297+ } ) ;
277298
278299 // Special "alias" task to make custom build creation less grawlix-y
279300 // Translation example
@@ -289,6 +310,6 @@ module.exports = function( grunt ) {
289310
290311 grunt . log . writeln ( "Creating custom build...\n" ) ;
291312
292- grunt . task . run ( [ "build:*:*" + ( modules ? ":" + modules : "" ) , "uglify" , "dist" ] ) ;
293- } ) ;
313+ grunt . task . run ( [ "build:*:*" + ( modules ? ":" + modules : "" ) , "uglify" , "dist" ] ) ;
314+ } ) ;
294315} ;
0 commit comments