CSS: Justify use of rtrim on CSS property values
[jquery.git] / Gruntfile.js
blob7514c9a75e40618397abca8ed0f488fddba60009
1 "use strict";
3 module.exports = function( grunt ) {
4         function readOptionalJSON( filepath ) {
5                 var stripJSONComments = require( "strip-json-comments" ),
6                         data = {};
7                 try {
8                         data = JSON.parse( stripJSONComments(
9                                 fs.readFileSync( filepath, { encoding: "utf8" } )
10                         ) );
11                 } catch ( e ) {}
12                 return data;
13         }
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;
20         }
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" );
30         }
32         grunt.initConfig( {
33                 pkg: grunt.file.readJSON( "package.json" ),
34                 dst: readOptionalJSON( "dist/.destination.json" ),
35                 compare_size: {
36                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
37                         options: {
38                                 compress: {
39                                         gz: function( contents ) {
40                                                 return gzip.zip( contents, {} ).length;
41                                         }
42                                 },
43                                 cache: "build/.sizecache.json"
44                         }
45                 },
46                 babel: {
47                         options: {
48                                 sourceMap: "inline",
49                                 retainLines: true,
50                                 plugins: [ "@babel/transform-for-of" ]
51                         },
52                         tests: {
53                                 files: {
54                                         "test/data/core/jquery-iterability-transpiled.js":
55                                                 "test/data/core/jquery-iterability-transpiled-es6.js"
56                                 }
57                         }
58                 },
59                 build: {
60                         all: {
61                                 dest: "dist/jquery.js",
62                                 minimum: [
63                                         "core",
64                                         "selector"
65                                 ],
67                                 // Exclude specified modules if the module matching the key is removed
68                                 removeWith: {
69                                         ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
70                                         callbacks: [ "deferred" ],
71                                         css: [ "effects", "dimensions", "offset" ],
72                                         "css/showHide": [ "effects" ],
73                                         deferred: {
74                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
75                                                 include: [ "core/ready-no-deferred" ]
76                                         },
77                                         event: [ "deprecated/ajax-event-alias", "deprecated/event" ]
78                                 }
79                         }
80                 },
81                 npmcopy: {
82                         all: {
83                                 options: {
84                                         destPrefix: "external"
85                                 },
86                                 files: {
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"
100                                 }
101                         }
102                 },
103                 jsonlint: {
104                         pkg: {
105                                 src: [ "package.json" ]
106                         }
107                 },
108                 eslint: {
109                         options: {
110                                 maxWarnings: 0
111                         },
113                         // We have to explicitly declare "src" property otherwise "newer"
114                         // task wouldn't work properly :/
115                         dist: {
116                                 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
117                         },
118                         dev: {
119                                 src: [
120                                         "src/**/*.js",
121                                         "Gruntfile.js",
122                                         "test/**/*.js",
123                                         "build/**/*.js",
125                                         // Ignore files from .eslintignore
126                                         // See https://github.com/sindresorhus/grunt-eslint/issues/119
127                                         ...fs
128                                                 .readFileSync( `${ __dirname }/.eslintignore`, "utf-8" )
129                                                 .split( "\n" )
130                                                 .filter( filePath => filePath )
131                                                 .map( filePath => filePath[ 0 ] === "!" ?
132                                                         filePath.slice( 1 ) :
133                                                         `!${ filePath }`
134                                                 )
135                                 ]
136                         }
137                 },
138                 testswarm: {
139                         tests: [
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.
144                                 "basic",
146                                 "ajax",
147                                 "animation",
148                                 "attributes",
149                                 "callbacks",
150                                 "core",
151                                 "css",
152                                 "data",
153                                 "deferred",
154                                 "deprecated",
155                                 "dimensions",
156                                 "effects",
157                                 "event",
158                                 "manipulation",
159                                 "offset",
160                                 "queue",
161                                 "selector",
162                                 "serialize",
163                                 "support",
164                                 "traversing",
165                                 "tween"
166                         ]
167                 },
168                 karma: {
169                         options: {
170                                 customContextFile: "test/karma.context.html",
171                                 customDebugFile: "test/karma.debug.html",
172                                 customLaunchers: {
173                                         ChromeHeadlessNoSandbox: {
174                                                 base: "ChromeHeadless",
175                                                 flags: [ "--no-sandbox" ]
176                                         }
177                                 },
178                                 frameworks: [ "qunit" ],
179                                 middleware: [ "mockserver" ],
180                                 plugins: [
181                                         "karma-*",
182                                         {
183                                                 "middleware:mockserver": [
184                                                         "factory",
185                                                         require( "./test/middleware-mockserver.js" )
186                                                 ]
187                                         }
188                                 ],
189                                 client: {
190                                         qunit: {
192                                                 // We're running `QUnit.start()` ourselves via `loadTests()`
193                                                 // in test/jquery.js
194                                                 autostart: false
195                                         }
196                                 },
197                                 files: [
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",
204                                         "test/jquery.js",
206                                         {
207                                                 pattern: "dist/jquery.*",
208                                                 included: false,
209                                                 served: true,
210                                                 nocache: true
211                                         },
212                                         {
213                                                 pattern: "src/**",
214                                                 type: "module",
215                                                 included: false,
216                                                 served: true,
217                                                 nocache: true
218                                         },
219                                         {
220                                                 pattern: "amd/**",
221                                                 included: false,
222                                                 served: true,
223                                                 nocache: true
224                                         },
225                                         { pattern: "external/**", included: false, served: true },
226                                         {
227                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
228                                                 included: false,
229                                                 served: true,
230                                                 nocache: true
231                                         }
232                                 ],
233                                 reporters: [ "dots" ],
234                                 autoWatch: false,
236                                 // 2 minutes; has to be longer than QUnit.config.testTimeout
237                                 browserNoActivityTimeout: 120e3,
239                                 concurrency: 3,
240                                 captureTimeout: 20 * 1000,
241                                 singleRun: true
242                         },
243                         main: {
244                                 browsers: isCi && ciBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
245                         },
246                         esmodules: {
247                                 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
248                                 options: {
249                                         client: {
250                                                 qunit: {
252                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
253                                                         // in test/jquery.js
254                                                         autostart: false,
256                                                         esmodules: true
257                                                 }
258                                         }
259                                 }
260                         },
261                         amd: {
262                                 browsers: isCi && ciBrowsers || [ "ChromeHeadless" ],
263                                 options: {
264                                         client: {
265                                                 qunit: {
267                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
268                                                         // in test/jquery.js
269                                                         autostart: false,
271                                                         amd: true
272                                                 }
273                                         }
274                                 }
275                         },
277                         jsdom: {
278                                 options: {
279                                         files: [
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.
285                                                 "dist/jquery.js",
287                                                 // A partial replacement for testinit.js#loadTests()
288                                                 "test/data/testrunner.js",
290                                                 // jsdom only runs basic tests
291                                                 "test/unit/basic.js",
293                                                 {
294                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
295                                                         included: false,
296                                                         served: true
297                                                 }
298                                         ]
299                                 },
300                                 browsers: [ "jsdom" ]
301                         },
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.
309                         "chrome-debug": {
310                                 browsers: [ "Chrome" ],
311                                 singleRun: false
312                         },
313                         "firefox-debug": {
314                                 browsers: [ "Firefox" ],
315                                 singleRun: false
316                         },
317                         "ie-debug": {
318                                 browsers: [ "IE" ],
319                                 singleRun: false
320                         }
321                 },
322                 watch: {
323                         files: [ "<%= eslint.dev.src %>" ],
324                         tasks: [ "dev" ]
325                 },
326                 uglify: {
327                         all: {
328                                 files: {
329                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
330                                                 "dist/<%= grunt.option('filename') %>"
331                                 },
332                                 options: {
333                                         preserveComments: false,
334                                         sourceMap: true,
335                                         sourceMapName:
336                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
337                                         report: "min",
338                                         output: {
339                                                 "ascii_only": true
340                                         },
341                                         banner: "/*! jQuery v<%= pkg.version %> | " +
342                                                 "(c) OpenJS Foundation and other contributors | jquery.org/license */",
343                                         compress: {
344                                                 "hoist_funs": false,
345                                                 loops: false
346                                         }
347                                 }
348                         }
349                 }
350         } );
352         // Load grunt tasks from NPM packages
353         require( "load-grunt-tasks" )( grunt, {
354                 pattern: oldNode ? [ "grunt-*", "!grunt-eslint" ] : [ "grunt-*" ]
355         } );
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..." );
363         } );
365         grunt.registerTask( "lint", [
366                 "jsonlint",
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" )
374         ] );
376         grunt.registerTask( "lint:newer", [
377                 "newer:jsonlint",
379                 // Don't replace it with just the task; see the above comment.
380                 runIfNewNode( "newer:eslint:dev" ),
381                 runIfNewNode( "newer:eslint:dist" )
382         ] );
384         grunt.registerTask( "test:fast", "node_smoke_tests" );
385         grunt.registerTask( "test:slow", [
386                 "promises_aplus_tests",
387                 "karma:jsdom"
388         ] );
390         grunt.registerTask( "test:prepare", [
391                 "npmcopy",
392                 "qunit_fixture",
393                 "babel:tests"
394         ] );
396         grunt.registerTask( "test", [
397                 "test:prepare",
398                 "test:fast",
399                 "test:slow"
400         ] );
402         grunt.registerTask( "dev", [
403                 "build:*:*",
404                 runIfNewNode( "newer:eslint:dev" ),
405                 "newer:uglify",
406                 "remove_map_comment",
407                 "dist:*",
408                 "qunit_fixture",
409                 "compare_size"
410         ] );
412         grunt.registerTask( "default", [
413                 runIfNewNode( "eslint:dev" ),
414                 "build:*:*",
415                 "amd",
416                 "uglify",
417                 "remove_map_comment",
418                 "dist:*",
419                 "test:prepare",
420                 runIfNewNode( "eslint:dist" ),
421                 "test:fast",
422                 "compare_size"
423         ] );