inital #2
This commit is contained in:
39
out/polyfill.js
Normal file
39
out/polyfill.js
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Polyfill = void 0;
|
||||
const polyfillLibrary = require("polyfill-library");
|
||||
const _1 = require(".");
|
||||
const threads_1 = require("threads");
|
||||
const features = new _1.WaitForSync();
|
||||
(() => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const worker = yield threads_1.spawn(new threads_1.Worker("./polyfill-worker"));
|
||||
const feats = yield worker();
|
||||
yield threads_1.Thread.terminate(worker);
|
||||
return feats;
|
||||
}))()
|
||||
.then(feats => {
|
||||
feats["fetch"] = {};
|
||||
_1.Logger.debug("Polyfill analysed:", Object.keys(feats));
|
||||
features.setData(feats);
|
||||
})
|
||||
.catch(err => features.setError(err));
|
||||
function getRouter(opts) {
|
||||
const options = Object.assign({ minify: _1.DefaultConfig.isProduction, unknown: "polyfill" }, opts);
|
||||
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
||||
const polyfillBundle = yield polyfillLibrary.getPolyfillString(Object.assign(Object.assign({}, options), { uaString: req.header("user-agent"), features: yield features.resolve(), stream: false }));
|
||||
res.setHeader('Content-Type', 'text/javascript');
|
||||
res.send(polyfillBundle);
|
||||
});
|
||||
}
|
||||
exports.Polyfill = {
|
||||
getRouter: getRouter,
|
||||
};
|
||||
Reference in New Issue
Block a user