UNPKG

@beyond-js/bundles-sdk

Version:
42 lines (35 loc) 1.05 kB
const DynamicProcessor = require('@beyond-js/dynamic-processor')(); const equal = require('@beyond-js/equal'); const crc32 = require('@beyond-js/crc32'); module.exports = class extends DynamicProcessor { get dp() { return 'bundler.transversal.packager.hash'; } // The transversal packager #value; get value() { return this.#value; } /** * Transversal packager hash constructor * * @param packagers {object} The packagers of the modules and libraries of the application */ constructor(packagers) { super(); super.setup(new Map([['packagers', { child: packagers }]])); } _prepared(require) { const packagers = this.children.get('packagers').child; packagers.forEach(packager => require(packager.hash)); } _process() { const packagers = this.children.get('packagers').child; const hashes = {}; packagers.forEach((packager, path) => (hashes[path] = packager.hash.value)); const value = crc32(equal.generate(hashes)); const changed = value !== this.#value; this.#value = value; return changed; } };