Build: Stop testing on Node.js 0.10
[jquery.git] / Gruntfile.js
blobd2ea5104faa65159bd416ec6ffabfda44b1f2068
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" ),
17                 oldNode = /^v0\./.test( process.version );
19         // Support: Node.js <4
20         // Skip running tasks that dropped support for Node.js 0.12
21         // in this Node version.
22         function runIfNewNode( task ) {
23                 return oldNode ? "print_old_node_message:" + task : task;
24         }
26         if ( !grunt.option( "filename" ) ) {
27                 grunt.option( "filename", "jquery.js" );
28         }
30         grunt.initConfig( {
31                 pkg: grunt.file.readJSON( "package.json" ),
32                 dst: readOptionalJSON( "dist/.destination.json" ),
33                 "compare_size": {
34                         files: [ "dist/jquery.js", "dist/jquery.min.js" ],
35                         options: {
36                                 compress: {
37                                         gz: function( contents ) {
38                                                 return gzip.zip( contents, {} ).length;
39                                         }
40                                 },
41                                 cache: "build/.sizecache.json"
42                         }
43                 },
44                 babel: {
45                         options: {
46                                 sourceMap: "inline",
47                                 retainLines: true
48                         },
49                         nodeSmokeTests: {
50                                 files: {
51                                         "test/node_smoke_tests/lib/ensure_iterability.js":
52                                                 "test/node_smoke_tests/lib/ensure_iterability_es6.js"
53                                 }
54                         }
55                 },
56                 build: {
57                         all: {
58                                 dest: "dist/jquery.js",
59                                 minimum: [
60                                         "core",
61                                         "selector"
62                                 ],
64                                 // Exclude specified modules if the module matching the key is removed
65                                 removeWith: {
66                                         ajax: [ "manipulation/_evalUrl", "event/ajax" ],
67                                         callbacks: [ "deferred" ],
68                                         css: [ "effects", "dimensions", "offset" ],
69                                         "css/showHide": [ "effects" ],
70                                         deferred: {
71                                                 remove: [ "ajax", "effects", "queue", "core/ready" ],
72                                                 include: [ "core/ready-no-deferred" ]
73                                         },
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/sinon.js": "sinon/pkg/sinon.js",
101                                         "sinon/LICENSE.txt": "sinon/LICENSE"
102                                 }
103                         }
104                 },
105                 jsonlint: {
106                         pkg: {
107                                 src: [ "package.json" ]
108                         }
109                 },
110                 eslint: {
111                         options: {
113                                 // See https://github.com/sindresorhus/grunt-eslint/issues/119
114                                 quiet: true
115                         },
117                         // We have to explicitly declare "src" property otherwise "newer"
118                         // task wouldn't work properly :/
119                         dist: {
120                                 src: "dist/jquery.js"
121                         },
122                         dev: {
123                                 src: [ "src/**/*.js", "Gruntfile.js", "test/**/*.js", "build/**/*.js" ]
124                         }
125                 },
126                 testswarm: {
127                         tests: [
129                                 // A special module with basic tests, meant for
130                                 // not fully supported environments like Android 2.3,
131                                 // jsdom or PhantomJS. We run it everywhere, though,
132                                 // to make sure tests are not broken.
133                                 "basic",
135                                 "ajax",
136                                 "animation",
137                                 "attributes",
138                                 "callbacks",
139                                 "core",
140                                 "css",
141                                 "data",
142                                 "deferred",
143                                 "deprecated",
144                                 "dimensions",
145                                 "effects",
146                                 "event",
147                                 "manipulation",
148                                 "offset",
149                                 "queue",
150                                 "selector",
151                                 "serialize",
152                                 "support",
153                                 "traversing",
154                                 "tween"
155                         ]
156                 },
157                 watch: {
158                         files: [ "<%= eslint.dev.src %>" ],
159                         tasks: [ "dev" ]
160                 },
161                 uglify: {
162                         all: {
163                                 files: {
164                                         "dist/<%= grunt.option('filename').replace('.js', '.min.js') %>":
165                                                 "dist/<%= grunt.option('filename') %>"
166                                 },
167                                 options: {
168                                         preserveComments: false,
169                                         sourceMap: true,
170                                         ASCIIOnly: true,
171                                         sourceMapName:
172                                                 "dist/<%= grunt.option('filename').replace('.js', '.min.map') %>",
173                                         report: "min",
174                                         beautify: {
175                                                 "ascii_only": true
176                                         },
177                                         banner: "/*! jQuery v<%= pkg.version %> | " +
178                                                 "(c) jQuery Foundation | jquery.org/license */",
179                                         compress: {
180                                                 "hoist_funs": false,
181                                                 loops: false,
182                                                 unused: false
183                                         }
184                                 }
185                         }
186                 }
187         } );
189         // Load grunt tasks from NPM packages
190         // Support: Node.js <4
191         // Don't load the eslint task in old Node.js, it won't parse.
192         require( "load-grunt-tasks" )( grunt, {
193                 pattern: oldNode ? [ "grunt-*", "!grunt-eslint" ] : [ "grunt-*" ]
194         } );
196         // Integrate jQuery specific tasks
197         grunt.loadTasks( "build/tasks" );
199         grunt.registerTask( "print_old_node_message", function() {
200                 var task = [].slice.call( arguments ).join( ":" );
201                 grunt.log.writeln( "Old Node.js detected, running the task \"" + task + "\" skipped..." );
202         } );
204         grunt.registerTask( "lint", [
205                 "jsonlint",
206                 runIfNewNode( "eslint" )
207         ] );
209         grunt.registerTask( "lint:newer", [
210                 "newer:jsonlint",
211                 runIfNewNode( "newer:eslint" )
212         ] );
214         grunt.registerTask( "test:fast", runIfNewNode( "node_smoke_tests" ) );
215         grunt.registerTask( "test:slow", runIfNewNode( "promises_aplus_tests" ) );
217         grunt.registerTask( "test", [
218                 "test:fast",
219                 "test:slow"
220         ] );
222         grunt.registerTask( "dev", [
223                 "build:*:*",
224                 runIfNewNode( "newer:eslint:dev" ),
225                 "newer:uglify",
226                 "remove_map_comment",
227                 "dist:*",
228                 "compare_size"
229         ] );
231         grunt.registerTask( "default", [
232                 runIfNewNode( "eslint:dev" ),
233                 "build:*:*",
234                 "uglify",
235                 "remove_map_comment",
236                 "dist:*",
237                 runIfNewNode( "eslint:dist" ),
238                 "test:fast",
239                 "compare_size"
240         ] );