babel-preset-expo
Advanced tools
Comparing version 8.1.0 to 8.2.0
49
index.js
@@ -5,7 +5,18 @@ const lazyImportsBlacklist = require('./lazy-imports-blacklist'); | ||
const { web = {}, native = {} } = options; | ||
const isWeb = api.caller(isTargetWeb); | ||
const platformOptions = isWeb | ||
? { disableImportExportTransform: true, ...web } | ||
: { disableImportExportTransform: false, ...native }; | ||
const bundler = api.caller(getBundler); | ||
const isWebpack = bundler === 'webpack'; | ||
let platform = api.caller(getPlatform); | ||
// If the `platform` prop is not defined then this must be a custom config that isn't | ||
// defining a platform in the babel-loader. Currently this may happen with Next.js + Expo web. | ||
if (!platform && isWebpack) { | ||
platform = 'web'; | ||
} | ||
const platformOptions = | ||
platform === 'web' | ||
? { disableImportExportTransform: true, ...web } | ||
: { disableImportExportTransform: false, ...native }; | ||
// Note that if `options.lazyImports` is not set (i.e., `null` or `undefined`), | ||
@@ -44,3 +55,4 @@ // `metro-react-native-babel-preset` will handle it. | ||
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }], | ||
isWeb && [require.resolve('babel-plugin-react-native-web')], | ||
platform === 'web' && [require.resolve('babel-plugin-react-native-web')], | ||
isWebpack && platform !== 'web' && [require.resolve('./plugins/disable-ambiguous-requires')], | ||
].filter(Boolean), | ||
@@ -79,4 +91,27 @@ }; | ||
function isTargetWeb(caller) { | ||
return caller && caller.name === 'babel-loader'; | ||
function getPlatform(caller) { | ||
return caller && caller.platform; | ||
} | ||
/** | ||
* Get the name of the `bundler`. | ||
* | ||
* @param {*} caller | ||
*/ | ||
function getBundler(caller) { | ||
if (!caller) return null; | ||
const { bundler, name } = caller; | ||
if (!bundler) { | ||
if (name === 'metro') { | ||
// This is a hack to determine if metro is being used. | ||
return 'metro'; | ||
} else if (name === 'babel-loader') { | ||
// This won't work in all cases as tools like Next.js could change the name of their loader. | ||
return 'webpack'; | ||
} | ||
} | ||
// Perhaps we should add a check to log once when an unexpected bundler is being used. | ||
return bundler || null; | ||
} |
{ | ||
"name": "babel-preset-expo", | ||
"version": "8.1.0", | ||
"version": "8.2.0", | ||
"description": "The Babel preset for Expo projects", | ||
@@ -57,3 +57,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "3ad68bbd9847ebc8a55272c263b17d998a92f64f" | ||
"gitHead": "d0ab2ab84b3aa64c69575167b0e59b8ab44c85eb" | ||
} |
@@ -12,2 +12,33 @@ # babel-preset-expo | ||
## Expo Bundler Spec Compliance | ||
A bundler must follow these requirements if they are to be considered spec compliant for use with a **universal React** (Expo) project. | ||
### Babel Loader | ||
The babel loading mechanism must include the following properties on its `caller`. | ||
#### platform | ||
A `platform` property denoting the target platform. If the `platform` is not defined, it will default to using `web` when the `bundler` is `webpack` -- this is temporary and will throw an error in the future. | ||
| Value | Description | | ||
| --------- | ----------------------- | | ||
| `ios` | Runs on iOS devices | | ||
| `android` | Runs on Android devices | | ||
| `web` | Runs in web browsers | | ||
#### bundler | ||
A `bundler` property denoting the name of the bundler that is being used to create the JavaScript bundle. | ||
If the `bundler` is not defined, it will default to checking if a `babel-loader` is used, if so then `webpack` will be used, otherwise it will default to `metro`. | ||
| Value | Description | | ||
| --------- | -------------------------------- | | ||
| `metro` | Bundling with [Metro][metro] | | ||
| `webpack` | Bundling with [Webpack][webpack] | | ||
[metro]: https://facebook.github.io/metro/ | ||
[webpack]: https://webpack.js.org/ | ||
## Options | ||
@@ -14,0 +45,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
9845
105
94
0
1