-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill missing std lib fns for module browsers (#17083)
- Loading branch information
Showing
7 changed files
with
121 additions
and
29 deletions.
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@next/polyfill-module", | ||
"version": "9.5.4-canary.16", | ||
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)", | ||
"main": "dist/polyfill-module.js", | ||
"license": "MIT", | ||
"repository": { | ||
"url": "vercel/next.js", | ||
"directory": "packages/next-polyfill-module" | ||
}, | ||
"scripts": { | ||
"prepublish": "microbundle src/index.js -f iife --no-sourcemap --external none", | ||
"build": "microbundle watch src/index.js -f iife --no-sourcemap --external none" | ||
}, | ||
"devDependencies": { | ||
"microbundle": "0.11.0" | ||
} | ||
} |
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,94 @@ | ||
/* eslint-disable no-extend-native */ | ||
|
||
// Contains polyfills for methods missing after browser version(s): | ||
// Edge 16, Firefox 60, Chrome 61, Safari 10.1 | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 61 | ||
* Chrome: 66 | ||
* Safari: 12 | ||
* | ||
* https://caniuse.com/mdn-javascript_builtins_string_trimstart | ||
* https://caniuse.com/mdn-javascript_builtins_string_trimend | ||
*/ | ||
if (!('trimStart' in String.prototype)) { | ||
String.prototype.trimStart = String.prototype.trimLeft | ||
} | ||
if (!('trimEnd' in String.prototype)) { | ||
String.prototype.trimEnd = String.prototype.trimRight | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 63 | ||
* Chrome: 70 | ||
* Safari: 12.1 | ||
* | ||
* https://caniuse.com/mdn-javascript_builtins_symbol_description | ||
*/ | ||
if (!('description' in Symbol.prototype)) { | ||
Object.defineProperty(Symbol.prototype, 'description', { | ||
get: function get() { | ||
return /\((.+)\)/.exec(this)[1] | ||
}, | ||
}) | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: never | ||
* Firefox: 62 | ||
* Chrome: 69 | ||
* Safari: 12 | ||
* | ||
* https://caniuse.com/array-flat | ||
*/ | ||
// Copied from https://gist.github.com/developit/50364079cf0390a73e745e513fa912d9 | ||
// Licensed Apache-2.0 | ||
if (!Array.prototype.flat) { | ||
Array.prototype.flat = function flat(d, c) { | ||
return ( | ||
(c = this.concat.apply([], this)), | ||
d > 1 && c.some(Array.isArray) ? c.flat(d - 1) : c | ||
) | ||
} | ||
Array.prototype.flatMap = function (c, a) { | ||
return this.map(c, a).flat() | ||
} | ||
} | ||
|
||
/** | ||
* Available in: | ||
* Edge: 18 | ||
* Firefox: 58 | ||
* Chrome: 63 | ||
* Safari: 11.1 | ||
* | ||
* https://caniuse.com/promise-finally | ||
*/ | ||
// Modified from https://gist.github.com/developit/e96097d9b657f2a2f3e588ffde433437 | ||
// Licensed Apache-2.0 | ||
if (!Promise.prototype.finally) { | ||
Promise.prototype.finally = function (callback) { | ||
if (typeof callback !== 'function') { | ||
return this.then(callback, callback) | ||
} | ||
|
||
var P = this.constructor || Promise | ||
return this.then( | ||
function (value) { | ||
return P.resolve(callback()).then(function () { | ||
return value | ||
}) | ||
}, | ||
function (err) { | ||
return P.resolve(callback()).then(function () { | ||
throw err | ||
}) | ||
} | ||
) | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -7545,11 +7545,6 @@ finalhandler@~1.1.2: | |
statuses "~1.5.0" | ||
unpipe "~1.0.0" | ||
|
||
[email protected]: | ||
version "0.1.0" | ||
resolved "https://registry.yarnpkg.com/finally-polyfill/-/finally-polyfill-0.1.0.tgz#2a17b16581d9477db16a703c7b79a898ac0b7d50" | ||
integrity sha512-J1LEcZ5VXe1l3sEO+S//WqL5wcJ/ep7QeKJA6HhNZrcEEFj0eyC8IW3DEZhxySI2bx3r85dwAXz+vYPGuHx5UA== | ||
|
||
[email protected], find-cache-dir@^3.0.0, find-cache-dir@^3.3.1: | ||
version "3.3.1" | ||
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880" | ||
|
By any chance, do you know why this file uses the
export
syntax, even though it's a Node script? It seems to work in most cases, but I don't understand why, and it breaks under a specific config of mine .. is there a magic live transpile somewhere 🤔