🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

polyfills-loader

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyfills-loader - npm Package Compare versions

Comparing version

to
1.4.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.4.0](https://github.com/open-wc/open-wc/compare/polyfills-loader@1.3.1...polyfills-loader@1.4.0) (2020-03-08)
### Features
* **polyfills-loader:** add preload links ([23428e3](https://github.com/open-wc/open-wc/commit/23428e344154af6826e7db6a72f67533f3bd9511))
## [1.3.1](https://github.com/open-wc/open-wc/compare/polyfills-loader@1.3.0...polyfills-loader@1.3.1) (2020-03-06)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "polyfills-loader",
"version": "1.3.1",
"version": "1.4.0",
"publishConfig": {

@@ -54,3 +54,3 @@ "access": "public"

},
"gitHead": "d91e325385b15637e49b4231ab17972cf4e7555f"
"gitHead": "f58e5d4852e63244eeacc1f524894e18efac3915"
}
/** @typedef {import('parse5').Document} DocumentAst */
/** @typedef {import('./types').PolyfillsLoaderConfig} PolyfillsLoaderConfig */
/** @typedef {import('./types').PolyfillsLoader} PolyfillsLoader */
/** @typedef {import('./types').GeneratedFile} GeneratedFile */

@@ -14,3 +15,3 @@

} = require('@open-wc/building-utils/dom5-fork');
const { createScript, findImportMapScripts } = require('@open-wc/building-utils');
const { createScript, createElement, findImportMapScripts } = require('@open-wc/building-utils');
const { createPolyfillsLoader } = require('./create-polyfills-loader');

@@ -60,2 +61,35 @@ const { hasFileOfType, fileTypes } = require('./utils');

/**
* @param {*} bodyAst
* @param {PolyfillsLoader} polyfillsLoader
*/
function injectLoaderScript(bodyAst, polyfillsLoader) {
const loaderScript = createScript({}, polyfillsLoader.code);
append(bodyAst, loaderScript);
}
/**
* @param {any} headAst
* @param {PolyfillsLoaderConfig} cfg
*/
function injectPrefetchLinks(headAst, cfg) {
for (const file of cfg.modern.files) {
const { path } = file;
const href = path.startsWith('.') || path.startsWith('/') ? path : `./${path}`;
if ([fileTypes.MODULE, fileTypes.ES_MODULE_SHIMS].includes(file.type)) {
append(
headAst,
createElement('link', {
rel: 'preload',
href,
as: 'script',
crossorigin: 'anonymous',
}),
);
} else {
append(headAst, createElement('link', { rel: 'preload', href, as: 'script' }));
}
}
}
/**
* Transforms an index.html file, injecting a polyfills loader for

@@ -84,6 +118,7 @@ * compatibility with older browsers.

const loaderScript = createScript({}, polyfillsLoader.code);
append(bodyAst, loaderScript);
if (cfg.preload) {
injectPrefetchLinks(headAst, cfg);
}
injectImportMapPolyfills(documentAst, headAst, cfg);
injectLoaderScript(bodyAst, polyfillsLoader);

@@ -90,0 +125,0 @@ return {

@@ -17,2 +17,5 @@ export interface PolyfillsLoaderConfig {

minify?: boolean;
// whether to preload the modern entrypoint, best for performance
// defaults to true
preload?: boolean;
}

@@ -19,0 +22,0 @@