getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.94k stars 1.56k forks source link

[v9] Drop polyfills from build output #8795

Open mydea opened 1 year ago

mydea commented 1 year ago

Currently, we include a few polyfills in our build:

_asyncNullishCoalesce
_asyncOptionalChain
_asyncOptionalChainDelete
_createNamedExportFrom
_createStarExport
_interopDefault
_interopNamespace
_interopNamespaceDefaultOnly
_interopRequireDefault
_interopRequireWildcard
_nullishCoalesce
_optionalChain
_optionalChainDelete

These are a bit tricky, increase complexity and build size.

These can be split into two categories:

  1. nullish coalesce & optional chaining polyfills
  2. Bundler-related polyfills

The first category is actually disallowed by eslint rules, as the polyfills increase bundle size considerably when used. We do not use any nullish coalesce/optional chaining in all core/browser SDKs, only in node & nextjs.

I propose to remove these polyfills in v8, if we decide to bump the min. Node version to 14+. Node 14 supports both nullish coalescing as well as optional chaining.

I propose to leave the eslint rules for core/browser SDKs in place, but simply rely on them to ensure we don't use them outside of node context. We also have tests covering that the ES5 CDN bundles are valid ES5, which should cover any regressions there. This allows us to get rid of these polyfills:

_asyncNullishCoalesce
_asyncOptionalChain
_asyncOptionalChainDelete
_nullishCoalesce
_optionalChain
_optionalChainDelete

The other category of polyfills:

_createNamedExportFrom
_createStarExport
_interopDefault
_interopNamespace
_interopNamespaceDefaultOnly
_interopRequireDefault
_interopRequireWildcard

I propose we investigate if we can solve this with rollup instead.

Benefits of dropping the polyfills

mydea commented 1 year ago

Update for this issue: We dropped the build-related polyfills, so the remaining ones are the nullish coalesce & optional chaining ones.

timfish commented 6 months ago

It looks like we can drop the polyfills entirely for @sentry/node and @sentry/profiling-node and @sentry/bun

AbhiPrasad commented 6 months ago

So we did some refactors, but we still have https://github.com/getsentry/sentry-javascript/tree/develop/packages/utils/src/buildPolyfills left. Can we safely remove this?

mydea commented 4 months ago

Honestly I think at this stage we'll simply remove this once we update support policy to not need polyfills for optional chaining etc anymore 😬