diff --git a/.eslintrc b/.eslintrc index 8020549c6fd..23887170377 100644 --- a/.eslintrc +++ b/.eslintrc @@ -204,7 +204,7 @@ } }, { - files: ["**/amd/src/*.js"], + files: ["**/amd/src/*.js", "**/amd/src/**/*.js"], // We support es6 now. Woot! env: { es6: true diff --git a/Gruntfile.js b/Gruntfile.js index 765a5a2aad2..771bed1f101 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -64,7 +64,14 @@ module.exports = function(grunt) { var inAMD = path.basename(cwd) == 'amd'; // Globbing pattern for matching all AMD JS source files. - var amdSrc = [inAMD ? cwd + '/src/*.js' : '**/amd/src/*.js']; + var amdSrc = []; + if (inAMD) { + amdSrc.push(cwd + "/src/*.js"); + amdSrc.push(cwd + "/src/**/*.js"); + } else { + amdSrc.push("**/amd/src/*.js"); + amdSrc.push("**/amd/src/**/*.js"); + } /** * Function to generate the destination for the uglify task diff --git a/lib/classes/requirejs.php b/lib/classes/requirejs.php index 934b52a9df5..4f45dacb071 100644 --- a/lib/classes/requirejs.php +++ b/lib/classes/requirejs.php @@ -114,11 +114,14 @@ class core_requirejs { // Skip it - RecursiveDirectoryIterator fatals if the directory is not readable as an iterator. continue; } - $items = new RecursiveDirectoryIterator($srcdir); + $srcdir = realpath($srcdir); + $directory = new RecursiveDirectoryIterator($srcdir); + $items = new RecursiveIteratorIterator($directory); foreach ($items as $item) { $extension = $item->getExtension(); if ($extension === 'js') { - $filename = str_replace('.min', '', $item->getBaseName('.js')); + $filename = substr($item->getRealpath(), strlen($srcdir) + 1); + $filename = str_replace('.min', '', $filename); // We skip lazy loaded modules unless specifically requested. if ($includelazy || strpos($filename, '-lazy') === false) { $modulename = $component . '/' . $filename; diff --git a/lib/jssourcemap.php b/lib/jssourcemap.php index 3a1c0d59c0a..a39a451b64c 100644 --- a/lib/jssourcemap.php +++ b/lib/jssourcemap.php @@ -44,11 +44,6 @@ $file = '/' . min_clean_param($file, 'SAFEPATH'); // Only load js files from the js modules folder from the components. [$unused, $component, $module] = explode('/', $file, 3); -// No subdirs allowed - only flat module structure please. -if (strpos('/', $module) !== false) { - die('Invalid module'); -} - // 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); $jsfile = reset($jsfiles); diff --git a/lib/requirejs.php b/lib/requirejs.php index 047fa3f8824..49c0db77c46 100644 --- a/lib/requirejs.php +++ b/lib/requirejs.php @@ -52,11 +52,6 @@ $file = '/' . min_clean_param($file, 'SAFEPATH'); $jsfiles = array(); list($unused, $component, $module) = explode('/', $file, 3); -// No subdirs allowed - only flat module structure please. -if (strpos('/', $module) !== false) { - die('Invalid module'); -} - // Use the caching only for meaningful revision numbers which prevents future cache poisoning. if ($rev > 0 and $rev < (time() + 60 * 60)) { // This is "production mode". diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 4c55269eb64..c4aa0a3ffed 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -26,6 +26,17 @@ information provided here is intended especially for developers. are now public. If you are overriding these then you will need to change your methods to public in your class. * $CFG->httpswwwroot has been removed. It is no longer necessary as loginhttps has already been removed and it's no longer being used anywhere in core. +* It is now possible to use sub-directories for AMD modules. + The standard rules for Level 2 namespaces also apply to AMD modules. + The sub-directory used must be either an valid component, or placed inside a 'local' directory to ensure that it does not conflict with other components. + + The following are all valid module names and locations in your plugin: + mod_forum/view: mod/forum/amd/src/view.js + mod_forum/local/views/post: mod/forum/amd/src/local/views/post + mod_forum/form/checkbox-toggle: mod/forum/amd/src/form/checkbox-toggle.js + + The following are all invalid module names and locations in your plugin: + mod_forum/views/post: mod/forum/amd/src/views/post === 3.7 ===