Skip to content

Commit 438132f

Browse files
committed
External Libraries: Upgrade CodeMirror to latest v5 in addition to updating CSSLint, Esprima, HTMLHint, and JSONLint.
This installs npm packages for `codemirror`, `csslint`, `esprima`, `htmlhint`, and `jsonlint` to replace the libraries which had been copied into SVN. A new `grunt build:codemirror` task is responsible for building CodeMirror as part of the build process. This finally revisits the original CodeMirror integration which was originally developed in the [https://github.com/WordPress/better-code-editing/ Better Code Editing] feature plugin in 2017. ||= Package =||= Old Version =||= New Version =|| || codemirror || 5.29.1-alpha-ee20357 || 5.65.20 || || esprima || 4.0.0 || 4.0.1 || || jsonlint || 1.6.2 || 1.6.3 || || htmlhint || 0.9.14-xwp || 1.8.0 || Follow-up to [41376]. Props westonruter, jonsurrell, tobiasbg, desrosj, adamsilverstein, WraithKenny, rafa8626, netweb. See #12423. Fixes #48456, #41870. git-svn-id: https://develop.svn.wordpress.org/trunk@61539 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c59df25 commit 438132f

13 files changed

Lines changed: 625 additions & 11354 deletions

File tree

Gruntfile.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* jshint node:true */
22
/* jshint esversion: 6 */
3+
/* eslint-env es6 */
34
/* globals Set */
45
var webpackConfig = require( './webpack.config' );
56
var installChanged = require( 'install-changed' );
@@ -175,6 +176,17 @@ module.exports = function(grunt) {
175176
banner: BANNER_TEXT,
176177
linebreak: true
177178
},
179+
codemirror: {
180+
options: {
181+
linebreak: false,
182+
banner: require( './tools/webpack/codemirror-banner' )
183+
},
184+
files: {
185+
src: [
186+
WORKING_DIR + 'wp-includes/js/codemirror/codemirror.min.css'
187+
]
188+
}
189+
},
178190
files: {
179191
src: [
180192
WORKING_DIR + 'wp-admin/css/*.min.css',
@@ -311,6 +323,33 @@ module.exports = function(grunt) {
311323
}
312324
]
313325
},
326+
'codemirror': {
327+
options: {
328+
process: function( content, srcpath ) {
329+
if ( srcpath.includes( 'htmlhint.min.js' ) ) {
330+
return content + '\nif ( window.HTMLHint && window.HTMLHint.HTMLHint ) { window.HTMLHint = window.HTMLHint.HTMLHint; }';
331+
}
332+
return content;
333+
}
334+
},
335+
files: [
336+
{
337+
[ WORKING_DIR + 'wp-includes/js/codemirror/csslint.js' ]: [ './node_modules/csslint/dist/csslint.js' ],
338+
[ WORKING_DIR + 'wp-includes/js/codemirror/esprima.js' ]: [ './node_modules/esprima/dist/esprima.js' ],
339+
[ WORKING_DIR + 'wp-includes/js/codemirror/htmlhint.js' ]: [ './node_modules/htmlhint/dist/htmlhint.min.js' ],
340+
[ WORKING_DIR + 'wp-includes/js/codemirror/jsonlint.js' ]: [ './node_modules/jsonlint/web/jsonlint.js' ],
341+
},
342+
{
343+
expand: true,
344+
cwd: SOURCE_DIR + 'js/_enqueues/vendor/codemirror/',
345+
src: [
346+
'fakejshint.js',
347+
'htmlhint-kses.js',
348+
],
349+
dest: WORKING_DIR + 'wp-includes/js/codemirror/'
350+
}
351+
]
352+
},
314353
'vendor-js': {
315354
files: [
316355
{
@@ -562,6 +601,22 @@ module.exports = function(grunt) {
562601
options: {
563602
compatibility: 'ie11'
564603
},
604+
codemirror: {
605+
files: {
606+
[ WORKING_DIR + 'wp-includes/js/codemirror/codemirror.min.css' ]: [
607+
'node_modules/codemirror/lib/codemirror.css',
608+
'node_modules/codemirror/addon/hint/show-hint.css',
609+
'node_modules/codemirror/addon/lint/lint.css',
610+
'node_modules/codemirror/addon/dialog/dialog.css',
611+
'node_modules/codemirror/addon/display/fullscreen.css',
612+
'node_modules/codemirror/addon/fold/foldgutter.css',
613+
'node_modules/codemirror/addon/merge/merge.css',
614+
'node_modules/codemirror/addon/scroll/simplescrollbars.css',
615+
'node_modules/codemirror/addon/search/matchesonscrollbar.css',
616+
'node_modules/codemirror/addon/tern/tern.css'
617+
]
618+
}
619+
},
565620
core: {
566621
expand: true,
567622
cwd: WORKING_DIR,
@@ -921,7 +976,8 @@ module.exports = function(grunt) {
921976
webpack: {
922977
prod: webpackConfig( { environment: 'production', buildTarget: WORKING_DIR } ),
923978
dev: webpackConfig( { environment: 'development', buildTarget: WORKING_DIR } ),
924-
watch: webpackConfig( { environment: 'development', watch: true } )
979+
watch: webpackConfig( { environment: 'development', watch: true } ),
980+
codemirror: require( './tools/webpack/codemirror.config.js' )( { buildTarget: WORKING_DIR } ),
925981
},
926982
concat: {
927983
tinymce: {
@@ -1652,6 +1708,13 @@ module.exports = function(grunt) {
16521708
'uglify:moment'
16531709
] );
16541710

1711+
grunt.registerTask( 'build:codemirror', [
1712+
'webpack:codemirror',
1713+
'cssmin:codemirror',
1714+
'usebanner:codemirror',
1715+
'copy:codemirror'
1716+
] );
1717+
16551718
grunt.registerTask( 'build:webpack', [
16561719
'clean:webpack-assets',
16571720
'webpack:prod',
@@ -1679,7 +1742,7 @@ module.exports = function(grunt) {
16791742
'cssmin:rtl',
16801743
'cssmin:colors',
16811744
'cssmin:themes',
1682-
'usebanner'
1745+
'usebanner:files'
16831746
] );
16841747

16851748
grunt.registerTask( 'certificates:upgrade-package', 'Upgrades the package responsible for supplying the certificate authority certificate store bundled with WordPress.', function() {
@@ -1902,6 +1965,7 @@ module.exports = function(grunt) {
19021965
grunt.task.run( [
19031966
'build:js',
19041967
'build:css',
1968+
'build:codemirror',
19051969
'gutenberg-sync',
19061970
'gutenberg-copy',
19071971
'copy-vendor-scripts',
@@ -1913,6 +1977,7 @@ module.exports = function(grunt) {
19131977
'build:files',
19141978
'build:js',
19151979
'build:css',
1980+
'build:codemirror',
19161981
'gutenberg-sync',
19171982
'gutenberg-copy',
19181983
'copy-vendor-scripts',

0 commit comments

Comments
 (0)