Skip to content

Commit 7185b9d

Browse files
committed
Improved Babel config.
Includes a workaround for babel/babel#8462 .
1 parent 5ae172e commit 7185b9d

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

.size-limit.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
"name": "Browser",
1010
"path": "size-limit-entries/browser.mjs",
1111
"limit": "2.5 KB",
12-
"ignore": ["prop-types", "object-assign"]
12+
"ignore": ["prop-types"]
1313
}
1414
]
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
/**
4+
* A Babel plugin that adds missing `.js` file extensions to Babel runtime
5+
* import specifiers.
6+
* @param {object} babel Current Babel object.
7+
* @returns {object} Babel plugin object.
8+
* @see [babel/babel#8462](https://github.com/babel/babel/issues/8462).
9+
* @ignore
10+
*/
11+
module.exports = function babelPluginAddBabelRuntimeFileExtensions({ types }) {
12+
return {
13+
visitor: {
14+
'ImportDeclaration|ExportNamedDeclaration'(path) {
15+
if (
16+
path.node.source &&
17+
path.node.source.value.startsWith('@babel/runtime/helpers/') &&
18+
!path.node.source.value.endsWith('.js')
19+
)
20+
path
21+
.get('source')
22+
.replaceWith(types.stringLiteral(`${path.node.source.value}.js`))
23+
}
24+
}
25+
}
26+
}

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
### Patch
1111

1212
- Updated tests for compatibility with updated dependencies.
13+
- Removed the [`object-assign`](https://npm.im/object-assign) dependency and several Babel dev dependencies after simplifying the Babel config.
1314
- Added a new [`babel-plugin-transform-require-extensions`](https://npm.im/babel-plugin-transform-require-extensions) dev dependency and ensured ESM import specifiers in both source and published `.mjs` files contain file names with extensions, which [are mandatory in the final Node.js ESM implementation](https://nodejs.org/api/esm.html#esm_mandatory_file_extensions). Published CJS `.js` files now also have file extensions in `require` paths.
1415
- Stop using [`husky`](https://npm.im/husky) and [`lint-staged`](https://npm.im/lint-staged).
1516
- Tidied Babel configs.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,17 @@
4545
"extract-files": "^7.0.0",
4646
"fnv1a": "^1.0.1",
4747
"mitt": "^1.1.3",
48-
"object-assign": "^4.1.1",
4948
"prop-types": "^15.7.2"
5049
},
5150
"devDependencies": {
5251
"@babel/cli": "^7.8.4",
5352
"@babel/core": "^7.9.0",
5453
"@babel/plugin-proposal-class-properties": "^7.8.3",
55-
"@babel/plugin-proposal-object-rest-spread": "^7.9.0",
5654
"@babel/plugin-transform-runtime": "^7.9.0",
5755
"@babel/preset-env": "^7.9.0",
5856
"@babel/preset-react": "^7.9.1",
5957
"@size-limit/preset-small-lib": "^4.4.0",
6058
"babel-eslint": "^10.1.0",
61-
"babel-plugin-transform-replace-object-assign": "^2.0.0",
6259
"babel-plugin-transform-require-extensions": "^2.0.0",
6360
"cross-fetch": "^3.0.4",
6461
"eslint": "^6.8.0",

src/server/.babelrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
'use strict'
22

3+
const plugins = ['@babel/transform-runtime', 'transform-require-extensions']
4+
5+
if (process.env.BABEL_ESM)
6+
plugins.push(require('../../babelPluginAddBabelRuntimeFileExtensions.js'))
7+
38
module.exports = {
49
comments: false,
5-
plugins: ['@babel/transform-runtime', 'transform-require-extensions'],
10+
plugins,
611
presets: [
712
[
813
'@babel/env',

src/test/.babelrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
'use strict'
22

3+
const plugins = ['@babel/transform-runtime', 'transform-require-extensions']
4+
5+
if (process.env.BABEL_ESM)
6+
plugins.push(require('../../babelPluginAddBabelRuntimeFileExtensions.js'))
7+
38
module.exports = {
49
comments: false,
5-
plugins: ['@babel/transform-runtime', 'transform-require-extensions'],
10+
plugins,
611
presets: [
712
[
813
'@babel/env',

src/universal/.babelrc.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
'use strict'
22

3+
const plugins = [
4+
['@babel/proposal-class-properties', { loose: true }],
5+
'@babel/transform-runtime',
6+
'transform-require-extensions'
7+
]
8+
9+
if (process.env.BABEL_ESM)
10+
plugins.push(require('../../babelPluginAddBabelRuntimeFileExtensions.js'))
11+
312
module.exports = {
413
comments: false,
5-
plugins: [
6-
['@babel/proposal-object-rest-spread', { loose: true, useBuiltIns: true }],
7-
['@babel/proposal-class-properties', { loose: true }],
8-
'@babel/transform-runtime',
9-
'transform-require-extensions'
10-
],
14+
plugins,
1115
presets: [
12-
{ plugins: ['transform-replace-object-assign'] },
1316
[
1417
'@babel/env',
1518
{
@@ -19,6 +22,6 @@ module.exports = {
1922
loose: true
2023
}
2124
],
22-
['@babel/react', { useBuiltIns: true }]
25+
'@babel/react'
2326
]
2427
}

0 commit comments

Comments
 (0)