diff --git a/packages/next/client/dev/amp-dev.js b/packages/next/client/dev/amp-dev.js index f46bcac4db562554ae56c89f1e44ab7e35ef27e1..5ad1fbf0543f7d71da5850d095af8057669dc819 100644 --- a/packages/next/client/dev/amp-dev.js +++ b/packages/next/client/dev/amp-dev.js @@ -1,5 +1,5 @@ /* globals __webpack_hash__ */ -import fetch from 'unfetch' +import fetch from 'next/dist/build/polyfills/unfetch' import EventSourcePolyfill from './event-source-polyfill' import { getEventSourceWrapper } from './error-overlay/eventsource' import { setupPing } from './on-demand-entries-utils' diff --git a/packages/next/client/dev/error-overlay/hot-dev-client.js b/packages/next/client/dev/error-overlay/hot-dev-client.js index 1a4b7dd432a43d0e7780bcc96c280666398f5355..09cbfbaf79924e1079ce670d5d64ff28359aed78 100644 --- a/packages/next/client/dev/error-overlay/hot-dev-client.js +++ b/packages/next/client/dev/error-overlay/hot-dev-client.js @@ -28,9 +28,9 @@ SOFTWARE. import { getEventSourceWrapper } from './eventsource' import formatWebpackMessages from './format-webpack-messages' import * as ErrorOverlay from 'react-error-overlay' -import stripAnsi from 'strip-ansi' +import stripAnsi from 'next/dist/compiled/strip-ansi' import { rewriteStacktrace } from './source-map-support' -import fetch from 'unfetch' +import fetch from 'next/dist/build/polyfills/unfetch' // This alternative WebpackDevServer combines the functionality of: // https://github.com/webpack/webpack-dev-server/blob/webpack-1/client/index.js diff --git a/packages/next/client/dev/event-source-polyfill.js b/packages/next/client/dev/event-source-polyfill.js index ac556236c815469c9c672a8e0b8a9ef2210217c4..6173a4004911b18cac1a0020520c0c5b027b4ba3 100644 --- a/packages/next/client/dev/event-source-polyfill.js +++ b/packages/next/client/dev/event-source-polyfill.js @@ -2,7 +2,7 @@ // Improved version of https://github.com/Yaffle/EventSource/ // Available under MIT License (MIT) // Only tries to support IE11 and nothing below -import fetch from 'unfetch' +import fetch from 'next/dist/build/polyfills/unfetch' var document = window.document var Response = window.Response diff --git a/packages/next/client/dev/on-demand-entries-utils.js b/packages/next/client/dev/on-demand-entries-utils.js index d2ca9bd76033cbec96e92cd619773fc01bb34d18..22f6f037df1c6701a9ea14d6a11a71c9cf48e5f1 100644 --- a/packages/next/client/dev/on-demand-entries-utils.js +++ b/packages/next/client/dev/on-demand-entries-utils.js @@ -1,6 +1,6 @@ /* global location */ -import fetch from 'unfetch' +import fetch from 'next/dist/build/polyfills/unfetch' import { getEventSourceWrapper } from './error-overlay/eventsource' let evtSource diff --git a/packages/next/client/index.js b/packages/next/client/index.js index 56f722114f77967a7419c3d5347ee13e8d3e19de..f1ac8ad697e041598f194c740e608d0a06ffaf02 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -21,7 +21,7 @@ import { if (!('finally' in Promise.prototype)) { // eslint-disable-next-line no-extend-native - Promise.prototype.finally = require('finally-polyfill') + Promise.prototype.finally = require('next/dist/build/polyfills/finally-polyfill.min') } const data = JSON.parse(document.getElementById('__NEXT_DATA__').textContent) diff --git a/packages/next/client/polyfills.js b/packages/next/client/polyfills.js index 5682d2a0577ab9f1c4dc17746c186287061f4b2b..6b8b07f6926307d2cc3fcb39f0d97a0644de0540 100644 --- a/packages/next/client/polyfills.js +++ b/packages/next/client/polyfills.js @@ -1 +1 @@ -import '@next/polyfill-nomodule' +import 'next/dist/build/polyfills/polyfill-nomodule' diff --git a/packages/next/package.json b/packages/next/package.json index 6381458fb9b6602ecc03126ececc2d090989e944..302b5a2f37e46571fba7decf91f7b4b4266b803d 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -59,13 +59,11 @@ "dependencies": { "@ampproject/toolbox-optimizer": "2.0.1", "@babel/runtime": "7.7.2", - "@next/polyfill-nomodule": "9.3.4-canary.0", "autodll-webpack-plugin": "0.4.2", "cache-loader": "4.1.0", "css-loader": "3.3.0", "cssnano-simple": "1.0.0", "file-loader": "4.2.0", - "finally-polyfill": "0.1.0", "fork-ts-checker-webpack-plugin": "3.1.1", "ignore-loader": "0.1.2", "jest-worker": "24.9.0", @@ -86,7 +84,6 @@ "style-loader": "1.0.0", "styled-jsx": "3.2.5", "thread-loader": "2.1.3", - "unfetch": "4.1.0", "url": "0.11.0", "use-subscription": "1.1.1", "watchpack": "2.0.0-beta.13", @@ -115,6 +112,7 @@ "@babel/preset-react": "7.7.0", "@babel/preset-typescript": "7.7.2", "@babel/types": "7.7.4", + "@next/polyfill-nomodule": "9.3.4-canary.0", "@taskr/clear": "1.1.0", "@taskr/esnext": "1.1.0", "@taskr/watch": "1.1.0", @@ -173,6 +171,7 @@ "dotenv-expand": "5.1.0", "escape-string-regexp": "2.0.0", "etag": "1.8.1", + "finally-polyfill": "0.1.0", "find-up": "4.0.0", "fresh": "0.5.2", "gzip-size": "5.1.1", @@ -198,6 +197,7 @@ "terser": "4.4.2", "text-table": "0.2.0", "typescript": "3.7.3", + "unfetch": "4.1.0", "unistore": "3.4.1" }, "engines": { diff --git a/packages/next/taskfile.js b/packages/next/taskfile.js index 2a8821e4d976167f30854f1f46b69e2e1640afa1..07e1949c4e61bc24723baa7e44324ad376a1404d 100644 --- a/packages/next/taskfile.js +++ b/packages/next/taskfile.js @@ -1,6 +1,37 @@ const notifier = require('node-notifier') const relative = require('path').relative +export async function next__polyfill_nomodule(task, opts) { + await task + .source( + opts.src || + relative(__dirname, require.resolve('@next/polyfill-nomodule')) + ) + .target('dist/build/polyfills') +} + +export async function finally_polyfill(task, opts) { + await task + .source( + opts.src || relative(__dirname, require.resolve('finally-polyfill')) + ) + .target('dist/build/polyfills') +} + +export async function unfetch(task, opts) { + await task + .source(opts.src || relative(__dirname, require.resolve('unfetch'))) + .target('dist/build/polyfills') +} + +export async function browser_polyfills(task) { + await task.parallel([ + 'next__polyfill_nomodule', + 'finally_polyfill', + 'unfetch', + ]) +} + const externals = { '@babel/core': 'next/dist/compiled/babel--core', '@babel/helper-plugin-utils': 'next/dist/compiled/babel--helper-plugin-utils', @@ -553,6 +584,7 @@ export async function ncc_unistore(task, opts) { export async function precompile(task) { await task.parallel([ + 'browser_polyfills', 'ncc_amphtml_validator', 'ncc_arg', 'ncc_async_retry',