Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define our own in-repo babel configuration #8624

Merged
merged 4 commits into from
Mar 10, 2023
Merged

Define our own in-repo babel configuration #8624

merged 4 commits into from
Mar 10, 2023

Conversation

BPScott
Copy link
Member

@BPScott BPScott commented Mar 10, 2023

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

BPScott added 2 commits March 9, 2023 17:03
This commit is a non-breaking change. There are slight differences with
how class properties are initialised - it removes setting them to
undefined before reassigning them, which isn't needed.
Now we transpile based upon our browserslist, we don't force the usage
of these transpilations.

In practice, given our current browserslist config this means that the
following transforms are now no longer ran (for instance our compiled
output now contains `foo?.bar` instead of that being transformed):

- proposal-numeric-separator
- proposal-nullish-coalescing-operator
- proposal-optional-chaining
@BPScott BPScott requested a review from alex-page March 10, 2023 02:14
Copy link
Member

@alex-page alex-page left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some v11 docs. Happy to expand them but keeping them simple for now.

Comment on lines +1 to +5
---
'@shopify/polaris': major
---

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thanks Ben!

@BPScott BPScott merged commit d1c9d98 into v11-major Mar 10, 2023
@BPScott BPScott deleted the babel-presets branch March 10, 2023 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants