Skip to content

Commit

Permalink
MDL-77559 js: Revert "MDL-75012 js: Drop support for modules built pr…
Browse files Browse the repository at this point in the history
…e-babel"

This reverts commit 84c6504.
  • Loading branch information
andrewnicols committed Mar 9, 2023
1 parent 103892b commit dde8111
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
28 changes: 17 additions & 11 deletions lib/requirejs.php
Expand Up @@ -104,12 +104,13 @@
$js = rtrim($js);
$js .= "\n";

if (!preg_match('/define\(\s*["\']/', $js)) {
$shortfilename = str_replace($CFG->dirroot, '', $jsfile);
error_log(
"JS file: '{$shortfilename}' cannot be loaded, or does not contain a javascript" .
' module in AMD format. "define()" not found.'
);
if (preg_match('/define\(\s*(\[|function)/', $js)) {
// If the JavaScript module has been defined without specifying a name then we'll
// add the Moodle module name now.
$replace = 'define(\'' . $modulename . '\', ';
$search = 'define(';
// Replace only the first occurrence.
$js = implode($replace, explode($search, $js, 2));
}

$content .= $js;
Expand Down Expand Up @@ -156,11 +157,16 @@
$js = rtrim($js);
}

if (!preg_match('/define\(\s*["\']/', $js)) {
error_log(
"JS file: '{$shortfilename}' cannot be loaded, or does not contain a javascript" .
' module in AMD format. "define()" not found.'
);
if (preg_match('/define\(\s*(\[|function)/', $js)) {
// If the JavaScript module has been defined without specifying a name then we'll
// add the Moodle module name now.
$replace = 'define(\'' . $modulename . '\', ';

// Replace only the first occurrence.
$js = implode($replace, explode('define(', $js, 2));
} else if (!preg_match('/define\s*\(/', $js)) {
debugging('JS file: ' . $shortfilename . ' cannot be loaded, or does not contain a javascript' .
' module in AMD format. "define()" not found.', DEBUG_DEVELOPER);
}

js_send_uncached($js, 'requirejs.php');
Expand Down
5 changes: 0 additions & 5 deletions lib/upgrade.txt
Expand Up @@ -75,14 +75,9 @@ information provided here is intended especially for developers.
* The core/modal module and all their versions (SAVE_CANCEL, DELETE_CANCEL...) now has a setButtonDisable to disable or enable
specific modal action buttons. This function allows developers to have modals that could only be submited if the user do some
action in the modal body like ticking a checkbox or selecting an element.
<<<<<<< HEAD
* Course module indentation has been recovered for course format using components via Move right/left feature.
Course formats using components will be allowed to use one level indentation only.
* The method `flexible_table::set_columnsattributes` now can be used with 'class' key to add custom classes to the DOM.
=======
* Support for serving of AMD modules built in really old versions of Moodle (<= 3.8) has been removed.
Please ensure that your AMD modules have been rebuilt with a supported Moodle version.
>>>>>>> 33b1e41f137ebbdf63f771e8424f7dcc81a5cee8

=== 4.1 ===

Expand Down

0 comments on commit dde8111

Please sign in to comment.