3 module.exports = function( grunt ) {
4 function readOptionalJSON( filepath ) {
5 var stripJSONComments = require( "strip-json-comments" ),
8 data = JSON.parse( stripJSONComments(
9 fs.readFileSync( filepath, { encoding: "utf8" } )
15 // Support: Node.js <12
16 // Skip running tasks that dropped support for Node.js 10
17 // in this Node version.
18 function runIfNewNode( task ) {
19 return oldNode ? "print_old_node_message:" + task : task;
22 var fs = require( "fs" ),
23 gzip = require( "gzip-js" ),
24 oldNode = /^v10\./.test( process.version ),
25 nodeV17OrNewer = !/^v1[0246]\./.test( process.version ),
26 isCi = process.env.GITHUB_ACTION,
27 ciBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
29 if ( !grunt.option( "filename" ) ) {
30 grunt.option( "filename", "jquery.js" );
34 pkg: grunt.file.readJSON( "package.json" ),
35 dst: readOptionalJSON( "dist/.destination.json" ),
37 files: [ "dist/jquery.js", "dist/jquery.min.js" ],
40 gz: function( contents ) {
41 return gzip.zip( contents, {} ).length;
44 cache: "build/.sizecache.json"
51 plugins: [ "@babel/transform-for-of" ]
55 "test/data/core/jquery-iterability-transpiled.js":
56 "test/data/core/jquery-iterability-transpiled-es6.js"
62 dest: "dist/jquery.js",
67 // Exclude specified modules if the module matching the key is removed
69 ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
70 callbacks: [ "deferred" ],
71 css: [ "effects", "dimensions", "offset" ],
72 "css/showHide": [ "effects" ],
74 remove: [ "ajax", "effects", "queue", "core/ready" ],
75 include: [ "core/ready-no-deferred" ]
77 event: [ "deprecated/ajax-event-alias", "deprecated/event" ],
78 selector: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
85 destPrefix: "external"
88 "core-js-bundle/core-js-bundle.js": "core-js-bundle/minified.js",
89 "core-js-bundle/LICENSE": "core-js-bundle/LICENSE",
91 "npo/npo.js": "native-promise-only/lib/npo.src.js",
93 "qunit/qunit.js": "qunit/qunit/qunit.js",
94 "qunit/qunit.css": "qunit/qunit/qunit.css",
95 "qunit/LICENSE.txt": "qunit/LICENSE.txt",
97 "requirejs/require.js": "requirejs/require.js",
99 "sinon/sinon.js": "sinon/pkg/sinon.js",
100 "sinon/LICENSE.txt": "sinon/LICENSE"
106 src: [ "package.json" ]
114 // We have to explicitly declare "src" property otherwise "newer"
115 // task wouldn't work properly :/
117 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
126 // Ignore files from .eslintignore
127 // See https://github.com/sindresorhus/grunt-eslint/issues/119
129 .readFileSync( `${ __dirname }/.eslintignore`, "utf-8" )
131 .filter( filePath => filePath )
132 .map( filePath => filePath[ 0 ] === "!" ?
133 filePath.slice( 1 ) :
142 // A special module with basic tests, meant for not fully
143 // supported environments like jsdom. We run it everywhere,
144 // though, to make sure tests are not broken.
171 customContextFile: "test/karma.context.html",
172 customDebugFile: "test/karma.debug.html",
174 ChromeHeadlessNoSandbox: {
175 base: "ChromeHeadless",
176 flags: [ "--no-sandbox" ]
179 frameworks: [ "qunit" ],
180 middleware: [ "mockserver" ],
184 "middleware:mockserver": [
186 require( "./test/middleware-mockserver.js" )
193 // We're running `QUnit.start()` ourselves via `loadTests()`
199 "test/data/jquery-1.9.1.js",
200 "external/sinon/sinon.js",
201 "external/npo/npo.js",
202 "external/requirejs/require.js",
203 "test/data/testinit.js",
208 pattern: "dist/jquery.*",
226 { pattern: "external/**", included: false, served: true },
228 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
234 reporters: [ "dots" ],
237 // 2 minutes; has to be longer than QUnit.config.testTimeout
238 browserNoActivityTimeout: 120e3,
241 captureTimeout: 20 * 1000,
245 browsers: isCi && ciBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
248 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
253 // We're running `QUnit.start()` ourselves via `loadTests()`
263 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
268 // We're running `QUnit.start()` ourselves via `loadTests()`
281 "test/data/jquery-1.9.1.js",
282 "test/data/testinit-jsdom.js",
284 // We don't support various loading methods like esmodules,
285 // choosing a version etc. for jsdom.
288 // A partial replacement for testinit.js#loadTests()
289 "test/data/testrunner.js",
291 // jsdom only runs basic tests
292 "test/unit/basic.js",
295 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
301 browsers: [ "jsdom" ]
304 // To debug tests with Karma:
305 // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
306 // (any karma subtask that has singleRun=false)
307 // 2. Press "Debug" in the opened browser window to start
308 // the tests. Unlike the other karma tasks, the debug task will
309 // keep the browser window open.
311 browsers: [ "Chrome" ],
315 browsers: [ "Firefox" ],
324 files: [ "<%= eslint.dev.src %>" ],
330 "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
331 "dist/<%= grunt.option('filename') %>"
334 preserveComments: false,
337 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
342 banner: "/*! jQuery v<%= pkg.version %> | " +
343 "(c) OpenJS Foundation and other contributors | jquery.org/license */",
353 // Load grunt tasks from NPM packages
354 require( "load-grunt-tasks" )( grunt, {
355 pattern: oldNode ? [ "grunt-*", "!grunt-eslint" ] : [ "grunt-*" ]
358 // Integrate jQuery specific tasks
359 grunt.loadTasks( "build/tasks" );
361 grunt.registerTask( "print_old_node_message", ( ...args ) => {
362 var task = args.join( ":" );
363 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
366 grunt.registerTask( "print_jsdom_message", () => {
367 grunt.log.writeln( "Node.js 17 or newer detected, skipping jsdom tests..." );
370 grunt.registerTask( "lint", [
373 // Running the full eslint task without breaking it down to targets
374 // would run the dist target first which would point to errors in the built
375 // file, making it harder to fix them. We want to check the built file only
376 // if we already know the source files pass the linter.
377 runIfNewNode( "eslint:dev" ),
378 runIfNewNode( "eslint:dist" )
381 grunt.registerTask( "lint:newer", [
384 // Don't replace it with just the task; see the above comment.
385 runIfNewNode( "newer:eslint:dev" ),
386 runIfNewNode( "newer:eslint:dist" )
389 grunt.registerTask( "test:fast", runIfNewNode( "node_smoke_tests" ) );
390 grunt.registerTask( "test:slow", [
391 runIfNewNode( "promises_aplus_tests" ),
393 // Support: Node.js 17+
394 // jsdom fails to connect to the Karma server in Node 17+.
395 // Until we figure out a fix, skip jsdom tests there.
396 nodeV17OrNewer ? "print_jsdom_message" : runIfNewNode( "karma:jsdom" )
399 grunt.registerTask( "test:prepare", [
405 grunt.registerTask( "test", [
411 grunt.registerTask( "dev", [
413 runIfNewNode( "newer:eslint:dev" ),
415 "remove_map_comment",
421 grunt.registerTask( "default", [
422 runIfNewNode( "eslint:dev" ),
426 "remove_map_comment",
429 runIfNewNode( "eslint:dist" ),