UNPKG

@modern-js/server-core

Version:

A Progressive React Framework for modern web development.

71 lines (70 loc) 1.85 kB
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array"; function getHookRunners(context) { var hooks = context.hooks; return { config: function(params) { return hooks.modifyConfig.call(params); }, prepare: function() { return hooks.onPrepare.call(); }, reset: function(params) { return hooks.onReset.call(params); }, fallback: function(input) { return hooks.fallback.call(input); }, prepareWebServer: function(input) { return hooks.prepareWebServer.call(input); }, prepareApiServer: function(input) { return hooks.prepareApiServer.call(input); }, afterMatch: function(ctx) { return hooks.afterMatch.call(ctx); }, afterRender: function(ctx) { return hooks.afterRender.call(ctx); }, afterStreamingRender: function(ctx) { return hooks.afterStreamingRender.call(ctx); } }; } function transformHookRunner(hookRunnerName) { switch (hookRunnerName) { case "config": return "modifyConfig"; case "prepare": return "onPrepare"; case "reset": return "onReset"; default: return hookRunnerName; } } function handleSetupResult(setupResult, api) { if (!setupResult) { return; } Object.keys(setupResult).forEach(function(key) { var fn = setupResult[key]; if (typeof fn === "function") { var newAPI = transformHookRunner(key); if (api[newAPI]) { api[newAPI](function() { for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) { params[_key] = arguments[_key]; } var res = fn.apply(void 0, _to_consumable_array(params)); return res; }); } } }); } export { getHookRunners, handleSetupResult, transformHookRunner };