Skip to content

Commit

Permalink
MDL-66192 javascript: Allow subdirs in AMD module names
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 25, 2019
1 parent f622ee9 commit 9ea892d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
}
},
{
files: ["**/amd/src/*.js"],
files: ["**/amd/src/*.js", "**/amd/src/**/*.js"],
// We support es6 now. Woot!
env: {
es6: true
Expand Down
9 changes: 8 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lib/classes/requirejs.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ public static function find_all_amd_modules($debug = false, $includelazy = false
// 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;
Expand Down
5 changes: 0 additions & 5 deletions lib/jssourcemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
// 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);
Expand Down
5 changes: 0 additions & 5 deletions lib/requirejs.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@
$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".
Expand Down
11 changes: 11 additions & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ information provided here is intended especially for developers.
at least a single checkbox item is selected or not.
* Final deprecation (removal) of the core/modal_confirm dialogue.
* Upgrade scssphp to v1.0.2, This involves renaming classes from Leafo => ScssPhp as the repo has changed.
* 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 ===

Expand Down

0 comments on commit 9ea892d

Please sign in to comment.