Skip to content

Commit

Permalink
issue/3208 Correct bad libraries/ imports (#3209)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Jul 26, 2021
1 parent c0e308f commit b5989a1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions grunt/config/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ module.exports = function(grunt, options) {
'<%= sourcedir %>menu/*/templates/**/*.jsx',
'<%= sourcedir %>theme/*/templates/**/*.jsx'
],
externalMap: {
'.*/libraries/(?!mediaelement-fullscreen-hook)+': 'libraries/'
},
external: {
jquery: 'empty:',
underscore: 'empty:',
Expand Down Expand Up @@ -95,6 +98,9 @@ module.exports = function(grunt, options) {
'<%= sourcedir %>menu/*/templates/**/*.jsx',
'<%= sourcedir %>theme/*/templates/**/*.jsx'
],
externalMap: {
'.*/libraries/(?!mediaelement-fullscreen-hook)+': 'libraries/'
},
external: {
jquery: 'empty:',
underscore: 'empty:',
Expand Down
4 changes: 4 additions & 0 deletions grunt/tasks/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ module.exports = function(grunt) {
// Process remapping and external model configurations
const mapParts = Object.keys(options.map);
const externalParts = Object.keys(options.external);
const externalMap = options.externalMap;

const findFile = function(filename) {
filename = filename.replace(convertSlashes, '/');
Expand Down Expand Up @@ -194,6 +195,8 @@ module.exports = function(grunt) {
// Remap module, usually coreJS/adapt to core/js/adapt etc
moduleId = moduleId.replace(mapPart, options.map[mapPart]);
}
// Remap ../libraries/ or core/js/libraries/ to libraries/
moduleId = Object.entries(externalMap).reduce((moduleId, [ match, replaceWith ]) => moduleId.replace((new RegExp(match, 'g')), replaceWith), moduleId);
const isRelative = (moduleId[0] === '.');
if (isRelative) {
if (!parentId) {
Expand Down Expand Up @@ -307,6 +310,7 @@ module.exports = function(grunt) {
[
'transform-amd-to-es6',
{
umdToAMDModules: true,
amdToES6Modules: true,
amdDefineES6Modules: true,
ignoreNestedRequires: true,
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@types/backbone": "^1.4.1",
"@types/jquery": "^3.3.31",
"async": "^3.1.1",
"babel-plugin-transform-amd-to-es6": "^0.5.4",
"babel-plugin-transform-amd-to-es6": "^0.6.1",
"babel-plugin-transform-react-templates": "^0.1.0",
"chalk": "^2.4.1",
"columnify": "^1.5.4",
Expand Down

0 comments on commit b5989a1

Please sign in to comment.