Bug scripts.php grunt-wp-version

Hi

Like Roots - done some customisation (converted to use SASS rather than LESS) - getting on OK.

In lib/scripts.php I added an array of dependencies for the ‘roots_scripts’ script handle:

wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', array('handlebars', 'date_lib'), '82f41f90eb1b58bdd7333ebb15bfe473', true);

Problem comes when I update any of the js scripts which are being watched by grunt task. The RegExp in grunt-wp-verion/tasks/version.js mangles the function call in scripts.php and removes the dependencies array. I tried to alter the js RegExp pattern but I’m not clever enough. So, following from Stephen Harris on Add a script as a dependency to a registered script - WordPress Development Stack Exchange

First add:

global $wp_scripts

at the start of the roots_scripts function declaration:

function roots_scripts() {
  global $wp_scripts;

After the wp_register_script call:

wp_register_script('roots_scripts', get_template_directory_uri() . '/assets/js/scripts.min.js', false, '82f41f90eb1b58bdd7333ebb15bfe473', true);

I added this code:

$js_dependencies = array('handlebars', 'date_lib');
$script = $wp_scripts->query( 'roots_scripts', 'registered' );
foreach($js_dependencies as $dep)
  {
  	$script->deps[] = $dep;
  }

Which effectively adds the dependencies after the version has has been updated.

Hope it helps someone.

Best wishes

Mike Jones