diff --git a/IntegrationTests/websocket_integration_test_server.js b/IntegrationTests/websocket_integration_test_server.js index 763668f32..50a656871 100755 --- a/IntegrationTests/websocket_integration_test_server.js +++ b/IntegrationTests/websocket_integration_test_server.js @@ -7,6 +7,7 @@ * LICENSE file in the root directory of this source tree. * * @flow + * @format */ 'use strict'; @@ -26,8 +27,8 @@ An incoming message of 'exit' will shut down the server. `); const server = new WebSocket.Server({port: 5555}); -server.on('connection', (ws) => { - ws.on('message', (message) => { +server.on('connection', ws => { + ws.on('message', message => { console.log('Received message:', message); if (message === 'exit') { console.log('WebSocket integration test server exit'); diff --git a/RNTester/js/http_test_server.js b/RNTester/js/http_test_server.js index 998d73dbf..c9a4be575 100755 --- a/RNTester/js/http_test_server.js +++ b/RNTester/js/http_test_server.js @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. * * @flow + * @format */ 'use strict'; diff --git a/RNTester/js/websocket_test_server.js b/RNTester/js/websocket_test_server.js index 3f3a23cfa..eacab9e21 100755 --- a/RNTester/js/websocket_test_server.js +++ b/RNTester/js/websocket_test_server.js @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. * * @flow + * @format */ 'use strict'; @@ -29,8 +30,8 @@ ArrayBuffer instead of a string. const respondWithBinary = process.argv.indexOf('--binary') !== -1; const server = new WebSocket.Server({port: 5555}); -server.on('connection', (ws) => { - ws.on('message', (message) => { +server.on('connection', ws => { + ws.on('message', message => { console.log('Received message:', message); console.log('Cookie:', ws.upgradeReq.headers.cookie); if (respondWithBinary) { diff --git a/local-cli/wrong-react-native.js b/local-cli/wrong-react-native.js index 57f04fead..3b949818a 100755 --- a/local-cli/wrong-react-native.js +++ b/local-cli/wrong-react-native.js @@ -5,6 +5,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ const isWindows = process.platform === 'win32'; @@ -14,23 +16,28 @@ if (isWindows) { const fs = require('fs'); const path = require('path'); // On Windows, assume we are installed globally if we can't find a package.json above node_modules. - installedGlobally = !(fs.existsSync(path.join(__dirname, '../../../package.json'))); + installedGlobally = !fs.existsSync( + path.join(__dirname, '../../../package.json'), + ); } else { // On non-windows, assume we are installed globally if we are called from outside of the node_mobules/.bin/react-native executable. var script = process.argv[1]; installedGlobally = script.indexOf('node_modules/.bin/react-native') === -1; } - if (installedGlobally) { const chalk = require('chalk'); - console.error([ - chalk.red('Looks like you installed react-native globally, maybe you meant react-native-cli?'), - chalk.red('To fix the issue, run:'), - 'npm uninstall -g react-native', - 'npm install -g react-native-cli' - ].join('\n')); + console.error( + [ + chalk.red( + 'Looks like you installed react-native globally, maybe you meant react-native-cli?', + ), + chalk.red('To fix the issue, run:'), + 'npm uninstall -g react-native', + 'npm install -g react-native-cli', + ].join('\n'), + ); process.exit(1); } else { require('./cli').run(); diff --git a/react-native-cli/index.js b/react-native-cli/index.js index 5cde16496..fa8305070 100755 --- a/react-native-cli/index.js +++ b/react-native-cli/index.js @@ -5,6 +5,8 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -60,12 +62,7 @@ var semver = require('semver'); var options = require('minimist')(process.argv.slice(2)); var CLI_MODULE_PATH = function() { - return path.resolve( - process.cwd(), - 'node_modules', - 'react-native', - 'cli.js' - ); + return path.resolve(process.cwd(), 'node_modules', 'react-native', 'cli.js'); }; var REACT_NATIVE_PACKAGE_JSON_PATH = function() { @@ -73,7 +70,7 @@ var REACT_NATIVE_PACKAGE_JSON_PATH = function() { process.cwd(), 'node_modules', 'react-native', - 'package.json' + 'package.json', ); }; @@ -90,7 +87,9 @@ function getYarnVersionIfAvailable() { if (process.platform.startsWith('win')) { yarnVersion = (execSync('yarn --version 2> NUL').toString() || '').trim(); } else { - yarnVersion = (execSync('yarn --version 2>/dev/null').toString() || '').trim(); + yarnVersion = ( + execSync('yarn --version 2>/dev/null').toString() || '' + ).trim(); } } catch (error) { return null; @@ -119,51 +118,51 @@ if (cli) { cli.run(); } else { if (options._.length === 0 && (options.h || options.help)) { - console.log([ - '', - ' Usage: react-native [command] [options]', - '', - '', - ' Commands:', - '', - ' init [options] generates a new project and installs its dependencies', - '', - ' Options:', - '', - ' -h, --help output usage information', - ' -v, --version use a specific version of React Native', - ' --template use an app template. Use --template to see available templates.', - '', - ].join('\n')); + console.log( + [ + '', + ' Usage: react-native [command] [options]', + '', + '', + ' Commands:', + '', + ' init [options] generates a new project and installs its dependencies', + '', + ' Options:', + '', + ' -h, --help output usage information', + ' -v, --version use a specific version of React Native', + ' --template use an app template. Use --template to see available templates.', + '', + ].join('\n'), + ); process.exit(0); } if (commands.length === 0) { console.error( - 'You did not pass any commands, run `react-native --help` to see a list of all available commands.' + 'You did not pass any commands, run `react-native --help` to see a list of all available commands.', ); process.exit(1); } switch (commands[0]) { - case 'init': - if (!commands[1]) { + case 'init': + if (!commands[1]) { + console.error('Usage: react-native init [--verbose]'); + process.exit(1); + } else { + init(commands[1], options); + } + break; + default: console.error( - 'Usage: react-native init [--verbose]' + 'Command `%s` unrecognized. ' + + 'Make sure that you have run `npm install` and that you are inside a react-native project.', + commands[0], ); process.exit(1); - } else { - init(commands[1], options); - } - break; - default: - console.error( - 'Command `%s` unrecognized. ' + - 'Make sure that you have run `npm install` and that you are inside a react-native project.', - commands[0] - ); - process.exit(1); - break; + break; } } @@ -172,7 +171,7 @@ function validateProjectName(name) { console.error( '"%s" is not a valid name for a project. Please use a valid identifier ' + 'name (alphanumeric).', - name + name, ); process.exit(1); } @@ -181,7 +180,7 @@ function validateProjectName(name) { console.error( '"%s" is not a valid name for a project. Please do not use the ' + 'reserved word "React".', - name + name, ); process.exit(1); } @@ -212,10 +211,10 @@ function createAfterConfirmation(name, options) { message: 'Directory ' + name + ' already exists. Continue?', validator: /y[es]*|n[o]?/, warning: 'Must respond yes or no', - default: 'no' + default: 'no', }; - prompt.get(property, function (err, result) { + prompt.get(property, function(err, result) { if (result.yesno[0] === 'y') { createProject(name, options); } else { @@ -231,7 +230,7 @@ function createProject(name, options) { console.log( 'This will walk you through creating a new React Native project in', - root + root, ); if (!fs.existsSync(root)) { @@ -246,9 +245,12 @@ function createProject(name, options) { start: 'node node_modules/react-native/local-cli/cli.js start', ios: 'react-native run-ios', android: 'react-native run-android', - } + }, }; - fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify(packageJson)); + fs.writeFileSync( + path.join(root, 'package.json'), + JSON.stringify(packageJson), + ); process.chdir(root); run(root, projectName, options); @@ -269,7 +271,7 @@ function getInstallPackage(rnPackage) { function run(root, projectName, options) { var rnPackage = options.version; // e.g. '0.38' or '/path/to/archive.tgz' var forceNpmClient = options.npm; - var yarnVersion = (!forceNpmClient) && getYarnVersionIfAvailable(); + var yarnVersion = !forceNpmClient && getYarnVersionIfAvailable(); var installCommand; if (options.installCommand) { // In CI environments it can be useful to provide a custom command, @@ -286,9 +288,12 @@ function run(root, projectName, options) { } else { console.log('Installing ' + getInstallPackage(rnPackage) + '...'); if (!forceNpmClient) { - console.log('Consider installing yarn to make this faster: https://yarnpkg.com'); + console.log( + 'Consider installing yarn to make this faster: https://yarnpkg.com', + ); } - installCommand = 'npm install --save --save-exact ' + getInstallPackage(rnPackage); + installCommand = + 'npm install --save --save-exact ' + getInstallPackage(rnPackage); if (options.verbose) { installCommand += ' --verbose'; } @@ -312,13 +317,15 @@ function checkNodeVersion() { return; } if (!semver.satisfies(process.version, packageJson.engines.node)) { - console.error(chalk.red( + console.error( + chalk.red( 'You are currently running Node %s but React Native requires %s. ' + - 'Please use a supported version of Node.\n' + - 'See https://facebook.github.io/react-native/docs/getting-started.html' + 'Please use a supported version of Node.\n' + + 'See https://facebook.github.io/react-native/docs/getting-started.html', ), process.version, - packageJson.engines.node); + packageJson.engines.node, + ); } } @@ -327,7 +334,9 @@ function printVersionsAndExit(reactNativePackageJsonPath) { try { console.log('react-native: ' + require(reactNativePackageJsonPath).version); } catch (e) { - console.log('react-native: n/a - not inside a React Native project directory'); + console.log( + 'react-native: n/a - not inside a React Native project directory', + ); } process.exit(); } diff --git a/react-native-git-upgrade/index.js b/react-native-git-upgrade/index.js index dea50c344..c5e927312 100644 --- a/react-native-git-upgrade/index.js +++ b/react-native-git-upgrade/index.js @@ -5,30 +5,34 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. + * + * @format */ var argv = require('minimist')(process.argv.slice(2)); var cli = require('./cli'); if (argv._.length === 0 && (argv.h || argv.help)) { - console.log([ - '', - ' Usage: react-native-git-upgrade [version] [options]', - '', - '', - ' Commands:', - '', - ' [Version] upgrades React Native and app templates to the desired version', - ' (latest, if not specified)', - '', - ' Options:', - '', - ' -h, --help output usage information', - ' -v, --version output the version number', - ' --verbose output debugging info', - ' --npm force using the npm client even if your project uses yarn', - '', - ].join('\n')); + console.log( + [ + '', + ' Usage: react-native-git-upgrade [version] [options]', + '', + '', + ' Commands:', + '', + ' [Version] upgrades React Native and app templates to the desired version', + ' (latest, if not specified)', + '', + ' Options:', + '', + ' -h, --help output usage information', + ' -v, --version output the version number', + ' --verbose output debugging info', + ' --npm force using the npm client even if your project uses yarn', + '', + ].join('\n'), + ); process.exit(0); } @@ -37,5 +41,4 @@ if (argv._.length === 0 && (argv.v || argv.version)) { process.exit(0); } -cli.run(argv._[0], argv) - .catch(console.error); +cli.run(argv._[0], argv).catch(console.error); diff --git a/scripts/bump-oss-version.js b/scripts/bump-oss-version.js index 11ac0f940..6af9eb227 100755 --- a/scripts/bump-oss-version.js +++ b/scripts/bump-oss-version.js @@ -4,6 +4,8 @@ * * 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'; @@ -14,13 +16,7 @@ * All you have to do is push changes to remote and CI will make a new build. */ const fs = require('fs'); -const { - cat, - echo, - exec, - exit, - sed, -} = require('shelljs'); +const {cat, echo, exec, exit, sed} = require('shelljs'); const minimist = require('minimist'); @@ -30,7 +26,9 @@ let argv = minimist(process.argv.slice(2), { }); // - check we are in release branch, e.g. 0.33-stable -let branch = exec('git symbolic-ref --short HEAD', {silent: true}).stdout.trim(); +let branch = exec('git symbolic-ref --short HEAD', { + silent: true, +}).stdout.trim(); if (branch.indexOf('-stable') === -1) { echo('You must be in 0.XX-stable branch to bump a version'); @@ -44,14 +42,18 @@ let versionMajor = branch.slice(0, branch.indexOf('-stable')); // e.g. 0.33.1 or 0.33.0-rc4 let version = argv._[0]; if (!version || version.indexOf(versionMajor) !== 0) { - echo(`You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`); + echo( + `You must pass a tag like 0.${versionMajor}.[X]-rc[Y] to bump a version`, + ); exit(1); } // Generate version files to detect mismatches between JS and native. let match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/); if (!match) { - echo(`You must pass a correctly formatted version; couldn't parse ${version}`); + echo( + `You must pass a correctly formatted version; couldn't parse ${version}`, + ); exit(1); } let [, major, minor, patch, prerelease] = match; @@ -62,8 +64,11 @@ fs.writeFileSync( .replace('${major}', major) .replace('${minor}', minor) .replace('${patch}', patch) - .replace('${prerelease}', prerelease !== undefined ? `"${prerelease}"` : 'null'), - 'utf-8' + .replace( + '${prerelease}', + prerelease !== undefined ? `"${prerelease}"` : 'null', + ), + 'utf-8', ); fs.writeFileSync( @@ -72,8 +77,11 @@ fs.writeFileSync( .replace('${major}', `@(${major})`) .replace('${minor}', `@(${minor})`) .replace('${patch}', `@(${patch})`) - .replace('${prerelease}', prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]'), - 'utf-8' + .replace( + '${prerelease}', + prerelease !== undefined ? `@"${prerelease}"` : '[NSNull null]', + ), + 'utf-8', ); fs.writeFileSync( @@ -82,8 +90,11 @@ fs.writeFileSync( .replace('${major}', major) .replace('${minor}', minor) .replace('${patch}', patch) - .replace('${prerelease}', prerelease !== undefined ? `'${prerelease}'` : 'null'), - 'utf-8' + .replace( + '${prerelease}', + prerelease !== undefined ? `'${prerelease}'` : 'null', + ), + 'utf-8', ); let packageJson = JSON.parse(cat('package.json')); @@ -91,16 +102,27 @@ packageJson.version = version; fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2), 'utf-8'); // - change ReactAndroid/gradle.properties -if (sed('-i', /^VERSION_NAME=.*/, `VERSION_NAME=${version}`, 'ReactAndroid/gradle.properties').code) { - echo('Couldn\'t update version for Gradle'); +if ( + sed( + '-i', + /^VERSION_NAME=.*/, + `VERSION_NAME=${version}`, + 'ReactAndroid/gradle.properties', + ).code +) { + echo("Couldn't update version for Gradle"); exit(1); } // verify that files changed, we just do a git diff and check how many times version is added across files -let numberOfChangedLinesWithNewVersion = exec(`git diff -U0 | grep '^[+]' | grep -c ${version} `, {silent: true}) - .stdout.trim(); +let numberOfChangedLinesWithNewVersion = exec( + `git diff -U0 | grep '^[+]' | grep -c ${version} `, + {silent: true}, +).stdout.trim(); if (+numberOfChangedLinesWithNewVersion !== 2) { - echo('Failed to update all the files. package.json and gradle.properties must have versions in them'); + echo( + 'Failed to update all the files. package.json and gradle.properties must have versions in them', + ); echo('Fix the issue, revert and try again'); exec('git diff'); exit(1); @@ -114,7 +136,9 @@ if (exec(`git commit -a -m "[${version}] Bump version numbers"`).code) { // - add tag v0.21.0-rc if (exec(`git tag v${version}`).code) { - echo(`failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`); + echo( + `failed to tag the commit with v${version}, are you sure this release wasn't made earlier?`, + ); echo('You may want to rollback the last commit'); echo('git reset --hard HEAD~1'); exit(1);