Skip to content

Commit 2ae875c

Browse files
committed
change: replace useBuiltIns with polyfill-regenerator
- preset-env's useBuiltIns isn't pure, so it pollutes the global env when used - TSDX is used by libraries, and libraries really shouldn't pollute their consumers' global envs - so use the fairly recent babel-plugin-polyfill-regenerator with its usage-pure option instead - since we're not using useBuiltIns, we don't need core-js either, and can remove it, reverting back to the previous behavior - this ensures that the PR is less breaking and does not really introduce new behavior, just replaces async-to-promises with regenerator - useBuiltIns was previously unset, i.e. defaulted to false, so @babel/polyfill was an extraneous package and we don't need to add that back - revert the rollup-plugin-commonjs usage change since core-js isn't used anymore - ensure that customOptions.targets is passed into polyfill-regenerator's config so it's the same targets as preset-env - so there's some work/discussion upstream in Babel on consolidating targets, but maybe we should have polyfill-regenerator inherit preset-env's targets if it were customized... - problem with that is that it may be breaking once we switch babelPluginTsdx to an actual preset...
1 parent 63e488c commit 2ae875c

File tree

4 files changed

+61
-34
lines changed

4 files changed

+61
-34
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@
5858
"babel-plugin-annotate-pure-calls": "^0.4.0",
5959
"babel-plugin-dev-expression": "^0.2.1",
6060
"babel-plugin-macros": "^2.6.1",
61+
"babel-plugin-polyfill-regenerator": "^0.0.4",
6162
"babel-plugin-transform-rename-import": "^2.3.0",
6263
"babel-traverse": "^6.26.0",
6364
"babylon": "^6.18.0",
6465
"camelcase": "^6.0.0",
6566
"chalk": "^4.0.0",
66-
"core-js": "^2.6.5",
6767
"enquirer": "^2.3.4",
6868
"eslint": "^6.1.0",
6969
"eslint-config-prettier": "^6.0.0",

