npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@soundworks/plugin-scripting

v5.0.6

Published

soundworks plugin for managing and editing shared scripts at runtime

Downloads

581

Readme

soundworks | plugin scripting

npm version

soundworks plugin for runtime distributed scripting.

Table of Contents

Installation

npm install @soundworks/plugin-scripting --save

Usage

Server

// src/server/index.js
import { Server } from '@soundworks/core/server.js';
import ServerPluginScripting from '@soundworks/plugin-scripting/server.js';

const server = new Server(config);
// register the plugin with an optional dirname
server.pluginManager.register('scripting', ServerPluginScripting, {
  dirname: 'my-script',
});
await server.start();
// use the plugin once the server is started
const scripting = await server.pluginManager.get('scripting');

Given that there is a file my-constants.js in the watched my-script directory:

// my-script/my-constants.js
export const answer = 42;

Client

// src/client/**/index.js
import { Client } from '@soundworks/core/client.js';
import ClientPluginScripting from '@soundworks/plugin-scripting/client.js';

const client = new Client(config);
// register the plugin
client.pluginManager.register('scripting', ClientPluginScripting);
await client.start();
// use the plugin once the client is started
const scripting = await client.pluginManager.get('scripting');
const script = await scripting.attach('my-constants');
const mod = await script.import();
console.log(mod.answer);
// > 42

Notes

Where do the scripts live

The shared scripts are stored in the file system as raw Javascript files located in the directory defined on the server side configuration of the plugin (cf. dirname option).

This is the responsibility of the code consuming the shared scripts to define the API that the scripts should expose.

Limitations

The scripts are simple JavaScript modules that are re-bundled using esbuild each time their content is modified. As such, they can import installed dependencies (i.e. node_modules) or import other scripts. However, using such bundle leads to a restriction in Node.js clients, that can't import native addons directly (in such case you should inject the dependency into the script at runtime). This might change in the future as dynamic import/require of ES modules is more stable (cf. https://github.com/nodejs/help/issues/2751).

Creating / updating / deleting scripts

Internally the scripting plugin relies on the @soundworks/plugin-filesystem plugin, which should be use to make any modifications in the script directory:

// register and get the scripting plugin
server.pluginManager.register('scripting', ServerPluginScripting, { dirname: 'my-script' });
await server.start();
const scripting = await server.pluginManager.get('scripting');
// create a new script in the 'my-script' directory using the scripting related filesystem
const code = `export function add(a, b) { return a + b }`;
await scripting.filesystem.writeFile('add.js', code);

API

Table of Contents

ClientPluginScripting

Extends ClientPlugin

Client-side representation of the soundworks' scripting plugin.

The constructor should never be called manually. The plugin will be instantiated automatically when registered in the pluginManager

Parameters

  • client
  • id
  • options (optional, default {})

Examples

client.pluginManager.register('scripting', ClientPluginScripting, { dirname });

filesystem

Instance of the underlying filesystem plugin

getList

Returns the list of all available scripts.

Returns Array

getCollection

Return the SharedStateCollection of all the scripts underlying share states. Provided for build and error monitoring purposes. Can also be used to maintain a list of existing script, e.g. in a drop-down menu

If you want a full featured / executable Script instance, use the attach instead.

Returns Promise<SharedStateCollection>

setGlobalScriptingContext

Registers a global context object to be used in scripts. Note that the context is store globally, so several scripting plugins running in parallel will share the same underlying object. The global getGlobalScriptingContext function will allow to retrieve the given object from within scripts.

Parameters

  • ctx Object Object to store in global context

attach

Attach to a script.

Parameters

  • name string Name of the script

Returns Promise<SharedScript> Promise that resolves on a new Script instance.

ServerPluginScripting

Extends ServerPlugin

Server-side representation of the soundworks' scripting plugin.

The constructor should never be called manually. The plugin will be instantiated by soundworks when registered in the pluginManager

Available options:

  • dirname {String} - directory in which the script files are located

If no option is given, for example before a user selects a project, the plugin will stay idle until switch is called.

documentation

Examples

server.pluginManager.register('scripting', ServerPluginScripting, { dirname });

options

Type: object

Properties

  • dirname (string | null)? Path to the directory in which the script are located
  • verbose boolean?

filesystem

Instance of the underlying filesystem plugin.

getList

Returns the list of all available scripts.

Returns Array

getCollection

Return the SharedStateCollection of all the scripts underlying share states. Provided for build and error monitoring purposes. If you want a full featured Script instance, see attach instead.

Returns Promise<SharedStateCollection>

setGlobalScriptingContext

Registers a global context object to be used in scripts. Note that the context is store globally, so several scripting plugins running in parallel will share the same underlying object. The global getGlobalScriptingContext function will allow to retrieve the given object from within scripts.

Parameters

  • ctx Object Object to store in global context

onUpdate

Register callback to execute when a script is created or deleted.

Parameters

  • callback Function Callback function to execute
  • executeListener boolean If true, execute the given callback immediately. (optional, default false)

Returns Function Function that unregister the listener when executed.

switch

Switch the plugin to watch and use another directory

Parameters

  • dirname (String | Object) Path to the new directory. As a convenience to match the plugin filesystem API, an object containing the 'dirname' key can also be passed

attach

Attach to a script.

Parameters

  • name string Name of the script

Returns Promise<SharedScript> Promise that resolves on a new Script instance.

Development Notes

Credits

https://soundworks.dev/credits.html

License

BSD-3-Clause