Dimensions: Improve offsetWidth/offsetHeight fallback
[jquery.git] / Gruntfile.js
blob0c2ba19fa19ae437270b1345e7387720d0b8899a
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" );
18         if ( !grunt.option( "filename" ) ) {
19                 grunt.option( "filename", "jquery.js" );
20         }
22         grunt.initConfig( {
23                 pkg: grunt.file.readJSON( "package.json" ),
24                 dst: readOptionalJSON( "dist/.destination.json" ),
25                 "compare_size": {
26                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
27                         options: {
28                                 compress: {
29                                         gz: function( contents ) {
30                                                 return gzip.zip( contents, {} ).length;
31                                         }
32                                 },
33                                 cache: "build/.sizecache.json"
34                         }
35                 },
36                 babel: {
37                         options: {
38                                 sourceMap: "inline",
39                                 retainLines: true
40                         },
41                         nodeSmokeTests: {
42                                 files: {
43                                         "test/node_smoke_tests/lib/ensure_iterability.js":
44                                                 "test/node_smoke_tests/lib/ensure_iterability_es6.js"
45                                 }
46                         }
47                 },
48                 build: {
49                         all: {
50                                 dest: "dist/jquery.js",
51                                 minimum: [
52                                         "core",
53                                         "selector"
54                                 ],
56                                 // Exclude specified modules if the module matching the key is removed
57                                 removeWith: {
58                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
59                                         callbacks: [ "deferred" ],
60                                         css: [ "effects", "dimensions", "offset" ],
61                                         "css/showHide": [ "effects" ],
62                                         deferred: {
63                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
64                                                 include: [ "core/ready-no-deferred" ]
65                                         },
66                                         sizzle: [ "css/hiddenVisibleSelectors", "effects/animatedSelector" ]
67                                 }
68                         }
69                 },
70                 npmcopy: {
71                         all: {
72                                 options: {
73                                         destPrefix: "external"
74                                 },
75                                 files: {
76                                         "sizzle/dist": "sizzle/dist",
77                                         "sizzle/LICENSE.txt": "sizzle/LICENSE.txt",
79                                         "npo/npo.js": "native-promise-only/npo.js",
81                                         "qunit/qunit.js": "qunitjs/qunit/qunit.js",
82                                         "qunit/qunit.css": "qunitjs/qunit/qunit.css",
83                                         "qunit/LICENSE.txt": "qunitjs/LICENSE.txt",
85                                         "qunit-assert-step/qunit-assert-step.js":
86                                         "qunit-assert-step/qunit-assert-step.js",
87                                         "qunit-assert-step/MIT-LICENSE.txt":
88                                         "qunit-assert-step/MIT-LICENSE.txt",
90                                         "requirejs/require.js": "requirejs/require.js",
92                                         "sinon/sinon.js": "sinon/pkg/sinon.js",
93                                         "sinon/LICENSE.txt": "sinon/LICENSE"
94                                 }
95                         }
96                 },
97                 jsonlint: {
98                         pkg: {
99                                 src: [ "package.json" ]
100                         }
101                 },
102                 eslint: {
103                         options: {
105                                 // See https://github.com/sindresorhus/grunt-eslint/issues/119
106                                 quiet: true
107                         },
109                         // We have to explicitly declare "src" property otherwise "newer"
110                         // task wouldn't work properly :/
111                         dist: {
112                                 src: "dist/jquery.js"
113                         },
114                         dev: {
115                                 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
116                         }
117                 },
118                 testswarm: {
119                         tests: [
121                                 // A special module with basic tests, meant for
122                                 // not fully supported environments like Android 2.3,
123                                 // jsdom or PhantomJS. We run it everywhere, though,
124                                 // to make sure tests are not broken.
125                                 "basic",
127                                 "ajax",
128                                 "animation",
129                                 "attributes",
130                                 "callbacks",
131                                 "core",
132                                 "css",
133                                 "data",
134                                 "deferred",
135                                 "deprecated",
136                                 "dimensions",
137                                 "effects",
138                                 "event",
139                                 "manipulation",
140                                 "offset",
141                                 "queue",
142                                 "selector",
143                                 "serialize",
144                                 "support",
145                                 "traversing",
146                                 "tween"
147                         ]
148                 },
149                 watch: {
150                         files: [ "<%= eslint.dev.src %>" ],
151                         tasks: [ "dev" ]
152                 },
153                 uglify: {
154                         all: {
155                                 files: {
156                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
157                                                 "dist/<%= grunt.option('filename') %>"
158                                 },
159                                 options: {
160                                         preserveComments: false,
161                                         sourceMap: true,
162                                         sourceMapName:
163                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
164                                         report: "min",
165                                         output: {
166                                                 "ascii_only": true
167                                         },
168                                         banner: "/*! jQuery v<%= pkg.version %> | " +
169                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
170                                         compress: {
171                                                 "hoist_funs": false,
172                                                 loops: false,
173                                                 unused: false,
175                                                 // Support: IE <11
176                                                 // typeofs transformation is unsafe for IE9-10
177                                                 // See https://github.com/mishoo/UglifyJS2/issues/2198
178                                                 typeofs: false
179                                         }
180                                 }
181                         }
182                 }
183         } );
185         // Load grunt tasks from NPM packages
186         require( "load-grunt-tasks" )( grunt );
188         // Integrate jQuery specific tasks
189         grunt.loadTasks( "build/tasks" );
191         grunt.registerTask( "lint", [
192                 "jsonlint",
194                 // Running the full eslint task without breaking it down to targets
195                 // would run the dist target first which would point to errors in the built
196                 // file, making it harder to fix them. We want to check the built file only
197                 // if we already know the source files pass the linter.
198                 "eslint:dev",
199                 "eslint:dist"
200         ] );
202         grunt.registerTask( "lint:newer", [
203                 "newer:jsonlint",
205                 // Don't replace it with just the task; see the above comment.
206                 "newer:eslint:dev",
207                 "newer:eslint:dist"
208         ] );
210         grunt.registerTask( "test:fast", "node_smoke_tests" );
211         grunt.registerTask( "test:slow", "promises_aplus_tests" );
213         grunt.registerTask( "test", [
214                 "test:fast",
215                 "test:slow"
216         ] );
218         grunt.registerTask( "dev", [
219                 "build:*:*",
220                 "newer:eslint:dev",
221                 "newer:uglify",
222                 "remove_map_comment",
223                 "dist:*",
224                 "compare_size"
225         ] );
227         grunt.registerTask( "default", [
228                 "eslint:dev",
229                 "build:*:*",
230                 "uglify",
231                 "remove_map_comment",
232                 "dist:*",
233                 "eslint:dist",
234                 "test:fast",
235                 "compare_size"
236         ] );