scmJS docs

Libraries from other plugins

A plugin can provide a library of its own: TrigScript modules a script imports by the library's name, as it imports the standard library by trigscript/…. import { spawnWave } from "waves/spawn" is the module spawn of the library waves, and import { spawnWave } from "waves" is its index. While the plugin is on, the editor completes the library's names, and hovering one shows the library's own source and comments.

import { announce, spawnWave } from "waves";

program(() => {
  for (let wave = 1; wave <= 5; wave++) {
    announce(`Wave ${wave}`);
    spawnWave(P2, units.ZergZergling, wave, locations.Spawn);
    sleep(seconds(20));
  }
});

The map keeps its own copy. When the script is applied, which saving does, each library the script imports is copied into the map beside the script's files, and from then on the map builds with that copy. So a map opened where the plugin is not installed still builds, and so does a map shared with someone who has another version of the plugin. A library the script stops importing leaves the map at the next apply.

A newer version is offered, not taken. When the installed plugin has a different version of a library from the map's copy, the editor says so and offers Update, which replaces the copy. Keep the map's copy leaves it as it is.

A library is TrigScript, like the script's own files, and runs with the same rights: a library in someone else's map is no different from that map's own script. A module joins the build only when something imports it.

Making a library for your own maps is a plugin of your own that provides the modules. How is in the TrigScript plugin's README, and Plugins covers writing a plugin.