Skip to content

Commit

Permalink
feature(expo-module-scripts): add cli-specific babel and jest configs (
Browse files Browse the repository at this point in the history
…#25458)

# Why

This is a follow-up to both deprecate `@expo/babel-preset-cli` and allow
all `@expo/*` or CLI packages to use `expo-module-scripts` within this
repository.

An open question here would be, do we want all Expo Config Plugins also
to reuse this new Node target babel config. These plugins should always
execute in the same environment as the CLI tooling, so I see no reason
why it should extend the `babel-preset-expo`, which targets Metro/RN.

Alternatively, if we don't want to merge `@expo/babel-preset-cli` inside
`expo-module-scripts`, we can still move over `@expo/babel-preset-cli`
and keep it around for now.

# How

- Added `babel.config.node.js`, which is specific to our Node CLI
target.
- Added `jest-preset-node.js` that uses the `babel.config.node.js` by
default.

# Test Plan

See if CI passes. If this PR gets accepted, I'll rebase the huge list of
#25426 and ensure the config is good to
go.

# Checklist

<!--
Please check the appropriate items below if they apply to your diff.
This is required for changes to Expo modules.
-->

- [x] Documentation is up to date to reflect these changes (eg:
https://docs.expo.dev and README.md).
- [ ] Conforms with the [Documentation Writing Style
Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
- [ ] This diff will work correctly for `npx expo prebuild` & EAS Build
(eg: updated a module plugin).

---------

Co-authored-by: Expo Bot <34669131+expo-bot@users.noreply.github.com>
  • Loading branch information
byCedric and expo-bot committed Nov 21, 2023
1 parent 7b55f08 commit f9681fb
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions packages/expo-module-scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### 🎉 New features

- Add Node-specific Babel and Jest configurations. ([#25458](https://github.com/expo/expo/pull/25458) by [@byCedric](https://github.com/byCedric))

### 🐛 Bug fixes

### 💡 Others
Expand Down
2 changes: 1 addition & 1 deletion packages/expo-module-scripts/babel.config.base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(api) {
module.exports = function (api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
Expand Down
27 changes: 27 additions & 0 deletions packages/expo-module-scripts/babel.config.cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = function (api) {
api.cache(true);
return {
presets: [
[
require('@babel/preset-env'),
{
modules: false, // Disable the default `modules-commonjs`, to enable lazy evaluation
targets: {
node: '12.0.0',
},
},
],
require('@babel/preset-typescript'),
],
plugins: [
require('babel-plugin-dynamic-import-node'),
require('@babel/plugin-proposal-export-namespace-from'),
[
require('@babel/plugin-transform-modules-commonjs'),
{
lazy: /* istanbul ignore next */ (source) => true,
},
],
],
};
};
4 changes: 2 additions & 2 deletions packages/expo-module-scripts/babel.config.plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = function(api) {
module.exports = function (api) {
api.cache(true);
return {
plugins: ['@babel/plugin-transform-flow-strip-types'],
plugins: ['@babel/plugin-transform-flow-strip-types'],
};
};
12 changes: 12 additions & 0 deletions packages/expo-module-scripts/jest-preset-cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @type {import('jest').Config} */
module.exports = {
testEnvironment: 'node',
testRegex: '/__tests__/.*(test|spec)\\.[jt]sx?$',
transform: {
'^.+\\.[jt]sx?$': ['babel-jest', { configFile: require.resolve('./babel.config.cli.js') }],
},
watchPlugins: [
require.resolve('jest-watch-typeahead/filename'),
require.resolve('jest-watch-typeahead/testname'),
],
};
5 changes: 2 additions & 3 deletions packages/expo-module-scripts/jest-preset-plugin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const nodePreset = {
/** @type {import('jest').Config} */
module.exports = {
testEnvironment: 'node',
testRegex: '/__tests__/.*(test|spec)\\.[jt]sx?$',
transform: {
Expand All @@ -9,5 +10,3 @@ const nodePreset = {
require.resolve('jest-watch-typeahead/testname'),
],
};

module.exports = nodePreset;
4 changes: 4 additions & 0 deletions packages/expo-module-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
"homepage": "https://github.com/expo/expo/tree/main/packages/expo-module-scripts#readme",
"dependencies": {
"@babel/cli": "^7.1.2",
"@babel/plugin-proposal-export-namespace-from": "^7.18.9",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.12.12",
"@expo/npm-proofread": "^1.0.1",
"@testing-library/react-hooks": "^7.0.1",
"@tsconfig/node18": "^18.2.2",
"@types/jest": "^29.2.1",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-preset-expo": "~9.9.0",
"commander": "^2.19.0",
"eslint-config-universe": "^12.0.0",
Expand Down
2 changes: 1 addition & 1 deletion react-native-lab/react-native
Submodule react-native updated 3969 files
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@
"@babel/helper-create-regexp-features-plugin" "^7.18.6"
"@babel/helper-plugin-utils" "^7.18.6"

"@babel/preset-env@^7.20.0", "@babel/preset-env@^7.4.4":
"@babel/preset-env@^7.20.0", "@babel/preset-env@^7.20.2", "@babel/preset-env@^7.4.4":
version "7.20.2"
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.20.2.tgz#9b1642aa47bb9f43a86f9630011780dab7f86506"
integrity sha512-1G0efQEWR1EHkKvKHqbG+IN/QdgwfByUpM5V5QroDzGV2t3S/WXNQd693cHiHTlCFMpr9B6FkPFXDA2lQcKoDg==
Expand Down Expand Up @@ -1179,7 +1179,7 @@
"@babel/plugin-transform-react-jsx-development" "^7.22.5"
"@babel/plugin-transform-react-pure-annotations" "^7.22.5"

"@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.16.7", "@babel/preset-typescript@^7.3.3", "@babel/preset-typescript@^7.7.4":
"@babel/preset-typescript@^7.12.12", "@babel/preset-typescript@^7.13.0", "@babel/preset-typescript@^7.16.7", "@babel/preset-typescript@^7.3.3", "@babel/preset-typescript@^7.7.4":
version "7.17.12"
resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.17.12.tgz#40269e0a0084d56fc5731b6c40febe1c9a4a3e8c"
integrity sha512-S1ViF8W2QwAKUGJXxP9NAfNaqGDdEBJKpYkxHf5Yy2C4NPPzXGeR3Lhk7G8xJaaLcFTRfNjVbtbVtm8Gb0mqvg==
Expand Down Expand Up @@ -15554,7 +15554,7 @@ pinkie@^2.0.0:
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=

pirates@^4.0.1, pirates@^4.0.4, pirates@^4.0.5:
pirates@^4.0.4, pirates@^4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.5.tgz#feec352ea5c3268fb23a37c702ab1699f35a5f3b"
integrity sha512-8V9+HQPupnaXMA23c5hvl69zXvTwTzyAYasnkb0Tts4XvO4CliqONMOnvlq26rkhLC3nWDFBJf73LU1e1VZLaQ==
Expand Down

0 comments on commit f9681fb

Please sign in to comment.