@expo/metro-config 0.2.3 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -32,17 +32,15 @@ const getBabelRC = (function () {
|
|
|
32
32
|
// Let's look for a babel config file in the project root.
|
|
33
33
|
// TODO look into adding a command line option to specify this location
|
|
34
34
|
let projectBabelRCPath;
|
|
35
|
-
// Since this is an opt-in system, we can make certain
|
|
36
|
-
// assumptions like dropping support for `.babelrc` to speed up resolution.
|
|
37
35
|
// .babelrc
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
if (projectRoot) {
|
|
37
|
+
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc');
|
|
38
|
+
}
|
|
41
39
|
if (projectBabelRCPath) {
|
|
42
40
|
// .babelrc.js
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (!fs_1.default.existsSync(projectBabelRCPath)) {
|
|
42
|
+
projectBabelRCPath = path_1.default.resolve(projectRoot, '.babelrc.js');
|
|
43
|
+
}
|
|
46
44
|
// babel.config.js
|
|
47
45
|
if (!fs_1.default.existsSync(projectBabelRCPath)) {
|
|
48
46
|
projectBabelRCPath = path_1.default.resolve(projectRoot, 'babel.config.js');
|
|
@@ -63,6 +61,8 @@ const getBabelRC = (function () {
|
|
|
63
61
|
[
|
|
64
62
|
require(presetPath),
|
|
65
63
|
{
|
|
64
|
+
// Default to React 17 automatic JSX transform.
|
|
65
|
+
jsxRuntime: 'automatic',
|
|
66
66
|
...presetOptions,
|
|
67
67
|
disableImportExportTransform: experimentalImportSupport,
|
|
68
68
|
enableBabelRuntime: options.enableBabelRuntime,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBabelConfig.js","sourceRoot":"","sources":["../../src/transformer/getBabelConfig.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAGH,4CAAoB;AAEpB,gDAAwB;AACxB,gEAAuC;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,GAAG,OAAO,EAAE,GAAG,WAAW,EAAE,CAAC;IAEnD,oBAAoB;IACpB,MAAM,YAAY,GAA4B,EAAE,CAAC;IAEjD,qCAAqC;IACrC,IAAI,OAAO,CAAC,cAAc,EAAE;QAC1B,MAAM,oBAAoB,GAAG,sBAAW,CACtC,OAAO,CAAC,WAAW,EACnB,2CAA2C,CAC5C,CAAC;QACF,YAAY,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;KACzC;IAED,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAE9D,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE;QAC9B,sEAAsE;QACtE,uEAAuE;QACvE,qEAAqE;QACrE,uEAAuE;QACvE,sCAAsC;QACtC,0BAA0B;QAC1B,MAAM,iCAAiC,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;QAElF,IAAI,iCAAiC,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;gBACnB,MAAM,CAAC,OAAO,GAAG,EAAE,CAAC;aACrB;YACD,6BAA6B;YAC7B,+EAA+E;YAC/E,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,sBAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC;SACrF;KACF;IAED,OAAO,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;AACnC,CAAC;AAlDD,wCAkDC","sourcesContent":["/**\n * Copyright (c) Expo.\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n * Forks the default metro-react-native-babel-transformer and adds support for known transforms.\n */\n\nimport type { PluginItem as BabelPlugins, PluginItem } from '@babel/core';\nimport fs from 'fs';\nimport type { BabelTransformerOptions } from 'metro-babel-transformer';\nimport path from 'path';\nimport resolveFrom from 'resolve-from';\n\n/**\n * Return a memoized function that checks for the existence of a\n * project level .babelrc file, and if it doesn't exist, reads the\n * default RN babelrc file and uses that.\n */\nconst getBabelRC = (function () {\n let babelRC: {\n // `any` to avoid flow type mismatch with Babel 7's internal type of\n // `Array<string>` even though it correctly accepts the usage below.\n presets?: any;\n extends?: string;\n plugins: BabelPlugins;\n } | null = null;\n\n return function _getBabelRC(projectRoot: string, options: BabelTransformerOptions) {\n if (babelRC != null) {\n return babelRC;\n }\n\n babelRC = { plugins: [] };\n\n // Let's look for a babel config file in the project root.\n // TODO look into adding a command line option to specify this location\n let projectBabelRCPath;\n\n // .babelrc\n if (projectRoot) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc');\n }\n\n if (projectBabelRCPath) {\n // .babelrc.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, '.babelrc.js');\n }\n\n // babel.config.js\n if (!fs.existsSync(projectBabelRCPath)) {\n projectBabelRCPath = path.resolve(projectRoot, 'babel.config.js');\n }\n\n // If we found a babel config file, extend our config off of it\n // otherwise the default config will be used\n if (fs.existsSync(projectBabelRCPath)) {\n babelRC.extends = projectBabelRCPath;\n }\n }\n\n // If a babel config file doesn't exist in the project then\n // the default preset for react-native will be used instead.\n if (!babelRC.extends) {\n const { experimentalImportSupport, ...presetOptions } = options;\n\n // Use `babel-preset-expo` instead of `metro-react-native-babel-preset`.\n const presetPath =\n resolveFrom.silent(projectRoot, 'babel-preset-expo') ??\n resolveFrom.silent(projectRoot, 'metro-react-native-babel-preset') ??\n require.resolve('babel-preset-expo');\n\n babelRC.presets = [\n [\n require(presetPath),\n {\n // Default to React 17 automatic JSX transform.\n jsxRuntime: 'automatic',\n ...presetOptions,\n disableImportExportTransform: experimentalImportSupport,\n enableBabelRuntime: options.enableBabelRuntime,\n },\n ],\n ];\n }\n\n return babelRC;\n };\n})();\n\n/**\n * Given a filename and options, build a Babel\n * config object with the appropriate plugins.\n */\nexport function getBabelConfig(\n filename: string,\n options: BabelTransformerOptions,\n plugins: BabelPlugins = []\n) {\n const babelRC = getBabelRC(options.projectRoot, options);\n\n const extraConfig = {\n babelrc: typeof options.enableBabelRCLookup === 'boolean' ? options.enableBabelRCLookup : true,\n code: false,\n filename,\n highlightCode: true,\n };\n\n const config: any = { ...babelRC, ...extraConfig };\n\n // Add extra plugins\n const extraPlugins: (string | PluginItem)[] = [];\n\n // TODO: This probably can be removed\n if (options.inlineRequires) {\n const inlineRequiresPlugin = resolveFrom(\n options.projectRoot,\n 'babel-preset-fbjs/plugins/inline-requires'\n );\n extraPlugins.push(inlineRequiresPlugin);\n }\n\n config.plugins = extraPlugins.concat(config.plugins, plugins);\n\n if (options.dev && options.hot) {\n // Note: this intentionally doesn't include the path separator because\n // I'm not sure which one it should use on Windows, and false positives\n // are unlikely anyway. If you later decide to include the separator,\n // don't forget that the string usually *starts* with \"node_modules\" so\n // the first one often won't be there.\n // TODO: Support monorepos\n const mayContainEditableReactComponents = filename.indexOf('node_modules') === -1;\n\n if (mayContainEditableReactComponents) {\n if (!config.plugins) {\n config.plugins = [];\n }\n // Add react refresh runtime.\n // NOTICE: keep in sync with 'metro-react-native-babel-preset/src/configs/hmr'.\n config.plugins.push(resolveFrom.silent(options.projectRoot, 'react-refresh/babel'));\n }\n }\n\n return { ...babelRC, ...config };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@expo/metro-config",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "A Metro config for running React Native projects with the Metro bundler",
|
|
5
5
|
"main": "build/ExpoMetroConfig.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"transformer"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@expo/config": "6.0.
|
|
37
|
+
"@expo/config": "6.0.6",
|
|
38
38
|
"chalk": "^4.1.0",
|
|
39
39
|
"debug": "^4.3.2",
|
|
40
40
|
"getenv": "^1.0.0",
|