Core: Update isFunction to handle unusual-@@toStringTag input
[jquery.git] / Gruntfile.js
blob12ae0087e87a3467ca49f3294cd2f19bae8214b0
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                                         ASCIIOnly: true,
163                                         sourceMapName:
164                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
165                                         report: "min",
166                                         beautify: {
167                                                 "ascii_only": true
168                                         },
169                                         banner: "/*! jQuery v<%= pkg.version %> | " +
170                                                 "(c) JS Foundation and other contributors | jquery.org/license */",
171                                         compress: {
172                                                 "hoist_funs": false,
173                                                 loops: false,
174                                                 unused: false
175                                         }
176                                 }
177                         }
178                 }
179         } );
181         // Load grunt tasks from NPM packages
182         require( "load-grunt-tasks" )( grunt );
184         // Integrate jQuery specific tasks
185         grunt.loadTasks( "build/tasks" );
187         grunt.registerTask( "lint", [
188                 "jsonlint",
190                 // Running the full eslint task without breaking it down to targets
191                 // would run the dist target first which would point to errors in the built
192                 // file, making it harder to fix them. We want to check the built file only
193                 // if we already know the source files pass the linter.
194                 "eslint:dev",
195                 "eslint:dist"
196         ] );
198         grunt.registerTask( "lint:newer", [
199                 "newer:jsonlint",
201                 // Don't replace it with just the task; see the above comment.
202                 "newer:eslint:dev",
203                 "newer:eslint:dist"
204         ] );
206         grunt.registerTask( "test:fast", "node_smoke_tests" );
207         grunt.registerTask( "test:slow", "promises_aplus_tests" );
209         grunt.registerTask( "test", [
210                 "test:fast",
211                 "test:slow"
212         ] );
214         grunt.registerTask( "dev", [
215                 "build:*:*",
216                 "newer:eslint:dev",
217                 "newer:uglify",
218                 "remove_map_comment",
219                 "dist:*",
220                 "compare_size"
221         ] );
223         grunt.registerTask( "default", [
224                 "eslint:dev",
225                 "build:*:*",
226                 "uglify",
227                 "remove_map_comment",
228                 "dist:*",
229                 "eslint:dist",
230                 "test:fast",
231                 "compare_size"
232         ] );