|
| 1 | +export function isInitialOrHasNoParents(chunk) { |
| 2 | + return chunk.isInitial() || chunk.parents.length === 0; |
| 3 | +} |
| 4 | + |
| 5 | +export function isInvalidOrder(a, b) { |
| 6 | + const bBeforeA = a.getPrevModules().includes(b); |
| 7 | + const aBeforeB = b.getPrevModules().includes(a); |
| 8 | + return aBeforeB && bBeforeA; |
| 9 | +} |
| 10 | + |
| 11 | +export function getOrder(a, b) { |
| 12 | + const aOrder = a.getOrder(); |
| 13 | + const bOrder = b.getOrder(); |
| 14 | + if (aOrder < bOrder) return -1; |
| 15 | + if (aOrder > bOrder) return 1; |
| 16 | + const aIndex = a.getOriginalModule().index2; |
| 17 | + const bIndex = b.getOriginalModule().index2; |
| 18 | + if (aIndex < bIndex) return -1; |
| 19 | + if (aIndex > bIndex) return 1; |
| 20 | + const bBeforeA = a.getPrevModules().includes(b); |
| 21 | + const aBeforeB = b.getPrevModules().includes(a); |
| 22 | + if (aBeforeB && !bBeforeA) return -1; |
| 23 | + if (!aBeforeB && bBeforeA) return 1; |
| 24 | + const ai = a.identifier(); |
| 25 | + const bi = b.identifier(); |
| 26 | + if (ai < bi) return -1; |
| 27 | + if (ai > bi) return 1; |
| 28 | + return 0; |
| 29 | +} |
| 30 | + |
| 31 | +export function getLoaderObject(loader) { |
| 32 | + if (isString(loader)) { |
| 33 | + return { loader }; |
| 34 | + } |
| 35 | + return loader; |
| 36 | +} |
| 37 | + |
| 38 | +export function mergeOptions(a, b) { |
| 39 | + if (!b) return a; |
| 40 | + Object.keys(b).forEach((key) => { |
| 41 | + a[key] = b[key]; |
| 42 | + }); |
| 43 | + return a; |
| 44 | +} |
| 45 | + |
| 46 | +export function isString(a) { |
| 47 | + return typeof a === 'string'; |
| 48 | +} |
| 49 | + |
| 50 | +export function isFunction(a) { |
| 51 | + return isType('Function', a); |
| 52 | +} |
| 53 | + |
| 54 | +export function isType(type, obj) { |
| 55 | + return Object.prototype.toString.call(obj) === `[object ${type}]`; |
| 56 | +} |
0 commit comments