@webiny/plugins
Advanced tools
@@ -1,3 +0,3 @@ | ||
| import type { PluginCollection } from "./types"; | ||
| import { PluginsContainer } from "./types"; | ||
| import type { PluginCollection } from "./types.js"; | ||
| import { PluginsContainer } from "./types.js"; | ||
| export declare class AsyncPluginsContainer { | ||
@@ -4,0 +4,0 @@ private readonly plugins; |
@@ -1,14 +0,8 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.AsyncPluginsContainer = void 0; | ||
| var _types = require("./types"); | ||
| import { PluginsContainer } from "./types.js"; | ||
| const isPluginLoader = value => { | ||
| return typeof value === "function"; | ||
| }; | ||
| class AsyncPluginsContainer { | ||
| export class AsyncPluginsContainer { | ||
| constructor(plugins) { | ||
| this.plugins = plugins instanceof _types.PluginsContainer ? plugins.all() : plugins; | ||
| this.plugins = plugins instanceof PluginsContainer ? plugins.all() : plugins; | ||
| } | ||
@@ -20,3 +14,3 @@ async init() { | ||
| const plugins = await this.traverseAndLoadPlugins(this.plugins); | ||
| this.pluginsContainer = new _types.PluginsContainer(plugins); | ||
| this.pluginsContainer = new PluginsContainer(plugins); | ||
| return this.pluginsContainer; | ||
@@ -39,4 +33,3 @@ } | ||
| } | ||
| exports.AsyncPluginsContainer = AsyncPluginsContainer; | ||
| //# sourceMappingURL=AsyncPluginsContainer.js.map |
+3
-3
@@ -1,5 +0,5 @@ | ||
| import { PluginsContainer } from "./PluginsContainer"; | ||
| import { AsyncPluginsContainer } from "./AsyncPluginsContainer"; | ||
| import { Plugin } from "./Plugin"; | ||
| import { PluginsContainer } from "./PluginsContainer.js"; | ||
| import { AsyncPluginsContainer } from "./AsyncPluginsContainer.js"; | ||
| import { Plugin } from "./Plugin.js"; | ||
| declare const plugins: PluginsContainer; | ||
| export { Plugin, PluginsContainer, plugins, AsyncPluginsContainer }; |
+5
-28
@@ -1,30 +0,7 @@ | ||
| "use strict"; | ||
| import { PluginsContainer } from "./PluginsContainer.js"; | ||
| import { AsyncPluginsContainer } from "./AsyncPluginsContainer.js"; | ||
| import { Plugin } from "./Plugin.js"; | ||
| const plugins = new PluginsContainer(); | ||
| export { Plugin, PluginsContainer, plugins, AsyncPluginsContainer }; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "AsyncPluginsContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _AsyncPluginsContainer.AsyncPluginsContainer; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "Plugin", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _Plugin.Plugin; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "PluginsContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _PluginsContainer.PluginsContainer; | ||
| } | ||
| }); | ||
| exports.plugins = void 0; | ||
| var _PluginsContainer = require("./PluginsContainer"); | ||
| var _AsyncPluginsContainer = require("./AsyncPluginsContainer"); | ||
| var _Plugin = require("./Plugin"); | ||
| const plugins = exports.plugins = new _PluginsContainer.PluginsContainer(); | ||
| //# sourceMappingURL=index.js.map |
+8
-10
| { | ||
| "name": "@webiny/plugins", | ||
| "version": "0.0.0-unstable.e53eceafb5", | ||
| "version": "0.0.0-unstable.e622468070", | ||
| "type": "module", | ||
| "main": "index.js", | ||
@@ -19,6 +20,7 @@ "repository": { | ||
| "devDependencies": { | ||
| "@types/uniqid": "5.3.2", | ||
| "@webiny/project-utils": "0.0.0-unstable.e53eceafb5", | ||
| "rimraf": "6.0.1", | ||
| "typescript": "5.3.3" | ||
| "@types/uniqid": "5.3.4", | ||
| "@webiny/build-tools": "0.0.0-unstable.e622468070", | ||
| "rimraf": "6.1.2", | ||
| "typescript": "5.9.3", | ||
| "vitest": "3.2.4" | ||
| }, | ||
@@ -29,7 +31,3 @@ "publishConfig": { | ||
| }, | ||
| "scripts": { | ||
| "build": "node ../cli/bin.js run build", | ||
| "watch": "node ../cli/bin.js run watch" | ||
| }, | ||
| "gitHead": "e53eceafb5ce1a3872c9b4548939bb2eae5b1aef" | ||
| "gitHead": "e622468070839dc3f9552c85bf2bbac12d2ef88f" | ||
| } |
+1
-8
@@ -1,8 +0,2 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.Plugin = void 0; | ||
| class Plugin { | ||
| export class Plugin { | ||
| constructor() { | ||
@@ -17,4 +11,3 @@ if (!this.constructor.type) { | ||
| } | ||
| exports.Plugin = Plugin; | ||
| //# sourceMappingURL=Plugin.js.map |
@@ -1,2 +0,2 @@ | ||
| import type { Plugin, PluginCollection } from "./types"; | ||
| import type { Plugin, PluginCollection } from "./types.js"; | ||
| export type WithName<T extends Plugin> = T & { | ||
@@ -3,0 +3,0 @@ name: string; |
+3
-11
@@ -1,9 +0,2 @@ | ||
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.PluginsContainer = void 0; | ||
| var _uniqid = _interopRequireDefault(require("uniqid")); | ||
| import uniqid from "uniqid"; | ||
| const isOptionsObject = item => item && !Array.isArray(item) && !item.type && !item.name; | ||
@@ -37,3 +30,3 @@ const normalizeArgs = args => { | ||
| if (!name) { | ||
| plugin.name = name = (0, _uniqid.default)(plugin.type + "-"); | ||
| plugin.name = name = uniqid(plugin.type + "-"); | ||
| } | ||
@@ -48,3 +41,3 @@ | ||
| }; | ||
| class PluginsContainer { | ||
| export class PluginsContainer { | ||
| plugins = {}; | ||
@@ -114,4 +107,3 @@ _byTypeCache = {}; | ||
| } | ||
| exports.PluginsContainer = PluginsContainer; | ||
| //# sourceMappingURL=PluginsContainer.js.map |
+6
-69
| # @webiny/plugins | ||
| [](https://www.npmjs.com/package/@webiny/plugins) | ||
| [](https://www.npmjs.com/package/@webiny/plugins) | ||
| [](https://github.com/prettier/prettier) | ||
| [](http://makeapullrequest.com) | ||
| A simple registry that stores all plugins in a shared object. | ||
| The only requirement for a plugin is to have a `name` and a `type` properties. | ||
| The rest is entirely up to you. | ||
| > [!NOTE] | ||
| > This package is part of the [Webiny](https://www.webiny.com) monorepo. | ||
| > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package. | ||
| There is nothing spectacular going on under the hood, just a simple | ||
| object for storing references and a few utility functions. | ||
| 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs) | ||
| For more information, please visit [the official docs](https://docs.webiny.com/docs/developer-tutorials/plugins-crash-course). | ||
| ## Install | ||
| ``` | ||
| npm install --save @webiny/plugins | ||
| ``` | ||
| --- | ||
| Or if you prefer yarn: | ||
| ``` | ||
| yarn add @webiny/plugins | ||
| ``` | ||
| ## Usage | ||
| ### Adding a plugin | ||
| ``` | ||
| import { plugins } from "@webiny/plugins"; | ||
| // Add a plugin | ||
| plugins.register({ | ||
| name: "my-plugin", | ||
| type: "say-hi", | ||
| salute: () => "Hi!" | ||
| }); | ||
| plugins.register({ | ||
| name: "my-second-plugin", | ||
| type: "say-hi", | ||
| salute: () => "Yo!" | ||
| }); | ||
| ``` | ||
| ### Getting plugins by type | ||
| ``` | ||
| // anywhere in your app | ||
| import { plugins } from "@webiny/plugins"; | ||
| const pluginList = plugins.byType("say-hi"); | ||
| pluginList.forEach(plugin => { | ||
| // Call "salute" function | ||
| plugin.salute(); | ||
| }); | ||
| ``` | ||
| ### Getting a single plugin by name | ||
| ``` | ||
| // anywhere in your app | ||
| import { plugins } from "@webiny/plugins"; | ||
| const plugin = plugins.byName("my-plugin"); | ||
| // Call "salute" function | ||
| plugin.salute(); | ||
| ``` | ||
| ### Removing a plugin | ||
| ``` | ||
| // anywhere in your app | ||
| import { plugins } from "@webiny/plugins"; | ||
| plugins.unregister("my-plugin"); | ||
| ``` | ||
| _This README file is automatically generated during the publish process._ |
+1
-1
@@ -1,2 +0,2 @@ | ||
| export { PluginsContainer } from "./PluginsContainer"; | ||
| export { PluginsContainer } from "./PluginsContainer.js"; | ||
| export type Plugin<T = Record<string, any>> = { | ||
@@ -3,0 +3,0 @@ type: string; |
+1
-12
@@ -1,14 +0,3 @@ | ||
| "use strict"; | ||
| export { PluginsContainer } from "./PluginsContainer.js"; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| Object.defineProperty(exports, "PluginsContainer", { | ||
| enumerable: true, | ||
| get: function () { | ||
| return _PluginsContainer.PluginsContainer; | ||
| } | ||
| }); | ||
| var _PluginsContainer = require("./PluginsContainer"); | ||
| //# sourceMappingURL=types.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Yes
NaN21560
-12.83%5
25%197
-20.56%11
-85.33%