Skip to content

Commit 3a46d39

Browse files
authored
fix(babel): prepare for Rollup 3 (#1303)
BREAKING CHANGES: Requires Node 14
1 parent 1ddb5b5 commit 3a46d39

12 files changed

+200
-179
lines changed

packages/babel/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Using Rollup with `@rollup/plugin-babel` makes the process far easier.
2626

2727
## Requirements
2828

29-
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v10.0.0+) and Rollup v1.20.0+.
29+
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v14.0.0+) and Rollup v1.20.0+.
3030

3131
## Install
3232

@@ -45,7 +45,7 @@ const config = {
4545
input: 'src/index.js',
4646
output: {
4747
dir: 'output',
48-
format: 'esm'
48+
format: 'es'
4949
},
5050
plugins: [babel({ babelHelpers: 'bundled' })]
5151
};
@@ -174,7 +174,7 @@ export default {
174174
],
175175
output: [
176176
{ file: 'bundle.cjs.js', format: 'cjs' },
177-
{ file: 'bundle.esm.js', format: 'esm' }
177+
{ file: 'bundle.es.js', format: 'es' }
178178
]
179179
};
180180
```
@@ -188,10 +188,10 @@ import { getBabelOutputPlugin } from '@rollup/plugin-babel';
188188
export default {
189189
input: 'main.js',
190190
output: [
191-
{ file: 'bundle.js', format: 'esm' },
191+
{ file: 'bundle.js', format: 'es' },
192192
{
193193
file: 'bundle.es5.js',
194-
format: 'esm',
194+
format: 'es',
195195
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })]
196196
}
197197
]
@@ -212,7 +212,7 @@ export default {
212212
output: [
213213
{
214214
file: 'bundle.js',
215-
format: 'esm',
215+
format: 'es',
216216
plugins: [getBabelOutputPlugin({ presets: ['@babel/preset-env'] })]
217217
}
218218
]
@@ -231,7 +231,7 @@ getBabelOutputPlugin({
231231

232232
### Using formats other than ES modules or CommonJS
233233

234-
As `getBabelOutputPlugin(...)` will run _after_ Rollup has done all its transformations, it needs to make sure it preserves the semantics of Rollup's output format. This is especially important for Babel plugins that add, modify or remove imports or exports, but also for other transformations that add new variables as they can accidentally become global variables depending on the format. Therefore it is recommended that for formats other than `esm` or `cjs`, you set Rollup to use the `esm` output format and let Babel handle the transformation to another format, e.g. via
234+
As `getBabelOutputPlugin(...)` will run _after_ Rollup has done all its transformations, it needs to make sure it preserves the semantics of Rollup's output format. This is especially important for Babel plugins that add, modify or remove imports or exports, but also for other transformations that add new variables as they can accidentally become global variables depending on the format. Therefore it is recommended that for formats other than `es` or `cjs`, you set Rollup to use the `es` output format and let Babel handle the transformation to another format, e.g. via
235235

236236
```
237237
presets: [['@babel/preset-env', { modules: 'umd' }], ...]
@@ -256,12 +256,12 @@ By default, helpers e.g. when transpiling classes will be inserted at the top of
256256

