Made polyfill route more flexible
This commit is contained in:
@@ -5,14 +5,14 @@ import {analyze} from '@10xjs/polyfill-analyzer';
|
||||
import allPolyfills from '@10xjs/polyfill-analyzer/dist/polyfills';
|
||||
import {PolyfillFeatureList} from 'polyfill-library';
|
||||
|
||||
expose(() => {
|
||||
expose((fileToWatch) => {
|
||||
const exclude = [
|
||||
"console.markTimeline",
|
||||
"console.timeline",
|
||||
"console.timelineEnd",
|
||||
];
|
||||
const featureList = analyze({
|
||||
source: fs.readFileSync('./public/js/bundle.js', 'utf-8'),
|
||||
source: fs.readFileSync(fileToWatch, 'utf-8'),
|
||||
include: allPolyfills.filter(x => !exclude.includes(x)),
|
||||
// Not all features listed by polyfillLibrary.listAllPolyfills()` can be detected.
|
||||
unsupportedPolyfill: 'ignore',
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user