You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check for a yui/src directory when running the Grunt YUI task
This commit solves an issue in some repositories where the following
message is shown:
Unable to find local grunt
This message is a little confusing because the Grunt uses both a global,
and a local copy of the Grunt executable. The global variant comes from
the `npm install grunt-cli` Installation task, whilst the local variant
is a dependency of Moodle.
The message actually occurs when the global executable is unable to find
the local variant from the current working directory.
To give an example, given the following directory:
/home/travis/build/moodle/local/chatlogs/yui/src
Grunt will check each of the parent directories until it finds a
`Gruntfile.js` and/or relevant `node_modules/.bin/grunt` executable, i.e.:
/home/travis/build/moodle/local/chatlogs/yui/src
/home/travis/build/moodle/local/chatlogs/yui
/home/travis/build/moodle/local/chatlogs
/home/travis/build/moodle/local
/home/travis/build/moodle
/home/travis/build
/home/travis
/home
/
If none is found then the "Unable to find local grunt" message is then
shown.
In the issue where this fault was detected, the plugin does have a `yui`
directory, but it uses the legacy module structure where the YUI module
is placed directly into the directory, and not within a Shifted module
structure. That is to say that the following is the actual directory
structure of the plugin:
```
└── yui
├── jabberaliases
│ └── jabberaliases.js
└── keyboard
└── keyboard.js
```
This is a perfectly valid YUI structure, but Grunt is unaware of it, and
its use has not been recommended for many years. There is no `src`
directory present, and each module is just in it's own directory outside
of the src structure.
The Grunt Command was configured to perform the following when
processing a `yui` task:
```
case 'yui':
$yuiDir = $this->plugin->directory.'/yui';
if (!is_dir($yuiDir)) {
return null;
}
return new GruntTaskModel($task, $yuiDir.'/src', 'yui/build');
```
Essentially it assumes that if the `yui` directory exists then the task
should pass a workingDirectory for `yui/src`.
In this case there is no yui/src directory, but the full path is passed
as a working directory to the `ProcessBuilder`. The ProcessBuilder does
not care that the directory does not exist (presumably because it may
not exist during build, but may do prior to execution), but the result
is that `grunt` is called with a non-existent working directory.
It is not possible to traverse anywhere where the working directory does
not exist, and so the local Grunt cannot be found.
The solution here is to always look for `yui/src` within the plugin
directory.
Grunt is not aware of the older-style directories and does not perform
any checks on those so there is no loss of functionality.
Fixes#45
0 commit comments