src/babelPluginTsdx.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
7474
name: 'babel-plugin-transform-rename-import',
7575
replacements,
7676
},
77+
{
78+
name: 'babel-plugin-polyfill-regenerator',
79+
// don't pollute global env as this is being used in a library
80+
method: 'usage-pure',
81+
targets: customOptions.targets,
82+
},
7783
{
7884
name: '@babel/plugin-proposal-class-properties',
7985
loose: true,
@@ -101,8 +107,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
101107
{
102108
loose: true,
103109
targets: customOptions.targets,
104-
useBuiltIns: 'usage',
105-
corejs: 2,
106110
},
107111
presetEnv.options,
108112
{
@@ -120,8 +124,6 @@ export const babelPluginTsdx = babelPlugin.custom(() => ({
120124
{
121125
name: '@babel/preset-env',
122126
targets: customOptions.targets,
123-
useBuiltIns: 'usage',
124-
corejs: 2,
125127
modules: false,
126128
loose: true,
127129
},

src/createRollupConfig.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ export async function createRollupConfig(
6060
input: opts.input,
6161
// Tell Rollup which packages to ignore
6262
external: (id: string) => {
63-
// bundle in any polyfills as TSDX can't control whether polyfills are installed as deps
64-
if (id.startsWith('regenerator-runtime') || id.startsWith('core-js')) {
63+
// bundle in polyfills as TSDX can't (yet) ensure installed as deps
64+
if (id.startsWith('regenerator-runtime')) {
6565
return false;
6666
}
6767

@@ -120,12 +120,11 @@ export async function createRollupConfig(
120120
// defaults + .jsx
121121
extensions: ['.mjs', '.js', '.jsx', '.json', '.node'],
122122
}),
123-
commonjs({
124-
// Use a regex to make sure to include eventual hoisted packages (umd).
125-
// Always transform core-js, so its internal dependencies are found
126-
// by rollup's external() resolution.
127-
include: opts.format === 'umd' ? /\/node_modules\// : /core-js\//,
128-
}),
123+
opts.format === 'umd' &&
124+
commonjs({
125+
// use a regex to make sure to include eventual hoisted packages
126+
include: /\/node_modules\//,
127+
}),
129128
json(),
130129
{
131130
// Custom plugin that removes shebang from code because newer

yarn.lock

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
semver "^5.4.1"
4141
source-map "^0.5.0"
4242

43-
"@babel/generator@^7.11.0", "@babel/generator@^7.9.0":
44-
version "7.11.4"
45-
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.11.4.tgz#1ec7eec00defba5d6f83e50e3ee72ae2fee482be"
46-
integrity sha512-Rn26vueFx0eOoz7iifCN2UHT6rGtnkSGWSoDRIy8jZN3B91PzeSULbswfLoOWuTuAcNwpG/mxy+uCTDnZ9Mp1g==
43+
"@babel/generator@^7.11.0", "@babel/generator@^7.11.5", "@babel/generator@^7.9.0":
44+
version "7.11.6"
45+
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.11.6.tgz#b868900f81b163b4d464ea24545c61cbac4dc620"
46+
integrity sha512-DWtQ1PV3r+cLbySoHrwn9RWEgKMBLLma4OBQloPRyDYvc5msJM9kvTLo1YnlJd1P/ZuKbdli3ijr5q3FvAF3uA==
4747
dependencies:
48-
"@babel/types" "^7.11.0"
48+
"@babel/types" "^7.11.5"
4949
jsesc "^2.5.1"
5050
source-map "^0.5.0"
5151

@@ -105,6 +105,20 @@
105105
"@babel/types" "^7.10.5"
106106
lodash "^4.17.19"
107107

108+
"@babel/helper-define-polyfill-provider@^0.0.3":
109+
version "0.0.3"
110+
resolved "https://registry.yarnpkg.com/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.0.3.tgz#df9da66285b884ce66417abdd0b6ca91198149bd"
111+
integrity sha512-dULDd/APiP4JowYDAMosecKOi/1v+UId99qhBGiO3myM29KtAVKS/R3x3OJJNBR0FeYB1BcYb2dCwkhqvxWXXQ==
112+
dependencies:
113+
"@babel/helper-compilation-targets" "^7.10.4"
114+
"@babel/helper-module-imports" "^7.10.4"
115+
"@babel/helper-plugin-utils" "^7.10.4"
116+
"@babel/traverse" "^7.11.5"
117+
debug "^4.1.1"
118+
lodash.debounce "^4.0.8"
119+
resolve "^1.14.2"
120+
semver "^6.1.2"
121+
108122
"@babel/helper-explode-assignable-expression@^7.10.4":
109123
version "7.11.4"
110124
resolved "https://registry.yarnpkg.com/@babel/helper-explode-assignable-expression/-/helper-explode-assignable-expression-7.11.4.tgz#2d8e3470252cc17aba917ede7803d4a7a276a41b"
@@ -256,10 +270,10 @@
256270
chalk "^2.0.0"
257271
js-tokens "^4.0.0"
258272

259-
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.10.4", "@babel/parser@^7.11.0", "@babel/parser@^7.7.5", "@babel/parser@^7.9.0":
260-
version "7.11.4"
261-
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.11.4.tgz#6fa1a118b8b0d80d0267b719213dc947e88cc0ca"
262-
integrity sha512-MggwidiH+E9j5Sh8pbrX5sJvMcsqS5o+7iB42M9/k0CD63MjYbdP4nhSh7uB5wnv2/RVzTZFTxzF/kIa5mrCqA==
273+
"@babel/parser@^7.0.0", "@babel/parser@^7.1.0", "@babel/parser@^7.10.4", "@babel/parser@^7.11.0", "@babel/parser@^7.11.5", "@babel/parser@^7.7.5", "@babel/parser@^7.9.0":
274+
version "7.11.5"
275+
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.11.5.tgz#c7ff6303df71080ec7a4f5b8c003c58f1cf51037"
276+
integrity sha512-X9rD8qqm695vgmeaQ4fvz/o3+Wk4ZzQvSHkDBgpYKxpD4qTAUm88ZKtHkVqIOsYFFbIQ6wQYhC6q7pjqVK0E0Q==
263277

264278
"@babel/plugin-proposal-async-generator-functions@^7.10.4":
265279
version "7.10.5"
@@ -829,25 +843,25 @@
829843
"@babel/parser" "^7.10.4"
830844
"@babel/types" "^7.10.4"
831845

832-
"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.10.4", "@babel/traverse@^7.4.5", "@babel/traverse@^7.7.4", "@babel/traverse@^7.9.0":
833-
version "7.11.0"
834-
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.11.0.tgz#9b996ce1b98f53f7c3e4175115605d56ed07dd24"
835-
integrity sha512-ZB2V+LskoWKNpMq6E5UUCrjtDUh5IOTAyIl0dTjIEoXum/iKWkoIEKIRDnUucO6f+2FzNkE0oD4RLKoPIufDtg==
846+
"@babel/traverse@^7.0.0", "@babel/traverse@^7.1.0", "@babel/traverse@^7.10.4", "@babel/traverse@^7.11.5", "@babel/traverse@^7.4.5", "@babel/traverse@^7.7.4", "@babel/traverse@^7.9.0":
847+
version "7.11.5"
848+
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.11.5.tgz#be777b93b518eb6d76ee2e1ea1d143daa11e61c3"
849+
integrity sha512-EjiPXt+r7LiCZXEfRpSJd+jUMnBd4/9OUv7Nx3+0u9+eimMwJmG0Q98lw4/289JCoxSE8OolDMNZaaF/JZ69WQ==
836850
dependencies:
837851
"@babel/code-frame" "^7.10.4"
838-
"@babel/generator" "^7.11.0"
852+
"@babel/generator" "^7.11.5"
839853
"@babel/helper-function-name" "^7.10.4"
840854
"@babel/helper-split-export-declaration" "^7.11.0"
841-
"@babel/parser" "^7.11.0"
842-
"@babel/types" "^7.11.0"
855+
"@babel/parser" "^7.11.5"
856+
"@babel/types" "^7.11.5"
843857
debug "^4.1.0"
844858
globals "^11.1.0"
845859
lodash "^4.17.19"
846860

847-
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.11.0", "@babel/types@^7.3.0", "@babel/types@^7.4.4", "@babel/types@^7.9.0":
848-
version "7.11.0"
849-
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.0.tgz#2ae6bf1ba9ae8c3c43824e5861269871b206e90d"
850-
integrity sha512-O53yME4ZZI0jO1EVGtF1ePGl0LHirG4P1ibcD80XyzZcKhcMFeCXmh4Xb1ifGBIV233Qg12x4rBfQgA+tmOukA==
861+
"@babel/types@^7.0.0", "@babel/types@^7.10.4", "@babel/types@^7.10.5", "@babel/types@^7.11.0", "@babel/types@^7.11.5", "@babel/types@^7.3.0", "@babel/types@^7.4.4", "@babel/types@^7.9.0":
862+
version "7.11.5"
863+
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.11.5.tgz#d9de577d01252d77c6800cee039ee64faf75662d"
864+
integrity sha512-bvM7Qz6eKnJVFIn+1LPtjlBFPVN5jNDc1XmN15vWe7Q3DPBufWWsLiIvUu7xW87uTG6QoggpIDnUgLQvPheU+Q==
851865
dependencies:
852866
"@babel/helper-validator-identifier" "^7.10.4"
853867
lodash "^4.17.19"
@@ -1881,6 +1895,13 @@ babel-plugin-macros@^2.6.1:
18811895
cosmiconfig "^6.0.0"
18821896
resolve "^1.12.0"
18831897

1898+
babel-plugin-polyfill-regenerator@^0.0.4:
1899+
version "0.0.4"
1900+
resolved "https://registry.yarnpkg.com/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.0.4.tgz#588641af9a2cb4e299b1400c47672a4a104d2459"
1901+
integrity sha512-+/uCzO9JTYVZVGCpZpVAQkgPGt2zkR0VYiZvJ4aVoCe4ccgpKvNQqcjzAgQzSsjK64Jhc5hvrCR3l0087BevkA==
1902+
dependencies:
1903+
"@babel/helper-define-polyfill-provider" "^0.0.3"
1904+
18841905
babel-plugin-replace-identifiers@^0.1.1:
18851906
version "0.1.1"
18861907
resolved "https://registry.yarnpkg.com/babel-plugin-replace-identifiers/-/babel-plugin-replace-identifiers-0.1.1.tgz#38819617d814ab0e4b35cfa373e40758b359f68f"
@@ -2540,7 +2561,7 @@ core-js-pure@^3.0.0:
25402561
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.4.7.tgz#c998e1892da9949200c7452cbd33c0df95be9f54"
25412562
integrity sha512-Am3uRS8WCdTFA3lP7LtKR0PxgqYzjAMGKXaZKSNSC/8sqU0Wfq8R/YzoRs2rqtOVEunfgH+0q3O0BKOg0AvjPw==
25422563

2543-
core-js@^2.4.0, core-js@^2.6.5:
2564+
core-js@^2.4.0:
25442565
version "2.6.10"
25452566
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.6.10.tgz#8a5b8391f8cc7013da703411ce5b585706300d7f"
25462567
integrity sha512-I39t74+4t+zau64EN1fE5v2W31Adtc/REhzWN+gWRRXg6WH5qAsZm62DHpQ1+Yhe4047T55jvzz7MUqF/dBBlA==
@@ -5348,6 +5369,11 @@ lodash.camelcase@^4.3.0:
53485369
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
53495370
integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY=
53505371

5372+
lodash.debounce@^4.0.8:
5373+
version "4.0.8"
5374+
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
5375+
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
5376+
53515377
lodash.memoize@4.x, lodash.memoize@^4.1.2:
53525378
version "4.1.2"
53535379
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"

0 commit comments

Comments
 (0)