@beyond-js/bundles-sdk
Version:
BeyondJS Bundles SDK
62 lines (52 loc) • 1.77 kB
JavaScript
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 'processor.extender.extension.hashes';
}
get extension() {
return this.children.get('extension').child;
}
constructor(extension) {
super();
super.setup(new Map([['extension', { child: extension }]]));
}
/**
* The root hash is required to avoid invalid compilations due to race conditions
* Ex: svelte extends ts and sass, then ts or sass are takes different times to compiled
* once the svelte preprocessed code has been changed.
* Finally, the svelte compiler must check that the ts and sass compilations are synchronized
* with the root hash to assure that they are both related with the last svelte preprocessed code
*/
get root() {
return this.
}
get synchronized() {
const { preprocessor } = this.extension;
return preprocessor.synchronized && this.
}
/**
* The hash calculated from the preprocessed code of the current extension
*/
get sources() {
if (this.
const compute = { files: {}, overwrites: {} };
const { extension } = this;
let sources;
if (extension.valid) {
extension.files.forEach((source, file) => (compute.files[file] = source.hashes.preprocessed));
extension.overwrites.forEach((source, file) => (compute.overwrites[file] = source.hashes.preprocessed));
sources = crc32(equal.generate(compute));
} else {
sources = 0;
}
return (this.
}
_process() {
this.
this.
}
};