UNPKG

@modern-js/utils

Version:

A Progressive React Framework for modern web development.

76 lines (75 loc) 2.85 kB
"use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { pluginDagSort: ()=>pluginDagSort }); const pluginDagSort = (plugins, key = 'name', preKey = 'pre', postKey = 'post')=>{ let allLines = []; function getPluginByAny(q) { const target = plugins.find((item)=>'string' == typeof q ? item[key] === q : item[key] === q[key]); if (!target) throw new Error(`plugin ${q} not existed`); return target; } plugins.forEach((item)=>{ item[preKey]?.forEach((p)=>{ if (plugins.find((ap)=>ap.name === p)) allLines.push([ getPluginByAny(p)[key], getPluginByAny(item)[key] ]); }); item[postKey]?.forEach((pt)=>{ if (plugins.find((ap)=>ap.name === pt)) allLines.push([ getPluginByAny(item)[key], getPluginByAny(pt)[key] ]); }); }); let zeroEndPoints = plugins.filter((item)=>!allLines.find((l)=>l[1] === item[key])); const sortedPoint = []; while(zeroEndPoints.length){ const zep = zeroEndPoints.shift(); sortedPoint.push(getPluginByAny(zep)); allLines = allLines.filter((l)=>l[0] !== getPluginByAny(zep)[key]); const restPoints = plugins.filter((item)=>!sortedPoint.find((sp)=>sp[key] === item[key])); zeroEndPoints = restPoints.filter((item)=>!allLines.find((l)=>l[1] === item[key])); } if (allLines.length) { const restInRingPoints = {}; allLines.forEach((l)=>{ restInRingPoints[l[0]] = true; restInRingPoints[l[1]] = true; }); throw new Error(`plugins dependencies has loop: ${Object.keys(restInRingPoints).join(',')}`); } return sortedPoint; }; exports.pluginDagSort = __webpack_exports__.pluginDagSort; for(var __rspack_i in __webpack_exports__)if (-1 === [ "pluginDagSort" ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i]; Object.defineProperty(exports, '__esModule', { value: true });