Héctor Ramos e315ec9891 Fix iOS e2e tests: bump react-native-babel-preset to ^5 (#19625)
Summary:
We opt in to version ^5 of the React Native Babel Preset, as required after the bump to Babel 7. This fixes the Objective-C end-to-end test failure in master. (Fixes #19538)

See 34bd776af2 (commitcomment-29024085) for prior discussion.

There have already been several changes made to the repo during the transition to Babel 7. This PR brings all tests back to green and allows us to move forward with the 0.56 branch cut.

We also bump our tests to use Xcode 9.4.0 and iOS 11.4, the latest stable versions of both.

Once the 0.56 branch makes it to stable, we can change `react-native-babel-preset@latest` on npm to point to `react-native-babel-preset@5.0.1` (or newer), and undo the change made to `init.js` we made as part of this diff.

Wait for Circle CI to run: https://circleci.com/workflow-run/e39a66d7-bf8a-4b31-a22f-eef30a2c53bc

[GENERAL] [BREAKING] [Babel] - Bump React Native Babel Preset version used by RN CLI to Babel v7 compliant release
Closes https://github.com/facebook/react-native/pull/19625

Reviewed By: TheSavior

Differential Revision: D8343861

Pulled By: hramos

fbshipit-source-id: 42644d5b0bfb40a8bc592ae3461c5008deef8232
2018-06-10 17:08:56 -07:00

132 lines
4.0 KiB
JavaScript

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const {
listTemplatesAndExit,
createProjectFromTemplate,
} = require('../generator/templates');
const execSync = require('child_process').execSync;
const fs = require('fs');
const minimist = require('minimist');
const path = require('path');
const printRunInstructions = require('../generator/printRunInstructions');
const process = require('process');
const yarn = require('../util/yarn');
/**
* Creates the template for a React Native project given the provided
* parameters:
* @param projectDir Templates will be copied here.
* @param argsOrName Project name or full list of custom arguments
* for the generator.
* @param options Command line options passed from the react-native-cli directly.
* E.g. `{ version: '0.43.0', template: 'navigation' }`
*/
function init(projectDir, argsOrName) {
const args = Array.isArray(argsOrName)
? argsOrName // argsOrName was e.g. ['AwesomeApp', '--verbose']
: [argsOrName].concat(process.argv.slice(4)); // argsOrName was e.g. 'AwesomeApp'
// args array is e.g. ['AwesomeApp', '--verbose', '--template', 'navigation']
if (!args || args.length === 0) {
console.error('react-native init requires a project name.');
return;
}
const newProjectName = args[0];
const options = minimist(args);
if (listTemplatesAndExit(newProjectName, options)) {
// Just listing templates using 'react-native init --template'
// Not creating a new app.
return;
} else {
console.log('Setting up new React Native app in ' + projectDir);
generateProject(projectDir, newProjectName, options);
}
}
/**
* Generates a new React Native project based on the template.
* @param Absolute path at which the project folder should be created.
* @param options Command line arguments parsed by minimist.
*/
function generateProject(destinationRoot, newProjectName, options) {
var reactNativePackageJson = require('../../package.json');
var {peerDependencies} = reactNativePackageJson;
if (!peerDependencies) {
console.error(
"Missing React peer dependency in React Native's package.json. Aborting.",
);
return;
}
var reactVersion = peerDependencies.react;
if (!reactVersion) {
console.error(
"Missing React peer dependency in React Native's package.json. Aborting.",
);
return;
}
const yarnVersion =
!options.npm &&
yarn.getYarnVersionIfAvailable() &&
yarn.isGlobalCliUsingYarn(destinationRoot);
createProjectFromTemplate(
destinationRoot,
newProjectName,
options.template,
yarnVersion,
);
if (yarnVersion) {
console.log('Adding React...');
execSync(`yarn add react@${reactVersion}`, {stdio: 'inherit'});
} else {
console.log('Installing React...');
execSync(`npm install react@${reactVersion} --save --save-exact`, {
stdio: 'inherit',
});
}
if (!options['skip-jest']) {
const jestDeps = `jest babel-jest babel-preset-react-native@^5 react-test-renderer@${reactVersion}`;
if (yarnVersion) {
console.log('Adding Jest...');
execSync(`yarn add ${jestDeps} --dev --exact`, {stdio: 'inherit'});
} else {
console.log('Installing Jest...');
execSync(`npm install ${jestDeps} --save-dev --save-exact`, {
stdio: 'inherit',
});
}
addJestToPackageJson(destinationRoot);
}
printRunInstructions(destinationRoot, newProjectName);
}
/**
* Add Jest-related stuff to package.json, which was created by the react-native-cli.
*/
function addJestToPackageJson(destinationRoot) {
var packageJSONPath = path.join(destinationRoot, 'package.json');
var packageJSON = JSON.parse(fs.readFileSync(packageJSONPath));
packageJSON.scripts.test = 'jest';
packageJSON.jest = {
preset: 'react-native',
};
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
}
module.exports = init;