Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
update babel preset (#4580)
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon authored Oct 28, 2022
1 parent 077a1e9 commit 63af7b0
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 40 deletions.
2 changes: 1 addition & 1 deletion packages/next-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"dependencies": {
"@expo/package-manager": "0.0.56",
"@expo/webpack-config": "0.17.2",
"babel-preset-expo": "^8.4.1",
"babel-preset-expo": "^9.2.0",
"chalk": "^4.0.0",
"commander": "^4.0.1",
"fs-extra": "9.0.0",
Expand Down
33 changes: 1 addition & 32 deletions packages/next-adapter/src/babel.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,18 @@
// Learn more: https://github.com/expo/expo/blob/master/docs/pages/versions/unversioned/guides/using-nextjs.md#shared-steps

let hasCheckedModules = false;

module.exports = function (api: any) {
// Detect web usage (this may change in the future if Next.js changes the loader)
const isWeb = api.caller(
(caller?: { name: string }) =>
caller && (caller.name === 'babel-loader' || caller.name === 'next-babel-turbo-loader')
);

// Check peer dependencies
if (!hasCheckedModules) {
hasCheckedModules = true;
// Only check for next support in the browser...
const missingPackages = [isWeb && 'next/babel', 'babel-preset-expo'].filter(
packageName => packageName && !hasModule(packageName)
);
// Throw an error if anything is missing
if (missingPackages.length)
throw new Error(
`[BABEL]: preset \`@expo/next-adapter/babel\` is missing peer dependencies: ${missingPackages.join(
', '
)}`
);
}

return {
presets: [
// Only use next in the browser, it'll break your native project
isWeb && require('next/babel'),
[
require('babel-preset-expo'),
{
web: { useTransformReactJsxExperimental: true },
web: { useTransformReactJSXExperimental: true },
// Disable the `no-anonymous-default-export` plugin in babel-preset-expo
// so users don't see duplicate warnings.
'no-anonymous-default-export': false,
Expand All @@ -41,14 +21,3 @@ module.exports = function (api: any) {
].filter(Boolean),
};
};

function hasModule(name: string): boolean {
try {
return !!require.resolve(name);
} catch (error: any) {
if (error.code === 'MODULE_NOT_FOUND' && error.message.includes(name)) {
return false;
}
throw error;
}
}
Loading

0 comments on commit 63af7b0

Please sign in to comment.