Release: Update AUTHORS.txt
[jquery.git] / Gruntfile.js
blob012ce95dba38bfbbe81b0510b832eabd4329bd9a
1 module.exports = function( grunt ) {
2         "use strict";
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         var fs = require( "fs" ),
16                 gzip = require( "gzip-js" ),
17                 isTravis = process.env.TRAVIS;
19         if ( !grunt.option( "filename" ) ) {
20                 grunt.option( "filename", "jquery.js" );
21         }
23         grunt.initConfig( {
24                 pkg: grunt.file.readJSON( "package.json" ),
25                 dst: readOptionalJSON( "dist/.destination.json" ),
26                 "compare_size": {
27                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
28                         options: {
29                                 compress: {
30                                         gz: function( contents ) {
31                                                 return gzip.zip( contents, {} ).length;
32                                         }
33                                 },
34                                 cache: "build/.sizecache.json"
35                         }
36                 },
37                 babel: {
38                         options: {
39                                 sourceMap: "inline",
40                                 retainLines: true,
41                                 plugins: [ "@babel/transform-for-of" ]
42                         },
43                         nodeSmokeTests: {
44                                 files: {
45                                         "test/data/core/jquery-iterability-transpiled.js":
46                                                 "test/data/core/jquery-iterability-transpiled-es6.js"
47                                 }
48                         }
49                 },
50                 build: {
51                         all: {
52                                 dest: "dist/jquery.js",
53                                 minimum: [
54                                         "core",
55                                         "selector"
56                                 ],
58                                 // Exclude specified modules if the module matching the key is removed
59                                 removeWith: {
60                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
61                                         callbacks: [ "deferred" ],
62                                         css: [ "effects", "dimensions", "offset" ],
63                                         "css/showHide": [ "effects" ],
64                                         deferred: {
65                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
66                                                 include: [ "core/ready-no-deferred" ]
67                                         }
68                                 }
69                         }
70                 },
71                 jsonlint: {
72                         pkg: {
73                                 src: [ "package.json" ]
74                         }
75                 },
76                 eslint: {
77                         options: {
79                                 // See https://github.com/sindresorhus/grunt-eslint/issues/119
80                                 quiet: true
81                         },
83                         // We have to explicitly declare "src" property otherwise "newer"
84                         // task wouldn't work properly :/
85                         dist: {
86                                 src: "dist/jquery.js"
87                         },
88                         dev: {
89                                 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
90                         }
91                 },
92                 testswarm: {
93                         tests: [
95                                 // A special module with basic tests, meant for not fully
96                                 // supported environments like jsdom. We run it everywhere,
97                                 // though, to make sure tests are not broken.
98                                 "basic",
100                                 "ajax",
101                                 "animation",
102                                 "attributes",
103                                 "callbacks",
104                                 "core",
105                                 "css",
106                                 "data",
107                                 "deferred",
108                                 "deprecated",
109                                 "dimensions",
110                                 "effects",
111                                 "event",
112                                 "manipulation",
113                                 "offset",
114                                 "queue",
115                                 "selector",
116                                 "serialize",
117                                 "support",
118                                 "traversing",
119                                 "tween"
120                         ]
121                 },
122                 karma: {
123                         options: {
124                                 customContextFile: "test/karma.context.html",
125                                 customDebugFile: "test/karma.debug.html",
126                                 customLaunchers: {
127                                         ChromeHeadlessNoSandbox: {
128                                                 base: "ChromeHeadless",
129                                                 flags: [ "--no-sandbox" ]
130                                         }
131                                 },
132                                 frameworks: [ "qunit" ],
133                                 middleware: [ "mockserver" ],
134                                 plugins: [
135                                         "karma-*",
136                                         {
137                                                 "middleware:mockserver": [
138                                                         "factory",
139                                                         require( "./test/middleware-mockserver.js" )
140                                                 ]
141                                         }
142                                 ],
143                                 files: [
144                                         "test/data/jquery-1.9.1.js",
145                                         "node_modules/sinon/pkg/sinon.js",
146                                         "node_modules/native-promise-only/lib/npo.src.js",
147                                         "node_modules/requirejs/require.js",
148                                         "test/data/testinit.js",
150                                         "test/jquery.js",
152                                         // Replacement for testinit.js#loadTests()
153                                         "test/data/testrunner.js",
154                                         "test/unit/basic.js",
155                                         "test/unit/core.js",
156                                         "test/unit/callbacks.js",
157                                         "test/unit/deferred.js",
158                                         "test/unit/deprecated.js",
159                                         "test/unit/support.js",
160                                         "test/unit/data.js",
161                                         "test/unit/queue.js",
162                                         "test/unit/attributes.js",
163                                         "test/unit/event.js",
164                                         "test/unit/selector.js",
165                                         "test/unit/traversing.js",
166                                         "test/unit/manipulation.js",
167                                         "test/unit/wrap.js",
168                                         "test/unit/css.js",
169                                         "test/unit/serialize.js",
170                                         "test/unit/ajax.js",
171                                         "test/unit/effects.js",
172                                         "test/unit/offset.js",
173                                         "test/unit/dimensions.js",
174                                         "test/unit/animation.js",
175                                         "test/unit/tween.js",
176                                         "test/unit/ready.js",
178                                         { pattern: "dist/jquery.*", included: false, served: true },
179                                         { pattern: "src/**", included: false, served: true },
180                                         { pattern: "node_modules/**", included: false, served: true },
181                                         {
182                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
183                                                 included: false,
184                                                 served: true
185                                         }
186                                 ],
187                                 reporters: [ "dots" ],
188                                 autoWatch: false,
189                                 concurrency: 3,
190                                 captureTimeout: 20 * 1000,
191                                 singleRun: true
192                         },
193                         main: {
195                                 // The Chrome sandbox doesn't work on Travis.
196                                 browsers: [ isTravis ? "ChromeHeadlessNoSandbox" : "ChromeHeadless" ]
197                         },
199                         jsdom: {
200                                 options: {
201                                         files: [
202                                                 "test/data/jquery-1.9.1.js",
203                                                 "test/data/testinit-jsdom.js",
205                                                 // We don't support various loading methods like AMD,
206                                                 // choosing a version etc. for jsdom.
207                                                 "dist/jquery.js",
209                                                 // Replacement for testinit.js#loadTests()
210                                                 "test/data/testrunner.js",
212                                                 // jsdom only runs basic tests
213                                                 "test/unit/basic.js",
215                                                 {
216                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
217                                                         included: false,
218                                                         served: true
219                                                 }
220                                         ]
221                                 },
222                                 browsers: [ "jsdom" ]
223                         },
225                         // To debug tests with Karma:
226                         // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
227                         //    (any karma subtask that has singleRun=false)
228                         // 2. Press "Debug" in the opened browser window to start
229                         //    the tests. Unlike the other karma tasks, the debug task will
230                         //    keep the browser window open.
231                         "chrome-debug": {
232                                 browsers: [ "Chrome" ],
233                                 singleRun: false
234                         },
235                         "firefox-debug": {
236                                 browsers: [ "Firefox" ],
237                                 singleRun: false
238                         },
239                         "ie-debug": {
240                                 browsers: [ "IE" ],
241                                 singleRun: false
242                         }
243                 },
244                 watch: {
245                         files: [ "<%= eslint.dev.src %>" ],
246                         tasks: [ "dev" ]
247                 },
248                 uglify: {
249                         all: {
250                                 files: {
251                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
252                                                 "dist/<%= grunt.option('filename') %>"
253                                 },
254                                 options: {
255                                         preserveComments: false,
256                                         sourceMap: true,
257                                         sourceMapName:
258                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
259                                         report: "min",
260                                         output: {
261                                                 "ascii_only": true
262                                         },
263                                         banner: "/*! jQuery v<%= pkg.version %> | " +
264                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
265                                         compress: {
266                                                 "hoist_funs": false,
267                                                 loops: false
268                                         }
269                                 }
270                         }
271                 }
272         } );
274         // Load grunt tasks from NPM packages
275         require( "load-grunt-tasks" )( grunt );
277         // Integrate jQuery specific tasks
278         grunt.loadTasks( "build/tasks" );
280         grunt.registerTask( "lint", [
281                 "jsonlint",
283                 // Running the full eslint task without breaking it down to targets
284                 // would run the dist target first which would point to errors in the built
285                 // file, making it harder to fix them. We want to check the built file only
286                 // if we already know the source files pass the linter.
287                 "eslint:dev",
288                 "eslint:dist"
289         ] );
291         grunt.registerTask( "lint:newer", [
292                 "newer:jsonlint",
294                 // Don't replace it with just the task; see the above comment.
295                 "newer:eslint:dev",
296                 "newer:eslint:dist"
297         ] );
299         grunt.registerTask( "test:fast", "node_smoke_tests" );
300         grunt.registerTask( "test:slow", [
301                 "promises_aplus_tests",
302                 "karma:jsdom"
303         ] );
305         grunt.registerTask( "test", [
306                 "test:fast",
307                 "test:slow"
308         ] );
310         grunt.registerTask( "dev", [
311                 "build:*:*",
312                 "newer:eslint:dev",
313                 "newer:uglify",
314                 "remove_map_comment",
315                 "dist:*",
316                 "qunit_fixture",
317                 "compare_size"
318         ] );
320         grunt.registerTask( "default", [
321                 "eslint:dev",
322                 "build:*:*",
323                 "uglify",
324                 "remove_map_comment",
325                 "dist:*",
326                 "qunit_fixture",
327                 "eslint:dist",
328                 "test:fast",
329                 "compare_size"
330         ] );