babel-preset-react-native: Make sure that `react-transform-hmr/lib/index.js` is included correctly for every module in the bundle

Summary:This imports `react-transform-hmr/lib/index.js` with a relative path from every module, to make sure we don’t rely on the current (broken) behaviour.

It works now, because:
- the dependency is added by a transform
- we extract dependencies before transforming
- we include `react-transform-hmr/lib/index.js` manually
- packager incorrectly names modules by the name of their package (i.e. packages with multiple versions overwrite each other)

This blocks transforming before extracting dependencies, switching to numeric module IDs, and unbundling/random access bundles.

Reviewed By: bestander

Differential Revision: D2994024

fb-gh-sync-id: 23c56397b768775ff56e3d6924f50a9e39e8ce8c
shipit-source-id: 23c56397b768775ff56e3d6924f50a9e39e8ce8c
This commit is contained in:
David Aurelio 2016-03-01 03:20:54 -08:00 committed by Facebook Github Bot 7
parent 7e3266d7de
commit a72c2950d6
2 changed files with 10 additions and 3 deletions

View File

@ -8,16 +8,23 @@
*/ */
'use strict'; 'use strict';
var path = require('path');
var resolvePlugins = require('../lib/resolvePlugins'); var resolvePlugins = require('../lib/resolvePlugins');
module.exports = function(options) { var hmrTransform = 'react-transform-hmr/lib/index.js';
var transformPath = require.resolve(hmrTransform);
module.exports = function(options, filename) {
var transform = filename
? path.relative(path.dirname(filename), transformPath) // packager can't handle absolute paths
: hmrTransform;
return { return {
plugins: resolvePlugins([ plugins: resolvePlugins([
[ [
'react-transform', 'react-transform',
{ {
transforms: [{ transforms: [{
transform: 'react-transform-hmr/lib/index.js', transform: transform,
imports: ['React'], imports: ['React'],
locals: ['module'], locals: ['module'],
}] }]

View File

@ -1,6 +1,6 @@
{ {
"name": "babel-preset-react-native", "name": "babel-preset-react-native",
"version": "1.4.0", "version": "1.5.0",
"description": "Babel preset for React Native applications", "description": "Babel preset for React Native applications",
"main": "index.js", "main": "index.js",
"repository": "https://github.com/facebook/react-native/tree/master/babel-preset", "repository": "https://github.com/facebook/react-native/tree/master/babel-preset",