-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract dedicated polyfill package #6060
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
30085fe
Extract dedicated polyfill package
aduth 1c437db
Restore test env auto-initialize exclusion
aduth 45f9eeb
Fix webauthn-setup specs
aduth c375c10
Fix ScriptHelper spec
aduth f02d7d2
Exclude URLSearchParams polyfill, document
aduth 2aab4c0
changelog: Improvements, Optimization, Skip polyfill load behavior fo…
aduth d9dbfa9
Prevent preload header for polyfill pack
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
import { ClipboardButton } from '@18f/identity-clipboard-button'; | ||
|
||
loadPolyfills(['custom-elements', 'clipboard']) | ||
.then(() => import('@18f/identity-clipboard-button')) | ||
.then(({ ClipboardButton }) => customElements.define('lg-clipboard-button', ClipboardButton)); | ||
customElements.define('lg-clipboard-button', ClipboardButton); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
import { PhoneInput } from '@18f/identity-phone-input'; | ||
|
||
loadPolyfills(['custom-elements', 'classlist', 'custom-event']) | ||
.then(() => import('@18f/identity-phone-input')) | ||
.then(({ PhoneInput }) => customElements.define('lg-phone-input', PhoneInput)); | ||
customElements.define('lg-phone-input', PhoneInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
import { TimeElement } from '@18f/identity-time-element'; | ||
|
||
loadPolyfills(['custom-elements']) | ||
.then(() => import('@18f/identity-time-element')) | ||
.then(({ TimeElement }) => customElements.define('lg-time', TimeElement)); | ||
customElements.define('lg-time', TimeElement); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
import { ValidatedField } from '@18f/identity-validated-field'; | ||
|
||
loadPolyfills(['custom-elements', 'classlist']) | ||
.then(() => import('@18f/identity-validated-field')) | ||
.then(({ ValidatedField }) => customElements.define('lg-validated-field', ValidatedField)); | ||
customElements.define('lg-validated-field', ValidatedField); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,8 @@ | ||
import isSafe from './is-safe'; | ||
|
||
/** | ||
* @typedef Polyfill | ||
* | ||
* @prop {()=>boolean} test Test function, returning true if feature is detected as supported. | ||
* @prop {()=>Promise} load Function to load polyfill module. | ||
*/ | ||
|
||
/** | ||
* @typedef {"fetch"|"classlist"|"clipboard"|"crypto"|"custom-elements"|"custom-event"|"url"} SupportedPolyfills | ||
*/ | ||
|
||
/** | ||
* @type {Record<SupportedPolyfills,Polyfill>} | ||
*/ | ||
const POLYFILLS = { | ||
fetch: { | ||
test: () => 'fetch' in window, | ||
load: () => import(/* webpackChunkName: "whatwg-fetch" */ 'whatwg-fetch'), | ||
}, | ||
classlist: { | ||
test: () => 'classList' in Element.prototype, | ||
load: () => import(/* webpackChunkName: "classlist-polyfill" */ 'classlist-polyfill'), | ||
}, | ||
clipboard: { | ||
test: () => 'clipboard' in navigator, | ||
load: () => | ||
import(/* webpackChunkName: "clipboard-polyfill" */ 'clipboard-polyfill/overwrite-globals'), | ||
}, | ||
crypto: { | ||
test: () => 'crypto' in window, | ||
load: () => import(/* webpackChunkName: "webcrypto-shim" */ 'webcrypto-shim'), | ||
}, | ||
'custom-elements': { | ||
test: () => 'customElements' in window, | ||
load: () => | ||
import(/* webpackChunkName: "custom-elements-polyfill" */ '@webcomponents/custom-elements'), | ||
}, | ||
'custom-event': { | ||
test: () => isSafe(() => new window.CustomEvent('test')), | ||
load: () => import(/* webpackChunkName: "custom-event-polyfill" */ 'custom-event-polyfill'), | ||
}, | ||
url: { | ||
test: () => isSafe(() => new URL('http://example.com')) && isSafe(() => new URLSearchParams()), | ||
load: () => import(/* webpackChunkName: "js-polyfills-url" */ 'js-polyfills/url'), | ||
}, | ||
}; | ||
|
||
/** | ||
* Given an array of supported polyfill names, loads polyfill if necessary. Returns a promise which | ||
* resolves once all have been loaded. | ||
* | ||
* @param {SupportedPolyfills[]} polyfills Names of polyfills to load, if necessary. | ||
* | ||
* @return {Promise} | ||
*/ | ||
export function loadPolyfills(polyfills) { | ||
return Promise.all( | ||
polyfills.map((name) => { | ||
const { test, load } = POLYFILLS[name]; | ||
return test() ? Promise.resolve() : load(); | ||
}), | ||
); | ||
} | ||
import 'promise-polyfill/src/polyfill'; | ||
import 'whatwg-fetch'; | ||
import 'classlist-polyfill'; | ||
import 'clipboard-polyfill/overwrite-globals'; | ||
import 'webcrypto-shim'; | ||
import '@webcomponents/custom-elements'; | ||
import 'custom-event-polyfill'; | ||
import 'js-polyfills/url'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
import { DocumentCapturePolling } from '@18f/identity-document-capture-polling'; | ||
import { getPageData } from '@18f/identity-page-data'; | ||
|
||
loadPolyfills(['fetch', 'classlist']).then(() => { | ||
new DocumentCapturePolling({ | ||
statusEndpoint: /** @type {string} */ (getPageData('docCaptureStatusEndpoint')), | ||
elements: { | ||
backLink: /** @type {HTMLAnchorElement} */ (document.querySelector('.link-sent-back-link')), | ||
form: /** @type {HTMLFormElement} */ (document.querySelector( | ||
'.link-sent-continue-button-form', | ||
)), | ||
}, | ||
}).bind(); | ||
}); | ||
new DocumentCapturePolling({ | ||
statusEndpoint: /** @type {string} */ (getPageData('docCaptureStatusEndpoint')), | ||
elements: { | ||
backLink: /** @type {HTMLAnchorElement} */ (document.querySelector('.link-sent-back-link')), | ||
form: /** @type {HTMLFormElement} */ (document.querySelector( | ||
'.link-sent-continue-button-form', | ||
)), | ||
}, | ||
}).bind(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
import OneTimeCodeInput from '@18f/identity-one-time-code-input'; | ||
import { loadPolyfills } from '@18f/identity-polyfill'; | ||
|
||
const fakeField = /** @type {HTMLInputElement?} */ (document.querySelector('.one-time-code-input')); | ||
|
||
if (fakeField) { | ||
loadPolyfills(['custom-event']).then(() => new OneTimeCodeInput(fakeField).bind()); | ||
new OneTimeCodeInput(fakeField).bind(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@18f/identity-polyfill'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promises were only polyfilled previously because we use them in our own code, via
@babel/preset-env
'suseBuiltIns: 'usage'
option. By default, third-party packages are excluded from Babel transforms. Since some of the polyfills themselves rely on thePromise
polyfill (fetch
,webcrypto-shim
), it needs to be explicitly included.