Manipulation: execute scripts from iframe in the iframe's context
[jquery.git] / Gruntfile.js
blobdd4b07d30852a2c627d50ccaa953311be0c541bf
1 module.exports = function( grunt ) {
2         "use strict";
4         function readOptionalJSON( filepath ) {
5                 var data = {};
6                 try {
7                         data = JSON.parse( stripJSONComments(
8                                 fs.readFileSync( filepath, { encoding: "utf8" } )
9                         ) );
10                 } catch ( e ) {}
11                 return data;
12         }
14         var fs = require( "fs" ),
15                 stripJSONComments = require( "strip-json-comments" ),
16                 gzip = require( "gzip-js" ),
17                 srcHintOptions = readOptionalJSON( "src/.jshintrc" ),
18                 newNode = !/^v0/.test( process.version ),
20                 // Allow to skip jsdom-related tests in Node.js < 1.0.0
21                 runJsdomTests = newNode || ( function() {
22                         try {
23                                 require( "jsdom" );
24                                 return true;
25                         } catch ( e ) {
26                                 return false;
27                         }
28                 } )();
30         // The concatenated file won't pass onevar
31         // But our modules can
32         delete srcHintOptions.onevar;
34         grunt.initConfig( {
35                 pkg: grunt.file.readJSON( "package.json" ),
36                 dst: readOptionalJSON( "dist/.destination.json" ),
37                 "compare_size": {
38                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
39                         options: {
40                                 compress: {
41                                         gz: function( contents ) {
42                                                 return gzip.zip( contents, {} ).length;
43                                         }
44                                 },
45                                 cache: "build/.sizecache.json"
46                         }
47                 },
48                 babel: {
49                         options: {
50                                 sourceMap: "inline",
51                                 retainLines: true
52                         },
53                         nodeSmokeTests: {
54                                 files: {
55                                         "test/node_smoke_tests/lib/ensure_iterability.js":
56                                                 "test/node_smoke_tests/lib/ensure_iterability_es6.js"
57                                 }
58                         }
59                 },
60                 build: {
61                         all: {
62                                 dest: "dist/jquery.js",
63                                 minimum: [
64                                         "core",
65                                         "selector"
66                                 ],
68                                 // Exclude specified modules if the module matching the key is removed
69                                 removeWith: {
70                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
71                                         callbacks: [ "deferred" ],
72                                         css: [ "effects", "dimensions", "offset" ],
73                                         "css/showHide": [ "effects" ],
74                                         sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
75                                 }
76                         }
77                 },
78                 npmcopy: {
79                         all: {
80                                 options: {
81                                         destPrefix: "external"
82                                 },
83                                 files: {
84                                         "sizzle/dist": "sizzle/dist",
85                                         "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
87                                         "npo/npo.js": "native-promise-only/npo.js",
89                                         "qunit/qunit.js": "qunitjs/qunit/qunit.js",
90                                         "qunit/qunit.css": "qunitjs/qunit/qunit.css",
91                                         "qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
93                                         "qunit-assert-step/qunit-assert-step.js":
94                                         "qunit-assert-step/qunit-assert-step.js",
95                                         "qunit-assert-step/MIT-LICENSE.txt":
96                                         "qunit-assert-step/MIT-LICENSE.txt",
98                                         "requirejs/require.js": "requirejs/require.js",
100                                         "sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js",
101                                         "sinon/LICENSE.txt": "sinon/LICENSE"
102                                 }
103                         }
104                 },
105                 jsonlint: {
106                         pkg: {
107                                 src: [ "package.json" ]
108                         }
109                 },
110                 jshint: {
111                         all: {
112                                 src: [
113                                         "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js"
114                                 ],
115                                 options: {
116                                         jshintrc: true
117                                 }
118                         },
119                         dist: {
120                                 src: "dist/jquery.js",
121                                 options: srcHintOptions
122                         }
123                 },
124                 jscs: {
125                         src: "src",
126                         gruntfile: "Gruntfile.js",
128                         // Check parts of tests that pass
129                         test: [
130                                 "test/data/testrunner.js",
131                                 "test/unit/animation.js",
132                                 "test/unit/basic.js",
133                                 "test/unit/tween.js",
134                                 "test/unit/wrap.js"
135                         ],
136                         build: "build"
137                 },
138                 testswarm: {
139                         tests: [
141                                 // A special module with basic tests, meant for
142                                 // not fully supported environments like Android 2.3,
143                                 // jsdom or PhantomJS. We run it everywhere, though,
144                                 // to make sure tests are not broken.
145                                 "basic",
147                                 "ajax",
148                                 "animation",
149                                 "attributes",
150                                 "callbacks",
151                                 "core",
152                                 "css",
153                                 "data",
154                                 "deferred",
155                                 "deprecated",
156                                 "dimensions",
157                                 "effects",
158                                 "event",
159                                 "manipulation",
160                                 "offset",
161                                 "queue",
162                                 "selector",
163                                 "serialize",
164                                 "support",
165                                 "traversing",
166                                 "tween"
167                         ]
168                 },
169                 watch: {
170                         files: [ "<%= jshint.all.src %>" ],
171                         tasks: [ "dev" ]
172                 },
173                 uglify: {
174                         all: {
175                                 files: {
176                                         "dist/jquery.min.js": [ "dist/jquery.js" ]
177                                 },
178                                 options: {
179                                         preserveComments: false,
180                                         sourceMap: true,
181                                         sourceMapName: "dist/jquery.min.map",
182                                         report: "min",
183                                         beautify: {
184                                                 "ascii_only": true
185                                         },
186                                         banner: "/*! jQuery v<%= pkg.version %> | " +
187                                                 "(c) jQuery Foundation | jquery.org/license */",
188                                         compress: {
189                                                 "hoist_funs": false,
190                                                 loops: false,
191                                                 unused: false
192                                         }
193                                 }
194                         }
195                 }
196         } );
198         // Load grunt tasks from NPM packages
199         require( "load-grunt-tasks" )( grunt );
201         // Integrate jQuery specific tasks
202         grunt.loadTasks( "build/tasks" );
204         grunt.registerTask( "lint", [ "jsonlint", "jshint", "jscs" ] );
206         // Don't run Node-related tests in Node.js < 1.0.0 as they require an old
207         // jsdom version that needs compiling, making it harder for people to compile
208         // jQuery on Windows. (see gh-2519)
209         grunt.registerTask( "test_fast", runJsdomTests ? [ "node_smoke_tests" ] : [] );
211         grunt.registerTask( "test", [ "test_fast" ].concat(
212                 runJsdomTests ? [ "promises_aplus_tests" ] : []
213         ) );
215         // Short list as a high frequency watch task
216         grunt.registerTask( "dev", [ "build:*:*", "lint", "uglify", "remove_map_comment", "dist:*" ] );
218         grunt.registerTask( "default", [ "dev", "test_fast", "compare_size" ] );