Manipulation: Respect script crossorigin attribute in DOM manipulation
[jquery.git] / Gruntfile.js
blob5021c59e9e8e082f313d0a8b9f184344285521fd
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                 jsonlint: {
75                         pkg: {
76                                 src: [ "package.json" ]
77                         }
78                 },
79                 eslint: {
80                         options: {
81                                 maxWarnings: 0
82                         },
84                         // We have to explicitly declare "src" property otherwise "newer"
85                         // task wouldn't work properly :/
86                         dist: {
87                                 src: [ "dist/jquery.js", "dist/jquery.min.js" ]
88                         },
89                         dev: {
90                                 src: [
91                                         "src/**/*.js",
92                                         "Gruntfile.js",
93                                         "test/**/*.js",
94                                         "build/**/*.js",
96                                         // Ignore files from .eslintignore
97                                         // See https://github.com/sindresorhus/grunt-eslint/issues/119
98                                         ...new CLIEngine()
99                                                 .getConfigForFile( "Gruntfile.js" )
100                                                 .ignorePatterns.map( ( p ) => `!${ p }` )
101                                 ]
102                         }
103                 },
104                 testswarm: {
105                         tests: [
107                                 // A special module with basic tests, meant for not fully
108                                 // supported environments like jsdom. We run it everywhere,
109                                 // though, to make sure tests are not broken.
110                                 "basic",
112                                 "ajax",
113                                 "animation",
114                                 "attributes",
115                                 "callbacks",
116                                 "core",
117                                 "css",
118                                 "data",
119                                 "deferred",
120                                 "deprecated",
121                                 "dimensions",
122                                 "effects",
123                                 "event",
124                                 "manipulation",
125                                 "offset",
126                                 "queue",
127                                 "selector",
128                                 "serialize",
129                                 "support",
130                                 "traversing",
131                                 "tween"
132                         ]
133                 },
134                 karma: {
135                         options: {
136                                 customContextFile: "test/karma.context.html",
137                                 customDebugFile: "test/karma.debug.html",
138                                 customLaunchers: {
139                                         ChromeHeadlessNoSandbox: {
140                                                 base: "ChromeHeadless",
141                                                 flags: [ "--no-sandbox" ]
142                                         }
143                                 },
144                                 frameworks: [ "qunit" ],
145                                 middleware: [ "mockserver" ],
146                                 plugins: [
147                                         "karma-*",
148                                         {
149                                                 "middleware:mockserver": [
150                                                         "factory",
151                                                         require( "./test/middleware-mockserver.js" )
152                                                 ]
153                                         }
154                                 ],
155                                 client: {
156                                         qunit: {
158                                                 // We're running `QUnit.start()` ourselves via `loadTests()`
159                                                 // in test/jquery.js
160                                                 autostart: false
161                                         }
162                                 },
163                                 files: [
164                                         "test/data/jquery-1.9.1.js",
165                                         "node_modules/sinon/pkg/sinon.js",
166                                         "node_modules/native-promise-only/lib/npo.src.js",
167                                         "node_modules/requirejs/require.js",
168                                         "test/data/testinit.js",
170                                         "test/jquery.js",
172                                         {
173                                                 pattern: "dist/jquery.*",
174                                                 included: false,
175                                                 served: true,
176                                                 nocache: true
177                                         },
178                                         {
179                                                 pattern: "src/**",
180                                                 type: "module",
181                                                 included: false,
182                                                 served: true,
183                                                 nocache: true
184                                         },
185                                         {
186                                                 pattern: "amd/**",
187                                                 included: false,
188                                                 served: true,
189                                                 nocache: true
190                                         },
191                                         { pattern: "node_modules/**", included: false, served: true },
192                                         {
193                                                 pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
194                                                 included: false,
195                                                 served: true,
196                                                 nocache: true
197                                         }
198                                 ],
199                                 reporters: [ "dots" ],
200                                 autoWatch: false,
201                                 concurrency: 3,
202                                 captureTimeout: 20 * 1000,
203                                 singleRun: true
204                         },
205                         main: {
206                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless", "FirefoxHeadless" ]
207                         },
208                         esmodules: {
209                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless" ],
210                                 options: {
211                                         client: {
212                                                 qunit: {
214                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
215                                                         // in test/jquery.js
216                                                         autostart: false,
218                                                         esmodules: true
219                                                 }
220                                         }
221                                 }
222                         },
223                         amd: {
224                                 browsers: isTravis && travisBrowsers || [ "ChromeHeadless" ],
225                                 options: {
226                                         client: {
227                                                 qunit: {
229                                                         // We're running `QUnit.start()` ourselves via `loadTests()`
230                                                         // in test/jquery.js
231                                                         autostart: false,
233                                                         amd: true
234                                                 }
235                                         }
236                                 }
237                         },
239                         jsdom: {
240                                 options: {
241                                         files: [
242                                                 "test/data/jquery-1.9.1.js",
243                                                 "test/data/testinit-jsdom.js",
245                                                 // We don't support various loading methods like esmodules,
246                                                 // choosing a version etc. for jsdom.
247                                                 "dist/jquery.js",
249                                                 // A partial replacement for testinit.js#loadTests()
250                                                 "test/data/testrunner.js",
252                                                 // jsdom only runs basic tests
253                                                 "test/unit/basic.js",
255                                                 {
256                                                         pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
257                                                         included: false,
258                                                         served: true
259                                                 }
260                                         ]
261                                 },
262                                 browsers: [ "jsdom" ]
263                         },
265                         // To debug tests with Karma:
266                         // 1. Run 'grunt karma:chrome-debug' or 'grunt karma:firefox-debug'
267                         //    (any karma subtask that has singleRun=false)
268                         // 2. Press "Debug" in the opened browser window to start
269                         //    the tests. Unlike the other karma tasks, the debug task will
270                         //    keep the browser window open.
271                         "chrome-debug": {
272                                 browsers: [ "Chrome" ],
273                                 singleRun: false
274                         },
275                         "firefox-debug": {
276                                 browsers: [ "Firefox" ],
277                                 singleRun: false
278                         },
279                         "ie-debug": {
280                                 browsers: [ "IE" ],
281                                 singleRun: false
282                         }
283                 },
284                 watch: {
285                         files: [ "<%= eslint.dev.src %>" ],
286                         tasks: [ "dev" ]
287                 },
288                 uglify: {
289                         all: {
290                                 files: {
291                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
292                                                 "dist/<%= grunt.option('filename') %>"
293                                 },
294                                 options: {
295                                         preserveComments: false,
296                                         sourceMap: true,
297                                         sourceMapName:
298                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
299                                         report: "min",
300                                         output: {
301                                                 "ascii_only": true
302                                         },
303                                         banner: "/*! jQuery v<%= pkg.version %> | " +
304                                                 "(c) OpenJS Foundation and other contributors | jquery.org/license */",
305                                         compress: {
306                                                 "hoist_funs": false,
307                                                 loops: false
308                                         }
309                                 }
310                         }
311                 }
312         } );
314         // Load grunt tasks from NPM packages
315         require( "load-grunt-tasks" )( grunt );
317         // Integrate jQuery specific tasks
318         grunt.loadTasks( "build/tasks" );
320         grunt.registerTask( "lint", [
321                 "jsonlint",
323                 // Running the full eslint task without breaking it down to targets
324                 // would run the dist target first which would point to errors in the built
325                 // file, making it harder to fix them. We want to check the built file only
326                 // if we already know the source files pass the linter.
327                 "eslint:dev",
328                 "eslint:dist"
329         ] );
331         grunt.registerTask( "lint:newer", [
332                 "newer:jsonlint",
334                 // Don't replace it with just the task; see the above comment.
335                 "newer:eslint:dev",
336                 "newer:eslint:dist"
337         ] );
339         grunt.registerTask( "test:fast", "node_smoke_tests" );
340         grunt.registerTask( "test:slow", [
341                 "promises_aplus_tests",
342                 "karma:jsdom"
343         ] );
345         grunt.registerTask( "test:prepare", [
346                 "qunit_fixture",
347                 "babel:tests"
348         ] );
350         grunt.registerTask( "test", [
351                 "test:prepare",
352                 "test:fast",
353                 "test:slow"
354         ] );
356         grunt.registerTask( "dev", [
357                 "build:*:*",
358                 "newer:eslint:dev",
359                 "newer:uglify",
360                 "remove_map_comment",
361                 "dist:*",
362                 "qunit_fixture",
363                 "compare_size"
364         ] );
366         grunt.registerTask( "default", [
367                 "eslint:dev",
368                 "build:*:*",
369                 "amd",
370                 "uglify",
371                 "remove_map_comment",
372                 "dist:*",
373                 "test:prepare",
374                 "eslint:dist",
375                 "test:fast",
376                 "compare_size"
377         ] );