Skip to content

Commit 3eb0258

Browse files
committed
[RN72][skip-ci] Update Babel config for monorepo setup
Summary: In the next diff, we update ESLint, which necessitates replacing the deprecated `babel-eslint` with the new `@babel/eslint-parser`. The new `@babel/eslint-parser` appears to break `yarn eslint:fix` from the repo root, since it can't find a Babel config file. To address this, I had to update our Babel config to work from the root. Some relevant docs I had to read: - https://babeljs.io/docs/config-files#project-wide-configuration - https://babeljs.io/docs/config-files#file-relative-configuration - https://babeljs.io/docs/config-files#monorepos - https://babeljs.io/docs/options#babelrcroots In short, Babel's docs recommend that for a monorepo setup, you use a single `babel.config.cjs` file in the root, and then specify `.babelrc.cjs` files for individual workspaces. However, this didn't work with Jest, which was ignoring the `.babelrc.cjs` files. This is [documented](jestjs/jest#8365) in [issues](jestjs/jest#10017) on [the](jestjs/jest#10256) Jest repo, but there are no official solutions. To get around this, I ended up also specifying `babel.config.cjs` files for the individual workspaces, that simply reference the `.babelrc.cjs` files. Depends on D10536 Test Plan: In combination with the next diff, run `yarn eslint:fix` from the repo root Reviewers: atul Reviewed By: atul Subscribers: tomek Differential Revision: https://phab.comm.dev/D10537
1 parent eb98149 commit 3eb0258

15 files changed

+89
-83
lines changed

lib/babel.config.cjs renamed to babel.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = {
77
'@babel/plugin-proposal-nullish-coalescing-operator',
88
['@babel/plugin-transform-runtime', { useESModules: true }],
99
],
10-
1110
env: {
1211
test: {
1312
presets: [
@@ -22,4 +21,5 @@ module.exports = {
2221
],
2322
},
2423
},
24+
babelrcRoots: ['.', 'keyserver', 'web', 'native', 'desktop', 'landing'],
2525
};
File renamed without changes.

keyserver/.babelrc.cjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module.exports = {
2+
presets: ['@babel/preset-react', '@babel/preset-flow'],
3+
plugins: [
4+
'@babel/plugin-proposal-class-properties',
5+
'@babel/plugin-proposal-object-rest-spread',
6+
'@babel/plugin-syntax-dynamic-import',
7+
'@babel/plugin-proposal-optional-chaining',
8+
'@babel/plugin-proposal-nullish-coalescing-operator',
9+
['@babel/plugin-transform-runtime', { useESModules: true }],
10+
],
11+
env: {
12+
test: {
13+
presets: [
14+
[
15+
'@babel/preset-env',
16+
{
17+
targets: {
18+
node: 'current',
19+
},
20+
},
21+
],
22+
],
23+
plugins: [
24+
// Replace the import.meta object in the Jest testing environment.
25+
// This allows Jest to understand import.meta.url in rust-node-addon.
26+
[
27+
'babel-plugin-transform-import-meta',
28+
{
29+
replaceWith: '({ url: __filename })',
30+
},
31+
],
32+
],
33+
},
34+
},
35+
};

keyserver/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ RUN cd keyserver && bash/docker-update-geoip.sh
163163
# These are needed for babel-build-comm-config
164164
COPY --chown=comm keyserver/src keyserver/src
165165
COPY --chown=comm keyserver/bash/source-nvm.sh keyserver/bash/source-nvm.sh
166-
COPY --chown=comm keyserver/babel.config.cjs keyserver/babel.config.cjs
166+
COPY --chown=comm keyserver/.babelrc.cjs keyserver/.babelrc.cjs
167167

168168
COPY --chown=comm lib lib/
169169

keyserver/babel.config.cjs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,2 @@
1-
module.exports = {
2-
presets: ['@babel/preset-react', '@babel/preset-flow'],
3-
plugins: [
4-
'@babel/plugin-proposal-class-properties',
5-
'@babel/plugin-proposal-object-rest-spread',
6-
'@babel/plugin-syntax-dynamic-import',
7-
'@babel/plugin-proposal-optional-chaining',
8-
'@babel/plugin-proposal-nullish-coalescing-operator',
9-
['@babel/plugin-transform-runtime', { useESModules: true }],
10-
],
11-
env: {
12-
test: {
13-
presets: [
14-
[
15-
'@babel/preset-env',
16-
{
17-
targets: {
18-
node: 'current',
19-
},
20-
},
21-
],
22-
],
23-
plugins: [
24-
// Replace the import.meta object in the Jest testing environment.
25-
// This allows Jest to understand import.meta.url in rust-node-addon.
26-
[
27-
'babel-plugin-transform-import-meta',
28-
{
29-
replaceWith: '({ url: __filename })',
30-
},
31-
],
32-
],
33-
},
34-
},
35-
};
1+
const config = require('./.babelrc.cjs');
2+
module.exports = config;