257257
Alternatively, you can use imported runtime helpers by adding the `@babel/transform-runtime` plugin. This will make `@babel/runtime` an external dependency of your project, see [@babel/plugin-transform-runtime](https://babeljs.io/docs/en/babel-plugin-transform-runtime) for details.
258258

259-
Note that this will only work for `esm` and `cjs` formats, and you need to make sure to set the `useESModules` option of `@babel/plugin-transform-runtime` to `true` if you create ESM output:
259+
Note that this will only work for `es` and `cjs` formats, and you need to make sure to set the `useESModules` option of `@babel/plugin-transform-runtime` to `true` if you create ES output:
260260

261261
```js
262262
rollup.rollup({...})
263263
.then(bundle => bundle.generate({
264-
format: 'esm',
264+
format: 'es',
265265
plugins: [getBabelOutputPlugin({
266266
presets: ['@babel/preset-env'],
267267
plugins: [['@babel/plugin-transform-runtime', { useESModules: true }]]

packages/babel/package.json

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
"author": "Rich Harris",
1414
"homepage": "https://github.com/rollup/plugins/tree/master/packages/babel#readme",
1515
"bugs": "https://github.com/rollup/plugins/issues",
16-
"main": "dist/index.js",
17-
"module": "dist/index.es.js",
16+
"main": "./dist/cjs/index.js",
17+
"module": "./dist/es/index.js",
18+
"exports": {
19+
"types": "./types/index.d.ts",
20+
"import": "./dist/es/index.js",
21+
"default": "./dist/cjs/index.js"
22+
},
1823
"engines": {
19-
"node": ">= 10.0.0"
24+
"node": ">=14.0.0"
2025
},
2126
"scripts": {
2227
"build": "rollup -c",
@@ -33,6 +38,7 @@
3338
},
3439
"files": [
3540
"dist",
41+
"!dist/**/*.map",
3642
"types",
3743
"README.md",
3844
"LICENSE"
@@ -48,35 +54,35 @@
4854
"peerDependencies": {
4955
"@babel/core": "^7.0.0",
5056
"@types/babel__core": "^7.1.9",
51-
"rollup": "^1.20.0||^2.0.0"
57+
"rollup": "^1.20.0||^2.0.0||^3.0.0"
5258
},
5359
"peerDependenciesMeta": {
60+
"rollup": {
61+
"optional": true
62+
},
5463
"@types/babel__core": {
5564
"optional": true
5665
}
5766
},
5867
"dependencies": {
59-
"@babel/helper-module-imports": "^7.10.4",
60-
"@rollup/pluginutils": "^3.1.0"
68+
"@babel/helper-module-imports": "^7.18.6",
69+
"@rollup/pluginutils": "^4.2.1"
6170
},
6271
"devDependencies": {
63-
"@babel/core": "^7.10.5",
64-
"@babel/plugin-external-helpers": "^7.10.4",
65-
"@babel/plugin-proposal-decorators": "^7.10.5",
72+
"@babel/core": "^7.19.1",
73+
"@babel/plugin-external-helpers": "^7.18.6",
74+
"@babel/plugin-proposal-decorators": "^7.19.1",
6675
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
67-
"@babel/plugin-transform-runtime": "^7.10.5",
68-
"@babel/preset-env": "^7.10.4",
76+
"@babel/plugin-transform-runtime": "^7.19.1",
77+
"@babel/preset-env": "^7.19.1",
6978
"@rollup/plugin-json": "^4.1.0",
70-
"@rollup/plugin-node-resolve": "^10.0.0",
79+
"@rollup/plugin-node-resolve": "^14.1.0",
7180
"@types/babel__core": "^7.1.9",
72-
"rollup": "^2.67.3",
73-
"source-map": "^0.7.3"
81+
"rollup": "^3.0.0-7",
82+
"source-map": "^0.7.4"
7483
},
75-
"types": "types/index.d.ts",
84+
"types": "./types/index.d.ts",
7685
"ava": {
77-
"babel": {
78-
"compileEnhancements": false
79-
},
8086
"files": [
8187
"!**/fixtures/**",
8288
"!**/helpers/**",

packages/babel/rollup.config.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/babel/rollup.config.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { readFileSync } from 'fs';
2+
3+
import { createConfig } from '../../shared/rollup.config.mjs';
4+
5+
import { babel } from './src/index.js';
6+
7+
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8'));
8+
9+
export default {
10+
...createConfig({ pkg }),
11+
input: './src/index.js',
12+
plugins: [
13+
babel({
14+
presets: [['@babel/preset-env', { targets: { node: 14 } }]],
15+
babelHelpers: 'bundled'
16+
})
17+
]
18+
};

packages/babel/src/bundledHelpersPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addNamed } from '@babel/helper-module-imports';
22

3-
import { HELPERS } from './constants';
3+
import { HELPERS } from './constants.js';
44

55
export default function importHelperPlugin({ types: t }) {
66
return {

packages/babel/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import * as babel from '@babel/core';
22
import { createFilter } from '@rollup/pluginutils';
33

4-
import { BUNDLED, HELPERS } from './constants';
5-
import bundledHelpersPlugin from './bundledHelpersPlugin';
6-
import preflightCheck from './preflightCheck';
7-
import transformCode from './transformCode';
8-
import { addBabelPlugin, escapeRegExpCharacters, warnOnce, stripQuery } from './utils';
4+
import { BUNDLED, HELPERS } from './constants.js';
5+
import bundledHelpersPlugin from './bundledHelpersPlugin.js';
6+
import preflightCheck from './preflightCheck.js';
7+
import transformCode from './transformCode.js';
8+
import { addBabelPlugin, escapeRegExpCharacters, warnOnce, stripQuery } from './utils.js';
99

1010
const unpackOptions = ({
1111
extensions = babel.DEFAULT_EXTENSIONS,

packages/babel/src/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

packages/babel/src/preflightCheck.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as babel from '@babel/core';
22

3-
import { INLINE, RUNTIME, EXTERNAL, BUNDLED } from './constants';
4-
import { addBabelPlugin } from './utils';
3+
import { INLINE, RUNTIME, EXTERNAL, BUNDLED } from './constants.js';
4+
import { addBabelPlugin } from './utils.js';
55

66
const MODULE_ERROR =
77
'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' +

0 commit comments

Comments
 (0)