UNPKG

@agnostack/next-plugins

Version:

Please contact agnoStack via info@agnostack.com for any questions

58 lines 2.56 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withPlugins = void 0; const deepmerge_1 = __importDefault(require("deepmerge")); const env_1 = require("@agnostack/env"); const utils_1 = require("./utils"); const withPlugins = async (nextPhase, _a) => { var { defaultConfig, nextConfig, nextPlugins, env: nextEnv } = _a, nextProps = __rest(_a, ["defaultConfig", "nextConfig", "nextPlugins", "env"]); try { const chainedConfig = await (0, utils_1.ensureArray)(nextPlugins).reduce(async (_chainedConfigP, chained) => { const _chainedConfig = await _chainedConfigP; const { plugin, config } = (typeof chained === 'function') ? { plugin: chained } : chained; if (typeof plugin !== 'function') { return _chainedConfig; } try { // NOTE: some plugins are curried w/ second call containing nextPhase return plugin(nextPhase, Object.assign({ defaultConfig, nextConfig: _chainedConfig }, config)); } catch (error) { if (!(error instanceof TypeError)) { throw error; } return _chainedConfig; } }, Promise.resolve(nextConfig)); const env = deepmerge_1.default.all([ (0, utils_1.ensureObject)(defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.env), (0, env_1.cleanPublicEnv)(nextEnv), (0, env_1.cleanPublicEnv)(chainedConfig.env) ]); return Object.assign(Object.assign({}, deepmerge_1.default.all([ defaultConfig, chainedConfig, nextProps ])), { env }); } catch (error) { console.error('Error executing withPlugins', error); throw error; } }; exports.withPlugins = withPlugins; //# sourceMappingURL=withPlugins.js.map