diff --git a/packages/babel-preset-gatsby/package.json b/packages/babel-preset-gatsby/package.json index f158739147493..d44d173ad2374 100644 --- a/packages/babel-preset-gatsby/package.json +++ b/packages/babel-preset-gatsby/package.json @@ -21,7 +21,8 @@ "babel-plugin-dynamic-import-node": "^2.3.3", "babel-plugin-macros": "^2.8.0", "babel-plugin-transform-react-remove-prop-types": "^0.4.24", - "gatsby-core-utils": "^1.3.11" + "gatsby-core-utils": "^1.3.11", + "gatsby-legacy-polyfills": "^0.0.1" }, "peerDependencies": { "@babel/core": "^7.0.0", diff --git a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/dependencies.ts.snap b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/dependencies.ts.snap index ffcf375b9e0b5..e82fd4e6f11ef 100644 --- a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/dependencies.ts.snap +++ b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/dependencies.ts.snap @@ -22,8 +22,204 @@ Object { "corejs": 3, "exclude": Array [ "transform-typeof-symbol", + "transform-regenerator", + "es.symbol", + "es.symbol.async-iterator", + "es.symbol.has-instance", + "es.symbol.is-concat-spreadable", + "es.symbol.iterator", + "es.symbol.match", + "es.symbol.replace", + "es.symbol.search", + "es.symbol.species", + "es.symbol.split", + "es.symbol.to-primitive", + "es.symbol.to-string-tag", + "es.symbol.unscopables", + "es.array.concat", + "es.array.copy-within", + "es.array.every", + "es.array.fill", + "es.array.filter", + "es.array.find", + "es.array.find-index", + "es.array.for-each", + "es.array.from", + "es.array.includes", + "es.array.index-of", + "es.array.is-array", + "es.array.join", + "es.array.last-index-of", + "es.array.map", + "es.array.of", + "es.array.reduce", + "es.array.reduce-right", + "es.array.reverse", + "es.array.slice", + "es.array.some", + "es.array.sort", + "es.array.species", + "es.array.splice", + "es.array-buffer.constructor", + "es.array-buffer.is-view", + "es.array-buffer.slice", + "es.data-view", + "es.date.now", + "es.date.to-iso-string", + "es.date.to-json", + "es.date.to-primitive", + "es.function.bind", + "es.function.has-instance", + "es.function.name", + "es.json.to-string-tag", + "es.map", + "es.math.acosh", + "es.math.asinh", + "es.math.atanh", + "es.math.cbrt", + "es.math.clz32", + "es.math.cosh", + "es.math.expm1", + "es.math.fround", + "es.math.imul", + "es.math.log10", + "es.math.log1p", + "es.math.log2", + "es.math.sign", + "es.math.sinh", + "es.math.tanh", + "es.math.to-string-tag", + "es.math.trunc", + "es.number.constructor", + "es.number.epsilon", + "es.number.is-finite", + "es.number.is-integer", + "es.number.is-nan", + "es.number.is-safe-integer", + "es.number.max-safe-integer", + "es.number.min-safe-integer", + "es.number.parse-float", + "es.number.parse-int", + "es.number.to-fixed", + "es.number.to-precision", + "es.object.assign", + "es.object.create", + "es.object.define-getter", + "es.object.define-properties", + "es.object.define-property", + "es.object.define-setter", + "es.object.entries", + "es.object.freeze", + "es.object.get-own-property-descriptor", + "es.object.get-own-property-descriptors", + "es.object.get-own-property-names", + "es.object.get-prototype-of", + "es.object.is", + "es.object.is-extensible", + "es.object.is-frozen", + "es.object.is-sealed", + "es.object.keys", + "es.object.lookup-getter", + "es.object.lookup-setter", + "es.object.prevent-extensions", + "es.object.seal", + "es.object.set-prototype-of", + "es.object.to-string", + "es.object.values", + "es.parse-float", + "es.parse-int", + "es.reflect.apply", + "es.reflect.construct", + "es.reflect.define-property", + "es.reflect.delete-property", + "es.reflect.get", + "es.reflect.get-own-property-descriptor", + "es.reflect.get-prototype-of", + "es.reflect.has", + "es.reflect.is-extensible", + "es.reflect.own-keys", + "es.reflect.prevent-extensions", + "es.reflect.set", + "es.reflect.set-prototype-of", + "es.regexp.constructor", + "es.regexp.exec", + "es.regexp.flags", + "es.regexp.sticky", + "es.regexp.test", + "es.regexp.to-string", + "es.set", + "es.string.code-point-at", + "es.string.ends-with", + "es.string.from-code-point", + "es.string.includes", + "es.string.iterator", + "es.string.match", + "es.string.pad-end", + "es.string.pad-start", + "es.string.raw", + "es.string.repeat", + "es.string.replace", + "es.string.search", + "es.string.split", + "es.string.starts-with", + "es.string.trim", + "es.string.anchor", + "es.string.big", + "es.string.blink", + "es.string.bold", + "es.string.fixed", + "es.string.fontcolor", + "es.string.fontsize", + "es.string.italics", + "es.string.link", + "es.string.small", + "es.string.strike", + "es.string.sub", + "es.string.sup", + "es.typed-array.float32-array", + "es.typed-array.float64-array", + "es.typed-array.int8-array", + "es.typed-array.int16-array", + "es.typed-array.int32-array", + "es.typed-array.uint8-array", + "es.typed-array.uint8-clamped-array", + "es.typed-array.uint16-array", + "es.typed-array.uint32-array", + "es.typed-array.copy-within", + "es.typed-array.every", + "es.typed-array.fill", + "es.typed-array.filter", + "es.typed-array.find", + "es.typed-array.find-index", + "es.typed-array.for-each", + "es.typed-array.from", + "es.typed-array.includes", + "es.typed-array.index-of", + "es.typed-array.iterator", + "es.typed-array.join", + "es.typed-array.last-index-of", + "es.typed-array.map", + "es.typed-array.of", + "es.typed-array.reduce", + "es.typed-array.reduce-right", + "es.typed-array.reverse", + "es.typed-array.set", + "es.typed-array.slice", + "es.typed-array.some", + "es.typed-array.sort", + "es.typed-array.subarray", + "es.typed-array.to-locale-string", + "es.typed-array.to-string", + "es.weak-map", + "es.weak-set", + "es.object.assign", + "es.array.iterator", + "es.promise", + "es.symbol.description", + "web.*", ], "modules": false, + "targets": undefined, "useBuiltIns": "usage", }, ], diff --git a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap index fd425311be8ab..b9f5b84fb651b 100644 --- a/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap +++ b/packages/babel-preset-gatsby/src/__tests__/__snapshots__/index.js.snap @@ -26,9 +26,8 @@ Object { Array [ "/node_modules/@babel/plugin-transform-runtime/lib/index.js", Object { - "absoluteRuntimePath": "/node_modules/@babel/runtime", "corejs": false, - "helpers": false, + "helpers": true, "regenerator": true, "useESModules": true, }, @@ -48,6 +47,204 @@ Object { "corejs": 3, "exclude": Array [ "transform-typeof-symbol", + "transform-regenerator", + "transform-spread", + "proposal-nullish-coalescing-operator", + "proposal-optional-chaining", + "es.symbol", + "es.symbol.async-iterator", + "es.symbol.has-instance", + "es.symbol.is-concat-spreadable", + "es.symbol.iterator", + "es.symbol.match", + "es.symbol.replace", + "es.symbol.search", + "es.symbol.species", + "es.symbol.split", + "es.symbol.to-primitive", + "es.symbol.to-string-tag", + "es.symbol.unscopables", + "es.array.concat", + "es.array.copy-within", + "es.array.every", + "es.array.fill", + "es.array.filter", + "es.array.find", + "es.array.find-index", + "es.array.for-each", + "es.array.from", + "es.array.includes", + "es.array.index-of", + "es.array.is-array", + "es.array.join", + "es.array.last-index-of", + "es.array.map", + "es.array.of", + "es.array.reduce", + "es.array.reduce-right", + "es.array.reverse", + "es.array.slice", + "es.array.some", + "es.array.sort", + "es.array.species", + "es.array.splice", + "es.array-buffer.constructor", + "es.array-buffer.is-view", + "es.array-buffer.slice", + "es.data-view", + "es.date.now", + "es.date.to-iso-string", + "es.date.to-json", + "es.date.to-primitive", + "es.function.bind", + "es.function.has-instance", + "es.function.name", + "es.json.to-string-tag", + "es.map", + "es.math.acosh", + "es.math.asinh", + "es.math.atanh", + "es.math.cbrt", + "es.math.clz32", + "es.math.cosh", + "es.math.expm1", + "es.math.fround", + "es.math.imul", + "es.math.log10", + "es.math.log1p", + "es.math.log2", + "es.math.sign", + "es.math.sinh", + "es.math.tanh", + "es.math.to-string-tag", + "es.math.trunc", + "es.number.constructor", + "es.number.epsilon", + "es.number.is-finite", + "es.number.is-integer", + "es.number.is-nan", + "es.number.is-safe-integer", + "es.number.max-safe-integer", + "es.number.min-safe-integer", + "es.number.parse-float", + "es.number.parse-int", + "es.number.to-fixed", + "es.number.to-precision", + "es.object.assign", + "es.object.create", + "es.object.define-getter", + "es.object.define-properties", + "es.object.define-property", + "es.object.define-setter", + "es.object.entries", + "es.object.freeze", + "es.object.get-own-property-descriptor", + "es.object.get-own-property-descriptors", + "es.object.get-own-property-names", + "es.object.get-prototype-of", + "es.object.is", + "es.object.is-extensible", + "es.object.is-frozen", + "es.object.is-sealed", + "es.object.keys", + "es.object.lookup-getter", + "es.object.lookup-setter", + "es.object.prevent-extensions", + "es.object.seal", + "es.object.set-prototype-of", + "es.object.to-string", + "es.object.values", + "es.parse-float", + "es.parse-int", + "es.reflect.apply", + "es.reflect.construct", + "es.reflect.define-property", + "es.reflect.delete-property", + "es.reflect.get", + "es.reflect.get-own-property-descriptor", + "es.reflect.get-prototype-of", + "es.reflect.has", + "es.reflect.is-extensible", + "es.reflect.own-keys", + "es.reflect.prevent-extensions", + "es.reflect.set", + "es.reflect.set-prototype-of", + "es.regexp.constructor", + "es.regexp.exec", + "es.regexp.flags", + "es.regexp.sticky", + "es.regexp.test", + "es.regexp.to-string", + "es.set", + "es.string.code-point-at", + "es.string.ends-with", + "es.string.from-code-point", + "es.string.includes", + "es.string.iterator", + "es.string.match", + "es.string.pad-end", + "es.string.pad-start", + "es.string.raw", + "es.string.repeat", + "es.string.replace", + "es.string.search", + "es.string.split", + "es.string.starts-with", + "es.string.trim", + "es.string.anchor", + "es.string.big", + "es.string.blink", + "es.string.bold", + "es.string.fixed", + "es.string.fontcolor", + "es.string.fontsize", + "es.string.italics", + "es.string.link", + "es.string.small", + "es.string.strike", + "es.string.sub", + "es.string.sup", + "es.typed-array.float32-array", + "es.typed-array.float64-array", + "es.typed-array.int8-array", + "es.typed-array.int16-array", + "es.typed-array.int32-array", + "es.typed-array.uint8-array", + "es.typed-array.uint8-clamped-array", + "es.typed-array.uint16-array", + "es.typed-array.uint32-array", + "es.typed-array.copy-within", + "es.typed-array.every", + "es.typed-array.fill", + "es.typed-array.filter", + "es.typed-array.find", + "es.typed-array.find-index", + "es.typed-array.for-each", + "es.typed-array.from", + "es.typed-array.includes", + "es.typed-array.index-of", + "es.typed-array.iterator", + "es.typed-array.join", + "es.typed-array.last-index-of", + "es.typed-array.map", + "es.typed-array.of", + "es.typed-array.reduce", + "es.typed-array.reduce-right", + "es.typed-array.reverse", + "es.typed-array.set", + "es.typed-array.slice", + "es.typed-array.some", + "es.typed-array.sort", + "es.typed-array.subarray", + "es.typed-array.to-locale-string", + "es.typed-array.to-string", + "es.weak-map", + "es.weak-set", + "es.object.assign", + "es.array.iterator", + "es.promise", + "es.symbol.description", + "web.*", ], "loose": true, "modules": false, @@ -95,9 +292,8 @@ Object { Array [ "/node_modules/@babel/plugin-transform-runtime/lib/index.js", Object { - "absoluteRuntimePath": "/node_modules/@babel/runtime", "corejs": false, - "helpers": false, + "helpers": true, "regenerator": true, "useESModules": true, }, @@ -123,6 +319,204 @@ Object { "corejs": 3, "exclude": Array [ "transform-typeof-symbol", + "transform-regenerator", + "transform-spread", + "proposal-nullish-coalescing-operator", + "proposal-optional-chaining", + "es.symbol", + "es.symbol.async-iterator", + "es.symbol.has-instance", + "es.symbol.is-concat-spreadable", + "es.symbol.iterator", + "es.symbol.match", + "es.symbol.replace", + "es.symbol.search", + "es.symbol.species", + "es.symbol.split", + "es.symbol.to-primitive", + "es.symbol.to-string-tag", + "es.symbol.unscopables", + "es.array.concat", + "es.array.copy-within", + "es.array.every", + "es.array.fill", + "es.array.filter", + "es.array.find", + "es.array.find-index", + "es.array.for-each", + "es.array.from", + "es.array.includes", + "es.array.index-of", + "es.array.is-array", + "es.array.join", + "es.array.last-index-of", + "es.array.map", + "es.array.of", + "es.array.reduce", + "es.array.reduce-right", + "es.array.reverse", + "es.array.slice", + "es.array.some", + "es.array.sort", + "es.array.species", + "es.array.splice", + "es.array-buffer.constructor", + "es.array-buffer.is-view", + "es.array-buffer.slice", + "es.data-view", + "es.date.now", + "es.date.to-iso-string", + "es.date.to-json", + "es.date.to-primitive", + "es.function.bind", + "es.function.has-instance", + "es.function.name", + "es.json.to-string-tag", + "es.map", + "es.math.acosh", + "es.math.asinh", + "es.math.atanh", + "es.math.cbrt", + "es.math.clz32", + "es.math.cosh", + "es.math.expm1", + "es.math.fround", + "es.math.imul", + "es.math.log10", + "es.math.log1p", + "es.math.log2", + "es.math.sign", + "es.math.sinh", + "es.math.tanh", + "es.math.to-string-tag", + "es.math.trunc", + "es.number.constructor", + "es.number.epsilon", + "es.number.is-finite", + "es.number.is-integer", + "es.number.is-nan", + "es.number.is-safe-integer", + "es.number.max-safe-integer", + "es.number.min-safe-integer", + "es.number.parse-float", + "es.number.parse-int", + "es.number.to-fixed", + "es.number.to-precision", + "es.object.assign", + "es.object.create", + "es.object.define-getter", + "es.object.define-properties", + "es.object.define-property", + "es.object.define-setter", + "es.object.entries", + "es.object.freeze", + "es.object.get-own-property-descriptor", + "es.object.get-own-property-descriptors", + "es.object.get-own-property-names", + "es.object.get-prototype-of", + "es.object.is", + "es.object.is-extensible", + "es.object.is-frozen", + "es.object.is-sealed", + "es.object.keys", + "es.object.lookup-getter", + "es.object.lookup-setter", + "es.object.prevent-extensions", + "es.object.seal", + "es.object.set-prototype-of", + "es.object.to-string", + "es.object.values", + "es.parse-float", + "es.parse-int", + "es.reflect.apply", + "es.reflect.construct", + "es.reflect.define-property", + "es.reflect.delete-property", + "es.reflect.get", + "es.reflect.get-own-property-descriptor", + "es.reflect.get-prototype-of", + "es.reflect.has", + "es.reflect.is-extensible", + "es.reflect.own-keys", + "es.reflect.prevent-extensions", + "es.reflect.set", + "es.reflect.set-prototype-of", + "es.regexp.constructor", + "es.regexp.exec", + "es.regexp.flags", + "es.regexp.sticky", + "es.regexp.test", + "es.regexp.to-string", + "es.set", + "es.string.code-point-at", + "es.string.ends-with", + "es.string.from-code-point", + "es.string.includes", + "es.string.iterator", + "es.string.match", + "es.string.pad-end", + "es.string.pad-start", + "es.string.raw", + "es.string.repeat", + "es.string.replace", + "es.string.search", + "es.string.split", + "es.string.starts-with", + "es.string.trim", + "es.string.anchor", + "es.string.big", + "es.string.blink", + "es.string.bold", + "es.string.fixed", + "es.string.fontcolor", + "es.string.fontsize", + "es.string.italics", + "es.string.link", + "es.string.small", + "es.string.strike", + "es.string.sub", + "es.string.sup", + "es.typed-array.float32-array", + "es.typed-array.float64-array", + "es.typed-array.int8-array", + "es.typed-array.int16-array", + "es.typed-array.int32-array", + "es.typed-array.uint8-array", + "es.typed-array.uint8-clamped-array", + "es.typed-array.uint16-array", + "es.typed-array.uint32-array", + "es.typed-array.copy-within", + "es.typed-array.every", + "es.typed-array.fill", + "es.typed-array.filter", + "es.typed-array.find", + "es.typed-array.find-index", + "es.typed-array.for-each", + "es.typed-array.from", + "es.typed-array.includes", + "es.typed-array.index-of", + "es.typed-array.iterator", + "es.typed-array.join", + "es.typed-array.last-index-of", + "es.typed-array.map", + "es.typed-array.of", + "es.typed-array.reduce", + "es.typed-array.reduce-right", + "es.typed-array.reverse", + "es.typed-array.set", + "es.typed-array.slice", + "es.typed-array.some", + "es.typed-array.sort", + "es.typed-array.subarray", + "es.typed-array.to-locale-string", + "es.typed-array.to-string", + "es.weak-map", + "es.weak-set", + "es.object.assign", + "es.array.iterator", + "es.promise", + "es.symbol.description", + "web.*", ], "loose": true, "modules": false, @@ -168,9 +562,8 @@ Object { Array [ "/node_modules/@babel/plugin-transform-runtime/lib/index.js", Object { - "absoluteRuntimePath": "/node_modules/@babel/runtime", "corejs": false, - "helpers": false, + "helpers": true, "regenerator": true, "useESModules": true, }, @@ -190,6 +583,204 @@ Object { "corejs": 3, "exclude": Array [ "transform-typeof-symbol", + "transform-regenerator", + "transform-spread", + "proposal-nullish-coalescing-operator", + "proposal-optional-chaining", + "es.symbol", + "es.symbol.async-iterator", + "es.symbol.has-instance", + "es.symbol.is-concat-spreadable", + "es.symbol.iterator", + "es.symbol.match", + "es.symbol.replace", + "es.symbol.search", + "es.symbol.species", + "es.symbol.split", + "es.symbol.to-primitive", + "es.symbol.to-string-tag", + "es.symbol.unscopables", + "es.array.concat", + "es.array.copy-within", + "es.array.every", + "es.array.fill", + "es.array.filter", + "es.array.find", + "es.array.find-index", + "es.array.for-each", + "es.array.from", + "es.array.includes", + "es.array.index-of", + "es.array.is-array", + "es.array.join", + "es.array.last-index-of", + "es.array.map", + "es.array.of", + "es.array.reduce", + "es.array.reduce-right", + "es.array.reverse", + "es.array.slice", + "es.array.some", + "es.array.sort", + "es.array.species", + "es.array.splice", + "es.array-buffer.constructor", + "es.array-buffer.is-view", + "es.array-buffer.slice", + "es.data-view", + "es.date.now", + "es.date.to-iso-string", + "es.date.to-json", + "es.date.to-primitive", + "es.function.bind", + "es.function.has-instance", + "es.function.name", + "es.json.to-string-tag", + "es.map", + "es.math.acosh", + "es.math.asinh", + "es.math.atanh", + "es.math.cbrt", + "es.math.clz32", + "es.math.cosh", + "es.math.expm1", + "es.math.fround", + "es.math.imul", + "es.math.log10", + "es.math.log1p", + "es.math.log2", + "es.math.sign", + "es.math.sinh", + "es.math.tanh", + "es.math.to-string-tag", + "es.math.trunc", + "es.number.constructor", + "es.number.epsilon", + "es.number.is-finite", + "es.number.is-integer", + "es.number.is-nan", + "es.number.is-safe-integer", + "es.number.max-safe-integer", + "es.number.min-safe-integer", + "es.number.parse-float", + "es.number.parse-int", + "es.number.to-fixed", + "es.number.to-precision", + "es.object.assign", + "es.object.create", + "es.object.define-getter", + "es.object.define-properties", + "es.object.define-property", + "es.object.define-setter", + "es.object.entries", + "es.object.freeze", + "es.object.get-own-property-descriptor", + "es.object.get-own-property-descriptors", + "es.object.get-own-property-names", + "es.object.get-prototype-of", + "es.object.is", + "es.object.is-extensible", + "es.object.is-frozen", + "es.object.is-sealed", + "es.object.keys", + "es.object.lookup-getter", + "es.object.lookup-setter", + "es.object.prevent-extensions", + "es.object.seal", + "es.object.set-prototype-of", + "es.object.to-string", + "es.object.values", + "es.parse-float", + "es.parse-int", + "es.reflect.apply", + "es.reflect.construct", + "es.reflect.define-property", + "es.reflect.delete-property", + "es.reflect.get", + "es.reflect.get-own-property-descriptor", + "es.reflect.get-prototype-of", + "es.reflect.has", + "es.reflect.is-extensible", + "es.reflect.own-keys", + "es.reflect.prevent-extensions", + "es.reflect.set", + "es.reflect.set-prototype-of", + "es.regexp.constructor", + "es.regexp.exec", + "es.regexp.flags", + "es.regexp.sticky", + "es.regexp.test", + "es.regexp.to-string", + "es.set", + "es.string.code-point-at", + "es.string.ends-with", + "es.string.from-code-point", + "es.string.includes", + "es.string.iterator", + "es.string.match", + "es.string.pad-end", + "es.string.pad-start", + "es.string.raw", + "es.string.repeat", + "es.string.replace", + "es.string.search", + "es.string.split", + "es.string.starts-with", + "es.string.trim", + "es.string.anchor", + "es.string.big", + "es.string.blink", + "es.string.bold", + "es.string.fixed", + "es.string.fontcolor", + "es.string.fontsize", + "es.string.italics", + "es.string.link", + "es.string.small", + "es.string.strike", + "es.string.sub", + "es.string.sup", + "es.typed-array.float32-array", + "es.typed-array.float64-array", + "es.typed-array.int8-array", + "es.typed-array.int16-array", + "es.typed-array.int32-array", + "es.typed-array.uint8-array", + "es.typed-array.uint8-clamped-array", + "es.typed-array.uint16-array", + "es.typed-array.uint32-array", + "es.typed-array.copy-within", + "es.typed-array.every", + "es.typed-array.fill", + "es.typed-array.filter", + "es.typed-array.find", + "es.typed-array.find-index", + "es.typed-array.for-each", + "es.typed-array.from", + "es.typed-array.includes", + "es.typed-array.index-of", + "es.typed-array.iterator", + "es.typed-array.join", + "es.typed-array.last-index-of", + "es.typed-array.map", + "es.typed-array.of", + "es.typed-array.reduce", + "es.typed-array.reduce-right", + "es.typed-array.reverse", + "es.typed-array.set", + "es.typed-array.slice", + "es.typed-array.some", + "es.typed-array.sort", + "es.typed-array.subarray", + "es.typed-array.to-locale-string", + "es.typed-array.to-string", + "es.weak-map", + "es.weak-set", + "es.object.assign", + "es.array.iterator", + "es.promise", + "es.symbol.description", + "web.*", ], "loose": true, "modules": false, @@ -235,7 +826,6 @@ Object { Array [ "/node_modules/@babel/plugin-transform-runtime/lib/index.js", Object { - "absoluteRuntimePath": "/node_modules/@babel/runtime", "corejs": false, "helpers": true, "regenerator": true, @@ -257,6 +847,204 @@ Object { "corejs": 3, "exclude": Array [ "transform-typeof-symbol", + "transform-regenerator", + "transform-spread", + "proposal-nullish-coalescing-operator", + "proposal-optional-chaining", + "es.symbol", + "es.symbol.async-iterator", + "es.symbol.has-instance", + "es.symbol.is-concat-spreadable", + "es.symbol.iterator", + "es.symbol.match", + "es.symbol.replace", + "es.symbol.search", + "es.symbol.species", + "es.symbol.split", + "es.symbol.to-primitive", + "es.symbol.to-string-tag", + "es.symbol.unscopables", + "es.array.concat", + "es.array.copy-within", + "es.array.every", + "es.array.fill", + "es.array.filter", + "es.array.find", + "es.array.find-index", + "es.array.for-each", + "es.array.from", + "es.array.includes", + "es.array.index-of", + "es.array.is-array", + "es.array.join", + "es.array.last-index-of", + "es.array.map", + "es.array.of", + "es.array.reduce", + "es.array.reduce-right", + "es.array.reverse", + "es.array.slice", + "es.array.some", + "es.array.sort", + "es.array.species", + "es.array.splice", + "es.array-buffer.constructor", + "es.array-buffer.is-view", + "es.array-buffer.slice", + "es.data-view", + "es.date.now", + "es.date.to-iso-string", + "es.date.to-json", + "es.date.to-primitive", + "es.function.bind", + "es.function.has-instance", + "es.function.name", + "es.json.to-string-tag", + "es.map", + "es.math.acosh", + "es.math.asinh", + "es.math.atanh", + "es.math.cbrt", + "es.math.clz32", + "es.math.cosh", + "es.math.expm1", + "es.math.fround", + "es.math.imul", + "es.math.log10", + "es.math.log1p", + "es.math.log2", + "es.math.sign", + "es.math.sinh", + "es.math.tanh", + "es.math.to-string-tag", + "es.math.trunc", + "es.number.constructor", + "es.number.epsilon", + "es.number.is-finite", + "es.number.is-integer", + "es.number.is-nan", + "es.number.is-safe-integer", + "es.number.max-safe-integer", + "es.number.min-safe-integer", + "es.number.parse-float", + "es.number.parse-int", + "es.number.to-fixed", + "es.number.to-precision", + "es.object.assign", + "es.object.create", + "es.object.define-getter", + "es.object.define-properties", + "es.object.define-property", + "es.object.define-setter", + "es.object.entries", + "es.object.freeze", + "es.object.get-own-property-descriptor", + "es.object.get-own-property-descriptors", + "es.object.get-own-property-names", + "es.object.get-prototype-of", + "es.object.is", + "es.object.is-extensible", + "es.object.is-frozen", + "es.object.is-sealed", + "es.object.keys", + "es.object.lookup-getter", + "es.object.lookup-setter", + "es.object.prevent-extensions", + "es.object.seal", + "es.object.set-prototype-of", + "es.object.to-string", + "es.object.values", + "es.parse-float", + "es.parse-int", + "es.reflect.apply", + "es.reflect.construct", + "es.reflect.define-property", + "es.reflect.delete-property", + "es.reflect.get", + "es.reflect.get-own-property-descriptor", + "es.reflect.get-prototype-of", + "es.reflect.has", + "es.reflect.is-extensible", + "es.reflect.own-keys", + "es.reflect.prevent-extensions", + "es.reflect.set", + "es.reflect.set-prototype-of", + "es.regexp.constructor", + "es.regexp.exec", + "es.regexp.flags", + "es.regexp.sticky", + "es.regexp.test", + "es.regexp.to-string", + "es.set", + "es.string.code-point-at", + "es.string.ends-with", + "es.string.from-code-point", + "es.string.includes", + "es.string.iterator", + "es.string.match", + "es.string.pad-end", + "es.string.pad-start", + "es.string.raw", + "es.string.repeat", + "es.string.replace", + "es.string.search", + "es.string.split", + "es.string.starts-with", + "es.string.trim", + "es.string.anchor", + "es.string.big", + "es.string.blink", + "es.string.bold", + "es.string.fixed", + "es.string.fontcolor", + "es.string.fontsize", + "es.string.italics", + "es.string.link", + "es.string.small", + "es.string.strike", + "es.string.sub", + "es.string.sup", + "es.typed-array.float32-array", + "es.typed-array.float64-array", + "es.typed-array.int8-array", + "es.typed-array.int16-array", + "es.typed-array.int32-array", + "es.typed-array.uint8-array", + "es.typed-array.uint8-clamped-array", + "es.typed-array.uint16-array", + "es.typed-array.uint32-array", + "es.typed-array.copy-within", + "es.typed-array.every", + "es.typed-array.fill", + "es.typed-array.filter", + "es.typed-array.find", + "es.typed-array.find-index", + "es.typed-array.for-each", + "es.typed-array.from", + "es.typed-array.includes", + "es.typed-array.index-of", + "es.typed-array.iterator", + "es.typed-array.join", + "es.typed-array.last-index-of", + "es.typed-array.map", + "es.typed-array.of", + "es.typed-array.reduce", + "es.typed-array.reduce-right", + "es.typed-array.reverse", + "es.typed-array.set", + "es.typed-array.slice", + "es.typed-array.some", + "es.typed-array.sort", + "es.typed-array.subarray", + "es.typed-array.to-locale-string", + "es.typed-array.to-string", + "es.weak-map", + "es.weak-set", + "es.object.assign", + "es.array.iterator", + "es.promise", + "es.symbol.description", + "web.*", ], "loose": true, "modules": false, diff --git a/packages/babel-preset-gatsby/src/__tests__/index.js b/packages/babel-preset-gatsby/src/__tests__/index.js index 6ba025f9539c7..45589154e4273 100644 --- a/packages/babel-preset-gatsby/src/__tests__/index.js +++ b/packages/babel-preset-gatsby/src/__tests__/index.js @@ -1,6 +1,5 @@ -const path = require(`path`) - -const preset = require(`../`) +import * as path from "path" +import preset from "../index" import * as pathSerializer from "../utils/path-serializer" expect.addSnapshotSerializer(pathSerializer) @@ -22,14 +21,9 @@ describe(`babel-preset-gatsby`, () => { expect(presets[0]).toEqual([ expect.stringContaining(path.join(`@babel`, `preset-env`)), - { - exclude: [`transform-typeof-symbol`], - corejs: 3, - loose: true, - modules: false, - useBuiltIns: `usage`, + expect.objectContaining({ targets, - }, + }), ]) }) }) diff --git a/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js index cc0c91774650a..53dc378e88a1e 100644 --- a/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js +++ b/packages/babel-preset-gatsby/src/__tests__/optimize-hook-destructuring.js @@ -1,5 +1,5 @@ import { transform } from "@babel/core" -import preset from "babel-preset-gatsby" +import preset from "../index" import plugin from "../optimize-hook-destructuring" const trim = s => s.join(`\n`).trim().replace(/^\s+/gm, ``) diff --git a/packages/babel-preset-gatsby/src/dependencies.ts b/packages/babel-preset-gatsby/src/dependencies.ts index 8494fcadda7ae..101c2ddea0413 100644 --- a/packages/babel-preset-gatsby/src/dependencies.ts +++ b/packages/babel-preset-gatsby/src/dependencies.ts @@ -1,7 +1,9 @@ // This file is heavily based on create-react-app's implementation // @see https://github.com/facebook/create-react-app/blob/master/packages/babel-preset-react-app/dependencies.js -import path from "path" +import * as path from "path" +import { loadCachedConfig } from "./index" +import { CORE_JS_POLYFILL_EXCLUDE_LIST as polyfillsToExclude } from "gatsby-legacy-polyfills/dist/exclude" interface IPresetOptions { stage?: "build-javascript" | "build-html" | "develop" | "develop-html" @@ -18,6 +20,8 @@ export default (_?: unknown, options: IPresetOptions = {}) => { // TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test` + const pluginBabelConfig = loadCachedConfig() + const targets = pluginBabelConfig.browserslist return { // Babel assumes ES Modules, which isn't safe until CommonJS @@ -31,11 +35,19 @@ export default (_?: unknown, options: IPresetOptions = {}) => { require.resolve(`@babel/preset-env`), { // Allow importing core-js in entrypoint and use browserlist to select polyfills + // V3 change, make this entry useBuiltIns: `usage`, corejs: 3, modules: false, - // Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) - exclude: [`transform-typeof-symbol`], + // debug: true, + targets, + exclude: [ + // Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) + `transform-typeof-symbol`, + // we have @babel/plugin-transform-runtime that takes care of this + `transform-regenerator`, + ...polyfillsToExclude, + ], }, ], ], diff --git a/packages/babel-preset-gatsby/src/index.js b/packages/babel-preset-gatsby/src/index.js index 6fbb8adf299bc..13b7d3b14fd3e 100644 --- a/packages/babel-preset-gatsby/src/index.js +++ b/packages/babel-preset-gatsby/src/index.js @@ -1,10 +1,13 @@ const path = require(`path`) +const { + CORE_JS_POLYFILL_EXCLUDE_LIST: polyfillsToExclude, +} = require(`gatsby-legacy-polyfills/dist/exclude`) const resolve = m => require.resolve(m) const IS_TEST = (process.env.BABEL_ENV || process.env.NODE_ENV) === `test` -const loadCachedConfig = () => { +export function loadCachedConfig() { let pluginBabelConfig = {} if (!IS_TEST) { try { @@ -26,15 +29,16 @@ const loadCachedConfig = () => { return pluginBabelConfig } -module.exports = function preset(_, options = {}) { +export default function preset(_, options = {}) { let { targets = null } = options // TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test` const pluginBabelConfig = loadCachedConfig() - const absoluteRuntimePath = path.dirname( - require.resolve(`@babel/runtime/package.json`) - ) + // unused because of cloud builds + // const absoluteRuntimePath = path.dirname( + // require.resolve(`@babel/runtime/package.json`) + // ) if (!targets) { if (stage === `build-html` || stage === `test`) { @@ -56,8 +60,19 @@ module.exports = function preset(_, options = {}) { modules: stage === `test` ? `commonjs` : false, useBuiltIns: `usage`, targets, - // Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) - exclude: [`transform-typeof-symbol`], + // debug: true, + exclude: [ + // Exclude transforms that make all code slower (https://github.com/facebook/create-react-app/pull/5278) + `transform-typeof-symbol`, + // we have @babel/plugin-transform-runtime that takes care of this + `transform-regenerator`, + // we already have transforms for these + `transform-spread`, + `proposal-nullish-coalescing-operator`, + `proposal-optional-chaining`, + + ...polyfillsToExclude, + ], }, ], [ @@ -90,10 +105,11 @@ module.exports = function preset(_, options = {}) { resolve(`@babel/plugin-transform-runtime`), { corejs: false, - helpers: stage === `develop` || stage === `test`, + helpers: true, regenerator: true, useESModules: stage !== `test`, - absoluteRuntimePath, + // this breaks cloud builds so we disable it for now + // absoluteRuntime: absoluteRuntimePath, }, ], [ diff --git a/packages/gatsby-legacy-polyfills/.gitignore b/packages/gatsby-legacy-polyfills/.gitignore new file mode 100644 index 0000000000000..ff4d2da83ed3f --- /dev/null +++ b/packages/gatsby-legacy-polyfills/.gitignore @@ -0,0 +1,3 @@ +/dist/*.js +yarn.lock +.tmp diff --git a/packages/gatsby-legacy-polyfills/README.md b/packages/gatsby-legacy-polyfills/README.md new file mode 100644 index 0000000000000..d70f00256dff8 --- /dev/null +++ b/packages/gatsby-legacy-polyfills/README.md @@ -0,0 +1,3 @@ +# gatsby-legacy-polyfills + +A package that contains all polyfills necessary for legacy browsers. We load this package with the nomodule attribute. diff --git a/packages/gatsby-legacy-polyfills/package.json b/packages/gatsby-legacy-polyfills/package.json new file mode 100644 index 0000000000000..d925120d83870 --- /dev/null +++ b/packages/gatsby-legacy-polyfills/package.json @@ -0,0 +1,47 @@ +{ + "name": "gatsby-legacy-polyfills", + "description": "Polyfills for legacy browsers", + "version": "0.0.1", + "main": "dist/polyfills.js", + "author": "Ward Peeters ", + "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-legacy-polyfills#readme", + "repository": { + "type": "git", + "url": "https://github.com/gatsbyjs/gatsby.git", + "directory": "packages/gatsby-legacy-polyfills" + }, + "bugs": { + "url": "https://github.com/gatsbyjs/gatsby/issues" + }, + "license": "MIT", + "scripts": { + "build": "npm-run-all -p build:*", + "build:exclude": "cpy \"src/exclude.js\" \"./dist\"", + "build:polyfills": "microbundle -f iife -i src/polyfills.js --no-sourcemap --external=none", + "prepare": "cross-env NODE_ENV=production npm run build", + "watch": "npm-run-all -p watch:*", + "watch:exclude": "npm run build:exclude && chokidar \"src/exclude.js\" -c \"npm run build:exclude\"", + "watch:polyfills": "microbundle -f iife -i src/polyfills.js --no-sourcemap --external=none --watch" + }, + "dependencies": { + "core-js-compat": "^3.6.5" + }, + "files": [ + "dist/**" + ], + "devDependencies": { + "chokidar-cli": "^2.1.0", + "codegen.macro": "^4.0.0", + "core-js": "^3.6.5", + "cpy-cli": "^3.1.1", + "cross-env": "^5.2.1", + "execa": "^4.0.2", + "fs-extra": "^9.0.1", + "microbundle": "^0.12.0", + "npm-run-all": "^4.1.5", + "object-assign": "^4.1.1", + "source-map": "^0.7.3", + "url-polyfill": "^1.1.9", + "whatwg-fetch": "3.0.0" + } +} diff --git a/packages/gatsby-legacy-polyfills/src/__tests__/polyfills.js b/packages/gatsby-legacy-polyfills/src/__tests__/polyfills.js new file mode 100644 index 0000000000000..adb9b79191eb7 --- /dev/null +++ b/packages/gatsby-legacy-polyfills/src/__tests__/polyfills.js @@ -0,0 +1,57 @@ +const path = require(`path`) +const { SourceMapConsumer } = require(`source-map`) +const execa = require(`execa`) +const fs = require(`fs-extra`) + +jest.setTimeout(60000) + +describe(`polyfills`, () => { + const packageRoot = path.resolve(__dirname, `../../`) + const tmpDir = `.tmp` + + beforeAll(async () => { + const pkg = require(`../../package.json`) + const buildScript = pkg.scripts[`build:polyfills`].replace( + ` --no-sourcemap`, + `` + ) + + await execa( + `yarn`, + [ + ...buildScript.split(` `), + `--no-compress`, + `-o`, + path.join(tmpDir, `polyfills.js`), + ], + { cwd: packageRoot } + ) + }) + + afterAll(() => fs.remove(path.join(packageRoot, tmpDir))) + + it(`has the correct polyfills`, () => { + const polyfills = require(`../exclude`).LEGACY_POLYFILLS + const polyfillMap = path.join(packageRoot, tmpDir, `polyfills.js.map`) + expect(fs.existsSync(polyfillMap)).toBe(true) + + const fileMap = polyfills.map( + polyfill => + `core-js/modules/${polyfill + .replace(/^(features|modules)\//, `es.`) + .replace(`/`, `.`)}` + ) + + const polyfillMapSource = fs.readFileSync(polyfillMap, `utf8`) + SourceMapConsumer.with(polyfillMapSource, null, consumer => { + const sources = consumer.sources + + // check if all polyfills are in the bundle + expect(sources).toEqual( + expect.arrayContaining( + fileMap.map(file => expect.stringContaining(file)) + ) + ) + }) + }) +}) diff --git a/packages/gatsby-legacy-polyfills/src/exclude.js b/packages/gatsby-legacy-polyfills/src/exclude.js new file mode 100644 index 0000000000000..51964aaf8b533 --- /dev/null +++ b/packages/gatsby-legacy-polyfills/src/exclude.js @@ -0,0 +1,92 @@ +const { + targets: listOfPolyfillsByTarget, // object with targets for each module +} = require(`core-js-compat`)({ + // get all polyfills necessary for IE11, chrome > 63 or safari < 12.1 + // This will give us a comprehensive list of all polyfills of legacy polyfills and modern polyfills. + // Core-js will give us output like: + // "es.symbol.match-all": { + // "chrome": "64", + // "ie": "11", + // "safari": "3.1" + // }, + // "es.symbol.replace": { + // "ie": "11", + // "safari": "3.1" + // }, + // With this matrix we can remove all modern polyfills like es.symbol.match-all from the exclude list so babel-preset-env + // can still polyfill them for our users. + targets: `IE 11, chrome > 63, safari <= 12.1`, + filter: /^(es)\./, +}) + +const listOfLegacyPolyfills = [] +Object.keys(listOfPolyfillsByTarget).forEach(polyfill => { + const targets = listOfPolyfillsByTarget[polyfill] + // only add a list of polyfills that are necessary for IE, we don't want to exclude promise.finally... + if (!targets.chrome) { + listOfLegacyPolyfills.push(polyfill) + } +}) + +module.exports = { + // Is imported inside the legacy polyfill file + LEGACY_POLYFILLS: [ + `features/array/copy-within`, + `features/array/fill`, + `features/array/find`, + `features/array/find-index`, + `features/array/flat-map`, + `features/array/flat`, + `features/array/from`, + `features/array/includes`, + `features/array/iterator`, + `features/array/of`, + `features/function/has-instance`, + `features/function/name`, + `features/map`, + `features/set`, + `features/weak-map`, + `features/weak-set`, + `features/number/constructor`, + `features/number/epsilon`, + `features/number/is-finite`, + `features/number/is-integer`, + `features/number/is-nan`, + `features/number/is-safe-integer`, + `features/number/max-safe-integer`, + `features/number/min-safe-integer`, + `features/object/entries`, + `features/object/get-own-property-descriptors`, + `features/object/is`, + `features/object/keys`, + `features/object/values`, + `features/string/code-point-at`, + `features/string/ends-with`, + `features/string/from-code-point`, + `features/string/includes`, + `features/string/iterator`, + `features/string/pad-start`, + `features/string/pad-end`, + `features/string/raw`, + `features/string/repeat`, + `features/string/starts-with`, + `features/string/trim-start`, + `features/string/trim-end`, + `features/reflect`, + `features/regexp`, + `features/symbol`, + `features/promise`, + ], + // Will be used by preset-env to exclude already polyfilled features from the automatic polyfilling option + CORE_JS_POLYFILL_EXCLUDE_LIST: [ + ...listOfLegacyPolyfills, + `es.object.assign`, + + // These are added by default as the check in babel-preset-env isn't thorough enough + // ex if .forEach is used it adds a bunch of iterator polyfills even if it has nothing to do with that + `es.array.iterator`, + `es.promise`, + `es.symbol.description`, + `web.*`, + ], +} diff --git a/packages/gatsby-legacy-polyfills/src/polyfills.js b/packages/gatsby-legacy-polyfills/src/polyfills.js new file mode 100644 index 0000000000000..3e48a3cc7294d --- /dev/null +++ b/packages/gatsby-legacy-polyfills/src/polyfills.js @@ -0,0 +1,12 @@ +import codegen from "codegen.macro" + +codegen` + const imports = require('./exclude').LEGACY_POLYFILLS; + + module.exports = imports.map(file => 'import "core-js/' + file + '"').join("\\n") +` + +import "whatwg-fetch" +import "url-polyfill" +import assign from "object-assign" +Object.assign = assign diff --git a/packages/gatsby/cache-dir/__tests__/__snapshots__/static-entry.js.snap b/packages/gatsby/cache-dir/__tests__/__snapshots__/static-entry.js.snap index e0fd29cf1304f..a32218f3e0838 100644 --- a/packages/gatsby/cache-dir/__tests__/__snapshots__/static-entry.js.snap +++ b/packages/gatsby/cache-dir/__tests__/__snapshots__/static-entry.js.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`develop-static-entry onPreRenderHTML can be used to replace headComponents 1`] = `"
"`; +exports[`develop-static-entry onPreRenderHTML can be used to replace headComponents 1`] = `"
"`; -exports[`develop-static-entry onPreRenderHTML can be used to replace postBodyComponents 1`] = `"
div3
div2
div1
"`; +exports[`develop-static-entry onPreRenderHTML can be used to replace postBodyComponents 1`] = `"
div3
div2
div1
"`; -exports[`develop-static-entry onPreRenderHTML can be used to replace preBodyComponents 1`] = `"
div3
div2
div1
"`; +exports[`develop-static-entry onPreRenderHTML can be used to replace preBodyComponents 1`] = `"
div3
div2
div1
"`; exports[`static-entry onPreRenderHTML can be used to replace headComponents 1`] = `"
"`; diff --git a/packages/gatsby/cache-dir/develop-static-entry.js b/packages/gatsby/cache-dir/develop-static-entry.js index 7f2b3c9643c02..9e245316e40f2 100644 --- a/packages/gatsby/cache-dir/develop-static-entry.js +++ b/packages/gatsby/cache-dir/develop-static-entry.js @@ -109,6 +109,7 @@ export default (pagePath, callback) => { bodyAttributes, preBodyComponents, postBodyComponents: postBodyComponents.concat([ +