Make WordPress Core

source: tags/4.1.38/Gruntfile.js

Last change on this file was 50216, checked in by desrosj, 5 years ago

Build/Test Tools: Support NodeJS 14.x in the 4.1 branch.

This updates the 4.1 branch to support the latest LTS version of NodeJS (currently 14.x), allowing the same version to be used across all WordPress branches that receive security updates as a courtesy.

Because older branches use (really) old versions of NodeJS, the local Docker environment cannot be backported since the needed dependencies will not run on these older versions (see #48301). This also blocks the ability to move automated testing over to GitHub Actions (see #50401).

This change also introduces a packager-lock.json file to the branch.

In addition to backporting the package updates that happened after branching 4.1, dependencies that were removed in future releases have also been updated to their latest versions.

Props desrosj, dd32, netweb, jorbin.
Merges [31425,31504,31557,31648-31650,32356-32357,32988,33726,35363,35513,35521,35538-35541,35859,36861-36865,37017,37019-37020,37212,37612,38111,39110,39113,39115-39117,39478,41835,42460-42461,42463,42887,43320,43323,43977,44219,44233,45321,45765,46404,46408-46409,47404,47867,47872-47873,48705,49636,49933,49937,49939,50126,50176,50185] to the 4.1 branch.
See #52341.

File size: 13.0 KB
Line 
1/* jshint node:true */
2module.exports = function(grunt) {
3        var path = require('path'),
4                SOURCE_DIR = 'src/',
5                BUILD_DIR = 'build/',
6                sass = require( 'sass' );
7
8        // Load tasks.
9        require('matchdep').filterDev(['grunt-*', '!grunt-legacy-util']).forEach( grunt.loadNpmTasks );
10        // Load legacy utils
11        grunt.util = require('grunt-legacy-util');
12
13        // Project configuration.
14        grunt.initConfig({
15                autoprefixer: {
16                        options: {
17                                browsers: ['Android >= 2.1', 'Chrome >= 21', 'Explorer >= 7', 'Firefox >= 17', 'Opera >= 12.1', 'Safari >= 6.0'],
18                                cascade: false
19                        },
20                        core: {
21                                expand: true,
22                                cwd: SOURCE_DIR,
23                                dest: SOURCE_DIR,
24                                src: [
25                                        'wp-admin/css/*.css',
26                                        'wp-includes/css/*.css'
27                                ]
28                        },
29                        colors: {
30                                expand: true,
31                                cwd: BUILD_DIR,
32                                dest: BUILD_DIR,
33                                src: [
34                                        'wp-admin/css/colors/*/colors.css'
35                                ]
36                        }
37                },
38                clean: {
39                        all: [BUILD_DIR],
40                        dynamic: {
41                                dot: true,
42                                expand: true,
43                                cwd: BUILD_DIR,
44                                src: []
45                        },
46                        tinymce: ['<%= concat.tinymce.dest %>'],
47                        qunit: ['tests/qunit/compiled.html']
48                },
49                copy: {
50                        files: {
51                                files: [
52                                        {
53                                                dot: true,
54                                                expand: true,
55                                                cwd: SOURCE_DIR,
56                                                src: [
57                                                        '**',
58                                                        '!**/.{svn,git}/**', // Ignore version control directories.
59                                                        // Ignore unminified versions of external libs we don't ship:
60                                                        '!wp-includes/js/backbone.js',
61                                                        '!wp-includes/js/underscore.js',
62                                                        '!wp-includes/js/jquery/jquery.masonry.js',
63                                                        '!wp-includes/js/jquery/ui/*.js',
64                                                        '!wp-includes/js/tinymce/tinymce.js',
65                                                        '!wp-includes/version.php' // Exclude version.php
66                                                ],
67                                                dest: BUILD_DIR
68                                        },
69                                        {
70                                                src: 'wp-config-sample.php',
71                                                dest: BUILD_DIR
72                                        }
73                                ]
74                        },
75                        'wp-admin-rtl': {
76                                options: {
77                                        processContent: function( src ) {
78                                                return src.replace( /\.css/g, '-rtl.css' );
79                                        }
80                                },
81                                src: SOURCE_DIR + 'wp-admin/css/wp-admin.css',
82                                dest: BUILD_DIR + 'wp-admin/css/wp-admin-rtl.css'
83                        },
84                        version: {
85                                options: {
86                                        processContent: function( src ) {
87                                                return src.replace( /^\$wp_version = '(.+?)';/m, function( str, version ) {
88                                                        version = version.replace( /-src$/, '' );
89
90                                                        // If the version includes an SVN commit (-12345), it's not a released alpha/beta. Append a date.
91                                                        version = version.replace( /-[\d]{5}$/, '-' + grunt.template.today( 'yyyymmdd' ) );
92
93                                                        /* jshint quotmark: true */
94                                                        return "$wp_version = '" + version + "';";
95                                                });
96                                        }
97                                },
98                                src: SOURCE_DIR + 'wp-includes/version.php',
99                                dest: BUILD_DIR + 'wp-includes/version.php'
100                        },
101                        dynamic: {
102                                dot: true,
103                                expand: true,
104                                cwd: SOURCE_DIR,
105                                dest: BUILD_DIR,
106                                src: []
107                        },
108                        qunit: {
109                                src: 'tests/qunit/index.html',
110                                dest: 'tests/qunit/compiled.html',
111                                options: {
112                                        processContent: function( src ) {
113                                                return src.replace( /([^\.])*\.\.\/src/ig , '/../build' );
114                                        }
115                                }
116                        }
117                },
118                sass: {
119                        colors: {
120                                expand: true,
121                                cwd: SOURCE_DIR,
122                                dest: BUILD_DIR,
123                                ext: '.css',
124                                src: ['wp-admin/css/colors/*/colors.scss'],
125                                options: {
126                                        implementation: sass
127                                }
128                        }
129                },
130                cssmin: {
131                        options: {
132                                'wp-admin': ['wp-admin', 'color-picker', 'customize-controls', 'customize-widgets', 'ie', 'install', 'login', 'deprecated-*']
133                        },
134                        core: {
135                                expand: true,
136                                cwd: SOURCE_DIR,
137                                dest: BUILD_DIR,
138                                ext: '.min.css',
139                                src: [
140                                        'wp-admin/css/{<%= cssmin.options["wp-admin"] %>}.css',
141                                        'wp-includes/css/*.css'
142                                ]
143                        },
144                        rtl: {
145                                expand: true,
146                                cwd: BUILD_DIR,
147                                dest: BUILD_DIR,
148                                ext: '.min.css',
149                                src: [
150                                        'wp-admin/css/{<%= cssmin.options["wp-admin"] %>}-rtl.css',
151                                        'wp-includes/css/*-rtl.css'
152                                ]
153                        },
154                        colors: {
155                                expand: true,
156                                cwd: BUILD_DIR,
157                                dest: BUILD_DIR,
158                                ext: '.min.css',
159                                src: [
160                                        'wp-admin/css/colors/*/*.css'
161                                ]
162                        }
163                },
164                cssjanus: {
165                        core: {
166                                options: {
167                                        swapLtrRtlInUrl: false,
168                                        processContent: function( src ) {
169                                                return src.replace( /url\((.+?)\.css\)/g, 'url($1-rtl.css)' );
170                                        }
171                                },
172                                expand: true,
173                                cwd: SOURCE_DIR,
174                                dest: BUILD_DIR,
175                                ext: '-rtl.css',
176                                src: [
177                                        'wp-admin/css/*.css',
178                                        'wp-includes/css/*.css'
179                                ]
180                        },
181                        colors: {
182                                options: {
183                                        processContent: function( src ) {
184                                                return src.replace( /([^/]+)\.css/gi, '$1-rtl.css' );
185                                        }
186                                },
187                                expand: true,
188                                cwd: BUILD_DIR,
189                                dest: BUILD_DIR,
190                                ext: '-rtl.css',
191                                src: [
192                                        'wp-admin/css/colors/*/colors.css'
193                                ]
194                        },
195                        dynamic: {
196                                expand: true,
197                                cwd: SOURCE_DIR,
198                                dest: BUILD_DIR,
199                                ext: '-rtl.css',
200                                src: []
201                        }
202                },
203                jshint: {
204                        options: grunt.file.readJSON('.jshintrc'),
205                        grunt: {
206                                src: ['Gruntfile.js']
207                        },
208                        tests: {
209                                src: [
210                                        'tests/qunit/**/*.js',
211                                        '!tests/qunit/vendor/*',
212                                        '!tests/qunit/editor/**'
213                                ],
214                                options: grunt.file.readJSON('tests/qunit/.jshintrc')
215                        },
216                        themes: {
217                                expand: true,
218                                cwd: SOURCE_DIR + 'wp-content/themes',
219                                src: [
220                                        'twenty*/**/*.js',
221                                        '!twenty{eleven,twelve,thirteen}/**',
222                                        // Third party scripts
223                                        '!twenty{fourteen,fifteen}/js/html5.js'
224                                ]
225                        },
226                        core: {
227                                expand: true,
228                                cwd: SOURCE_DIR,
229                                src: [
230                                        'wp-admin/js/*.js',
231                                        'wp-includes/js/*.js',
232                                        // WordPress scripts inside directories
233                                        'wp-includes/js/jquery/jquery.table-hotkeys.js',
234                                        'wp-includes/js/mediaelement/wp-mediaelement.js',
235                                        'wp-includes/js/plupload/handlers.js',
236                                        'wp-includes/js/plupload/wp-plupload.js',
237                                        'wp-includes/js/tinymce/plugins/wordpress/plugin.js',
238                                        'wp-includes/js/tinymce/plugins/wp*/plugin.js',
239                                        // Third party scripts
240                                        '!wp-admin/js/farbtastic.js',
241                                        '!wp-includes/js/backbone*.js',
242                                        '!wp-includes/js/swfobject.js',
243                                        '!wp-includes/js/underscore*.js',
244                                        '!wp-includes/js/colorpicker.js',
245                                        '!wp-includes/js/hoverIntent.js',
246                                        '!wp-includes/js/json2.js',
247                                        '!wp-includes/js/tw-sack.js',
248                                        '!**/*.min.js'
249                                ],
250                                // Remove once other JSHint errors are resolved
251                                options: {
252                                        curly: false,
253                                        eqeqeq: false
254                                },
255                                // Limit JSHint's run to a single specified file:
256                                //
257                                //    grunt jshint:core --file=filename.js
258                                //
259                                // Optionally, include the file path:
260                                //
261                                //    grunt jshint:core --file=path/to/filename.js
262                                //
263                                filter: function( filepath ) {
264                                        var index, file = grunt.option( 'file' );
265
266                                        // Don't filter when no target file is specified
267                                        if ( ! file ) {
268                                                return true;
269                                        }
270
271                                        // Normalize filepath for Windows
272                                        filepath = filepath.replace( /\\/g, '/' );
273                                        index = filepath.lastIndexOf( '/' + file );
274
275                                        // Match only the filename passed from cli
276                                        if ( filepath === file || ( -1 !== index && index === filepath.length - ( file.length + 1 ) ) ) {
277                                                return true;
278                                        }
279
280                                        return false;
281                                }
282                        },
283                        plugins: {
284                                expand: true,
285                                cwd: SOURCE_DIR + 'wp-content/plugins',
286                                src: [
287                                        '**/*.js',
288                                        '!**/*.min.js'
289                                ],
290                                // Limit JSHint's run to a single specified plugin directory:
291                                //
292                                //    grunt jshint:plugins --dir=foldername
293                                //
294                                filter: function( dirpath ) {
295                                        var index, dir = grunt.option( 'dir' );
296
297                                        // Don't filter when no target folder is specified
298                                        if ( ! dir ) {
299                                                return true;
300                                        }
301
302                                        dirpath = dirpath.replace( /\\/g, '/' );
303                                        index = dirpath.lastIndexOf( '/' + dir );
304
305                                        // Match only the folder name passed from cli
306                                        if ( -1 !== index ) {
307                                                return true;
308                                        }
309
310                                        return false;
311                                }
312                        }
313                },
314                qunit: {
315                        files: [
316                                'tests/qunit/**/*.html',
317                                '!tests/qunit/editor/**'
318                        ]
319                },
320                phpunit: {
321                        'default': {
322                                cmd: 'phpunit',
323                                args: ['-c', 'phpunit.xml.dist']
324                        },
325                        ajax: {
326                                cmd: 'phpunit',
327                                args: ['-c', 'phpunit.xml.dist', '--group', 'ajax']
328                        },
329                        multisite: {
330                                cmd: 'phpunit',
331                                args: ['-c', 'tests/phpunit/multisite.xml']
332                        },
333                        'external-http': {
334                                cmd: 'phpunit',
335                                args: ['-c', 'phpunit.xml.dist', '--group', 'external-http']
336                        }
337                },
338                uglify: {
339                        options: {
340                                output: {
341                                        ie8: true
342                                }
343                        },
344                        core: {
345                                expand: true,
346                                cwd: SOURCE_DIR,
347                                dest: BUILD_DIR,
348                                ext: '.min.js',
349                                src: [
350                                        'wp-admin/js/*.js',
351                                        'wp-includes/js/*.js',
352                                        'wp-includes/js/plupload/handlers.js',
353                                        'wp-includes/js/plupload/wp-plupload.js',
354                                        'wp-includes/js/tinymce/plugins/wordpress/plugin.js',
355                                        'wp-includes/js/tinymce/plugins/wp*/plugin.js',
356
357                                        // Exceptions
358                                        '!wp-admin/js/custom-header.js', // Why? We should minify this.
359                                        '!wp-admin/js/farbtastic.js',
360                                        '!wp-admin/js/iris.min.js',
361                                        '!wp-includes/js/backbone.min.js',
362                                        '!wp-includes/js/swfobject.js',
363                                        '!wp-includes/js/underscore.min.js',
364                                        '!wp-includes/js/zxcvbn.min.js'
365                                ]
366                        },
367                        jqueryui: {
368                                options: {
369                                        output: {
370                                                comments: /^!/
371                                        }
372                                },
373                                expand: true,
374                                cwd: SOURCE_DIR,
375                                dest: BUILD_DIR,
376                                ext: '.min.js',
377                                src: ['wp-includes/js/jquery/ui/*.js']
378                        }
379                },
380                concat: {
381                        tinymce: {
382                                options: {
383                                        separator: '\n',
384                                        process: function( src, filepath ) {
385                                                return '// Source: ' + filepath.replace( BUILD_DIR, '' ) + '\n' + src;
386                                        }
387                                },
388                                src: [
389                                        BUILD_DIR + 'wp-includes/js/tinymce/tinymce.min.js',
390                                        BUILD_DIR + 'wp-includes/js/tinymce/themes/modern/theme.min.js',
391                                        BUILD_DIR + 'wp-includes/js/tinymce/plugins/*/plugin.min.js'
392                                ],
393                                dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js'
394                        }
395                },
396                compress: {
397                        tinymce: {
398                                options: {
399                                        mode: 'gzip',
400                                        level: 9
401                                },
402                                src: '<%= concat.tinymce.dest %>',
403                                dest: BUILD_DIR + 'wp-includes/js/tinymce/wp-tinymce.js.gz'
404                        }
405                },
406                jsvalidate:{
407                        options: {
408                                globals: {},
409                                esprimaOptions:{},
410                                verbose: false
411                        },
412                        build: {
413                                files: {
414                                        src: [
415                                                BUILD_DIR + 'wp-{admin,includes}/**/*.js',
416                                                BUILD_DIR + 'wp-content/themes/twenty*/**/*.js'
417                                        ]
418                                }
419                        }
420                },
421                imagemin: {
422                        core: {
423                                expand: true,
424                                cwd: SOURCE_DIR,
425                                src: [
426                                        'wp-{admin,includes}/images/**/*.{png,jpg,gif,jpeg}',
427                                        'wp-includes/js/tinymce/skins/wordpress/images/*.{png,jpg,gif,jpeg}'
428                                ],
429                                dest: SOURCE_DIR
430                        }
431                },
432                watch: {
433                        all: {
434                                files: [
435                                        SOURCE_DIR + '**',
436                                        // Ignore version control directories.
437                                        '!' + SOURCE_DIR + '**/.{svn,git}/**'
438                                ],
439                                tasks: ['clean:dynamic', 'copy:dynamic'],
440                                options: {
441                                        dot: true,
442                                        spawn: false,
443                                        interval: 2000
444                                }
445                        },
446                        config: {
447                                files: 'Gruntfile.js'
448                        },
449                        colors: {
450                                files: [SOURCE_DIR + 'wp-admin/css/colors/**'],
451                                tasks: ['sass:colors']
452                        },
453                        rtl: {
454                                files: [
455                                        SOURCE_DIR + 'wp-admin/css/*.css',
456                                        SOURCE_DIR + 'wp-includes/css/*.css'
457                                ],
458                                tasks: ['cssjanus:dynamic'],
459                                options: {
460                                        spawn: false,
461                                        interval: 2000
462                                }
463                        },
464                        test: {
465                                files: [
466                                        'tests/qunit/**',
467                                        '!tests/qunit/editor/**'
468                                ],
469                                tasks: ['qunit']
470                        }
471                }
472        });
473
474        // Register tasks.
475
476        // RTL task.
477        grunt.registerTask('rtl', ['cssjanus:core', 'cssjanus:colors']);
478
479        // Color schemes task.
480        grunt.registerTask('colors', ['sass:colors', 'autoprefixer:colors']);
481
482        // JSHint task.
483        grunt.registerTask('jshint:corejs', ['jshint:grunt', 'jshint:tests', 'jshint:themes', 'jshint:core']);
484
485        // Pre-commit task.
486        grunt.registerTask('precommit', 'Runs front-end dev/test tasks in preparation for a commit.',
487                ['autoprefixer:core', 'imagemin:core', 'jshint:corejs', 'qunit:compiled']);
488
489        // Copy task.
490        grunt.registerTask('copy:all', ['copy:files', 'copy:wp-admin-rtl', 'copy:version']);
491
492        // Build task.
493        grunt.registerTask('build', ['clean:all', 'copy:all', 'cssmin:core', 'colors', 'rtl', 'cssmin:rtl', 'cssmin:colors',
494                'uglify:core', 'uglify:jqueryui', 'concat:tinymce', 'compress:tinymce', 'clean:tinymce', 'jsvalidate:build']);
495
496        // Testing tasks.
497        grunt.registerMultiTask('phpunit', 'Runs PHPUnit tests, including the ajax, external-http, and multisite tests.', function() {
498                grunt.util.spawn({
499                        cmd: this.data.cmd,
500                        args: this.data.args,
501                        opts: {stdio: 'inherit'}
502                }, this.async());
503        });
504
505        grunt.registerTask('qunit:compiled', 'Runs QUnit tests on compiled as well as uncompiled scripts.',
506                ['build', 'copy:qunit', 'qunit']);
507
508        grunt.registerTask('test', 'Runs all QUnit and PHPUnit tasks.', ['qunit:compiled', 'phpunit']);
509
510        // Travis CI tasks.
511        grunt.registerTask('travis:js', 'Runs Javascript Travis CI tasks.', [ 'jshint:corejs', 'qunit:compiled' ]);
512        grunt.registerTask('travis:phpunit', 'Runs PHPUnit Travis CI tasks.', 'phpunit');
513
514        // Patch task.
515        grunt.renameTask('patch_wordpress', 'patch');
516
517        // Default task.
518        grunt.registerTask('default', ['build']);
519
520        // Add a listener to the watch task.
521        //
522        // On `watch:all`, automatically updates the `copy:dynamic` and `clean:dynamic`
523        // configurations so that only the changed files are updated.
524        // On `watch:rtl`, automatically updates the `cssjanus:dynamic` configuration.
525        grunt.event.on('watch', function( action, filepath, target ) {
526                if ( target !== 'all' && target !== 'rtl' ) {
527                        return;
528                }
529
530                var relativePath = path.relative( SOURCE_DIR, filepath ),
531                        cleanSrc = ( action === 'deleted' ) ? [relativePath] : [],
532                        copySrc = ( action === 'deleted' ) ? [] : [relativePath];
533
534                grunt.config(['clean', 'dynamic', 'src'], cleanSrc);
535                grunt.config(['copy', 'dynamic', 'src'], copySrc);
536                grunt.config(['cssjanus', 'dynamic', 'src'], copySrc);
537        });
538};
Note: See TracBrowser for help on using the repository browser.