From cf03ae99ea0459bba469ff8f26aa42803b9a5efb Mon Sep 17 00:00:00 2001 From: Christopher Blanchard Date: Wed, 10 Feb 2021 19:55:19 +0000 Subject: [PATCH] feat(Bundle): Scope ie11 polyfills Don't allow polyfils to affect global scope --- package-lock.json | 57 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 ++++- rollup.config.js | 47 +++++++++++++++++++------------------- 3 files changed, 85 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1f1d796..5cfdf72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,9 +20,11 @@ "@open-wc/karma-esm": "~4.0.0", "@rollup/plugin-babel": "~5.2.2", "@rollup/plugin-commonjs": "~17.1.0", + "@rollup/plugin-inject": "^4.0.2", "@rollup/plugin-node-resolve": "~11.1.0", "@types/mocha": "~8.2.0", "core-js": "~3.8.2", + "core-js-pure": "^3.8.3", "cypress": "~6.4.0", "dotenv": "~8.2.0", "http-server": "~0.12.3", @@ -34,6 +36,7 @@ "karma-typescript": "~5.2.0", "mocha": "~8.2.1", "prettier": "~2.2.1", + "promise-polyfill": "^8.2.0", "puppeteer": "~7.0.4", "rollup": "~2.38.5", "rollup-plugin-terser": "~7.0.2", @@ -3740,6 +3743,20 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, + "node_modules/@rollup/plugin-inject": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-4.0.2.tgz", + "integrity": "sha512-TSLMA8waJ7Dmgmoc8JfPnwUwVZgLjjIAM6MqeIFqPO2ODK36JqE0Cf2F54UTgCUuW8da93Mvoj75a6KAVWgylw==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^3.0.4", + "estree-walker": "^1.0.1", + "magic-string": "^0.25.5" + }, + "peerDependencies": { + "rollup": "^1.20.0 || ^2.0.0" + } + }, "node_modules/@rollup/plugin-node-resolve": { "version": "11.1.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.1.1.tgz", @@ -6859,6 +6876,17 @@ "semver": "bin/semver.js" } }, + "node_modules/core-js-pure": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.8.3.tgz", + "integrity": "sha512-V5qQZVAr9K0xu7jXg1M7qTEwuxUgqr7dUOezGaNa7i+Xn9oXAU/d1fzqD9ObuwpVQOaorO5s70ckyi1woP9lVA==", + "dev": true, + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -19089,6 +19117,12 @@ "node": ">=0.4.0" } }, + "node_modules/promise-polyfill": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-8.2.0.tgz", + "integrity": "sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g==", + "dev": true + }, "node_modules/proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", @@ -26576,6 +26610,17 @@ } } }, + "@rollup/plugin-inject": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-4.0.2.tgz", + "integrity": "sha512-TSLMA8waJ7Dmgmoc8JfPnwUwVZgLjjIAM6MqeIFqPO2ODK36JqE0Cf2F54UTgCUuW8da93Mvoj75a6KAVWgylw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.4", + "estree-walker": "^1.0.1", + "magic-string": "^0.25.5" + } + }, "@rollup/plugin-node-resolve": { "version": "11.1.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.1.1.tgz", @@ -29272,6 +29317,12 @@ } } }, + "core-js-pure": { + "version": "3.8.3", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.8.3.tgz", + "integrity": "sha512-V5qQZVAr9K0xu7jXg1M7qTEwuxUgqr7dUOezGaNa7i+Xn9oXAU/d1fzqD9ObuwpVQOaorO5s70ckyi1woP9lVA==", + "dev": true + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -38986,6 +39037,12 @@ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, + "promise-polyfill": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-8.2.0.tgz", + "integrity": "sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g==", + "dev": true + }, "proto-list": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", diff --git a/package.json b/package.json index 108f603..df8bf93 100644 --- a/package.json +++ b/package.json @@ -68,9 +68,11 @@ "@open-wc/karma-esm": "~4.0.0", "@rollup/plugin-babel": "~5.2.2", "@rollup/plugin-commonjs": "~17.1.0", + "@rollup/plugin-inject": "~4.0.2", "@rollup/plugin-node-resolve": "~11.1.0", "@types/mocha": "~8.2.0", "core-js": "~3.8.2", + "core-js-pure": "~3.8.3", "cypress": "~6.4.0", "dotenv": "~8.2.0", "http-server": "~0.12.3", @@ -82,11 +84,12 @@ "karma-typescript": "~5.2.0", "mocha": "~8.2.1", "prettier": "~2.2.1", + "promise-polyfill": "~8.2.0", "puppeteer": "~7.0.4", "rollup": "~2.38.5", "rollup-plugin-terser": "~7.0.2", "semantic-release": "~17.3.1", - "size-limit": "^4.9.2", + "size-limit": "~4.9.2", "ts-node": "~9.1.1", "typescript": "~4.1.3" }, diff --git a/rollup.config.js b/rollup.config.js index 8b11212..ea377a7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,14 @@ -import "core-js"; import babel from "@rollup/plugin-babel"; import { terser } from "rollup-plugin-terser"; import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; +import inject from "@rollup/plugin-inject"; + +export const polyfills = { + Promise: "promise-polyfill", + Set: "core-js-pure/features/set", + "Object.assign": "core-js-pure/features/object/assign", +}; import { version, dependencies, license } from "./package.json"; @@ -39,7 +45,8 @@ const include = [ "node_modules/@ideal-postcodes/core-interface/esm/**", "node_modules/@ideal-postcodes/jsutil/esm/**", "node_modules/capitalise-post-town/dist/**", - "node_modules/lodash-es/debounce.js", + "node_modules/lodash/debounce.js", + "node_modules/core-js-pure/**/*", ]; const context = "window"; @@ -58,11 +65,16 @@ export default [ exports: "named", }, plugins: [ - resolve({ browser: true }), + resolve({ + preferBuiltins: true, + dedupe: ["@ideal-postcodes/jsutil"], + mainFields: ["browser", "module", "main"], + browser: true, + }), commonjs(), + inject(polyfills), babel({ babelrc: false, - ignore: [/core-js/], include, sourceMap, babelHelpers, @@ -76,10 +88,6 @@ export default [ chrome: "61", safari: "11", }, - modules: false, - spec: true, - useBuiltIns: "usage", - corejs: 3, }, ], ], @@ -102,28 +110,21 @@ export default [ exports: "named", }, plugins: [ - resolve({ browser: true }), + resolve({ + preferBuiltins: true, + dedupe: ["@ideal-postcodes/jsutil"], + mainFields: ["browser", "module", "main"], + browser: true, + }), commonjs(), + inject(polyfills), babel({ babelrc: false, ignore: [/core-js/], include, babelHelpers, sourceMap, - presets: [ - [ - "@babel/preset-env", - { - targets: { - ie: "11", - }, - modules: false, - spec: true, - useBuiltIns: "usage", - corejs: 3, - }, - ], - ], + presets: [["@babel/preset-env", { targets: { ie: "11" } }]], }), terser(terserConfig), ],