@beyond-js/bundles-sdk
Version:
BeyondJS Bundles SDK
79 lines (63 loc) • 1.56 kB
JavaScript
const DynamicProcessor = require('@beyond-js/dynamic-processor')();
/**
* Processor declaration generator
*/
module.exports = class extends DynamicProcessor {
get dp() {
return 'packager.declaration';
}
#packager;
get packager() {
return this.#packager;
}
get id() {
return this.#packager.processor.id;
}
get hash() {
return this.#packager.processor.hash;
}
get compiler() {
return this.#packager.compiler;
}
#diagnostics;
get diagnostics() {
return this.#diagnostics;
}
get valid() {
return this.#diagnostics.valid;
}
#code;
get code() {
return this.#code;
}
constructor(packager) {
super();
this.#packager = packager;
// The txt bundle depends on the js code to generate the declaration.
// The ts bundle, on the other hand, uses the declarations of the source files generated by the compiler.
// As the dp (dynamic processor) that generates the code has the compiler as a child,
// configuring the code dp works for both cases.
super.setup(new Map([['code', { child: packager.js }]]));
}
_build() {
throw new Error('Method must be overridden');
}
/**
* The declaration is synchronized when the compiler is synchronized.
* @return {boolean}
*/
get synchronized() {
return this.update;
}
get update() {
return this.compiler.synchronized;
}
_process() {
if (!this.compiler.valid) {
this.#diagnostics = this.compiler.diagnostics;
return;
}
const diagnostics = (this.#diagnostics = new (require('./diagnostics'))());
this.#code = this._build(diagnostics);
}
};