keyserver/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"main": "dist/keyserver",
88
"scripts": {
99
"clean": "rm -rf dist/ && rm -rf node_modules/ && mkdir dist",
10-
"babel-build-comm-config": ". bash/source-nvm.sh && yarn --silent babel src/lib/utils/comm-config.js --out-dir dist/lib/utils/ --config-file ./babel.config.cjs",
11-
"babel-build": ". bash/source-nvm.sh && yarn --silent babel src/ --out-dir dist/ --config-file ./babel.config.cjs --verbose --ignore 'src/landing/flow-typed','src/landing/node_modules','src/landing/package.json','src/lib/flow-typed','src/lib/node_modules','src/lib/package.json','src/web/flow-typed','src/web/node_modules','src/web/package.json','src/web/dist','src/web/webpack.config.js','src/web/account-bar.react.js','src/web/app.react.js','src/web/calendar','src/web/chat','src/web/flow','src/web/loading-indicator.react.js','src/web/modals','src/web/root.js','src/web/router-history.js','src/web/script.js','src/web/selectors/chat-selectors.js','src/web/selectors/entry-selectors.js','src/web/splash','src/web/vector-utils.js','src/web/vectors.react.js'",
10+
"babel-build-comm-config": ". bash/source-nvm.sh && yarn --silent babel src/lib/utils/comm-config.js --out-dir dist/lib/utils/ --config-file ./.babelrc.cjs",
11+
"babel-build": ". bash/source-nvm.sh && yarn --silent babel src/ --out-dir dist/ --config-file ./.babelrc.cjs --verbose --ignore 'src/landing/flow-typed','src/landing/node_modules','src/landing/package.json','src/lib/flow-typed','src/lib/node_modules','src/lib/package.json','src/web/flow-typed','src/web/node_modules','src/web/package.json','src/web/dist','src/web/webpack.config.js','src/web/account-bar.react.js','src/web/app.react.js','src/web/calendar','src/web/chat','src/web/flow','src/web/loading-indicator.react.js','src/web/modals','src/web/root.js','src/web/router-history.js','src/web/script.js','src/web/selectors/chat-selectors.js','src/web/selectors/entry-selectors.js','src/web/splash','src/web/vector-utils.js','src/web/vectors.react.js'",
1212
"rsync": "rsync -rLpmuv --exclude '*/package.json' --exclude '*/node_modules/*' --include '*.json' --include '*.cjs' --include '*.node' --exclude '*.*' src/ dist/",
1313
"prod-build": "yarn babel-build && yarn rsync",
1414
"prod": "KEYSERVER=true node --trace-warnings --loader=./loader.mjs dist/keyserver",
@@ -102,7 +102,7 @@
102102
"<rootDir>/src"
103103
],
104104
"transform": {
105-
"\\.js$": "babel-jest"
105+
"\\.js$": ["babel-jest", { "rootMode": "upward" }]
106106
},
107107
"transformIgnorePatterns": [
108108
"/node_modules/(?!@babel/runtime)"
File renamed without changes.

landing/webpack.config.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {
77
createNodeServerRenderingConfig,
88
} = require('lib/webpack/shared.cjs');
99

10-
const babelConfig = require('./babel.config.cjs');
10+
const babelConfig = require('./.babelrc.cjs');
1111

1212
const baseBrowserConfig = {
1313
entry: {

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
},
6868
"jest": {
6969
"transform": {
70-
"\\.js$": "babel-jest"
70+
"\\.js$": ["babel-jest", { "rootMode": "upward" }]
7171
},
7272
"transformIgnorePatterns": [
7373
"/node_modules/(?!@babel/runtime)"

native/.babelrc.cjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
plugins: [
4+
'transform-remove-strict-mode',
5+
'@babel/plugin-proposal-optional-chaining',
6+
'@babel/plugin-proposal-nullish-coalescing-operator',
7+
// react-native-reanimated must be last
8+
'react-native-reanimated/plugin',
9+
],
10+
env: {
11+
production: {
12+
plugins: ['transform-remove-console'],
13+
},
14+
},
15+
};

0 commit comments

Comments
 (0)