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 isCi = process.env.GITHUB_ACTION,
26 ciBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," );
28 if ( !grunt.option( "filename" ) ) {
29 grunt.option( "filename", "jquery.js" );
33 pkg: grunt.file.readJSON( "package.json" ),
34 dst: readOptionalJSON( "dist/.destination.json" ),
36 files: [ "dist/jquery.js", "dist/jquery.min.js" ],
39 gz: function( contents ) {
40 return gzip.zip( contents, {} ).length;
43 cache: "build/.sizecache.json"
50 plugins: [ "@babel/transform-for-of" ]
54 "test/data/core/jquery-iterability-transpiled.js":
55 "test/data/core/jquery-iterability-transpiled-es6.js"
61 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" ]
84 destPrefix: "external"
87 "core-js-bundle/core-js-bundle.js": "core-js-bundle/minified.js",
88 "core-js-bundle/LICENSE": "core-js-bundle/LICENSE",
90 "npo/npo.js": "native-promise-only/lib/npo.src.js",
92 "qunit/qunit.js": "qunit/qunit/qunit.js",
93 "qunit/qunit.css": "qunit/qunit/qunit.css",
94 "qunit/LICENSE.txt": "qunit/LICENSE.txt",
96 "requirejs/require.js": "requirejs/require.js",
98 "sinon/sinon.js": "sinon/pkg/sinon.js",
99 "sinon/LICENSE.txt": "sinon/LICENSE"
105 src: [ "package.json" ]
113 // We have to explicitly declare "src" property otherwise "newer"
114 // task wouldn't work properly :/
116 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
125 // Ignore files from .eslintignore
126 // See https://github.com/sindresorhus/grunt-eslint/issues/119
128 .readFileSync( `${ __dirname }/.eslintignore`, "utf-8" )
130 .filter( filePath => filePath )
131 .map( filePath => filePath[ 0 ] === "!" ?
132 filePath.slice( 1 ) :
141 // A special module with basic tests, meant for not fully
142 // supported environments like jsdom. We run it everywhere,
143 // though, to make sure tests are not broken.
170 customContextFile: "test/karma.context.html",
171 customDebugFile: "test/karma.debug.html",
173 ChromeHeadlessNoSandbox: {
174 base: "ChromeHeadless",
175 flags: [ "--no-sandbox" ]
178 frameworks: [ "qunit" ],
179 middleware: [ "mockserver" ],
183 "middleware:mockserver": [
185 require( "./test/middleware-mockserver.js" )
192 // We're running `QUnit.start()` ourselves via `loadTests()`
198 "test/data/jquery-1.9.1.js",
199 "external/sinon/sinon.js",
200 "external/npo/npo.js",
201 "external/requirejs/require.js",
202 "test/data/testinit.js",
207 pattern: "dist/jquery.*",
225 { pattern: "external/**", included: false, served: true },
227 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
233 reporters: [ "dots" ],
236 // 2 minutes; has to be longer than QUnit.config.testTimeout
237 browserNoActivityTimeout: 120e3,
240 captureTimeout: 20 * 1000,
244 browsers: isCi && ciBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
247 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
252 // We're running `QUnit.start()` ourselves via `loadTests()`
262 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
267 // We're running `QUnit.start()` ourselves via `loadTests()`
280 "test/data/jquery-1.9.1.js",
281 "test/data/testinit-jsdom.js",
283 // We don't support various loading methods like esmodules,
284 // choosing a version etc. for jsdom.
287 // A partial replacement for testinit.js#loadTests()
288 "test/data/testrunner.js",
290 // jsdom only runs basic tests
291 "test/unit/basic.js",
294 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
300 browsers: [ "jsdom" ]
303 // To debug tests with Karma:
304 // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
305 // (any karma subtask that has singleRun=false)
306 // 2. Press "Debug" in the opened browser window to start
307 // the tests. Unlike the other karma tasks, the debug task will
308 // keep the browser window open.
310 browsers: [ "Chrome" ],
314 browsers: [ "Firefox" ],
323 files: [ "<%= eslint.dev.src %>" ],
329 "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
330 "dist/<%= grunt.option('filename') %>"
333 preserveComments: false,
336 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
341 banner: "/*! jQuery v<%= pkg.version %> | " +
342 "(c) OpenJS Foundation and other contributors | jquery.org/license */",
352 // Load grunt tasks from NPM packages
353 require( "load-grunt-tasks" )( grunt, {
354 pattern: oldNode ? [ "grunt-*", "!grunt-eslint" ] : [ "grunt-*" ]
357 // Integrate jQuery specific tasks
358 grunt.loadTasks( "build/tasks" );
360 grunt.registerTask( "print_old_node_message", ( ...args ) => {
361 var task = args.join( ":" );
362 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
365 grunt.registerTask( "lint", [
368 // Running the full eslint task without breaking it down to targets
369 // would run the dist target first which would point to errors in the built
370 // file, making it harder to fix them. We want to check the built file only
371 // if we already know the source files pass the linter.
372 runIfNewNode( "eslint:dev" ),
373 runIfNewNode( "eslint:dist" )
376 grunt.registerTask( "lint:newer", [
379 // Don't replace it with just the task; see the above comment.
380 runIfNewNode( "newer:eslint:dev" ),
381 runIfNewNode( "newer:eslint:dist" )
384 grunt.registerTask( "test:fast", "node_smoke_tests" );
385 grunt.registerTask( "test:slow", [
386 "promises_aplus_tests",
390 grunt.registerTask( "test:prepare", [
396 grunt.registerTask( "test", [
402 grunt.registerTask( "dev", [
404 runIfNewNode( "newer:eslint:dev" ),
406 "remove_map_comment",
412 grunt.registerTask( "default", [
413 runIfNewNode( "eslint:dev" ),
417 "remove_map_comment",
420 runIfNewNode( "eslint:dist" ),