From f84949f98d37ccfd4b28b131ca77eaf8ff30c030 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 24 Oct 2023 10:19:51 +0100 Subject: [PATCH] Add Babel polyfill provider ES shims Rollup will log a warning for code requiring polyfills: > (!) Unresolved dependencies > https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency > error-cause/Error (imported by "src/govuk/errors/index.mjs") Babel will also log a warning: > Some polyfills have been added but are not present in your dependencies. > > Please run one of the following commands: > npm install --save error-cause@^1.0.1 > yarn add error-cause@^1.0.1 See ES shims on GitHub: https://github.com/es-shims --- package-lock.json | 13 +++++++++++++ packages/govuk-frontend/babel.config.js | 14 ++++++++++++++ packages/govuk-frontend/package.json | 1 + 3 files changed, 28 insertions(+) diff --git a/package-lock.json b/package-lock.json index 048aaa8201..bedec78ed9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6427,6 +6427,18 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-polyfill-es-shims": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-es-shims/-/babel-plugin-polyfill-es-shims-0.10.0.tgz", + "integrity": "sha512-+wJQdSNHoLrEbCUIzyMXEZd55EyBOqRdMB2JtBMgk9rXpBYdorcW2JT/KXYhbKNYR3bZ6rYvD7ciF42juwZdQA==", + "dev": true, + "dependencies": { + "@babel/helper-define-polyfill-provider": "^0.4.3" + }, + "peerDependencies": { + "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" + } + }, "node_modules/babel-plugin-polyfill-regenerator": { "version": "0.5.3", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.5.3.tgz", @@ -30358,6 +30370,7 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", "autoprefixer": "^10.4.16", + "babel-plugin-polyfill-es-shims": "^0.10.0", "cssnano": "^6.0.1", "cssnano-preset-default": "^6.0.1", "govuk-prototype-kit": "^13.13.6", diff --git a/packages/govuk-frontend/babel.config.js b/packages/govuk-frontend/babel.config.js index a8d26f7e95..37f484e5c1 100644 --- a/packages/govuk-frontend/babel.config.js +++ b/packages/govuk-frontend/babel.config.js @@ -5,6 +5,7 @@ */ module.exports = function (api) { const isBrowser = !api.env('test') + const isProduction = !api.env('development') // Apply Browserslist environment for supported targets // https://github.com/browserslist/browserslist#configuring-for-different-environments @@ -33,6 +34,19 @@ module.exports = function (api) { return !isPrivate && isDocumentation } }, + plugins: [ + [ + 'polyfill-es-shims', + { + // Add logging for required polyfills + debug: isProduction, + + // Replace unsupported code with polyfills + // without modifying window globals + method: 'usage-pure' + } + ] + ], presets: [ [ '@babel/preset-env', diff --git a/packages/govuk-frontend/package.json b/packages/govuk-frontend/package.json index e7d67d6f74..bbdeda3d98 100644 --- a/packages/govuk-frontend/package.json +++ b/packages/govuk-frontend/package.json @@ -73,6 +73,7 @@ "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", "autoprefixer": "^10.4.16", + "babel-plugin-polyfill-es-shims": "^0.10.0", "cssnano": "^6.0.1", "cssnano-preset-default": "^6.0.1", "govuk-prototype-kit": "^13.13.6",