How do I change the dependencies of a library from another module I have a Drupal 8 module with the following section in the file flot_d8.libraries.yml

flot:
  version: 1.x
  css:
    component:
      css/flot.css: {}
  js:
    lib/jquery.flot.js: {}
    js/flot_d8.js: {}
  dependencies:
    - core/jquery
    - core/drupalSettings


I have another module which is an optional dependency of flot. It does not need to be present, but if it is, it needs to be included in the dependencies section. So I need to add the line - timezone_js/timezone_js at the end...or, more likely, add the equivalent entry to the array that this yml file gets converted into.

Is there a way that one module can alter the assets of another module when it is installed?

I seems like I ~could~ just hard-code the line in myself, but I would like other people to be able to extend the flot module, without me having to add new dependency lines for every add-in.

Similarly, the Flot module has an element with a #pre_render function. Is there a way that a module can add an entry to the pre_render array of another module?
My flot plugin is called timezone_js. I created a file, timezone_js.module and added a call to hook_library_info_alter.

function timezone_js_library_info_alter(&amp;$libraries,$extension){
  //We need to add this module as a dependency of the flot module.
  if ($extension == "flot_d8") {
    $libraries['flot']['dependencies'][] = 'timezone_js/timezone_js';
  }
}