@polyfill-io-aot/builder
Version:
This is the builder module for polyfill-io-aot.
60 lines • 2.48 kB
JavaScript
;
const common_1 = require("@polyfill-io-aot/common");
const md5Hash_1 = require("@polyfill-io-aot/common/src/fns/md5Hash");
const reducePolyfills_1 = require("@polyfill-io-aot/common/src/fns/reducePolyfills");
const Bluebird = require("bluebird");
const Executor_1 = require("../Executor");
const BuildEvent_1 = require("../interfaces/BuildEvent");
const symbols_1 = require("../symbols");
/** @internal */
class GeneratePolyfillCombinations extends Executor_1.Executor {
execute() {
this._ora.start('Generating polyfill combinations');
const outMap = new Map();
const features = reducePolyfills_1.reducePolyfills(this.conf.polyfills, this.conf.flags || []);
const hashes = [];
const uaMap = {};
this.emit(BuildEvent_1.BuildEvent.GENERATE_COMBO_ALL_BEGIN);
Bluebird
.map(this.builder[symbols_1.USERAGENTS], (uaString) => {
return this.map(uaString, features, hashes, outMap, uaMap);
})
.then(() => {
this.builder[symbols_1.COMBO_HASHES] = hashes;
this.builder[symbols_1.COMBO_MAP] = outMap;
this.builder[symbols_1.COMBO_HASH_UA_MAP] = uaMap;
})
.then(() => {
this._ora.succeed('Generated polyfill combinations');
this.emit(BuildEvent_1.BuildEvent.GENERATE_COMBO_ALL_OK);
}, (e) => {
this._ora.fail(`Error generating polyfill combinations: ${this.formatError(e)}`);
this.onError(e);
});
}
map(uaString, features, hashes, outMap, uaMap) {
this.emit(BuildEvent_1.BuildEvent.GENERATE_COMBO_UA_BEGIN, uaString);
const p$ = common_1.getPolyfills({
excludes: this.conf.excludes,
features,
uaString
});
return p$
.then((obj) => {
const hash = md5Hash_1.md5Object(obj);
if (!outMap.has(hash)) {
outMap.set(hash, obj);
hashes.push(hash);
uaMap[hash] = uaString;
}
this._ora.text = `Generated combinations for ${uaString}`;
this.emit(BuildEvent_1.BuildEvent.GENERATE_COMBO_UA_OK, uaString);
})
.catch((e) => {
this.emit(BuildEvent_1.BuildEvent.GENERATE_COMBO_UA_ERR, uaString, e);
throw e;
});
}
}
module.exports = GeneratePolyfillCombinations;
//# sourceMappingURL=GeneratePolyfillCombinations.js.map