Skip to content

Commit 2fb47e4

Browse files
Build Tools: Restore license headers for CodeMirror JS and CSS.
Adds the required license header to the minified CodeMirror bundles during the build process. - Updates tools/webpack/codemirror.config.js to include the license header using BannerPlugin and ensures Terser preserves important comments. - Adds a usebanner:codemirror task to Gruntfile.js to append the license header to the minified CSS. - Dynamically retrieves the CodeMirror version from package.json for inclusion in the header. - Reformats the license headers to use multi-line backtick string literals for better maintainability. Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent ac581bc commit 2fb47e4

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

Gruntfile.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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' );
67

78
module.exports = function(grunt) {
9+
var pkg = grunt.file.readJSON( 'package.json' );
810
var path = require('path'),
911
fs = require( 'fs' ),
1012
glob = require( 'glob' ),
@@ -173,7 +175,27 @@ module.exports = function(grunt) {
173175
options: {
174176
position: 'top',
175177
banner: BANNER_TEXT,
176-
linebreak: true
178+
linebreak: false
179+
},
180+
codemirror: {
181+
options: {
182+
banner: `/*! This file is auto-generated from CodeMirror - v${ pkg.dependencies.codemirror }\n` +
183+
`\n` +
184+
`CodeMirror, copyright (c) by Marijn Haverbeke and others\n` +
185+
`Distributed under an MIT license: http://codemirror.net/LICENSE\n` +
186+
`\n` +
187+
`This is CodeMirror (http://codemirror.net), a code editor\n` +
188+
`implemented in JavaScript on top of the browser's DOM.\n` +
189+
`\n` +
190+
`You can find some technical background for some of the code below\n` +
191+
`at http://marijnhaverbeke.nl/blog/#cm-internals .\n` +
192+
`*/`
193+
},
194+
files: {
195+
src: [
196+
WORKING_DIR + 'wp-includes/js/codemirror/codemirror.min.css'
197+
]
198+
}
177199
},
178200
files: {
179201
src: [
@@ -1705,6 +1727,7 @@ module.exports = function(grunt) {
17051727
'webpack:codemirror',
17061728
'concat:codemirror',
17071729
'cssmin:codemirror',
1730+
'usebanner:codemirror',
17081731
'copy:codemirror'
17091732
] );
17101733

tools/webpack/codemirror.config.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const path = require( 'path' );
2+
const webpack = require( 'webpack' );
23
const TerserPlugin = require( 'terser-webpack-plugin' );
4+
const pkg = require( '../../package.json' );
35

46
const config = {
57
mode: 'production',
@@ -14,13 +16,30 @@ const config = {
1416
new TerserPlugin( {
1517
terserOptions: {
1618
format: {
17-
comments: false,
19+
comments: /^\!/,
1820
},
1921
},
2022
extractComments: false,
2123
} ),
2224
],
2325
},
26+
plugins: [
27+
new webpack.BannerPlugin( {
28+
banner: `/*! This file is auto-generated from CodeMirror - v${ pkg.dependencies.codemirror }\n` +
29+
`\n` +
30+
`CodeMirror, copyright (c) by Marijn Haverbeke and others\n` +
31+
`Distributed under an MIT license: http://codemirror.net/LICENSE\n` +
32+
`\n` +
33+
`This is CodeMirror (http://codemirror.net), a code editor\n` +
34+
`implemented in JavaScript on top of the browser's DOM.\n` +
35+
`\n` +
36+
`You can find some technical background for some of the code below\n` +
37+
`at http://marijnhaverbeke.nl/blog/#cm-internals .\n` +
38+
`*/\n`,
39+
raw: true,
40+
entryOnly: true,
41+
} ),
42+
],
2443
};
2544

2645
module.exports = config;

0 commit comments

Comments
 (0)