2013-08-15 18:15:49 +00:00
|
|
|
/**
|
2019-11-18 20:15:03 +00:00
|
|
|
* Special build task to handle various jQuery build requirements.
|
|
|
|
* Compiles JS modules into one bundle, sets the custom AMD name,
|
2014-07-17 17:25:59 +00:00
|
|
|
* and includes/excludes specified modules
|
2013-08-15 18:15:49 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-08 22:17:55 +00:00
|
|
|
"use strict";
|
2013-08-16 13:48:00 +00:00
|
|
|
|
2019-10-08 22:17:55 +00:00
|
|
|
module.exports = function( grunt ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
const fs = require( "fs" );
|
|
|
|
const path = require( "path" );
|
|
|
|
const rollup = require( "rollup" );
|
2022-06-28 10:39:01 +00:00
|
|
|
const slimBuildFlags = require( "./lib/slim-build-flags" );
|
2019-12-02 18:55:19 +00:00
|
|
|
const rollupFileOverrides = require( "./lib/rollup-plugin-file-overrides" );
|
2019-11-18 20:15:03 +00:00
|
|
|
const srcFolder = path.resolve( `${ __dirname }/../../src` );
|
|
|
|
const read = function( fileName ) {
|
|
|
|
return grunt.file.read( `${ srcFolder }/${ fileName }` );
|
|
|
|
};
|
|
|
|
|
|
|
|
// Catch `// @CODE` and subsequent comment lines event if they don't start
|
|
|
|
// in the first column.
|
|
|
|
const wrapper = read( "wrapper.js" )
|
|
|
|
.split( /[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/ );
|
|
|
|
|
|
|
|
const inputFileName = "jquery.js";
|
|
|
|
const inputRollupOptions = {
|
|
|
|
input: `${ srcFolder }/${ inputFileName }`
|
|
|
|
};
|
|
|
|
const outputRollupOptions = {
|
|
|
|
|
|
|
|
// The ESM format is not actually used as we strip it during
|
|
|
|
// the build; it's just that it doesn't generate any extra
|
|
|
|
// wrappers so there's nothing for us to remove.
|
|
|
|
format: "esm",
|
|
|
|
|
|
|
|
intro: wrapper[ 0 ]
|
|
|
|
.replace( /\n*$/, "" ),
|
|
|
|
outro: wrapper[ 1 ]
|
|
|
|
.replace( /^\n*/, "" )
|
|
|
|
};
|
2019-12-02 18:55:19 +00:00
|
|
|
const fileOverrides = new Map();
|
|
|
|
|
|
|
|
function getOverride( filePath ) {
|
|
|
|
return fileOverrides.get( path.resolve( filePath ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
function setOverride( filePath, source ) {
|
|
|
|
|
|
|
|
// We want normalized paths in overrides as they will be matched
|
|
|
|
// against normalized paths in the file overrides Rollup plugin.
|
|
|
|
fileOverrides.set( path.resolve( filePath ), source );
|
|
|
|
}
|
2013-08-15 18:15:49 +00:00
|
|
|
|
|
|
|
grunt.registerMultiTask(
|
|
|
|
"build",
|
2020-05-05 12:30:14 +00:00
|
|
|
"Build jQuery ECMAScript modules, " +
|
2014-07-17 17:25:59 +00:00
|
|
|
"(include/exclude modules with +/- flags), embed date/version",
|
2019-11-18 20:15:03 +00:00
|
|
|
async function() {
|
|
|
|
const done = this.async();
|
|
|
|
|
|
|
|
try {
|
|
|
|
const flags = this.flags;
|
|
|
|
const optIn = flags[ "*" ];
|
|
|
|
let name = grunt.option( "filename" );
|
|
|
|
const minimum = this.data.minimum;
|
|
|
|
const removeWith = this.data.removeWith;
|
|
|
|
const excluded = [];
|
|
|
|
const included = [];
|
|
|
|
let version = grunt.config( "pkg.version" );
|
2016-05-10 09:12:28 +00:00
|
|
|
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
// We'll skip printing the whole big exclusions for a bare `build:*:*:slim` which
|
|
|
|
// usually comes from `custom:slim`.
|
|
|
|
const isPureSlim = !!( flags.slim && flags[ "*" ] &&
|
|
|
|
Object.keys( flags ).length === 2 );
|
|
|
|
|
|
|
|
delete flags[ "*" ];
|
|
|
|
|
|
|
|
if ( flags.slim ) {
|
|
|
|
delete flags.slim;
|
2022-06-28 10:39:01 +00:00
|
|
|
for ( const flag of slimBuildFlags ) {
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
flags[ flag ] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
/**
|
|
|
|
* Recursively calls the excluder to remove on all modules in the list
|
|
|
|
* @param {Array} list
|
2014-07-17 17:25:59 +00:00
|
|
|
* @param {String} [prepend] Prepend this to the module name.
|
|
|
|
* Indicates we're walking a directory
|
2013-08-15 18:15:49 +00:00
|
|
|
*/
|
2019-11-18 20:15:03 +00:00
|
|
|
const excludeList = ( list, prepend ) => {
|
2013-08-15 18:15:49 +00:00
|
|
|
if ( list ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
prepend = prepend ? `${ prepend }/` : "";
|
2015-08-16 06:59:58 +00:00
|
|
|
list.forEach( function( module ) {
|
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Exclude var modules as well
|
|
|
|
if ( module === "var" ) {
|
2014-07-17 17:25:59 +00:00
|
|
|
excludeList(
|
2019-11-18 20:15:03 +00:00
|
|
|
fs.readdirSync( `${ srcFolder }/${ prepend }${ module }` ),
|
|
|
|
prepend + module
|
2014-07-17 17:25:59 +00:00
|
|
|
);
|
2013-08-15 18:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( prepend ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Skip if this is not a js file and we're walking files in a dir
|
2015-08-16 06:59:58 +00:00
|
|
|
if ( !( module = /([\w-\/]+)\.js$/.exec( module ) ) ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Prepend folder name if passed
|
|
|
|
// Remove .js extension
|
2015-08-16 06:59:58 +00:00
|
|
|
module = prepend + module[ 1 ];
|
2013-08-15 18:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid infinite recursion
|
|
|
|
if ( excluded.indexOf( module ) === -1 ) {
|
|
|
|
excluder( "-" + module );
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-08-15 18:15:49 +00:00
|
|
|
}
|
2019-11-18 20:15:03 +00:00
|
|
|
};
|
2016-05-10 09:12:28 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
/**
|
|
|
|
* Adds the specified module to the excluded or included list, depending on the flag
|
2014-07-17 17:25:59 +00:00
|
|
|
* @param {String} flag A module path relative to
|
|
|
|
* the src directory starting with + or - to indicate
|
2022-11-21 22:23:39 +00:00
|
|
|
* whether it should be included or excluded
|
2013-08-15 18:15:49 +00:00
|
|
|
*/
|
2019-11-18 20:15:03 +00:00
|
|
|
const excluder = flag => {
|
|
|
|
let additional;
|
2022-11-21 22:23:39 +00:00
|
|
|
const m = /^(\+|-|)([\w\/-]+)$/.exec( flag );
|
2019-11-18 20:15:03 +00:00
|
|
|
const exclude = m[ 1 ] === "-";
|
|
|
|
const module = m[ 2 ];
|
2013-08-15 18:15:49 +00:00
|
|
|
|
|
|
|
if ( exclude ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Can't exclude certain modules
|
|
|
|
if ( minimum.indexOf( module ) === -1 ) {
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Add to excluded
|
|
|
|
if ( excluded.indexOf( module ) === -1 ) {
|
|
|
|
grunt.log.writeln( flag );
|
|
|
|
excluded.push( module );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Exclude all files in the folder of the same name
|
|
|
|
// These are the removable dependencies
|
|
|
|
// It's fine if the directory is not there
|
|
|
|
try {
|
2022-11-21 22:23:39 +00:00
|
|
|
|
|
|
|
// `selector` is a special case as we don't just remove
|
|
|
|
// the module, but we replace it with `selector-native`
|
|
|
|
// which re-uses parts of the `src/selector` folder.
|
|
|
|
if ( module !== "selector" ) {
|
|
|
|
excludeList(
|
|
|
|
fs.readdirSync( `${ srcFolder }/${ module }` ),
|
|
|
|
module
|
|
|
|
);
|
|
|
|
}
|
2014-07-17 17:25:59 +00:00
|
|
|
} catch ( e ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
grunt.verbose.writeln( e );
|
|
|
|
}
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2016-01-19 19:47:52 +00:00
|
|
|
additional = removeWith[ module ];
|
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Check removeWith list
|
2016-01-19 19:47:52 +00:00
|
|
|
if ( additional ) {
|
|
|
|
excludeList( additional.remove || additional );
|
|
|
|
if ( additional.include ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
included.push( ...additional.include );
|
2016-01-19 19:47:52 +00:00
|
|
|
grunt.log.writeln( "+" + additional.include );
|
|
|
|
}
|
|
|
|
}
|
2013-08-15 18:15:49 +00:00
|
|
|
} else {
|
2015-08-16 06:59:58 +00:00
|
|
|
grunt.log.error( "Module \"" + module + "\" is a minimum requirement." );
|
2013-08-15 18:15:49 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
grunt.log.writeln( flag );
|
|
|
|
included.push( module );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// Filename can be passed to the command line using
|
|
|
|
// command line options
|
|
|
|
// e.g. grunt build --filename=jquery-custom.js
|
|
|
|
name = name ? `dist/${ name }` : this.data.dest;
|
2015-11-12 18:18:59 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// append commit id to version
|
|
|
|
if ( process.env.COMMIT ) {
|
|
|
|
version += " " + process.env.COMMIT;
|
|
|
|
}
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// figure out which files to exclude based on these rules in this order:
|
|
|
|
// dependency explicit exclude
|
|
|
|
// > explicit exclude
|
|
|
|
// > explicit include
|
|
|
|
// > dependency implicit exclude
|
|
|
|
// > implicit exclude
|
|
|
|
// examples:
|
|
|
|
// * none (implicit exclude)
|
|
|
|
// *:* all (implicit include)
|
|
|
|
// *:*:-css all except css and dependents (explicit > implicit)
|
|
|
|
// *:*:-css:+effects same (excludes effects because explicit include is
|
|
|
|
// trumped by explicit exclude of dependency)
|
|
|
|
// *:+effects none except effects and its dependencies
|
|
|
|
// (explicit include trumps implicit exclude of dependency)
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
for ( const flag in flags ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
excluder( flag );
|
|
|
|
}
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// Remove the jQuery export from the entry file, we'll use our own
|
|
|
|
// custom wrapper.
|
2019-12-02 18:55:19 +00:00
|
|
|
setOverride( inputRollupOptions.input,
|
|
|
|
read( inputFileName ).replace( /\n*export default jQuery;\n*/, "\n" ) );
|
2019-11-18 20:15:03 +00:00
|
|
|
|
|
|
|
// Replace exports/global with a noop noConflict
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
if ( excluded.includes( "exports/global" ) ) {
|
|
|
|
const index = excluded.indexOf( "exports/global" );
|
2019-12-02 18:55:19 +00:00
|
|
|
setOverride( `${ srcFolder }/exports/global.js`,
|
2019-11-18 20:15:03 +00:00
|
|
|
"import jQuery from \"../core.js\";\n\n" +
|
2019-12-02 18:55:19 +00:00
|
|
|
"jQuery.noConflict = function() {};" );
|
2019-11-18 20:15:03 +00:00
|
|
|
excluded.splice( index, 1 );
|
|
|
|
}
|
2013-12-19 20:00:06 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// Set a desired AMD name.
|
|
|
|
let amdName = grunt.option( "amd" );
|
|
|
|
if ( amdName != null ) {
|
|
|
|
if ( amdName ) {
|
|
|
|
grunt.log.writeln( "Naming jQuery with AMD name: " + amdName );
|
|
|
|
} else {
|
|
|
|
grunt.log.writeln( "AMD name now anonymous" );
|
|
|
|
}
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// Remove the comma for anonymous defines
|
2019-12-02 18:55:19 +00:00
|
|
|
setOverride( `${ srcFolder }/exports/amd.js`,
|
2019-11-18 20:15:03 +00:00
|
|
|
read( "exports/amd.js" )
|
2022-11-21 22:23:39 +00:00
|
|
|
.replace( /(\s*)"jquery"(,\s*)/,
|
2019-12-02 18:55:19 +00:00
|
|
|
amdName ? "$1\"" + amdName + "\"$2" : "" ) );
|
2019-11-18 20:15:03 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
grunt.verbose.writeflags( excluded, "Excluded" );
|
|
|
|
grunt.verbose.writeflags( included, "Included" );
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2022-11-21 22:23:39 +00:00
|
|
|
// Indicate a Slim build without listing all the exclusions
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
// to save space.
|
|
|
|
if ( isPureSlim ) {
|
|
|
|
version += " slim";
|
|
|
|
|
|
|
|
// Append excluded modules to version.
|
|
|
|
} else if ( excluded.length ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
version += " -" + excluded.join( ",-" );
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( excluded.length ) {
|
2019-11-18 20:15:03 +00:00
|
|
|
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
// Set pkg.version to version with excludes or with the "slim" marker,
|
|
|
|
// so minified file picks it up but skip the commit hash the same way
|
|
|
|
// it's done for the full build.
|
|
|
|
const commitlessVersion = version.replace( " " + process.env.COMMIT, "" );
|
|
|
|
grunt.config.set( "pkg.version", commitlessVersion );
|
|
|
|
grunt.verbose.writeln( "Version changed to " + commitlessVersion );
|
2019-11-18 20:15:03 +00:00
|
|
|
|
|
|
|
// Replace excluded modules with empty sources.
|
|
|
|
for ( const module of excluded ) {
|
2022-11-21 22:23:39 +00:00
|
|
|
setOverride(
|
|
|
|
`${ srcFolder }/${ module }.js`,
|
|
|
|
|
|
|
|
// The `selector` module is not removed, but replaced
|
|
|
|
// with `selector-native`.
|
|
|
|
module === "selector" ? read( "selector-native.js" ) : ""
|
|
|
|
);
|
2019-11-18 20:15:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn off opt-in if necessary
|
|
|
|
if ( !optIn ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
// Remove the default inclusions, they will be overwritten with the explicitly
|
|
|
|
// included ones.
|
2019-12-02 18:55:19 +00:00
|
|
|
setOverride( inputRollupOptions.input, "" );
|
2019-11-18 20:15:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Import the explicitly included modules.
|
|
|
|
if ( included.length ) {
|
2019-12-02 18:55:19 +00:00
|
|
|
setOverride( inputRollupOptions.input,
|
|
|
|
getOverride( inputRollupOptions.input ) + included
|
|
|
|
.map( module => `import "./${module}.js";` )
|
|
|
|
.join( "\n" ) );
|
2019-11-18 20:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const bundle = await rollup.rollup( {
|
|
|
|
...inputRollupOptions,
|
2019-12-02 18:55:19 +00:00
|
|
|
plugins: [ rollupFileOverrides( fileOverrides ) ]
|
2019-11-18 20:15:03 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
const { output: [ { code } ] } = await bundle.generate( outputRollupOptions );
|
|
|
|
|
|
|
|
const compiledContents = code
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Embed Version
|
|
|
|
.replace( /@VERSION/g, version )
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Embed Date
|
|
|
|
// yyyy-mm-ddThh:mmZ
|
2019-11-18 20:15:03 +00:00
|
|
|
.replace(
|
|
|
|
/@DATE/g,
|
|
|
|
( new Date() ).toISOString()
|
|
|
|
.replace( /:\d+\.\d+Z$/, "Z" )
|
|
|
|
);
|
2013-09-09 02:26:05 +00:00
|
|
|
|
2019-11-18 20:15:03 +00:00
|
|
|
grunt.file.write( name, compiledContents );
|
2020-05-05 12:30:14 +00:00
|
|
|
grunt.log.ok( `File '${ name }' created.` );
|
2013-08-15 18:15:49 +00:00
|
|
|
done();
|
2019-11-18 20:15:03 +00:00
|
|
|
} catch ( err ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
done( err );
|
2019-11-18 20:15:03 +00:00
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-08-15 18:15:49 +00:00
|
|
|
|
|
|
|
// Special "alias" task to make custom build creation less grawlix-y
|
|
|
|
// Translation example
|
|
|
|
//
|
|
|
|
// grunt custom:+ajax,-dimensions,-effects,-offset
|
|
|
|
//
|
|
|
|
// Becomes:
|
|
|
|
//
|
|
|
|
// grunt build:*:*:+ajax:-dimensions:-effects:-offset
|
2020-01-07 15:42:49 +00:00
|
|
|
//
|
|
|
|
// There's also a special "slim" alias that resolves to the jQuery Slim build
|
|
|
|
// configuration:
|
|
|
|
//
|
|
|
|
// grunt custom:slim
|
2013-08-15 18:15:49 +00:00
|
|
|
grunt.registerTask( "custom", function() {
|
2019-11-18 20:15:03 +00:00
|
|
|
const args = this.args;
|
2020-01-07 15:42:49 +00:00
|
|
|
const modules = args.length ?
|
Build: Reduce the slim build header comment & jQuery.fn.jquery
So far, the slim build was expanded to its full exclusion list, generating the
following `jQuery.fn.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
```
This commit changes it to just `v4.0.0-pre slim`. 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 `jQuery.fn.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
```
Since the version string is also put in the jQuery header comment, it also got
smaller.
Also, the logic to skip including the commit hash in the header comment - 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.
Closes gh-4649
2020-04-27 20:23:59 +00:00
|
|
|
args[ 0 ].split( "," ).join( ":" ) :
|
2020-01-07 15:42:49 +00:00
|
|
|
"";
|
2013-08-15 18:15:49 +00:00
|
|
|
|
|
|
|
grunt.log.writeln( "Creating custom build...\n" );
|
2022-12-20 20:57:49 +00:00
|
|
|
grunt.task.run( [ "build:*:*" + ( modules ? ":" + modules : "" ), "uglify", "dist" ] );
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2013-08-15 18:15:49 +00:00
|
|
|
};
|