mirror of https://github.com/status-im/metro.git
Export the hmr plugin directly
Summary: This will allow to configure the HMR plugin directly from `.babelrc` again, instead of having to create a bridge file: https://github.com/rafeca/metro-sample-app/blob/master/metro-babel7-plugin-react-transform.js#L3 Reviewed By: davidaurelio Differential Revision: D7707314 fbshipit-source-id: 4c5612e1e5d27874807f2dce50d99ec0f6354bbc
This commit is contained in:
parent
a8ce776044
commit
a6b61554ec
|
@ -18,7 +18,7 @@ const path = require('path');
|
|||
|
||||
/*eslint-disable import/no-extraneous-dependencies*/
|
||||
const {transformSync} = require('@babel/core');
|
||||
const reactPlugin = require('../lib/index.js').default;
|
||||
const reactPlugin = require('../lib/index.js');
|
||||
|
||||
describe('finds React components', () => {
|
||||
const fixturesDir = path.join(__dirname, '__fixtures__');
|
||||
|
|
|
@ -28,8 +28,7 @@ const find = require('lodash/find');
|
|||
|
||||
const {addDefault} = require('@babel/helper-module-imports');
|
||||
|
||||
module.exports = {
|
||||
default: function({types: t, template}) {
|
||||
module.exports = function({types: t, template}) {
|
||||
function matchesPatterns(path, patterns) {
|
||||
return !!find(patterns, pattern => {
|
||||
return (
|
||||
|
@ -115,8 +114,7 @@ module.exports = {
|
|||
path.node[VISITED_KEY] = true;
|
||||
|
||||
const componentName = (path.node.id && path.node.id.name) || null;
|
||||
const componentId =
|
||||
componentName || path.scope.generateUid('component');
|
||||
const componentId = componentName || path.scope.generateUid('component');
|
||||
const isInFunction = hasParentFunction(path);
|
||||
|
||||
this.components.push({
|
||||
|
@ -189,8 +187,7 @@ module.exports = {
|
|||
|
||||
// `foo({ displayName: 'NAME' });` => 'NAME'
|
||||
const componentName = getDisplayName(path.node);
|
||||
const componentId =
|
||||
componentName || path.scope.generateUid('component');
|
||||
const componentId = componentName || path.scope.generateUid('component');
|
||||
const isInFunction = hasParentFunction(path);
|
||||
|
||||
this.components.push({
|
||||
|
@ -338,10 +335,7 @@ module.exports = {
|
|||
objectKey = t.stringLiteral(componentId);
|
||||
}
|
||||
|
||||
return t.objectProperty(
|
||||
objectKey,
|
||||
t.objectExpression(componentProps),
|
||||
);
|
||||
return t.objectProperty(objectKey, t.objectExpression(componentProps));
|
||||
});
|
||||
|
||||
return t.variableDeclaration('const', [
|
||||
|
@ -385,9 +379,7 @@ module.exports = {
|
|||
configuredTransformId,
|
||||
t.callExpression(transformImportId, [
|
||||
toObjectExpression({
|
||||
filename: t.stringLiteral(
|
||||
this.file.opts.filename || 'unknown',
|
||||
),
|
||||
filename: t.stringLiteral(this.file.opts.filename || 'unknown'),
|
||||
components: componentsDeclarationId,
|
||||
locals: t.arrayExpression(transformLocals),
|
||||
imports: t.arrayExpression(transformImports),
|
||||
|
@ -437,5 +429,4 @@ module.exports = {
|
|||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -135,7 +135,7 @@ function makeMakeHMRConfig7() {
|
|||
return {
|
||||
plugins: [
|
||||
[
|
||||
require('metro-babel7-plugin-react-transform').default,
|
||||
require('metro-babel7-plugin-react-transform'),
|
||||
{
|
||||
transforms: [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue