This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

93
node_modules/babel-preset-expo/README.md generated vendored Normal file
View File

@ -0,0 +1,93 @@
# babel-preset-expo
This preset extends the default React Native preset (`metro-react-native-babel-preset`) and adds support for decorators, tree-shaking web packages, and loading font icons with optional native dependencies if they're installed.
You can use this preset in any React Native project as a drop-in replacement for `metro-react-native-babel-preset`. If your project isn't using native font loading or web support then this preset will only add support for decorators with `@babel/plugin-proposal-decorators` - this is mostly used for supporting legacy community libraries.
If you start your **web** project with `@expo/webpack-config` or `expo start:web` and your project doesn't contain a `babel.config.js` or a `.babelrc` then it will default to using `babel-preset-expo` for loading.
If you have problems with the code in this repository, please file issues & bug reports
at https://github.com/expo/expo. Thanks!
## 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
### [`lazyImports`](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy)
Changes Babel's compiled `import` statements to be lazily evaluated when their imported bindings are used for the first time.
_Note:_ this option has an effect only when the `disableImportExportTransform` option is set to `false`. On Android and iOS, `disableImportExportTransform` defaults to `false`, and on web it defaults to `true` to allow for tree shaking.
This can improve the initial load time of your app because evaluating dependencies up front is sometimes entirely un-necessary, particularly when the dependencies have no side effects.
The value of `lazyImports` has a few possible effects:
- `null` - [metro-react-native-babel-preset](https://github.com/facebook/metro/tree/master/packages/metro-react-native-babel-preset) will handle it. (Learn more about it here: https://github.com/facebook/metro/commit/23e3503dde5f914f3e642ef214f508d0a699851d)
- `false` - No lazy initialization of any imported module.
- `true` - Lazy-init all imported modules except local imports (e.g., `./foo`), certain Expo packages that have side effects, and the two cases mentioned [here](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy).
- `Array<string>` - [babel-plugin-transform-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy) will handle it.
- `(string) => boolean` - [babel-plugin-transform-modules-commonjs](https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#lazy) will handle it.
If you choose to do this, you can also access the list of Expo packages that have side effects by using `const lazyImportsBlacklist = require('babel-preset-expo/lazy-imports-blacklist');` which returns a `Set`.
**default:** `null`
```js
[
'babel-preset-expo',
{
lazyImports: true
}
],
```
### `web.disableImportExportTransform`
Enabling this option will allow your project to run with older JavaScript syntax (i.e. `module.exports`). This option will break tree shaking and increase your bundle size, but will eliminate the following error when `module.exports` is used:
> `TypeError: Cannot assign to read only property 'exports' of object '#<Object>'`
**default:** `false`
```js
[
'babel-preset-expo',
{
web: { disableImportExportTransform: true }
}
],
```

114
node_modules/babel-preset-expo/index.js generated vendored Normal file
View File

@ -0,0 +1,114 @@
const lazyImportsBlacklist = require('./lazy-imports-blacklist');
module.exports = function(api, options = {}) {
const { web = {}, native = {} } = options;
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`),
// `metro-react-native-babel-preset` will handle it.
const lazyImportsOption = options && options.lazyImports;
return {
presets: [
[
// We use `require` here instead of directly using the package name because we want to
// specifically use the `metro-react-native-babel-preset` installed by this package (ex:
// `babel-preset-expo/node_modules/`). This way the preset will not change unintentionally.
// Reference: https://github.com/expo/expo/pull/4685#discussion_r307143920
require('metro-react-native-babel-preset'),
{
disableImportExportTransform: platformOptions.disableImportExportTransform,
lazyImportExportTransform:
lazyImportsOption === true
? importModuleSpecifier => {
// Do not lazy-initialize packages that are local imports (similar to `lazy: true`
// behavior) or are in the blacklist.
return !(
importModuleSpecifier.includes('./') ||
lazyImportsBlacklist.has(importModuleSpecifier)
);
}
: // Pass the option directly to `metro-react-native-babel-preset`, which in turn
// passes it to `babel-plugin-transform-modules-commonjs`
lazyImportsOption,
},
],
],
plugins: [
getAliasPlugin(),
[require.resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
platform === 'web' && [require.resolve('babel-plugin-react-native-web')],
isWebpack && platform !== 'web' && [require.resolve('./plugins/disable-ambiguous-requires')],
].filter(Boolean),
};
};
function getAliasPlugin() {
const aliases = {};
if (hasModule('@expo/vector-icons')) {
aliases['react-native-vector-icons'] = '@expo/vector-icons';
}
if (Object.keys(aliases).length) {
return [
require.resolve('babel-plugin-module-resolver'),
{
alias: aliases,
},
];
}
return null;
}
function hasModule(name) {
try {
return !!require.resolve(name);
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND' && error.message.includes(name)) {
return false;
}
throw error;
}
}
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;
}

View File

@ -0,0 +1,6 @@
/**
* These Expo packages may have side-effects and should not be lazily initialized.
*/
'use strict';
module.exports = new Set(['expo', 'expo-asset', 'expo-task-manager']);

59
node_modules/babel-preset-expo/package.json generated vendored Normal file
View File

@ -0,0 +1,59 @@
{
"name": "babel-preset-expo",
"version": "8.3.0",
"description": "The Babel preset for Expo projects",
"main": "index.js",
"files": [
"index.js",
"lazy-imports-blacklist.js",
"plugins"
],
"scripts": {
"jest": "jest",
"lint": "eslint .",
"test": "jest --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo.git",
"directory": "packages/babel-preset-expo"
},
"keywords": [
"babel",
"babel-preset",
"expo",
"expo-web",
"react-native",
"react-native-web",
"metro",
"webpack"
],
"author": "Expo <support@expo.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"homepage": "https://github.com/expo/expo/tree/master/packages/babel-preset-expo#readme",
"eslintConfig": {
"extends": "universe/node"
},
"jest": {
"testEnvironment": "node",
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/__tests__/samples/"
]
},
"dependencies": {
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/preset-env": "^7.6.3",
"babel-plugin-module-resolver": "^3.2.0",
"babel-plugin-react-native-web": "~0.13.6",
"metro-react-native-babel-preset": "~0.59.0"
},
"devDependencies": {
"@babel/core": "^7.6.4",
"jest": "^25.2.0"
},
"gitHead": "2196cebae55bda181ccceadec809942f51ee9e39"
}

View File

@ -0,0 +1,52 @@
/**
* Disable ambiguous module ID requires from React Native:
* https://github.com/facebook/react-native/commit/06b5bda34923b68ba5141e78c36ccbdc5f4bcff1
*
* Without this operation, the following error will be thrown when bundling with Webpack:
* `Critical dependency: require function is used in a way in which dependencies cannot be statically extracted`
*
* - react-native/Libraries/Performance/Systrace.js 124:2-9
* - react-native/Libraries/Core/setUpReactRefresh.js 30:2-9
*/
module.exports = () => ({
visitor: {
AssignmentExpression(path) {
if (isValidRequire(path) && (isCastedRequire(path) || isChainedRequire(path))) {
path.remove();
}
},
},
});
/**
* Is a require statement being assigned to something.
* Prevents further checks when `path.node.left` is undefined.
*
* @param {*} path
*/
function isValidRequire(path) {
return path.node.operator === '=' && path.node.left.type === 'MemberExpression';
}
/**
* Is a require statement formatted like: `(require: any)`
*
* Example from `react-native/Libraries/Core/setUpReactRefresh.js 30:2-9`:
* `(require: any).Refresh = Refresh;`
*
* @param {*} path
*/
function isCastedRequire(path) {
const { object } = path.node.left;
return object.type === 'TypeCastExpression' && object.expression.name === 'require';
}
/**
* Is a require statement formatted like: `require.`
*
* @param {*} path
*/
function isChainedRequire(path) {
const { object } = path.node.left;
return object.type === 'Identifier' && object.name === 'require';
}