Skip to content

Commit ee3e80b

Browse files
committed
Build: Reduce the slim build comment header
So far, the slim build was expanded to its full exclusion list, generating the following in the comment header on `master`, for the unminified build: ``` * jQuery JavaScript Library v4.0.0-pre -ajax,-ajax/jsonp,-ajax/load,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-deprecated/ajax-event-alias,-callbacks,-deferred,-deferred/exceptionHook,-effects,-effects/Tween,-effects/animatedSelector,-queue,-queue/delay,-core/ready ``` and for the minified one: ``` /*! jQuery v4.0.0-pre -ajax,-ajax/jsonp,-ajax/load,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-deprecated/ajax-event-alias,-callbacks,-deferred,-deferred/exceptionHook,-effects,-effects/Tween,-effects/animatedSelector,-queue,-queue/delay,-core/ready | (c) JS Foundation and other contributors | jquery.org/license */ ``` This commit changes them to, respectively, for the unminified build: ``` * jQuery JavaScript Library v4.0.0-pre slim ``` and for the minified one: ``` /*! jQuery v4.0.0-pre slim | (c) JS Foundation and other contributors | jquery.org/license */ ``` Only the pure slim build is treated this way, any modification to it goes through the old expansion; e.g. for `custom:slim,-deprecated` we get the following for the unminified build: ``` * jQuery JavaScript Library v4.0.0-pre -deprecated,-deprecated/ajax-event-alias,-deprecated/event,-ajax,-ajax/jsonp,-ajax/load,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-callbacks,-deferred,-deferred/exceptionHook,-effects,-effects/Tween,-effects/animatedSelector,-queue,-queue/delay,-core/ready ``` and for the minified one: ``` /*! jQuery v4.0.0-pre -deprecated,-deprecated/ajax-event-alias,-deprecated/event,-ajax,-ajax/jsonp,-ajax/load,-ajax/script,-ajax/var/location,-ajax/var/nonce,-ajax/var/rquery,-ajax/xhr,-manipulation/_evalUrl,-callbacks,-deferred,-deferred/exceptionHook,-effects,-effects/Tween,-effects/animatedSelector,-queue,-queue/delay,-core/ready | (c) JS Foundation and other contributors | jquery.org/license */ ``` Also, the logic to skip including the commit hash - when provided through the COMMIT environment variable which we do in Jenkins - in minified builds headers has been applied to builds with exclusions as well.
1 parent 90fed4b commit ee3e80b

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

build/tasks/build.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports = function( grunt ) {
6060
const done = this.async();
6161

6262
try {
63-
let flag, index;
63+
const slimFlags = [ "-ajax", "-callbacks", "-deferred", "-effects" ];
6464
const flags = this.flags;
6565
const optIn = flags[ "*" ];
6666
let name = grunt.option( "filename" );
@@ -70,6 +70,21 @@ module.exports = function( grunt ) {
7070
const included = [];
7171
let version = grunt.config( "pkg.version" );
7272

73+
// We'll skip printing the whole big exclusions for a bare `build:*:*:slim` which
74+
// usually comes from `custom:slim`.
75+
const isPureSlim = !!( flags.slim && flags[ "*" ] &&
76+
Object.keys( flags ).length === 2 );
77+
78+
delete flags[ "*" ];
79+
80+
if ( flags.slim ) {
81+
delete flags.slim;
82+
for ( const flag of slimFlags ) {
83+
flags[ flag ] = true;
84+
}
85+
}
86+
87+
7388
/**
7489
* Recursively calls the excluder to remove on all modules in the list
7590
* @param {Array} list
@@ -187,8 +202,7 @@ module.exports = function( grunt ) {
187202
// trumped by explicit exclude of dependency)
188203
// *:+effects none except effects and its dependencies
189204
// (explicit include trumps implicit exclude of dependency)
190-
delete flags[ "*" ];
191-
for ( flag in flags ) {
205+
for ( const flag in flags ) {
192206
excluder( flag );
193207
}
194208

@@ -198,7 +212,8 @@ module.exports = function( grunt ) {
198212
read( inputFileName ).replace( /\n*export default jQuery;\n*/, "\n" ) );
199213

200214
// Replace exports/global with a noop noConflict
201-
if ( ( index = excluded.indexOf( "exports/global" ) ) > -1 ) {
215+
if ( excluded.includes( "exports/global" ) ) {
216+
const index = excluded.indexOf( "exports/global" );
202217
setOverride( `${ srcFolder }/exports/global.js`,
203218
"import jQuery from \"../core.js\";\n\n" +
204219
"jQuery.noConflict = function() {};" );
@@ -224,20 +239,32 @@ module.exports = function( grunt ) {
224239
grunt.verbose.writeflags( excluded, "Excluded" );
225240
grunt.verbose.writeflags( included, "Included" );
226241

227-
// append excluded modules to version
228-
if ( excluded.length ) {
229-
version += " -" + excluded.join( ",-" );
242+
// Indicate a Slim build without listing all of the exclusions
243+
// to save space.
244+
if ( isPureSlim ) {
245+
version += " slim";
246+
}
230247

231-
// set pkg.version to version with excludes, so minified file picks it up
232-
grunt.config.set( "pkg.version", version );
233-
grunt.verbose.writeln( "Version changed to " + version );
248+
// Append excluded modules to version.
249+
if ( !isPureSlim && excluded.length ) {
250+
version += " -" + excluded.join( ",-" );
234251

235252
// Replace excluded modules with empty sources.
236253
for ( const module of excluded ) {
237254
setOverride( `${ srcFolder }/${ module }.js`, "" );
238255
}
239256
}
240257

258+
if ( isPureSlim || excluded.length ) {
259+
260+
// Set pkg.version to version with excludes or with the "slim" marker,
261+
// so minified file picks it up but skip the commit hash the same way
262+
// it's done for the full build.
263+
const commitlessVersion = version.replace( " " + process.env.COMMIT, "" );
264+
grunt.config.set( "pkg.version", commitlessVersion );
265+
grunt.verbose.writeln( "Version changed to " + commitlessVersion );
266+
}
267+
241268
// Turn off opt-in if necessary
242269
if ( !optIn ) {
243270

@@ -299,18 +326,7 @@ module.exports = function( grunt ) {
299326
grunt.registerTask( "custom", function() {
300327
const args = this.args;
301328
const modules = args.length ?
302-
args[ 0 ]
303-
.split( "," )
304-
305-
// Replace "slim" with respective exclusions meant for
306-
// the official slim build
307-
.reduce( ( acc, elem ) => acc.concat(
308-
elem === "slim" ?
309-
[ "-ajax", "-callbacks", "-deferred", "-effects" ] :
310-
[ elem ]
311-
), [] )
312-
313-
.join( ":" ) :
329+
args[ 0 ].split( "," ).join( ":" ) :
314330
"";
315331
const done = this.async();
316332
const insight = new Insight( {

0 commit comments

Comments
 (0)