Made polyfill route more flexible

This commit is contained in:
Sebastian Seedorf
2020-11-16 13:11:15 +01:00
parent 110e6f74e8
commit 99527fdb49
5 changed files with 32 additions and 34 deletions

View File

@@ -19,23 +19,21 @@ export type PolyfillOptions = {
rum: boolean,
}
const features = new WaitForSync<PolyfillFeatureList>();
function getRouter(fileToWatch: string, opts?: Partial<PolyfillOptions>): RequestHandler {
const features = new WaitForSync<PolyfillFeatureList>();
(async () => {
const worker = await spawn<WorkerFunction>(new Worker("./polyfill-worker"));
const feats = await worker(fileToWatch) as PolyfillFeatureList;
await Thread.terminate(worker);
return feats;
})()
.then(feats => {
feats["fetch"] = {};
Logger.debug("Polyfill analysed:", Object.keys(feats));
features.setData(feats);
})
.catch(err => features.setError(err));
(async () => {
const worker = await spawn<WorkerFunction>(new Worker("./polyfill-worker"));
const feats = await worker() as PolyfillFeatureList;
await Thread.terminate(worker);
return feats;
})()
.then(feats => {
feats["fetch"] = {};
Logger.debug("Polyfill analysed:", Object.keys(feats));
features.setData(feats);
})
.catch(err => features.setError(err));
function getRouter(opts?: Partial<PolyfillOptions>): RequestHandler {
const options: Partial<PolyfillOptions> = {
minify: DefaultConfig.isProduction,
unknown: "polyfill",