createPlugin.js 961 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "default", {
  6. enumerable: true,
  7. get: function() {
  8. return _default;
  9. }
  10. });
  11. function createPlugin(plugin, config) {
  12. return {
  13. handler: plugin,
  14. config
  15. };
  16. }
  17. createPlugin.withOptions = function(pluginFunction, configFunction = ()=>({})) {
  18. const optionsFunction = function(options) {
  19. return {
  20. __options: options,
  21. handler: pluginFunction(options),
  22. config: configFunction(options)
  23. };
  24. };
  25. optionsFunction.__isOptionsFunction = true;
  26. // Expose plugin dependencies so that `object-hash` returns a different
  27. // value if anything here changes, to ensure a rebuild is triggered.
  28. optionsFunction.__pluginFunction = pluginFunction;
  29. optionsFunction.__configFunction = configFunction;
  30. return optionsFunction;
  31. };
  32. const _default = createPlugin;