diff --git a/lib/esbuild.config.js b/lib/esbuild.config.js index 20725b3..e3c5f01 100644 --- a/lib/esbuild.config.js +++ b/lib/esbuild.config.js @@ -109,10 +109,12 @@ if (WATCH) { // Add Polyfills await build({ ...config, - entryPoints: [resolve(SRC, '../polyfills.js')], - format: 'cjs', + entryPoints: [resolve(SRC, 'polyfills.ts')], outfile: resolve(DIST, 'polyfills.js'), treeShaking: true, + target: [ + 'es5', + ] }); if (DEBUG) { diff --git a/lib/package.json b/lib/package.json index 8cef576..baea3df 100644 --- a/lib/package.json +++ b/lib/package.json @@ -12,7 +12,8 @@ "test:unit": "jest" }, "dependencies": { - "@sentry/browser": "^7.73.0" + "@sentry/browser": "^7.73.0", + "core-js": "^3.35.1" }, "devDependencies": { "@hcaptcha/types": "^1.0.3", diff --git a/lib/polyfills.js b/lib/polyfills.js deleted file mode 100644 index fde7522..0000000 --- a/lib/polyfills.js +++ /dev/null @@ -1,88 +0,0 @@ -// Polyfills for ES5 browser support - -if (!Object.entries) { - Object.entries = function (obj) { - if (obj == null) { - throw new TypeError('Object.entries called on null or undefined'); - } - - var entries = []; - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - entries.push([key, obj[key]]); - } - } - - return entries; - }; -} - -if (typeof Object.assign !== 'function') { - Object.assign = function (target) { - if (target == null) { - throw new TypeError('Cannot convert undefined or null to object'); - } - - target = Object(target); - - for (var index = 1; index < arguments.length; index++) { - var source = arguments[index]; - - if (source != null) { - for (var key in source) { - if (Object.prototype.hasOwnProperty.call(source, key)) { - target[key] = source[key]; - } - } - } - } - - return target; - }; -} - -if (!Array.prototype.find) { - Object.defineProperty(Array.prototype, 'find', { - value: function (predicate, thisArg) { - if (this == null) { - throw new TypeError('Array.prototype.find called on null or undefined'); - } - - if (typeof predicate !== 'function') { - throw new TypeError('predicate must be a function'); - } - - var array = Object(this); - var length = array.length >>> 0; - - for (var i = 0; i < length; i++) { - var value = array[i]; - if (predicate.call(thisArg, value, i, array)) { - return value; - } - } - - return undefined; - }, - configurable: true, - writable: true - }); -} - -if (!Object.getOwnPropertyDescriptors) { - Object.defineProperty(Object, 'getOwnPropertyDescriptors', { - value: function(obj) { - var descriptors = {}; - - for (var key in obj) { - if (Object.prototype.hasOwnProperty.call(obj, key)) { - descriptors[key] = Object.getOwnPropertyDescriptor(obj, key); - } - } - - return descriptors; - }, - configurable: true, - writable: true - }); -} diff --git a/lib/src/polyfills.ts b/lib/src/polyfills.ts new file mode 100644 index 0000000..b46d37b --- /dev/null +++ b/lib/src/polyfills.ts @@ -0,0 +1,4 @@ +import 'core-js/es/array/find'; +import 'core-js/es/object/assign'; +import 'core-js/es/object/entries'; +import 'core-js/es/object/get-own-property-descriptors'; diff --git a/lib/tsconfig.types.json b/lib/tsconfig.types.json index 35f4d01..8cf2a7b 100644 --- a/lib/tsconfig.types.json +++ b/lib/tsconfig.types.json @@ -13,5 +13,8 @@ "include": [ "src/**/*" + ], + "exclude": [ + "src/polyfills.ts" ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2433bb8..5065438 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -43,6 +47,9 @@ importers: '@sentry/browser': specifier: ^7.73.0 version: 7.73.0 + core-js: + specifier: ^3.35.1 + version: 3.35.1 devDependencies: '@hcaptcha/types': specifier: ^1.0.3 @@ -2171,6 +2178,11 @@ packages: resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==} dev: true + /core-js@3.35.1: + resolution: {integrity: sha512-IgdsbxNyMskrTFxa9lWHyMwAJU5gXOPP+1yO+K59d50VLVAIDAbs7gIv705KzALModfK3ZrSZTPNpC0PQgIZuw==} + requiresBuild: true + dev: false + /corser@2.0.1: resolution: {integrity: sha512-utCYNzRSQIZNPIcGZdQc92UVJYAhtGAteCFg0yRaFm8f0P+CPtyGyHXJcGXnffjCybUCEx3FQ2G7U3/o9eIkVQ==} engines: {node: '>= 0.4.0'}