2019-10-08 22:17:55 +00:00
|
|
|
"use strict";
|
2012-10-16 14:10:17 +00:00
|
|
|
|
2019-10-08 22:17:55 +00:00
|
|
|
module.exports = function( grunt ) {
|
2013-09-12 20:51:59 +00:00
|
|
|
function readOptionalJSON( filepath ) {
|
2016-02-10 11:54:25 +00:00
|
|
|
var stripJSONComments = require( "strip-json-comments" ),
|
|
|
|
data = {};
|
2013-09-12 20:51:59 +00:00
|
|
|
try {
|
2015-08-01 23:48:54 +00:00
|
|
|
data = JSON.parse( stripJSONComments(
|
|
|
|
fs.readFileSync( filepath, { encoding: "utf8" } )
|
|
|
|
) );
|
2013-11-09 22:12:06 +00:00
|
|
|
} catch ( e ) {}
|
2013-09-12 20:51:59 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2015-08-01 23:48:54 +00:00
|
|
|
var fs = require( "fs" ),
|
2019-10-22 18:49:37 +00:00
|
|
|
gzip = require( "gzip-js" ),
|
2021-12-13 17:22:34 +00:00
|
|
|
isCi = process.env.GITHUB_ACTION,
|
2021-11-30 23:02:57 +00:00
|
|
|
ciBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
|
2013-04-09 16:48:34 +00:00
|
|
|
|
2015-11-12 18:18:59 +00:00
|
|
|
if ( !grunt.option( "filename" ) ) {
|
|
|
|
grunt.option( "filename", "jquery.js" );
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:59:58 +00:00
|
|
|
grunt.initConfig( {
|
2013-11-09 22:12:06 +00:00
|
|
|
pkg: grunt.file.readJSON( "package.json" ),
|
|
|
|
dst: readOptionalJSON( "dist/.destination.json" ),
|
2014-07-17 17:25:59 +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;
|
|
|
|
}
|
|
|
|
},
|
2013-10-15 20:14:10 +00:00
|
|
|
cache: "build/.sizecache.json"
|
2013-03-25 04:47:46 +00:00
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2015-06-01 21:25:38 +00:00
|
|
|
babel: {
|
|
|
|
options: {
|
|
|
|
sourceMap: "inline",
|
2017-09-25 17:02:19 +00:00
|
|
|
retainLines: true,
|
2018-11-11 04:52:13 +00:00
|
|
|
plugins: [ "@babel/transform-for-of" ]
|
2015-06-01 21:25:38 +00:00
|
|
|
},
|
2020-01-27 17:54:47 +00:00
|
|
|
tests: {
|
2015-06-01 21:25:38 +00:00
|
|
|
files: {
|
2019-03-04 17:30:51 +00:00
|
|
|
"test/data/core/jquery-iterability-transpiled.js":
|
|
|
|
"test/data/core/jquery-iterability-transpiled-es6.js"
|
2015-06-01 21:25:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
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"
|
|
|
|
],
|
2015-08-16 06:59:58 +00:00
|
|
|
|
2013-08-15 18:15:49 +00:00
|
|
|
// Exclude specified modules if the module matching the key is removed
|
|
|
|
removeWith: {
|
2020-01-21 13:12:35 +00:00
|
|
|
ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
|
2013-08-15 18:15:49 +00:00
|
|
|
callbacks: [ "deferred" ],
|
|
|
|
css: [ "effects", "dimensions", "offset" ],
|
2015-10-09 19:52:29 +00:00
|
|
|
"css/showHide": [ "effects" ],
|
2016-01-19 19:47:52 +00:00
|
|
|
deferred: {
|
|
|
|
remove: [ "ajax", "effects", "queue", "core/ready" ],
|
|
|
|
include: [ "core/ready-no-deferred" ]
|
|
|
|
},
|
2020-01-21 13:12:35 +00:00
|
|
|
event: [ "deprecated/ajax-event-alias", "deprecated/event" ],
|
2013-08-26 22:54:13 +00:00
|
|
|
sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
|
2013-08-15 18:15:49 +00:00
|
|
|
}
|
2013-01-26 18:38:04 +00:00
|
|
|
}
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2014-07-17 16:02:59 +00:00
|
|
|
npmcopy: {
|
2014-06-10 19:32:25 +00:00
|
|
|
all: {
|
2013-11-14 15:17:18 +00:00
|
|
|
options: {
|
2014-06-10 19:32:25 +00:00
|
|
|
destPrefix: "external"
|
2013-12-06 20:55:55 +00:00
|
|
|
},
|
|
|
|
files: {
|
2014-06-10 19:32:25 +00:00
|
|
|
"sizzle/dist": "sizzle/dist",
|
2014-07-01 20:50:27 +00:00
|
|
|
"sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
|
2014-06-10 19:32:25 +00:00
|
|
|
|
2021-04-13 20:10:09 +00:00
|
|
|
"core-js/core-js.js": "core-js/client/core.min.js",
|
|
|
|
"core-js/LICENSE.txt": "core-js/LICENSE",
|
|
|
|
|
2019-08-12 16:06:52 +00:00
|
|
|
"npo/npo.js": "native-promise-only/lib/npo.src.js",
|
2014-12-29 19:14:13 +00:00
|
|
|
|
2019-03-04 19:10:21 +00:00
|
|
|
"qunit/qunit.js": "qunit/qunit/qunit.js",
|
|
|
|
"qunit/qunit.css": "qunit/qunit/qunit.css",
|
|
|
|
"qunit/LICENSE.txt": "qunit/LICENSE.txt",
|
2015-05-10 23:39:26 +00:00
|
|
|
|
2014-06-10 19:32:25 +00:00
|
|
|
"requirejs/require.js": "requirejs/require.js",
|
|
|
|
|
2016-01-27 11:54:39 +00:00
|
|
|
"sinon/sinon.js": "sinon/pkg/sinon.js",
|
2014-06-10 19:32:25 +00:00
|
|
|
"sinon/LICENSE.txt": "sinon/LICENSE"
|
2013-11-14 15:17:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-07-19 13:53:57 +00:00
|
|
|
jsonlint: {
|
|
|
|
pkg: {
|
|
|
|
src: [ "package.json" ]
|
|
|
|
}
|
|
|
|
},
|
2016-05-10 09:06:37 +00:00
|
|
|
eslint: {
|
|
|
|
options: {
|
|
|
|
|
|
|
|
// See https://github.com/sindresorhus/grunt-eslint/issues/119
|
|
|
|
quiet: true
|
2013-09-06 18:31:18 +00:00
|
|
|
},
|
2016-07-25 23:53:57 +00:00
|
|
|
|
|
|
|
// We have to explicitly declare "src" property otherwise "newer"
|
|
|
|
// task wouldn't work properly :/
|
|
|
|
dist: {
|
2020-01-21 12:51:03 +00:00
|
|
|
src: [ "dist/jquery.js", "dist/jquery.min.js" ]
|
2016-07-25 23:53:57 +00:00
|
|
|
},
|
|
|
|
dev: {
|
|
|
|
src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
|
|
|
|
}
|
2013-09-12 20:51:59 +00:00
|
|
|
},
|
2012-12-13 01:19:18 +00:00
|
|
|
testswarm: {
|
2014-07-17 17:25:59 +00:00
|
|
|
tests: [
|
2015-07-29 22:54:00 +00:00
|
|
|
|
|
|
|
// A special module with basic tests, meant for
|
|
|
|
// not fully supported environments like Android 2.3,
|
|
|
|
// jsdom or PhantomJS. We run it everywhere, though,
|
|
|
|
// to make sure tests are not broken.
|
|
|
|
"basic",
|
|
|
|
|
2014-07-17 17:25:59 +00:00
|
|
|
"ajax",
|
2015-05-19 21:48:42 +00:00
|
|
|
"animation",
|
2014-07-17 17:25:59 +00:00
|
|
|
"attributes",
|
|
|
|
"callbacks",
|
|
|
|
"core",
|
|
|
|
"css",
|
|
|
|
"data",
|
|
|
|
"deferred",
|
2015-10-20 16:30:01 +00:00
|
|
|
"deprecated",
|
2014-07-17 17:25:59 +00:00
|
|
|
"dimensions",
|
|
|
|
"effects",
|
|
|
|
"event",
|
|
|
|
"manipulation",
|
|
|
|
"offset",
|
|
|
|
"queue",
|
|
|
|
"selector",
|
|
|
|
"serialize",
|
|
|
|
"support",
|
2015-05-18 21:11:21 +00:00
|
|
|
"traversing",
|
|
|
|
"tween"
|
2014-07-17 17:25:59 +00:00
|
|
|
]
|
2012-12-13 01:19:18 +00:00
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
karma: {
|
|
|
|
options: {
|
|
|
|
customContextFile: "test/karma.context.html",
|
|
|
|
customDebugFile: "test/karma.debug.html",
|
2018-03-19 17:12:23 +00:00
|
|
|
customLaunchers: {
|
|
|
|
ChromeHeadlessNoSandbox: {
|
|
|
|
base: "ChromeHeadless",
|
|
|
|
flags: [ "--no-sandbox" ]
|
|
|
|
}
|
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
frameworks: [ "qunit" ],
|
|
|
|
middleware: [ "mockserver" ],
|
|
|
|
plugins: [
|
|
|
|
"karma-*",
|
|
|
|
{
|
|
|
|
"middleware:mockserver": [
|
|
|
|
"factory",
|
|
|
|
require( "./test/middleware-mockserver.js" )
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2020-01-21 12:26:47 +00:00
|
|
|
client: {
|
|
|
|
qunit: {
|
|
|
|
|
|
|
|
// We're running `QUnit.start()` ourselves via `loadTests()`
|
|
|
|
// in test/jquery.js
|
|
|
|
autostart: false
|
|
|
|
}
|
|
|
|
},
|
2017-08-01 16:52:45 +00:00
|
|
|
files: [
|
|
|
|
"test/data/jquery-1.9.1.js",
|
|
|
|
"external/sinon/sinon.js",
|
|
|
|
"external/npo/npo.js",
|
|
|
|
"external/requirejs/require.js",
|
|
|
|
"test/data/testinit.js",
|
|
|
|
|
2018-09-07 14:14:01 +00:00
|
|
|
"test/jquery.js",
|
2017-08-01 16:52:45 +00:00
|
|
|
|
2020-01-21 12:26:47 +00:00
|
|
|
{
|
|
|
|
pattern: "dist/jquery.*",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "src/**",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pattern: "external/**",
|
|
|
|
included: false,
|
|
|
|
served: true,
|
|
|
|
nocache: true
|
|
|
|
},
|
|
|
|
{ pattern: "node_modules/**", included: false, served: true },
|
2017-08-01 16:52:45 +00:00
|
|
|
{
|
2018-05-14 17:36:30 +00:00
|
|
|
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
2017-08-01 16:52:45 +00:00
|
|
|
included: false,
|
2020-01-21 12:26:47 +00:00
|
|
|
served: true,
|
|
|
|
nocache: true
|
2017-08-01 16:52:45 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
reporters: [ "dots" ],
|
|
|
|
autoWatch: false,
|
2021-10-29 22:56:31 +00:00
|
|
|
|
|
|
|
// 2 minutes; has to be longer than QUnit.config.testTimeout
|
|
|
|
browserNoActivityTimeout: 120e3,
|
|
|
|
|
2017-08-01 16:52:45 +00:00
|
|
|
concurrency: 3,
|
|
|
|
captureTimeout: 20 * 1000,
|
2018-01-12 18:09:42 +00:00
|
|
|
singleRun: true
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
|
|
|
main: {
|
2021-11-30 23:02:57 +00:00
|
|
|
browsers: isCi && ciBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
2020-01-21 12:26:47 +00:00
|
|
|
amd: {
|
2021-11-30 23:02:57 +00:00
|
|
|
browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
|
2020-01-21 12:26:47 +00:00
|
|
|
options: {
|
|
|
|
client: {
|
|
|
|
qunit: {
|
|
|
|
|
|
|
|
// We're running `QUnit.start()` ourselves via `loadTests()`
|
|
|
|
// in test/jquery.js
|
|
|
|
autostart: false,
|
|
|
|
|
|
|
|
amd: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2018-01-12 18:09:42 +00:00
|
|
|
|
2019-03-11 19:03:54 +00:00
|
|
|
jsdom: {
|
|
|
|
options: {
|
|
|
|
files: [
|
|
|
|
"test/data/jquery-1.9.1.js",
|
|
|
|
"test/data/testinit-jsdom.js",
|
|
|
|
|
|
|
|
// We don't support various loading methods like AMD,
|
|
|
|
// choosing a version etc. for jsdom.
|
|
|
|
"dist/jquery.js",
|
|
|
|
|
2020-01-21 12:26:47 +00:00
|
|
|
// A partial replacement for testinit.js#loadTests()
|
2019-03-11 19:03:54 +00:00
|
|
|
"test/data/testrunner.js",
|
|
|
|
|
|
|
|
// jsdom only runs basic tests
|
|
|
|
"test/unit/basic.js",
|
|
|
|
|
|
|
|
{ pattern: "external/**", included: false, served: true },
|
|
|
|
{
|
|
|
|
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
|
|
|
included: false,
|
|
|
|
served: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
browsers: [ "jsdom" ]
|
|
|
|
},
|
|
|
|
|
2018-01-12 18:09:42 +00:00
|
|
|
// To debug tests with Karma:
|
|
|
|
// 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
|
|
|
|
// (any karma subtask that has singleRun=false)
|
|
|
|
// 2. Press "Debug" in the opened browser window to start
|
|
|
|
// the tests. Unlike the other karma tasks, the debug task will
|
|
|
|
// keep the browser window open.
|
|
|
|
"chrome-debug": {
|
|
|
|
browsers: [ "Chrome" ],
|
|
|
|
singleRun: false
|
2017-08-01 16:52:45 +00:00
|
|
|
},
|
2018-01-12 18:09:42 +00:00
|
|
|
"firefox-debug": {
|
|
|
|
browsers: [ "Firefox" ],
|
|
|
|
singleRun: false
|
2018-11-12 16:49:44 +00:00
|
|
|
},
|
|
|
|
"ie-debug": {
|
|
|
|
browsers: [ "IE" ],
|
|
|
|
singleRun: false
|
2017-08-01 16:52:45 +00:00
|
|
|
}
|
|
|
|
},
|
2012-04-18 20:07:35 +00:00
|
|
|
watch: {
|
2016-07-25 23:53:57 +00:00
|
|
|
files: [ "<%= eslint.dev.src %>" ],
|
2014-12-30 02:07:03 +00:00
|
|
|
tasks: [ "dev" ]
|
2012-04-18 20:07:35 +00:00
|
|
|
},
|
2012-10-11 13:38:44 +00:00
|
|
|
uglify: {
|
2012-12-19 04:02:50 +00:00
|
|
|
all: {
|
|
|
|
files: {
|
2015-11-12 18:18:59 +00:00
|
|
|
"dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
|
|
|
|
"dist/<%= grunt.option('filename') %>"
|
2012-12-19 04:02:50 +00:00
|
|
|
},
|
|
|
|
options: {
|
2013-11-09 22:12:06 +00:00
|
|
|
preserveComments: false,
|
2014-07-17 18:15:19 +00:00
|
|
|
sourceMap: true,
|
2015-11-12 18:18:59 +00:00
|
|
|
sourceMapName:
|
|
|
|
"dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
|
2013-04-18 17:19:22 +00:00
|
|
|
report: "min",
|
2017-07-03 18:25:32 +00:00
|
|
|
output: {
|
2018-01-03 17:19:37 +00:00
|
|
|
"ascii_only": true,
|
|
|
|
|
|
|
|
// Support: Android 4.0 only
|
|
|
|
// UglifyJS 3 breaks Android 4.0 if this option is not enabled.
|
|
|
|
// This is in lieu of setting ie8 for all of mangle, compress, and output
|
|
|
|
"ie8": true
|
2013-04-10 18:46:31 +00:00
|
|
|
},
|
2013-11-09 22:12:06 +00:00
|
|
|
banner: "/*! jQuery v<%= pkg.version %> | " +
|
2020-05-18 16:41:32 +00:00
|
|
|
"(c) OpenJS Foundation and other contributors | jquery.org/license */",
|
2013-04-18 13:16:59 +00:00
|
|
|
compress: {
|
2014-07-17 17:25:59 +00:00
|
|
|
"hoist_funs": false,
|
2013-10-15 21:59:58 +00:00
|
|
|
loops: false,
|
2017-07-03 18:25:32 +00:00
|
|
|
|
|
|
|
// Support: IE <11
|
|
|
|
// typeofs transformation is unsafe for IE9-10
|
|
|
|
// See https://github.com/mishoo/UglifyJS2/issues/2198
|
|
|
|
typeofs: false
|
2012-12-19 04:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-11 13:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-16 06:59:58 +00:00
|
|
|
} );
|
2012-04-18 20:07:35 +00:00
|
|
|
|
2012-12-19 04:02:50 +00:00
|
|
|
// Load grunt tasks from NPM packages
|
2016-12-30 11:17:00 +00:00
|
|
|
require( "load-grunt-tasks" )( grunt );
|
2013-08-16 13:48:00 +00:00
|
|
|
|
|
|
|
// Integrate jQuery specific tasks
|
|
|
|
grunt.loadTasks( "build/tasks" );
|
2012-12-19 04:02:50 +00:00
|
|
|
|
2016-07-11 17:21:57 +00:00
|
|
|
grunt.registerTask( "lint", [
|
|
|
|
"jsonlint",
|
2016-11-02 23:51:34 +00:00
|
|
|
|
|
|
|
// Running the full eslint task without breaking it down to targets
|
|
|
|
// would run the dist target first which would point to errors in the built
|
|
|
|
// file, making it harder to fix them. We want to check the built file only
|
|
|
|
// if we already know the source files pass the linter.
|
2016-12-30 11:17:00 +00:00
|
|
|
"eslint:dev",
|
|
|
|
"eslint:dist"
|
2016-07-11 17:21:57 +00:00
|
|
|
] );
|
|
|
|
|
2016-07-25 23:53:57 +00:00
|
|
|
grunt.registerTask( "lint:newer", [
|
|
|
|
"newer:jsonlint",
|
2016-11-02 23:51:34 +00:00
|
|
|
|
|
|
|
// Don't replace it with just the task; see the above comment.
|
2016-12-30 11:17:00 +00:00
|
|
|
"newer:eslint:dev",
|
|
|
|
"newer:eslint:dist"
|
2016-07-25 23:53:57 +00:00
|
|
|
] );
|
2014-09-11 20:18:34 +00:00
|
|
|
|
2016-12-30 11:17:00 +00:00
|
|
|
grunt.registerTask( "test:fast", "node_smoke_tests" );
|
2019-03-11 19:03:54 +00:00
|
|
|
grunt.registerTask( "test:slow", [
|
|
|
|
"promises_aplus_tests",
|
2019-10-22 18:09:15 +00:00
|
|
|
"karma:jsdom"
|
2019-03-11 19:03:54 +00:00
|
|
|
] );
|
2016-07-25 23:53:57 +00:00
|
|
|
|
2020-01-27 17:54:47 +00:00
|
|
|
grunt.registerTask( "test:prepare", [
|
|
|
|
"qunit_fixture",
|
|
|
|
"babel:tests"
|
|
|
|
] );
|
|
|
|
|
2016-07-25 23:53:57 +00:00
|
|
|
grunt.registerTask( "test", [
|
2020-01-27 17:54:47 +00:00
|
|
|
"test:prepare",
|
2016-07-25 23:53:57 +00:00
|
|
|
"test:fast",
|
|
|
|
"test:slow"
|
|
|
|
] );
|
2014-12-30 02:07:03 +00:00
|
|
|
|
2016-05-10 09:06:37 +00:00
|
|
|
grunt.registerTask( "dev", [
|
2016-07-25 23:53:57 +00:00
|
|
|
"build:*:*",
|
2016-12-30 11:17:00 +00:00
|
|
|
"newer:eslint:dev",
|
2016-07-25 23:53:57 +00:00
|
|
|
"newer:uglify",
|
|
|
|
"remove_map_comment",
|
|
|
|
"dist:*",
|
2017-08-01 16:52:45 +00:00
|
|
|
"qunit_fixture",
|
2016-07-25 23:53:57 +00:00
|
|
|
"compare_size"
|
|
|
|
] );
|
2014-09-11 20:18:34 +00:00
|
|
|
|
2016-07-11 17:21:57 +00:00
|
|
|
grunt.registerTask( "default", [
|
2016-12-30 11:17:00 +00:00
|
|
|
"eslint:dev",
|
2016-07-25 23:53:57 +00:00
|
|
|
"build:*:*",
|
|
|
|
"uglify",
|
|
|
|
"remove_map_comment",
|
|
|
|
"dist:*",
|
2020-01-27 17:54:47 +00:00
|
|
|
"test:prepare",
|
2016-12-30 11:17:00 +00:00
|
|
|
"eslint:dist",
|
2016-07-25 23:53:57 +00:00
|
|
|
"test:fast",
|
2016-07-11 17:21:57 +00:00
|
|
|
"compare_size"
|
|
|
|
] );
|
2012-04-18 20:07:35 +00:00
|
|
|
};
|