Skip to content

Commit d1c9d98

Browse files
BPScottalex-page
andauthored
Define our own in-repo babel configuration (#8624)
### WHY are these changes introduced? This PR replaces using `@shopify/babel-preset` with using the underlying presets directly. As part of this we simplify the plugins we use and lean more heavily on `@babel/preset-env`. As a result of this we no longer transpile numeric separators (`1_000`), nullish coalescing operators (`foo ?? 'bar'`) and optional chaining `foo?.bar` because our browserslist targets say that those features are all supported in the browsers that we target. This means that our build output now contains optional chaining et al. A breaking change side-effect of this is that code that uses these features will no longer successfully parse in webpack4, as webpack4 uses an old version of acorn does not understand these syntaxes. Webpack5 uses a newer version of acorn that can read this just fine. ### WHAT is this pull request doing? Replace `@shopify/babel-config` with using `@babel/preset-env`, `@babel/preset-typescript` and `@babel/preset-react` directly. This PR is split into two commits. The first replaces `@shopify/babel-preset` with inline config, with minimal changes. The second removes the forced compilation of the 5 plugins that were always forced to be enabled. ### How to 🎩 - Check out the main branch of polaris in your `~/projects/polaris` directory and run `cd package`, `yarn`, `yarn run turbo run build --filter='!polaris.shopify.com' --force` to produce a clean build - Check out this branch of polaris in your `~/src/github.com/Shopify/polaris` directory and run `cd package`, `yarn`, `yarn run turbo run build --filter='!polaris.shopify.com' --force` to produce a build - In the polaris in the src directory run `touch out.txt; for PACKAGENAME in $(ls -1 . | grep '^polaris-'); diff -ru ~/projects/polaris/$PACKAGENAME $PACKAGENAME -x '*.tsbuildinfo' -x '*.d.ts.map' -x'.turbo' -x '*.esnext' >> out.txt` to compare the build folder output. Note that the differences are as follows: - A handful of places where a class property is initialised to `void 0`. In all cases either the value is already implicitly undefined, or is assigned to a value shortly afterwards - Optional chaining is now left intact - Nullish coalesing is now left intact - numeric separators are now left intact --------- Co-authored-by: Alex Page <[email protected]>
1 parent 4cbc8b7 commit d1c9d98

File tree

5 files changed

+74
-74
lines changed

5 files changed

+74
-74
lines changed

.changeset/few-forks-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
No longer transpile optional chaining, nullish coalescing or numeric separators, as our target browser environments all have native support for these syntaxes. This removes support for apps using webpack4, which unable to parse these syntaxes.

babel.config.js

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,57 @@
11
/**
22
* @type {import('@babel/core').TransformOptions}
33
*/
4-
module.exports = {
5-
presets: [['@shopify/babel-preset', {typescript: true, react: true}]],
6-
babelrcRoots: [
7-
'.',
8-
// Note: The following projects use rootMode: 'upward' to inherit
9-
// and merge with this root level config.
10-
'./polaris-migrator',
11-
'./polaris-tokens',
12-
'./polaris-icons',
13-
'./polaris-react',
14-
],
4+
module.exports = function (api) {
5+
const envName = api.env();
6+
const development = envName === 'development' || envName === 'test';
7+
return {
8+
presets: [
9+
[
10+
'@babel/preset-env',
11+
{useBuiltIns: 'entry', corejs: '3.0', bugfixes: true},
12+
],
13+
['@babel/preset-typescript'],
14+
['@babel/preset-react', {development, useBuiltIns: true}],
15+
],
16+
assumptions: {
17+
setPublicClassFields: true,
18+
privateFieldsAsProperties: true,
19+
// nothing accesses `document.all`:
20+
noDocumentAll: true,
21+
// nothing relies on class constructors invoked without `new` throwing:
22+
noClassCalls: true,
23+
// nothing should be relying on tagged template strings being frozen:
24+
mutableTemplateObject: true,
25+
// nothing is relying on Function.prototype.length:
26+
ignoreFunctionLength: true,
27+
// nothing is relying on mutable re-exported bindings:
28+
constantReexports: true,
29+
// don't bother marking Module records non-enumerable:
30+
enumerableModuleMeta: true,
31+
// nothing uses [[Symbol.toPrimitive]]:
32+
// (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive)
33+
ignoreToPrimitiveHint: true,
34+
// nothing relies on spread copying Symbol keys: ({...{ [Symbol()]: 1 }})
35+
objectRestNoSymbols: true,
36+
// nothing relies on `new (() => {})` throwing:
37+
noNewArrows: true,
38+
// transpile object spread to assignment instead of defineProperty():
39+
setSpreadProperties: true,
40+
// nothing should be using custom iterator protocol:
41+
skipForOfIteratorClosing: true,
42+
// nothing inherits from a constructor function with explicit return value:
43+
superIsCallableConstructor: true,
44+
// nothing relies on CJS-transpiled namespace imports having all properties prior to module execution completing:
45+
noIncompleteNsImportDetection: true,
46+
},
47+
babelrcRoots: [
48+
'.',
49+
// Note: The following projects use rootMode: 'upward' to inherit
50+
// and merge with this root level config.
51+
'./polaris-migrator',
52+
'./polaris-tokens',
53+
'./polaris-icons',
54+
'./polaris-react',
55+
],
56+
};
1557
};

documentation/guides/migrating-from-v10-to-v11.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ NodeJS version 14 is no longer supported. NodeJS 18 is recommended and 16 is the
1818

1919
React version 16 and 17 is no longer supported. React 18 is the minimum supported version.
2020

21+
## Webpack support
22+
23+
Webpack version 4 is no longer supported. Webpack 5 is the minimum supported version.
24+
2125
## TypeScript
2226

2327
Built types in `@shopify/polaris` have moved from `build/ts/latest` to `build/ts`.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"devDependencies": {
4747
"@babel/core": "^7.20.12",
4848
"@babel/node": "^7.20.7",
49+
"@babel/preset-env": "^7.16.4",
50+
"@babel/preset-react": "^7.16.0",
4951
"@babel/preset-typescript": "^7.18.6",
5052
"@changesets/changelog-github": "^0.4.4",
5153
"@changesets/cli": "^2.23.0",
@@ -59,7 +61,6 @@
5961
"@rollup/plugin-replace": "^5.0.2",
6062
"@rollup/plugin-virtual": "^3.0.1",
6163
"@rollup/pluginutils": "^5.0.2",
62-
"@shopify/babel-preset": "^25.0.0",
6364
"@shopify/cli": "^3.10.1",
6465
"@shopify/eslint-plugin": "^42.0.1",
6566
"@shopify/prettier-config": "^1.1.2",

yarn.lock

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
semver "^5.4.1"
7878
source-map "^0.5.0"
7979

80-
"@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.12.10", "@babel/core@^7.12.3", "@babel/core@^7.13.16", "@babel/core@^7.16.0", "@babel/core@^7.4.5", "@babel/core@^7.7.2", "@babel/core@^7.7.5", "@babel/core@^7.8.0":
80+
"@babel/core@^7.0.0", "@babel/core@^7.1.0", "@babel/core@^7.12.10", "@babel/core@^7.12.3", "@babel/core@^7.13.16", "@babel/core@^7.4.5", "@babel/core@^7.7.2", "@babel/core@^7.7.5", "@babel/core@^7.8.0":
8181
version "7.18.9"
8282
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.18.9.tgz#805461f967c77ff46c74ca0460ccf4fe933ddd59"
8383
integrity sha512-1LIb1eL8APMy91/IMW+31ckrfBM4yCoLaVzoDhZUKSM4cu1L1nIidyxkCgzPAgrC5WEz36IPEr/eSeSF9pIn+g==
@@ -641,7 +641,7 @@
641641
"@babel/helper-remap-async-to-generator" "^7.18.9"
642642
"@babel/plugin-syntax-async-generators" "^7.8.4"
643643

644-
"@babel/plugin-proposal-class-properties@^7.12.1", "@babel/plugin-proposal-class-properties@^7.13.0", "@babel/plugin-proposal-class-properties@^7.16.0", "@babel/plugin-proposal-class-properties@^7.16.7", "@babel/plugin-proposal-class-properties@^7.18.6":
644+
"@babel/plugin-proposal-class-properties@^7.12.1", "@babel/plugin-proposal-class-properties@^7.13.0", "@babel/plugin-proposal-class-properties@^7.16.7", "@babel/plugin-proposal-class-properties@^7.18.6":
645645
version "7.18.6"
646646
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz#b110f59741895f7ec21a6fff696ec46265c446a3"
647647
integrity sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==
@@ -667,7 +667,7 @@
667667
"@babel/helper-plugin-utils" "^7.18.6"
668668
"@babel/plugin-syntax-class-static-block" "^7.14.5"
669669

670-
"@babel/plugin-proposal-decorators@^7.12.12", "@babel/plugin-proposal-decorators@^7.16.4":
670+
"@babel/plugin-proposal-decorators@^7.12.12":
671671
version "7.17.9"
672672
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-decorators/-/plugin-proposal-decorators-7.17.9.tgz#67a1653be9c77ce5b6c318aa90c8287b87831619"
673673
integrity sha512-EfH2LZ/vPa2wuPwJ26j+kYRkaubf89UlwxKXtxqEm57HrgSEYDB8t4swFP+p8LcI9yiP9ZRJJjo/58hS6BnaDA==
@@ -679,7 +679,7 @@
679679
"@babel/plugin-syntax-decorators" "^7.17.0"
680680
charcodes "^0.2.0"
681681

682-
"@babel/plugin-proposal-dynamic-import@^7.16.0", "@babel/plugin-proposal-dynamic-import@^7.16.7":
682+
"@babel/plugin-proposal-dynamic-import@^7.16.7":
683683
version "7.16.7"
684684
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.16.7.tgz#c19c897eaa46b27634a00fee9fb7d829158704b2"
685685
integrity sha512-I8SW9Ho3/8DRSdmDdH3gORdyUuYnk1m4cMxUAdu5oy4n3OfN8flDEH+d60iG7dUfi0KkYwSvoalHzzdRzpWHTg==
@@ -751,15 +751,15 @@
751751
"@babel/helper-plugin-utils" "^7.18.9"
752752
"@babel/plugin-syntax-logical-assignment-operators" "^7.10.4"
753753

754-
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1", "@babel/plugin-proposal-nullish-coalescing-operator@^7.13.8", "@babel/plugin-proposal-nullish-coalescing-operator@^7.16.0", "@babel/plugin-proposal-nullish-coalescing-operator@^7.16.7", "@babel/plugin-proposal-nullish-coalescing-operator@^7.18.6":
754+
"@babel/plugin-proposal-nullish-coalescing-operator@^7.12.1", "@babel/plugin-proposal-nullish-coalescing-operator@^7.13.8", "@babel/plugin-proposal-nullish-coalescing-operator@^7.16.7", "@babel/plugin-proposal-nullish-coalescing-operator@^7.18.6":
755755
version "7.18.6"
756756
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.18.6.tgz#fdd940a99a740e577d6c753ab6fbb43fdb9467e1"
757757
integrity sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==
758758
dependencies:
759759
"@babel/helper-plugin-utils" "^7.18.6"
760760
"@babel/plugin-syntax-nullish-coalescing-operator" "^7.8.3"
761761

762-
"@babel/plugin-proposal-numeric-separator@^7.16.0", "@babel/plugin-proposal-numeric-separator@^7.16.7":
762+
"@babel/plugin-proposal-numeric-separator@^7.16.7":
763763
version "7.16.7"
764764
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.16.7.tgz#d6b69f4af63fb38b6ca2558442a7fb191236eba9"
765765
integrity sha512-vQgPMknOIgiuVqbokToyXbkY/OmmjAzr/0lhSIbG/KmnzXPGwW/AdhdKpi+O4X/VkWiWjnkKOBiqJrTaC98VKw==
@@ -822,7 +822,7 @@
822822
"@babel/helper-plugin-utils" "^7.18.6"
823823
"@babel/plugin-syntax-optional-catch-binding" "^7.8.3"
824824

825-
"@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.13.12", "@babel/plugin-proposal-optional-chaining@^7.16.0", "@babel/plugin-proposal-optional-chaining@^7.16.7", "@babel/plugin-proposal-optional-chaining@^7.18.9":
825+
"@babel/plugin-proposal-optional-chaining@^7.12.7", "@babel/plugin-proposal-optional-chaining@^7.13.12", "@babel/plugin-proposal-optional-chaining@^7.16.7", "@babel/plugin-proposal-optional-chaining@^7.18.9":
826826
version "7.18.9"
827827
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.18.9.tgz#e8e8fe0723f2563960e4bf5e9690933691915993"
828828
integrity sha512-v5nwt4IqBXihxGsW2QmCWMDS3B3bzGIk/EQVZz2ei7f3NJl8NzAJVvUmpDW5q1CRNY+Beb/k58UAH1Km1N411w==
@@ -831,7 +831,7 @@
831831
"@babel/helper-skip-transparent-expression-wrappers" "^7.18.9"
832832
"@babel/plugin-syntax-optional-chaining" "^7.8.3"
833833

834-
"@babel/plugin-proposal-private-methods@^7.12.1", "@babel/plugin-proposal-private-methods@^7.16.0", "@babel/plugin-proposal-private-methods@^7.16.11":
834+
"@babel/plugin-proposal-private-methods@^7.12.1", "@babel/plugin-proposal-private-methods@^7.16.11":
835835
version "7.16.11"
836836
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-private-methods/-/plugin-proposal-private-methods-7.16.11.tgz#e8df108288555ff259f4527dbe84813aac3a1c50"
837837
integrity sha512-F/2uAkPlXDr8+BHpZvo19w3hLFKge+k75XUprE6jaqKxjGkSYcK+4c+bup5PdW/7W/Rpjwql7FTVEDW+fRAQsw==
@@ -1290,7 +1290,7 @@
12901290
"@babel/helper-plugin-utils" "^7.18.6"
12911291
babel-plugin-dynamic-import-node "^2.3.3"
12921292

1293-
"@babel/plugin-transform-modules-commonjs@^7.13.8", "@babel/plugin-transform-modules-commonjs@^7.16.0", "@babel/plugin-transform-modules-commonjs@^7.16.8", "@babel/plugin-transform-modules-commonjs@^7.18.6":
1293+
"@babel/plugin-transform-modules-commonjs@^7.13.8", "@babel/plugin-transform-modules-commonjs@^7.16.8", "@babel/plugin-transform-modules-commonjs@^7.18.6":
12941294
version "7.18.6"
12951295
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.18.6.tgz#afd243afba166cca69892e24a8fd8c9f2ca87883"
12961296
integrity sha512-Qfv2ZOWikpvmedXQJDSbxNqy7Xr/j2Y8/KfijM0iJyKkBTmWuvCA1yeH1yDM7NJhBW/2aXxeucLj6i80/LAJ/Q==
@@ -1411,13 +1411,6 @@
14111411
dependencies:
14121412
"@babel/helper-plugin-utils" "^7.18.6"
14131413

1414-
"@babel/plugin-transform-react-constant-elements@^7.16.0":
1415-
version "7.17.6"
1416-
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-constant-elements/-/plugin-transform-react-constant-elements-7.17.6.tgz#6cc273c2f612a6a50cb657e63ee1303e5e68d10a"
1417-
integrity sha512-OBv9VkyyKtsHZiHLoSfCn+h6yU7YKX8nrs32xUmOa1SRSk+t03FosB6fBZ0Yz4BpD1WV7l73Nsad+2Tz7APpqw==
1418-
dependencies:
1419-
"@babel/helper-plugin-utils" "^7.16.7"
1420-
14211414
"@babel/plugin-transform-react-display-name@^7.16.7":
14221415
version "7.16.7"
14231416
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.16.7.tgz#7b6d40d232f4c0f550ea348593db3b21e2404340"
@@ -1513,18 +1506,6 @@
15131506
dependencies:
15141507
"@babel/helper-plugin-utils" "^7.18.6"
15151508

1516-
"@babel/plugin-transform-runtime@^7.16.4":
1517-
version "7.17.0"
1518-
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.17.0.tgz#0a2e08b5e2b2d95c4b1d3b3371a2180617455b70"
1519-
integrity sha512-fr7zPWnKXNc1xoHfrIU9mN/4XKX4VLZ45Q+oMhfsYIaHvg7mHgmhfOy/ckRWqDK7XF3QDigRpkh5DKq6+clE8A==
1520-
dependencies:
1521-
"@babel/helper-module-imports" "^7.16.7"
1522-
"@babel/helper-plugin-utils" "^7.16.7"
1523-
babel-plugin-polyfill-corejs2 "^0.3.0"
1524-
babel-plugin-polyfill-corejs3 "^0.5.0"
1525-
babel-plugin-polyfill-regenerator "^0.3.0"
1526-
semver "^6.3.0"
1527-
15281509
"@babel/plugin-transform-shorthand-properties@^7.12.1", "@babel/plugin-transform-shorthand-properties@^7.16.7":
15291510
version "7.16.7"
15301511
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.16.7.tgz#e8549ae4afcf8382f711794c0c7b6b934c5fbd2a"
@@ -1841,7 +1822,7 @@
18411822
"@babel/plugin-transform-react-jsx-development" "^7.18.6"
18421823
"@babel/plugin-transform-react-pure-annotations" "^7.18.6"
18431824

1844-
"@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.16.0", "@babel/preset-typescript@^7.18.6":
1825+
"@babel/preset-typescript@^7.12.7", "@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.18.6":
18451826
version "7.18.6"
18461827
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.18.6.tgz#ce64be3e63eddc44240c6358daefac17b3186399"
18471828
integrity sha512-s9ik86kXBAnD760aybBucdpnLsAt0jK1xqJn2juOn9lkOvSHV60os5hxoVJsPzMQxvnUJFAlkont2DvvaYEBtQ==
@@ -3305,29 +3286,6 @@
33053286
resolved "https://registry.yarnpkg.com/@shopify/async/-/async-3.1.5.tgz#fcb1253ed2f41f22f9ce2ca28dc667003f4a1a71"
33063287
integrity sha512-kc/QSwQpcG2Enm6QqLUvCSbPuEabX34DTo/NKQh5eT6ud6gOCwTL3jdIiybK9RzRe3gbEUJ9cfCuggT87bXcZg==
33073288

3308-
"@shopify/babel-preset@^25.0.0":
3309-
version "25.0.0"
3310-
resolved "https://registry.yarnpkg.com/@shopify/babel-preset/-/babel-preset-25.0.0.tgz#57eaae6e250ab1a1daba26e6f1ecb42204aad929"
3311-
integrity sha512-2eVmLPGMLEdZ2u93pikVcwAf+XTpzYMtphFwuE1ZwlxBSQZg2H6OWbt/rnS79fAiJUmS7DSUel+ZlBzdSlg6Bg==
3312-
dependencies:
3313-
"@babel/core" "^7.16.0"
3314-
"@babel/plugin-proposal-class-properties" "^7.16.0"
3315-
"@babel/plugin-proposal-decorators" "^7.16.4"
3316-
"@babel/plugin-proposal-dynamic-import" "^7.16.0"
3317-
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.16.0"
3318-
"@babel/plugin-proposal-numeric-separator" "^7.16.0"
3319-
"@babel/plugin-proposal-optional-chaining" "^7.16.0"
3320-
"@babel/plugin-proposal-private-methods" "^7.16.0"
3321-
"@babel/plugin-transform-modules-commonjs" "^7.16.0"
3322-
"@babel/plugin-transform-react-constant-elements" "^7.16.0"
3323-
"@babel/plugin-transform-runtime" "^7.16.4"
3324-
"@babel/preset-env" "^7.16.4"
3325-
"@babel/preset-react" "^7.16.0"
3326-
"@babel/preset-typescript" "^7.16.0"
3327-
"@babel/runtime" "^7.16.3"
3328-
babel-plugin-react-test-id "^1.0.2"
3329-
babel-plugin-transform-inline-environment-variables "^0.4.3"
3330-
33313289
"@shopify/[email protected]":
33323290
version "3.10.1"
33333291
resolved "https://registry.yarnpkg.com/@shopify/cli-kit/-/cli-kit-3.10.1.tgz#deaf0ead4989ad4d7645a00b7f4b9cbeb8052993"
@@ -6602,16 +6560,6 @@ babel-plugin-react-docgen@^4.2.1:
66026560
lodash "^4.17.15"
66036561
react-docgen "^5.0.0"
66046562

6605-
babel-plugin-react-test-id@^1.0.2:
6606-
version "1.0.2"
6607-
resolved "https://registry.yarnpkg.com/babel-plugin-react-test-id/-/babel-plugin-react-test-id-1.0.2.tgz#90fb7ab91e9623bea47ad1f7eddd9a38e2dfc51b"
6608-
integrity sha1-kPt6uR6WI76ketH37d2aOOLfxRs=
6609-
6610-
babel-plugin-transform-inline-environment-variables@^0.4.3:
6611-
version "0.4.3"
6612-
resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-0.4.3.tgz#a3b09883353be8b5e2336e3ff1ef8a5d93f9c489"
6613-
integrity sha1-o7CYgzU76LXiM24/8e+KXZP5xIk=
6614-
66156563
babel-preset-current-node-syntax@^1.0.0:
66166564
version "1.0.1"
66176565
resolved "https://registry.yarnpkg.com/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz#b4399239b89b2a011f9ddbe3e4f401fc40cff73b"

0 commit comments

Comments
 (0)