@devsnicket/plugin-discovery-create-repository

1.5.1 • Public • Published

Plug-in Discovery

Build Status Gitter chat

DevSnicket Plug-in Discovery consists of a JavaScript repository object and a Babel plug-in that when used together can invert dependencies between modules and turn them into discovered plug-ins.

before after

Currently only CommonJS modules are supported (e.g. not ECMAScript ones).

Plug-in and repository files/modules in packages are supported (see "Forwarder lookup" in @devsnicket/plugin-discovery-commonjs-babel-plugin).

Create repository factory function / package

NPM

Install using npm:

npm install @devsnicket/plugin-discovery-create-repository

Or with yarn:

yarn add @devsnicket/plugin-discovery-create-repository

The create repository package contains a factory function. When this function is called and the return repository object is exported a plug-in contract is defined (in this example "someSortOfPlugins").

// someSortOfPlugins.js
module.exports =
	require("@devsnicket/plugin-discovery-create-repository")
	();

This can then be plugged into by objects/functions etc from other files.

// plugin1.js
require("./someSortOfPlugins")
.plugin("plug-in number 1");

The plug-ins can then be iterated and used from other files.

// consoleLogPlugins.js
for (const plugin require("./someSortOfPlugins"))
	console.log(plugin);
// output:
// plug-in number 1

The code above alone won't work as there isn't a module require call to import the 2nd plug-in file from the 3rd file that iterates the plug-ins. The purpose of the repository object is so plug-ins can be identified by the @devsnicket/plugin-discovery-commonjs-babel-plugin package as it will automatically add the missing module require calls.

Example

An example of Plug-in Discovery in use can be found in Eunice. A plug-in repository is defined for its test harnesses (Harnesses/processorPlugins.js) so processors can be discovered and included automatically.

Package Sidebar

Install

npm i @devsnicket/plugin-discovery-create-repository

Weekly Downloads

1

Version

1.5.1

License

MIT

Unpacked Size

4.68 kB

Total Files

3

Last publish

Collaborators

  • devsnicket