Build: Take core-js-bundle from the external directory as well
[jquery.git] / Gruntfile.js
blobfc35a843a49f66952f204a901e31cd64097a0096
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         var fs = require( "fs" ),
16                 gzip = require( "gzip-js" ),
17                 isTravis = process.env.TRAVIS,
18                 travisBrowsers = process.env.BROWSERS && process.env.BROWSERS.split( "," ),
19                 CLIEngine = require( "eslint" ).CLIEngine;
21         if ( !grunt.option( "filename" ) ) {
22                 grunt.option( "filename", "jquery.js" );
23         }
25         grunt.initConfig( {
26                 pkg: grunt.file.readJSON( "package.json" ),
27                 dst: readOptionalJSON( "dist/.destination.json" ),
28                 compare_size: {
29                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
30                         options: {
31                                 compress: {
32                                         gz: function( contents ) {
33                                                 return gzip.zip( contents, {} ).length;
34                                         }
35                                 },
36                                 cache: "build/.sizecache.json"
37                         }
38                 },
39                 babel: {
40                         options: {
41                                 sourceMap: "inline",
42                                 retainLines: true,
43                                 plugins: [ "@babel/transform-for-of" ]
44                         },
45                         tests: {
46                                 files: {
47                                         "test/data/core/jquery-iterability-transpiled.js":
48                                                 "test/data/core/jquery-iterability-transpiled-es6.js"
49                                 }
50                         }
51                 },
52                 build: {
53                         all: {
54                                 dest: "dist/jquery.js",
55                                 minimum: [
56                                         "core",
57                                         "selector"
58                                 ],
60                                 // Exclude specified modules if the module matching the key is removed
61                                 removeWith: {
62                                         ajax: [ "manipulation/_evalUrl", "deprecated/ajax-event-alias" ],
63                                         callbacks: [ "deferred" ],
64                                         css: [ "effects", "dimensions", "offset" ],
65                                         "css/showHide": [ "effects" ],
66                                         deferred: {
67                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
68                                                 include: [ "core/ready-no-deferred" ]
69                                         },
70                                         event: [ "deprecated/ajax-event-alias", "deprecated/event" ]
71                                 }
72                         }
73                 },
74                 npmcopy: {
75                         all: {
76                                 options: {
77                                         destPrefix: "external"
78                                 },
79                                 files: {
80                                         "core-js-bundle/core-js-bundle.js": "core-js-bundle/minified.js",
81                                         "core-js-bundle/LICENSE": "core-js-bundle/LICENSE",
83                                         "npo/npo.js": "native-promise-only/lib/npo.src.js",
85                                         "qunit/qunit.js": "qunit/qunit/qunit.js",
86                                         "qunit/qunit.css": "qunit/qunit/qunit.css",
87                                         "qunit/LICENSE.txt": "qunit/LICENSE.txt",
89                                         "requirejs/require.js": "requirejs/require.js",
91                                         "sinon/sinon.js": "sinon/pkg/sinon.js",
92                                         "sinon/LICENSE.txt": "sinon/LICENSE"
93                                 }
94                         }
95                 },
96                 jsonlint: {
97                         pkg: {
98                                 src: [ "package.json" ]
99                         }
100                 },
101                 eslint: {
102                         options: {
103                                 maxWarnings: 0
104                         },
106                         // We have to explicitly declare "src" property otherwise "newer"
107                         // task wouldn't work properly :/
108                         dist: {
109                                 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
110                         },
111                         dev: {
112                                 src: [
113                                         "src/**/*.js",
114                                         "Gruntfile.js",
115                                         "test/**/*.js",
116                                         "build/**/*.js",
118                                         // Ignore files from .eslintignore
119                                         // See https://github.com/sindresorhus/grunt-eslint/issues/119
120                                         ...new CLIEngine()
121                                                 .getConfigForFile( "Gruntfile.js" )
122                                                 .ignorePatterns.map( ( p ) => `!${ p }` )
123                                 ]
124                         }
125                 },
126                 testswarm: {
127                         tests: [
129                                 // A special module with basic tests, meant for not fully
130                                 // supported environments like jsdom. We run it everywhere,
131                                 // though, to make sure tests are not broken.
132                                 "basic",
134                                 "ajax",
135                                 "animation",
136                                 "attributes",
137                                 "callbacks",
138                                 "core",
139                                 "css",
140                                 "data",
141                                 "deferred",
142                                 "deprecated",
143                                 "dimensions",
144                                 "effects",
145                                 "event",
146                                 "manipulation",
147                                 "offset",
148                                 "queue",
149                                 "selector",
150                                 "serialize",
151                                 "support",
152                                 "traversing",
153                                 "tween"
154                         ]
155                 },
156                 karma: {
157                         options: {
158                                 customContextFile: "test/karma.context.html",
159                                 customDebugFile: "test/karma.debug.html",
160                                 customLaunchers: {
161                                         ChromeHeadlessNoSandbox: {
162                                                 base: "ChromeHeadless",
163                                                 flags: [ "--no-sandbox" ]
164                                         }
165                                 },
166                                 frameworks: [ "qunit" ],
167                                 middleware: [ "mockserver" ],
168                                 plugins: [
169                                         "karma-*",
170                                         {
171                                                 "middleware:mockserver": [
172                                                         "factory",
173                                                         require( "./test/middleware-mockserver.js" )
174                                                 ]
175                                         }
176                                 ],
177                                 client: {
178                                         qunit: {
180                                                 // We're running `QUnit.start()` ourselves via `loadTests()`
181                                                 // in test/jquery.js
182                                                 autostart: false
183                                         }
184                                 },
185                                 files: [
186                                         "test/data/jquery-1.9.1.js",
187                                         "external/sinon/sinon.js",
188                                         "external/npo/npo.js",
189                                         "external/requirejs/require.js",
190                                         "test/data/testinit.js",
192                                         "test/jquery.js",
194                                         {
195                                                 pattern: "dist/jquery.*",
196                                                 included: false,
197                                                 served: true,
198                                                 nocache: true
199                                         },
200                                         {
201                                                 pattern: "src/**",
202                                                 type: "module",
203                                                 included: false,
204                                                 served: true,
205                                                 nocache: true
206                                         },
207                                         {
208                                                 pattern: "amd/**",
209                                                 included: false,
210                                                 served: true,
211                                                 nocache: true
212                                         },
213                                         { pattern: "external/**", included: false, served: true },
214                                         {
215                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
216                                                 included: false,
217                                                 served: true,
218                                                 nocache: true
219                                         }
220                                 ],
221                                 reporters: [ "dots" ],
222                                 autoWatch: false,
223                                 concurrency: 3,
224                                 captureTimeout: 20 * 1000,
225                                 singleRun: true
226                         },
227                         main: {
228                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
229                         },
230                         esmodules: {
231                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless" ],
232                                 options: {
233                                         client: {
234                                                 qunit: {
236                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
237                                                         // in test/jquery.js
238                                                         autostart: false,
240                                                         esmodules: true
241                                                 }
242                                         }
243                                 }
244                         },
245                         amd: {
246                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless" ],
247                                 options: {
248                                         client: {
249                                                 qunit: {
251                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
252                                                         // in test/jquery.js
253                                                         autostart: false,
255                                                         amd: true
256                                                 }
257                                         }
258                                 }
259                         },
261                         jsdom: {
262                                 options: {
263                                         files: [
264                                                 "test/data/jquery-1.9.1.js",
265                                                 "test/data/testinit-jsdom.js",
267                                                 // We don't support various loading methods like esmodules,
268                                                 // choosing a version etc. for jsdom.
269                                                 "dist/jquery.js",
271                                                 // A partial replacement for testinit.js#loadTests()
272                                                 "test/data/testrunner.js",
274                                                 // jsdom only runs basic tests
275                                                 "test/unit/basic.js",
277                                                 {
278                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
279                                                         included: false,
280                                                         served: true
281                                                 }
282                                         ]
283                                 },
284                                 browsers: [ "jsdom" ]
285                         },
287                         // To debug tests with Karma:
288                         // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
289                         //    (any karma subtask that has singleRun=false)
290                         // 2. Press "Debug" in the opened browser window to start
291                         //    the tests. Unlike the other karma tasks, the debug task will
292                         //    keep the browser window open.
293                         "chrome-debug": {
294                                 browsers: [ "Chrome" ],
295                                 singleRun: false
296                         },
297                         "firefox-debug": {
298                                 browsers: [ "Firefox" ],
299                                 singleRun: false
300                         },
301                         "ie-debug": {
302                                 browsers: [ "IE" ],
303                                 singleRun: false
304                         }
305                 },
306                 watch: {
307                         files: [ "<%= eslint.dev.src %>" ],
308                         tasks: [ "dev" ]
309                 },
310                 uglify: {
311                         all: {
312                                 files: {
313                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
314                                                 "dist/<%= grunt.option('filename') %>"
315                                 },
316                                 options: {
317                                         preserveComments: false,
318                                         sourceMap: true,
319                                         sourceMapName:
320                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
321                                         report: "min",
322                                         output: {
323                                                 "ascii_only": true
324                                         },
325                                         banner: "/*! jQuery v<%= pkg.version %> | " +
326                                                 "(c) OpenJS Foundation and other contributors | jquery.org/license */",
327                                         compress: {
328                                                 "hoist_funs": false,
329                                                 loops: false
330                                         }
331                                 }
332                         }
333                 }
334         } );
336         // Load grunt tasks from NPM packages
337         require( "load-grunt-tasks" )( grunt );
339         // Integrate jQuery specific tasks
340         grunt.loadTasks( "build/tasks" );
342         grunt.registerTask( "lint", [
343                 "jsonlint",
345                 // Running the full eslint task without breaking it down to targets
346                 // would run the dist target first which would point to errors in the built
347                 // file, making it harder to fix them. We want to check the built file only
348                 // if we already know the source files pass the linter.
349                 "eslint:dev",
350                 "eslint:dist"
351         ] );
353         grunt.registerTask( "lint:newer", [
354                 "newer:jsonlint",
356                 // Don't replace it with just the task; see the above comment.
357                 "newer:eslint:dev",
358                 "newer:eslint:dist"
359         ] );
361         grunt.registerTask( "test:fast", "node_smoke_tests" );
362         grunt.registerTask( "test:slow", [
363                 "promises_aplus_tests",
364                 "karma:jsdom"
365         ] );
367         grunt.registerTask( "test:prepare", [
368                 "npmcopy",
369                 "qunit_fixture",
370                 "babel:tests"
371         ] );
373         grunt.registerTask( "test", [
374                 "test:prepare",
375                 "test:fast",
376                 "test:slow"
377         ] );
379         grunt.registerTask( "dev", [
380                 "build:*:*",
381                 "newer:eslint:dev",
382                 "newer:uglify",
383                 "remove_map_comment",
384                 "dist:*",
385                 "qunit_fixture",
386                 "compare_size"
387         ] );
389         grunt.registerTask( "default", [
390                 "eslint:dev",
391                 "build:*:*",
392                 "amd",
393                 "uglify",
394                 "remove_map_comment",
395                 "dist:*",
396                 "test:prepare",
397                 "eslint:dist",
398                 "test:fast",
399                 "compare_size"
400         ] );