mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Merge branch 'MDL-73183-master' of https://github.com/andrewnicols/moodle
This commit is contained in:
commit
dac4af8e4c
@ -40,11 +40,11 @@ class core_requirejs {
|
||||
*
|
||||
* @param string $component The component determines the folder the js file should be in.
|
||||
* @param string $jsfilename The filename for the module (with the js extension).
|
||||
* @param boolean $debug If true, returns the paths to the original (unminified) source files.
|
||||
* @param bool $unused
|
||||
* @return array $files An array of mappings from module names to file paths.
|
||||
* Empty array if the file does not exist.
|
||||
*/
|
||||
public static function find_one_amd_module($component, $jsfilename, $debug = false) {
|
||||
public static function find_one_amd_module($component, $jsfilename, $unused = false) {
|
||||
$jsfileroot = core_component::get_component_directory($component);
|
||||
if (!$jsfileroot) {
|
||||
return array();
|
||||
@ -54,10 +54,6 @@ class core_requirejs {
|
||||
|
||||
$srcdir = $jsfileroot . '/amd/build';
|
||||
$minpart = '.min';
|
||||
if ($debug) {
|
||||
$srcdir = $jsfileroot . '/amd/src';
|
||||
$minpart = '';
|
||||
}
|
||||
|
||||
$filename = $srcdir . '/' . $module . $minpart . '.js';
|
||||
if (!file_exists($filename)) {
|
||||
@ -74,11 +70,11 @@ class core_requirejs {
|
||||
* The expected location for amd modules is:
|
||||
* <componentdir>/amd/src/modulename.js
|
||||
*
|
||||
* @param boolean $debug If true, returns the paths to the original (unminified) source files.
|
||||
* @param boolean $unused
|
||||
* @param boolean $includelazy If true, includes modules with the -lazy suffix.
|
||||
* @return array $files An array of mappings from module names to file paths.
|
||||
*/
|
||||
public static function find_all_amd_modules($debug = false, $includelazy = false) {
|
||||
public static function find_all_amd_modules($unused = false, $includelazy = false) {
|
||||
global $CFG;
|
||||
|
||||
$jsdirs = array();
|
||||
@ -106,9 +102,6 @@ class core_requirejs {
|
||||
|
||||
foreach ($jsdirs as $component => $dir) {
|
||||
$srcdir = $dir . '/build';
|
||||
if ($debug) {
|
||||
$srcdir = $dir . '/src';
|
||||
}
|
||||
if (!is_dir($srcdir) || !is_readable($srcdir)) {
|
||||
// This is probably an empty amd directory without src or build.
|
||||
// Skip it - RecursiveDirectoryIterator fatals if the directory is not readable as an iterator.
|
||||
|
@ -45,7 +45,7 @@ $file = '/' . min_clean_param($file, 'SAFEPATH');
|
||||
[$unused, $component, $module] = explode('/', $file, 3);
|
||||
|
||||
// When running a lazy load, we only deal with one file so we can just return the working sourcemap.
|
||||
$jsfiles = core_requirejs::find_one_amd_module($component, $module, false);
|
||||
$jsfiles = core_requirejs::find_one_amd_module($component, $module);
|
||||
$jsfile = reset($jsfiles);
|
||||
|
||||
$mapfile = $jsfile . '.map';
|
||||
|
@ -128,7 +128,7 @@ if ($rev > 0 and $rev < (time() + 60 * 60)) {
|
||||
|
||||
// If we've made it here then we're in "dev mode" where everything is lazy loaded.
|
||||
// So all files will be served one at a time.
|
||||
$jsfiles = core_requirejs::find_one_amd_module($component, $module, false);
|
||||
$jsfiles = core_requirejs::find_one_amd_module($component, $module);
|
||||
|
||||
if (!empty($jsfiles)) {
|
||||
$modulename = array_keys($jsfiles)[0];
|
||||
|
@ -42,42 +42,17 @@ class core_requirejs_testcase extends advanced_testcase {
|
||||
global $CFG;
|
||||
|
||||
// Find a core module.
|
||||
$result = core_requirejs::find_one_amd_module('core', 'templates', false);
|
||||
$result = core_requirejs::find_one_amd_module('core', 'templates');
|
||||
$expected = ['core/templates' => $CFG->dirroot . '/lib/amd/build/templates.min.js'];
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
$result = core_requirejs::find_one_amd_module('core', 'templates', true);
|
||||
$expected = ['core/templates' => $CFG->dirroot . '/lib/amd/src/templates.js'];
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
// Find a subsystem module (none exist yet).
|
||||
$result = core_requirejs::find_one_amd_module('core_group', 'doesnotexist', false);
|
||||
$result = core_requirejs::find_one_amd_module('core_group', 'doesnotexist');
|
||||
$expected = [];
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
// Find a plugin module.
|
||||
$result = core_requirejs::find_one_amd_module('mod_assign', 'grading_panel', true);
|
||||
$expected = ['mod_assign/grading_panel' => $CFG->dirroot . '/mod/assign/amd/src/grading_panel.js'];
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
// Find all modules - no debugging.
|
||||
$result = core_requirejs::find_all_amd_modules(true);
|
||||
foreach ($result as $key => $path) {
|
||||
// Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not.
|
||||
list($component, $template) = explode('/', $key, 2);
|
||||
// Can we resolve it to a valid dir?
|
||||
$dir = core_component::get_component_directory($component);
|
||||
$this->assertNotEmpty($dir);
|
||||
|
||||
// Only "core" is allowed to have no _ in component names.
|
||||
if (strpos($component, '_') === false) {
|
||||
$this->assertEquals('core', $component);
|
||||
}
|
||||
$this->assertStringNotContainsString('.min', $path);
|
||||
}
|
||||
|
||||
// Find all modules - debugging.
|
||||
$result = core_requirejs::find_all_amd_modules(false);
|
||||
// Find all modules.
|
||||
$result = core_requirejs::find_all_amd_modules();
|
||||
foreach ($result as $key => $path) {
|
||||
// Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not.
|
||||
list($component, $template) = explode('/', $key, 2);
|
||||
|
Loading…
x
Reference in New Issue
Block a user