From 22fc71e0ae435688e8ad005c798d21476048750a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 9 Sep 2019 22:14:45 +0200 Subject: [PATCH 1/2] chore: migrate upgrade command to TS --- babel.config.js | 1 + package.json | 5 +- packages/cli/package.json | 1 + packages/cli/src/cliEntry.js | 2 +- packages/cli/src/commands/doctor/doctor.js | 1 + .../commands/doctor/healthchecks/cocoaPods.js | 1 + .../commands/doctor/healthchecks/common.js | 2 +- .../doctor/healthchecks/packageManagers.js | 1 + .../commands/doctor/healthchecks/watchman.js | 1 + .../src/commands/doctor/runAutomaticFix.js | 2 +- packages/cli/src/commands/index.js | 32 ---- packages/cli/src/commands/index.ts | 40 +++++ packages/cli/src/commands/init/init.js | 2 + .../src/commands/link/__tests__/link-test.js | 1 - ...rade.test.js.snap => upgrade.test.ts.snap} | 0 .../{upgrade.test.js => upgrade.test.ts} | 62 +++---- .../cli/src/commands/upgrade/legacyUpgrade.js | 154 ------------------ .../upgrade/{upgrade.js => upgrade.ts} | 74 ++++----- .../tools/{brewInstall.js => brewInstall.ts} | 3 +- .../cli/src/tools/{install.js => install.ts} | 5 +- .../tools/{installPods.js => installPods.ts} | 17 +- packages/cli/src/tools/loader.js | 22 --- packages/cli/src/tools/loader.ts | 48 ++++++ packages/cli/src/tools/logger.js | 1 - packages/cli/src/tools/packageManager.js | 2 +- .../tools/releaseChecker/getLatestRelease.js | 2 +- .../tools/releaseChecker/printNewRelease.js | 2 +- .../releaseChecker/releaseCacheManager.js | 2 +- yarn.lock | 109 ++++++++++++- 29 files changed, 287 insertions(+), 308 deletions(-) delete mode 100644 packages/cli/src/commands/index.js create mode 100644 packages/cli/src/commands/index.ts rename packages/cli/src/commands/upgrade/__tests__/__snapshots__/{upgrade.test.js.snap => upgrade.test.ts.snap} (100%) rename packages/cli/src/commands/upgrade/__tests__/{upgrade.test.js => upgrade.test.ts} (90%) delete mode 100644 packages/cli/src/commands/upgrade/legacyUpgrade.js rename packages/cli/src/commands/upgrade/{upgrade.js => upgrade.ts} (85%) rename packages/cli/src/tools/{brewInstall.js => brewInstall.ts} (85%) rename packages/cli/src/tools/{install.js => install.ts} (76%) rename packages/cli/src/tools/{installPods.js => installPods.ts} (93%) delete mode 100644 packages/cli/src/tools/loader.js create mode 100644 packages/cli/src/tools/loader.ts delete mode 100644 packages/cli/src/tools/logger.js diff --git a/babel.config.js b/babel.config.js index f7a77eb48..1356ac09e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -20,6 +20,7 @@ module.exports = { ], ], plugins: [ + require.resolve('@babel/plugin-proposal-class-properties'), require.resolve('@babel/plugin-transform-strict-mode'), [require.resolve('@babel/plugin-transform-modules-commonjs'), {lazy: true}], [ diff --git a/package.json b/package.json index 06fdca364..9d5b3baad 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,9 @@ "micromatch": "^3.1.10", "mkdirp": "^0.5.1", "string-length": "^2.0.0", - "typescript": "^3.4.5" + "typescript": "^3.6.2" + }, + "devDependencies": { + "@babel/plugin-proposal-class-properties": "^7.5.5" } } diff --git a/packages/cli/package.json b/packages/cli/package.json index ad3ad1271..b93da36e6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -64,6 +64,7 @@ "react-native": "^0.60.0" }, "devDependencies": { + "@types/semver": "^6.0.2", "slash": "^3.0.0", "snapshot-diff": "^0.5.0" } diff --git a/packages/cli/src/cliEntry.js b/packages/cli/src/cliEntry.js index b2342de34..93547041d 100644 --- a/packages/cli/src/cliEntry.js +++ b/packages/cli/src/cliEntry.js @@ -13,7 +13,7 @@ import commander from 'commander'; import path from 'path'; import type {CommandT, ConfigT} from 'types'; - +// $FlowFixMe - converted to TS import commands from './commands'; import init from './commands/init/initCompat'; import assertRequiredOptions from './tools/assertRequiredOptions'; diff --git a/packages/cli/src/commands/doctor/doctor.js b/packages/cli/src/commands/doctor/doctor.js index 474bd6e43..122554173 100644 --- a/packages/cli/src/commands/doctor/doctor.js +++ b/packages/cli/src/commands/doctor/doctor.js @@ -3,6 +3,7 @@ import chalk from 'chalk'; import envinfo from 'envinfo'; import {logger} from '@react-native-community/cli-tools'; import {getHealthchecks, HEALTHCHECK_TYPES} from './healthchecks'; +// $FlowFixMe - converted to TS import {getLoader} from '../../tools/loader'; import printFixOptions, {KEYS} from './printFixOptions'; import runAutomaticFix, {AUTOMATIC_FIX_LEVELS} from './runAutomaticFix'; diff --git a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js index 5644278c6..8ec16b405 100644 --- a/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js +++ b/packages/cli/src/commands/doctor/healthchecks/cocoaPods.js @@ -1,5 +1,6 @@ // @flow import {isSoftwareInstalled} from '../checkInstallation'; +// $FlowFixMe - converted to TS import {installCocoaPods} from '../../../tools/installPods'; import {type HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/common.js b/packages/cli/src/commands/doctor/healthchecks/common.js index 1bce843c3..67a397887 100644 --- a/packages/cli/src/commands/doctor/healthchecks/common.js +++ b/packages/cli/src/commands/doctor/healthchecks/common.js @@ -1,5 +1,5 @@ // @flow -import logger from '@react-native-community/cli-tools/build/logger'; +import {logger} from '@react-native-community/cli-tools'; import chalk from 'chalk'; // Space is necessary to keep correct ordering on screen diff --git a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js index 92433c7ad..0ffb26c79 100644 --- a/packages/cli/src/commands/doctor/healthchecks/packageManagers.js +++ b/packages/cli/src/commands/doctor/healthchecks/packageManagers.js @@ -6,6 +6,7 @@ import { PACKAGE_MANAGERS, doesSoftwareNeedToBeFixed, } from '../checkInstallation'; +// $FlowFixMe - converted to TS import {install} from '../../../tools/install'; import type {EnvironmentInfo, HealthCheckInterface} from '../types'; diff --git a/packages/cli/src/commands/doctor/healthchecks/watchman.js b/packages/cli/src/commands/doctor/healthchecks/watchman.js index 798708a78..07f2fe954 100644 --- a/packages/cli/src/commands/doctor/healthchecks/watchman.js +++ b/packages/cli/src/commands/doctor/healthchecks/watchman.js @@ -2,6 +2,7 @@ import Ora from 'ora'; import versionRanges from '../versionRanges'; import {doesSoftwareNeedToBeFixed} from '../checkInstallation'; +// $FlowFixMe - converted to TS import {install} from '../../../tools/install'; import type {EnvironmentInfo} from '../types'; diff --git a/packages/cli/src/commands/doctor/runAutomaticFix.js b/packages/cli/src/commands/doctor/runAutomaticFix.js index f954dd9b7..ac201526c 100644 --- a/packages/cli/src/commands/doctor/runAutomaticFix.js +++ b/packages/cli/src/commands/doctor/runAutomaticFix.js @@ -1,7 +1,7 @@ // @flow import chalk from 'chalk'; import ora from 'ora'; -import logger from '../../tools/logger'; +import {logger} from '@react-native-community/cli-tools'; import {HEALTHCHECK_TYPES} from './healthchecks'; import type {EnvironmentInfo} from './types'; diff --git a/packages/cli/src/commands/index.js b/packages/cli/src/commands/index.js deleted file mode 100644 index c2249da67..000000000 --- a/packages/cli/src/commands/index.js +++ /dev/null @@ -1,32 +0,0 @@ -/** - * @flow - */ -import {type CommandT} from 'types'; - -import server from './server/server'; -import bundle from './bundle/bundle'; -import ramBundle from './bundle/ramBundle'; -import link from './link/link'; -import unlink from './link/unlink'; -import install from './install/install'; -import uninstall from './install/uninstall'; -import upgrade from './upgrade/upgrade'; -import info from './info/info'; -import config from './config/config'; -import init from './init'; -import doctor from './doctor'; - -export default ([ - server, - bundle, - ramBundle, - link, - unlink, - install, - uninstall, - upgrade, - info, - config, - init, - doctor, -]: CommandT[]); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts new file mode 100644 index 000000000..3fb425892 --- /dev/null +++ b/packages/cli/src/commands/index.ts @@ -0,0 +1,40 @@ +import {Command} from '@react-native-community/cli-types'; + +// @ts-ignore - JS file +import server from './server/server'; +// @ts-ignore - JS file +import bundle from './bundle/bundle'; +// @ts-ignore - JS file +import ramBundle from './bundle/ramBundle'; +// @ts-ignore - JS file +import link from './link/link'; // eslint-disable-line +// @ts-ignore - JS file +import unlink from './link/unlink'; // eslint-disable-line +// @ts-ignore - JS file +import install from './install/install'; // eslint-disable-line +// @ts-ignore - JS file +import uninstall from './install/uninstall'; // eslint-disable-line +import upgrade from './upgrade/upgrade'; +// @ts-ignore - JS file +import info from './info/info'; // eslint-disable-line +// @ts-ignore - JS file +import config from './config/config'; // eslint-disable-line +// @ts-ignore - JS file +import init from './init'; +// @ts-ignore - JS file +import doctor from './doctor'; + +export default [ + server, + bundle, + ramBundle, + link, + unlink, + install, + uninstall, + upgrade, + info, + config, + init, + doctor, +] as Command[]; diff --git a/packages/cli/src/commands/init/init.js b/packages/cli/src/commands/init/init.js index ea364adb5..e80611bed 100644 --- a/packages/cli/src/commands/init/init.js +++ b/packages/cli/src/commands/init/init.js @@ -20,9 +20,11 @@ import { } from './template'; import {changePlaceholderInTemplate} from './editTemplate'; import * as PackageManager from '../../tools/packageManager'; +// $FlowFixMe - converted to TS import installPods from '../../tools/installPods'; import {processTemplateName} from './templateName'; import banner from './banner'; +// $FlowFixMe - converted to TS import {getLoader} from '../../tools/loader'; import {CLIError} from '@react-native-community/cli-tools'; diff --git a/packages/cli/src/commands/link/__tests__/link-test.js b/packages/cli/src/commands/link/__tests__/link-test.js index 02c537344..3487b09ec 100644 --- a/packages/cli/src/commands/link/__tests__/link-test.js +++ b/packages/cli/src/commands/link/__tests__/link-test.js @@ -4,7 +4,6 @@ import makeHook from '../makeHook'; jest.mock('chalk', () => ({grey: str => str, bold: str => str})); jest.mock('../../../tools/config'); -jest.mock('../../../tools/logger'); jest.mock('../makeHook', () => { return jest.fn(() => { return jest.fn(() => Promise.resolve()); diff --git a/packages/cli/src/commands/upgrade/__tests__/__snapshots__/upgrade.test.js.snap b/packages/cli/src/commands/upgrade/__tests__/__snapshots__/upgrade.test.ts.snap similarity index 100% rename from packages/cli/src/commands/upgrade/__tests__/__snapshots__/upgrade.test.js.snap rename to packages/cli/src/commands/upgrade/__tests__/__snapshots__/upgrade.test.ts.snap diff --git a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.ts similarity index 90% rename from packages/cli/src/commands/upgrade/__tests__/upgrade.test.js rename to packages/cli/src/commands/upgrade/__tests__/upgrade.test.ts index c4ad3379e..761a65fc8 100644 --- a/packages/cli/src/commands/upgrade/__tests__/upgrade.test.js +++ b/packages/cli/src/commands/upgrade/__tests__/upgrade.test.ts @@ -1,4 +1,3 @@ -// @flow import execa from 'execa'; import path from 'path'; import fs from 'fs'; @@ -6,7 +5,7 @@ import snapshotDiff from 'snapshot-diff'; import stripAnsi from 'strip-ansi'; import upgrade from '../upgrade'; import {fetch, logger} from '@react-native-community/cli-tools'; -import loadConfig from '../../../tools/config'; +import loadConfig from '../../../tools/config'; // eslint-disable-line import merge from '../../../tools/merge'; jest.mock('https'); @@ -56,7 +55,9 @@ jest.mock('@react-native-community/cli-tools', () => ({ })); const mockFetch = (value = '', status = 200) => { - (fetch: any).mockImplementation(() => Promise.resolve({data: value, status})); + (fetch as jest.Mock).mockImplementation(() => + Promise.resolve({data: value, status}), + ); }; const mockExecaDefault = (command, args) => { @@ -85,9 +86,6 @@ const currentVersion = '0.57.8'; const newVersion = '0.58.4'; const olderVersion = '0.56.0'; const ctx = loadConfig(); -const opts = { - legacy: false, -}; const samplePatch = jest .requireActual('fs') @@ -101,34 +99,30 @@ const flushOutput = () => stripAnsi(logs.join('\n')); beforeEach(() => { jest.clearAllMocks(); jest.restoreAllMocks(); - // $FlowFixMe fs.writeFileSync = jest.fn(filename => mockPushLog('[fs] write', filename)); - // $FlowFixMe fs.unlinkSync = jest.fn((...args) => mockPushLog('[fs] unlink', args)); logs = []; - (execa: any).mockImplementation(mockExecaDefault); + ((execa as unknown) as jest.Mock).mockImplementation(mockExecaDefault); Object.defineProperty(process, 'platform', { value: 'darwin', }); }); afterEach(() => { - // $FlowFixMe fs.writeFileSync = jest.requireMock('fs').writeFileSync; - // $FlowFixMe fs.unlinkSync = jest.requireMock('fs').unlinkSync; }); test('uses latest version of react-native when none passed', async () => { - await upgrade.func([], ctx, opts); + await upgrade.func([], ctx); expect(execa).toBeCalledWith('npm', ['info', 'react-native', 'version']); }, 60000); test('applies patch in current working directory when nested', async () => { mockFetch(samplePatch, 200); - (execa: any).mockImplementation(mockExecaNested); + ((execa as unknown) as jest.Mock).mockImplementation(mockExecaNested); const config = {...ctx, root: '/project/root/NestedApp'}; - await upgrade.func([newVersion], config, opts); + await upgrade.func([newVersion], config); expect(execa).toBeCalledWith('git', [ 'apply', @@ -141,25 +135,25 @@ test('applies patch in current working directory when nested', async () => { }); test('errors when invalid version passed', async () => { - await upgrade.func(['next'], ctx, opts); + await upgrade.func(['next'], ctx); expect(logger.error).toBeCalledWith( 'Provided version "next" is not allowed. Please pass a valid semver version', ); }, 60000); test('errors when older version passed', async () => { - await upgrade.func([olderVersion], ctx, opts); + await upgrade.func([olderVersion], ctx); expect(logger.error).toBeCalledWith( `Trying to upgrade from newer version "${currentVersion}" to older "${olderVersion}"`, ); - await upgrade.func(['0.57.10'], ctx, opts); + await upgrade.func(['0.57.10'], ctx); expect(logger.error).not.toBeCalledWith( `Trying to upgrade from newer version "${currentVersion}" to older "0.57.10"`, ); }, 60000); test('warns when dependency upgrade version is in semver range', async () => { - await upgrade.func([currentVersion], ctx, opts); + await upgrade.func([currentVersion], ctx); expect(logger.warn).toBeCalledWith( `Specified version "${currentVersion}" is already installed in node_modules and it satisfies "^0.57.8" semver range. No need to upgrade`, ); @@ -167,7 +161,7 @@ test('warns when dependency upgrade version is in semver range', async () => { test('fetches empty patch and installs deps', async () => { mockFetch(); - await upgrade.func([newVersion], ctx, opts); + await upgrade.func([newVersion], ctx); expect(flushOutput()).toMatchInlineSnapshot(` "info Fetching diff between v0.57.8 and v0.58.4... info Diff has no changes to apply, proceeding further @@ -192,7 +186,6 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes android: {packageName: 'com.testapp'}, }, }), - opts, ); expect(flushOutput()).toMatchInlineSnapshot(` "info Fetching diff between v0.57.8 and v0.58.4... @@ -215,18 +208,22 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes success Upgraded React Native to v0.58.4 🎉. Now you can review and commit the changes" `); expect( - snapshotDiff(samplePatch, (fs.writeFileSync: any).mock.calls[0][1], { - contextLines: 1, - }), + snapshotDiff( + samplePatch, + (fs.writeFileSync as jest.Mock).mock.calls[0][1], + { + contextLines: 1, + }, + ), ).toMatchSnapshot( 'RnDiffApp is replaced with app name (TestApp and com.testapp)', ); }, 60000); test('fetches regular patch, adds remote, applies patch, installs deps, removes remote when updated from nested directory', async () => { mockFetch(samplePatch, 200); - (execa: any).mockImplementation(mockExecaNested); + ((execa as unknown) as jest.Mock).mockImplementation(mockExecaNested); const config = {...ctx, root: '/project/root/NestedApp'}; - await upgrade.func([newVersion], config, opts); + await upgrade.func([newVersion], config); expect(flushOutput()).toMatchInlineSnapshot(` "info Fetching diff between v0.57.8 and v0.58.4... [fs] write tmp-upgrade-rn.patch @@ -250,7 +247,7 @@ test('fetches regular patch, adds remote, applies patch, installs deps, removes }, 60000); test('cleans up if patching fails,', async () => { mockFetch(samplePatch, 200); - (execa: any).mockImplementation((command, args) => { + ((execa as unknown) as jest.Mock).mockImplementation((command, args) => { mockPushLog('$', 'execa', command, args); if (command === 'npm' && args[3] === '--json') { return Promise.resolve({ @@ -270,7 +267,7 @@ test('cleans up if patching fails,', async () => { return Promise.resolve({stdout: ''}); }); try { - await upgrade.func([newVersion], ctx, opts); + await upgrade.func([newVersion], ctx); } catch (error) { expect(error.message).toBe( 'Upgrade failed. Please see the messages above for details', @@ -313,12 +310,15 @@ test('works with --name-ios and --name-android', async () => { android: {packageName: 'co.uk.customandroid.app'}, }, }), - opts, ); expect( - snapshotDiff(samplePatch, (fs.writeFileSync: any).mock.calls[0][1], { - contextLines: 1, - }), + snapshotDiff( + samplePatch, + (fs.writeFileSync as jest.Mock).mock.calls[0][1], + { + contextLines: 1, + }, + ), ).toMatchSnapshot( 'RnDiffApp is replaced with app name (CustomIos and co.uk.customandroid.app)', ); diff --git a/packages/cli/src/commands/upgrade/legacyUpgrade.js b/packages/cli/src/commands/upgrade/legacyUpgrade.js deleted file mode 100644 index 679e7a44b..000000000 --- a/packages/cli/src/commands/upgrade/legacyUpgrade.js +++ /dev/null @@ -1,154 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @format - * @flow - */ - -import fs from 'fs'; -import path from 'path'; -import semver from 'semver'; -import type {ConfigT} from 'types'; -import {logger} from '@react-native-community/cli-tools'; -import copyProjectTemplateAndReplace from '../../tools/generator/copyProjectTemplateAndReplace'; - -/** - * Migrate application to a new version of React Native. - * See http://facebook.github.io/react-native/docs/upgrading.html - */ -function validateAndUpgrade(argv: Array, ctx: ConfigT) { - const projectDir = ctx.root; - - const packageJSON = JSON.parse( - fs.readFileSync(path.resolve(projectDir, 'package.json'), 'utf8'), - ); - - warn( - 'You should consider using the new upgrade tool based on Git. It ' + - 'makes upgrades easier by resolving most conflicts automatically.\n' + - 'To use it:\n' + - '- Go back to the old version of React Native\n' + - '- Run "npm install -g react-native-git-upgrade"\n' + - '- Run "react-native-git-upgrade"\n' + - 'See https://facebook.github.io/react-native/docs/upgrading.html', - ); - - const projectName = packageJSON.name; - if (!projectName) { - warn( - 'Your project needs to have a name, declared in package.json, ' + - 'such as "name": "AwesomeApp". Please add a project name. Aborting.', - ); - return; - } - - const version = packageJSON.dependencies['react-native']; - if (!version) { - warn( - 'Your "package.json" file doesn\'t seem to declare "react-native" as ' + - 'a dependency. Nothing to upgrade. Aborting.', - ); - return; - } - - if (version === 'latest' || version === '*') { - warn( - 'Some major releases introduce breaking changes.\n' + - 'Please use a caret version number in your "package.json" file \n' + - 'to avoid breakage. Use e.g. react-native: ^0.38.0. Aborting.', - ); - return; - } - - const installed = JSON.parse( - fs.readFileSync( - path.resolve(projectDir, 'node_modules/react-native/package.json'), - 'utf8', - ), - ); - - if (!semver.satisfies(installed.version, version)) { - warn( - 'react-native version in "package.json" doesn\'t match ' + - 'the installed version in "node_modules".\n' + - 'Try running "npm install" to fix this. Aborting.', - ); - return; - } - - const v = version.replace(/^(~|\^|=)/, '').replace(/x/i, '0'); - - if (!semver.valid(v)) { - warn( - "A valid version number for 'react-native' is not specified in your " + - "'package.json' file. Aborting.", - ); - return; - } - - logger.info( - `Upgrading project to react-native v${installed.version}\n` + - 'Check out the release notes and breaking changes: ' + - `https://github.com/facebook/react-native/releases/tag/v${semver.major( - v, - )}.${semver.minor(v)}.0`, - ); - - // >= v0.21.0, we require react to be a peer dependency - if (semver.gte(v, '0.21.0') && !packageJSON.dependencies.react) { - warn( - 'Your "package.json" file doesn\'t seem to have "react" as a dependency.\n' + - '"react" was changed from a dependency to a peer dependency in react-native v0.21.0.\n' + - 'Therefore, it\'s necessary to include "react" in your project\'s dependencies.\n' + - 'Please run "npm install --save react", then re-run "react-native upgrade".\n', - ); - return; - } - - if (semver.satisfies(v, '~0.26.0')) { - warn( - 'React Native 0.26 introduced some breaking changes to the native files on iOS. You can\n' + - 'perform them manually by checking the release notes or use "rnpm" ' + - 'to do it automatically.\n' + - 'Just run:\n' + - '"npm install -g rnpm && npm install rnpm-plugin-upgrade@0.26 --save-dev", ' + - 'then run "rnpm upgrade".', - ); - } - - upgradeProjectFiles(projectDir, projectName); - - logger.info( - `Successfully upgraded this project to react-native v${installed.version}`, - ); -} - -/** - * Once all checks passed, upgrade the project files. - */ -function upgradeProjectFiles(projectDir, projectName) { - // Just overwrite - copyProjectTemplateAndReplace( - path.dirname(require.resolve('react-native/template')), - projectDir, - projectName, - {upgrade: true}, - ); -} - -function warn(message) { - logger.warn(message); -} - -const upgradeCommand = { - name: 'upgrade', - description: - "upgrade your app's template files to the latest version; run this after " + - 'updating the react-native version in your package.json and running npm install', - func: validateAndUpgrade, -}; - -export default upgradeCommand; diff --git a/packages/cli/src/commands/upgrade/upgrade.js b/packages/cli/src/commands/upgrade/upgrade.ts similarity index 85% rename from packages/cli/src/commands/upgrade/upgrade.js rename to packages/cli/src/commands/upgrade/upgrade.ts index 3ace9cf60..5abb5110b 100644 --- a/packages/cli/src/commands/upgrade/upgrade.js +++ b/packages/cli/src/commands/upgrade/upgrade.ts @@ -1,18 +1,14 @@ -// @flow import path from 'path'; import fs from 'fs'; import chalk from 'chalk'; import semver from 'semver'; import execa from 'execa'; -import type {ConfigT} from 'types'; +import {Config} from '@react-native-community/cli-types'; import {logger, CLIError, fetch} from '@react-native-community/cli-tools'; -import * as PackageManager from '../../tools/packageManager'; +// @ts-ignore JS file +import * as PackageManager from '../../tools/packageManager'; // eslint-disable-line import/namespace +// @ts-ignore JS file import installPods from '../../tools/installPods'; -import legacyUpgrade from './legacyUpgrade'; - -type FlagsT = { - legacy: boolean | void, -}; // https://react-native-community.github.io/upgrade-helper/?from=0.59.10&to=0.60.0-rc.3 const webDiffUrl = 'https://react-native-community.github.io/upgrade-helper'; @@ -21,7 +17,6 @@ const rawDiffUrl = const getLatestRNVersion = async (): Promise => { logger.info('No version passed. Fetching latest...'); - // $FlowFixMe - this is public API const {stdout} = await execa('npm', ['info', 'react-native', 'version']); return stdout; }; @@ -29,7 +24,6 @@ const getLatestRNVersion = async (): Promise => { const getRNPeerDeps = async ( version: string, ): Promise<{[key: string]: string}> => { - // $FlowFixMe - this is public API const {stdout} = await execa('npm', [ 'info', `react-native@${version}`, @@ -40,7 +34,11 @@ const getRNPeerDeps = async ( return JSON.parse(stdout); }; -const getPatch = async (currentVersion, newVersion, config) => { +const getPatch = async ( + currentVersion: string, + newVersion: string, + config: Config, +) => { let patch; logger.info(`Fetching diff between v${currentVersion} and v${newVersion}...`); @@ -73,20 +71,17 @@ const getPatch = async (currentVersion, newVersion, config) => { if (platform === 'ios') { patchWithRenamedProjects = patchWithRenamedProjects.replace( new RegExp('RnDiffApp', 'g'), - // $FlowFixMe - poor typings of ProjectConfigIOST - config.project[platform].projectName.replace('.xcodeproj', ''), + config.project[platform]!.projectName.replace('.xcodeproj', ''), ); } else if (platform === 'android') { patchWithRenamedProjects = patchWithRenamedProjects .replace( new RegExp('com\\.rndiffapp', 'g'), - // $FlowFixMe - poor typings of ProjectConfigAndroidT - config.project[platform].packageName, + config.project[platform]!.packageName, ) .replace( new RegExp('com\\.rndiffapp'.split('.').join('/'), 'g'), - // $FlowFixMe - poor typings of ProjectConfigAndroidT - config.project[platform].packageName.split('.').join('/'), + config.project[platform]!.packageName.split('.').join('/'), ); } else { logger.warn( @@ -98,10 +93,14 @@ const getPatch = async (currentVersion, newVersion, config) => { return patchWithRenamedProjects; }; -const getVersionToUpgradeTo = async (argv, currentVersion, projectDir) => { +const getVersionToUpgradeTo = async ( + argv: Array, + currentVersion: string, + projectDir: string, +) => { const newVersion = argv[0] ? semver.valid(argv[0]) || - (semver.coerce(argv[0]) ? semver.coerce(argv[0]).version : null) + (semver.coerce(argv[0]) ? semver.coerce(argv[0])!.version : null) : await getLatestRNVersion(); if (!newVersion) { @@ -139,7 +138,7 @@ const getVersionToUpgradeTo = async (argv, currentVersion, projectDir) => { return newVersion; }; -const installDeps = async (newVersion, projectDir) => { +const installDeps = async (newVersion: string) => { logger.info( `Installing "react-native@${newVersion}" and its peer dependencies...`, ); @@ -164,7 +163,10 @@ const installDeps = async (newVersion, projectDir) => { } }; -const installCocoaPodsDeps = async (projectDir, thirdPartyIOSDeps) => { +const installCocoaPodsDeps = async ( + projectDir: string, + thirdPartyIOSDeps: Array, +) => { if (process.platform === 'darwin') { try { logger.info( @@ -173,7 +175,7 @@ const installCocoaPodsDeps = async (projectDir, thirdPartyIOSDeps) => { )}`, ); await installPods({ - projectName: projectDir.split('/').pop(), + projectName: projectDir.split('/').pop() || '', shouldUpdatePods: thirdPartyIOSDeps.length > 0, }); } catch (error) { @@ -197,9 +199,9 @@ const applyPatch = async ( tmpPatchFile: string, ) => { const defaultExcludes = ['package.json']; - let filesThatDontExist = []; - let filesThatFailedToApply = []; - // $FlowFixMe ThenableChildProcess is incompatible with Promise + let filesThatDontExist: Array = []; + let filesThatFailedToApply: Array = []; + const {stdout: relativePathFromRoot} = await execa('git', [ 'rev-parse', '--show-prefix', @@ -224,7 +226,7 @@ const applyPatch = async ( ]); logger.info('Applying diff...'); } catch (error) { - const errorLines = error.stderr.split('\n'); + const errorLines: Array = error.stderr.split('\n'); filesThatDontExist = [ ...errorLines .filter(x => x.includes('does not exist in index')) @@ -283,10 +285,7 @@ const applyPatch = async ( /** * Upgrade application to a new version of React Native. */ -async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { - if (args.legacy) { - return legacyUpgrade.func(argv, ctx); - } +async function upgrade(argv: Array, ctx: Config) { const tmpPatchFile = 'tmp-upgrade-rn.patch'; const projectDir = ctx.root; const {version: currentVersion} = require(path.join( @@ -294,7 +293,6 @@ async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { 'node_modules/react-native/package.json', )); const thirdPartyIOSDeps = Object.values(ctx.dependencies).filter( - // $FlowFixMe dependency => dependency.platforms.ios, ); @@ -316,7 +314,7 @@ async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { if (patch === '') { logger.info('Diff has no changes to apply, proceeding further'); - await installDeps(newVersion, projectDir); + await installDeps(newVersion); await installCocoaPodsDeps(projectDir, thirdPartyIOSDeps); logger.success( @@ -343,7 +341,7 @@ async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { logger.warn( 'Continuing after failure. Some of the files are upgraded but you will need to deal with conflicts manually', ); - await installDeps(newVersion, projectDir); + await installDeps(newVersion); logger.info('Running "git status" to check what changed...'); await execa('git', ['status'], {stdio: 'inherit'}); } else { @@ -352,7 +350,7 @@ async function upgrade(argv: Array, ctx: ConfigT, args: FlagsT) { ); } } else { - await installDeps(newVersion, projectDir); + await installDeps(newVersion); await installCocoaPodsDeps(projectDir, thirdPartyIOSDeps); logger.info('Running "git status" to check what changed...'); await execa('git', ['status'], {stdio: 'inherit'}); @@ -393,13 +391,5 @@ const upgradeCommand = { description: "Upgrade your app's template files to the specified or latest npm version using `rn-diff-purge` project. Only valid semver versions are allowed.", func: upgrade, - options: [ - { - name: '--legacy [boolean]', - description: - "Legacy implementation. Upgrade your app's template files to the latest version; run this after " + - 'updating the react-native version in your package.json and running npm install', - }, - ], }; export default upgradeCommand; diff --git a/packages/cli/src/tools/brewInstall.js b/packages/cli/src/tools/brewInstall.ts similarity index 85% rename from packages/cli/src/tools/brewInstall.js rename to packages/cli/src/tools/brewInstall.ts index 4405d52c9..7d4c92d84 100644 --- a/packages/cli/src/tools/brewInstall.js +++ b/packages/cli/src/tools/brewInstall.ts @@ -1,9 +1,8 @@ -// @flow import {logger} from '@react-native-community/cli-tools'; import execa from 'execa'; import Ora from 'ora'; -async function brewInstall(pkg: string, loader: typeof Ora) { +async function brewInstall(pkg: string, loader: Ora.Ora) { loader.start(`Installing ${pkg}`); try { await execa('brew', ['install', pkg]); diff --git a/packages/cli/src/tools/install.js b/packages/cli/src/tools/install.ts similarity index 76% rename from packages/cli/src/tools/install.js rename to packages/cli/src/tools/install.ts index 27758d9d2..b51ee85fb 100644 --- a/packages/cli/src/tools/install.js +++ b/packages/cli/src/tools/install.ts @@ -1,8 +1,7 @@ -// @flow -import Ora from 'ora'; +import ora from 'ora'; import {brewInstall} from './brewInstall'; -async function install(pkg: string, source: string, loader: typeof Ora) { +async function install(pkg: string, source: string, loader: ora.Ora) { try { switch (process.platform) { case 'darwin': diff --git a/packages/cli/src/tools/installPods.js b/packages/cli/src/tools/installPods.ts similarity index 93% rename from packages/cli/src/tools/installPods.js rename to packages/cli/src/tools/installPods.ts index 6ce743dac..9de88a74b 100644 --- a/packages/cli/src/tools/installPods.js +++ b/packages/cli/src/tools/installPods.ts @@ -1,15 +1,16 @@ -// @flow import fs from 'fs'; import execa from 'execa'; import chalk from 'chalk'; -import Ora from 'ora'; +import ora from 'ora'; +// @ts-ignore untyped import inquirer from 'inquirer'; import {logger} from '@react-native-community/cli-tools'; import {NoopLoader} from './loader'; +// @ts-ignore untyped import sudo from 'sudo-prompt'; import {brewInstall} from './brewInstall'; -async function updatePods(loader: typeof Ora) { +async function updatePods(loader: ora.Ora) { try { loader.start( `Updating CocoaPods repositories ${chalk.dim( @@ -32,7 +33,7 @@ async function updatePods(loader: typeof Ora) { function runSudo(command: string): Promise { return new Promise((resolve, reject) => { - sudo.exec(command, error => { + sudo.exec(command, (error: Error) => { if (error) { reject(error); } @@ -42,7 +43,7 @@ function runSudo(command: string): Promise { }); } -async function installCocoaPods(loader: typeof Ora) { +async function installCocoaPods(loader: ora.Ora) { loader.stop(); const withGem = 'Yes, with gem (may require sudo)'; @@ -96,9 +97,9 @@ async function installPods({ loader, shouldUpdatePods, }: { - projectName: string, - loader?: typeof Ora, - shouldUpdatePods: boolean, + projectName: string; + loader?: ora.Ora; + shouldUpdatePods: boolean; }) { loader = loader || new NoopLoader(); try { diff --git a/packages/cli/src/tools/loader.js b/packages/cli/src/tools/loader.js deleted file mode 100644 index 9f7856651..000000000 --- a/packages/cli/src/tools/loader.js +++ /dev/null @@ -1,22 +0,0 @@ -// @flow -import Ora from 'ora'; -import logger from './logger'; - -class OraNoop { - succeed(text?: string) {} - fail(text?: string) {} - start(text?: string) {} - stop() {} - warn(text?: string) {} - info(text?: string) {} - stopAndPersist() {} - clear() {} - render() {} - frame() {} -} - -export function getLoader(): typeof Ora { - return logger.isVerbose() ? OraNoop : Ora; -} - -export const NoopLoader = OraNoop; diff --git a/packages/cli/src/tools/loader.ts b/packages/cli/src/tools/loader.ts new file mode 100644 index 000000000..f3940c1be --- /dev/null +++ b/packages/cli/src/tools/loader.ts @@ -0,0 +1,48 @@ +import ora from 'ora'; +import {logger} from '@react-native-community/cli-tools'; + +class OraNoop implements ora.Ora { + spinner: ora.Spinner = {interval: 1, frames: []}; + indent: number = 0; + isSpinning: boolean = false; + text: string = ''; + prefixText: string = ''; + color: ora.Color = 'blue'; + + succeed(_text?: string | undefined) { + return ora(); + } + fail(_text?: string) { + return ora(); + } + start(_text?: string) { + return ora(); + } + stop() { + return ora(); + } + warn(_text?: string) { + return ora(); + } + info(_text?: string) { + return ora(); + } + stopAndPersist() { + return ora(); + } + clear() { + return ora(); + } + render() { + return ora(); + } + frame() { + return ora(); + } +} + +export function getLoader() { + return logger.isVerbose() ? OraNoop : ora; +} + +export const NoopLoader = OraNoop; diff --git a/packages/cli/src/tools/logger.js b/packages/cli/src/tools/logger.js deleted file mode 100644 index 839cbbe63..000000000 --- a/packages/cli/src/tools/logger.js +++ /dev/null @@ -1 +0,0 @@ -export {logger as default} from '@react-native-community/cli-tools'; diff --git a/packages/cli/src/tools/packageManager.js b/packages/cli/src/tools/packageManager.js index b85e8c293..4a3527cdf 100644 --- a/packages/cli/src/tools/packageManager.js +++ b/packages/cli/src/tools/packageManager.js @@ -1,6 +1,6 @@ // @flow import execa from 'execa'; -import logger from './logger'; +import {logger} from '@react-native-community/cli-tools'; import {getYarnVersionIfAvailable, isProjectUsingYarn} from './yarn'; type Options = {| diff --git a/packages/cli/src/tools/releaseChecker/getLatestRelease.js b/packages/cli/src/tools/releaseChecker/getLatestRelease.js index eeeb9431d..d836aab98 100644 --- a/packages/cli/src/tools/releaseChecker/getLatestRelease.js +++ b/packages/cli/src/tools/releaseChecker/getLatestRelease.js @@ -2,7 +2,7 @@ * @flow */ import semver from 'semver'; -import logger from '../logger'; +import {logger} from '@react-native-community/cli-tools'; import cacheManager from './releaseCacheManager'; import {fetch} from '@react-native-community/cli-tools'; diff --git a/packages/cli/src/tools/releaseChecker/printNewRelease.js b/packages/cli/src/tools/releaseChecker/printNewRelease.js index b280d0963..10b895651 100644 --- a/packages/cli/src/tools/releaseChecker/printNewRelease.js +++ b/packages/cli/src/tools/releaseChecker/printNewRelease.js @@ -2,7 +2,7 @@ * @flow */ import chalk from 'chalk'; -import logger from '../logger'; +import {logger} from '@react-native-community/cli-tools'; import type {Release} from './getLatestRelease'; import cacheManager from './releaseCacheManager'; diff --git a/packages/cli/src/tools/releaseChecker/releaseCacheManager.js b/packages/cli/src/tools/releaseChecker/releaseCacheManager.js index 193af6c33..80d27472d 100644 --- a/packages/cli/src/tools/releaseChecker/releaseCacheManager.js +++ b/packages/cli/src/tools/releaseChecker/releaseCacheManager.js @@ -5,7 +5,7 @@ import path from 'path'; import fs from 'fs'; import os from 'os'; import mkdirp from 'mkdirp'; -import logger from '../logger'; +import {logger} from '@react-native-community/cli-tools'; type ReleaseCacheKey = 'eTag' | 'lastChecked' | 'latestVersion'; type Cache = {[key: ReleaseCacheKey]: string}; diff --git a/yarn.lock b/yarn.lock index b916aa78f..6b6712229 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9,6 +9,13 @@ dependencies: "@babel/highlight" "^7.0.0" +"@babel/code-frame@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" + integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw== + dependencies: + "@babel/highlight" "^7.0.0" + "@babel/core@^7.0.0": version "7.1.2" resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.1.2.tgz#f8d2a9ceb6832887329a7b60f9d035791400ba4e" @@ -69,6 +76,17 @@ source-map "^0.5.0" trim-right "^1.0.1" +"@babel/generator@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.6.0.tgz#e2c21efbfd3293ad819a2359b448f002bfdfda56" + integrity sha512-Ms8Mo7YBdMMn1BYuNtKuP/z0TgEIhbcyB8HVR6PPNYp4P61lMsABiS4A3VG1qznjXVCf3r+fVHhm4efTYVsySA== + dependencies: + "@babel/types" "^7.6.0" + jsesc "^2.5.1" + lodash "^4.17.13" + source-map "^0.5.0" + trim-right "^1.0.1" + "@babel/helper-annotate-as-pure@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.0.0.tgz#323d39dd0b50e10c7c06ca7d7638e6864d8c5c32" @@ -97,6 +115,18 @@ "@babel/traverse" "^7.1.0" "@babel/types" "^7.0.0" +"@babel/helper-create-class-features-plugin@^7.5.5": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.6.0.tgz#769711acca889be371e9bc2eb68641d55218021f" + integrity sha512-O1QWBko4fzGju6VoVvrZg0RROCVifcLxiApnGP3OWfWzvxRZFCoBD81K5ur5e3bVY2Vf/5rIJm8cqPKn8HUJng== + dependencies: + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-member-expression-to-functions" "^7.5.5" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/helper-replace-supers" "^7.5.5" + "@babel/helper-split-export-declaration" "^7.4.4" + "@babel/helper-define-map@^7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@babel/helper-define-map/-/helper-define-map-7.1.0.tgz#3b74caec329b3c80c116290887c0dd9ae468c20c" @@ -140,6 +170,13 @@ dependencies: "@babel/types" "^7.0.0" +"@babel/helper-member-expression-to-functions@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.5.5.tgz#1fb5b8ec4453a93c439ee9fe3aeea4a84b76b590" + integrity sha512-5qZ3D1uMclSNqYcXqiHoA0meVdv+xUEex9em2fqMnrk/scphGlGgg66zjMrPJESPwrFJ6sbfFQYUSa0Mz7FabA== + dependencies: + "@babel/types" "^7.5.5" + "@babel/helper-module-imports@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.0.0.tgz#96081b7111e486da4d2cd971ad1a4fe216cc2e3d" @@ -193,6 +230,16 @@ "@babel/traverse" "^7.1.0" "@babel/types" "^7.0.0" +"@babel/helper-replace-supers@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/helper-replace-supers/-/helper-replace-supers-7.5.5.tgz#f84ce43df031222d2bad068d2626cb5799c34bc2" + integrity sha512-XvRFWrNnlsow2u7jXDuH4jDDctkxbS7gXssrP4q2nUD606ukXHRvydj346wmNg+zAgpFx4MWf4+usfC93bElJg== + dependencies: + "@babel/helper-member-expression-to-functions" "^7.5.5" + "@babel/helper-optimise-call-expression" "^7.0.0" + "@babel/traverse" "^7.5.5" + "@babel/types" "^7.5.5" + "@babel/helper-simple-access@^7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@babel/helper-simple-access/-/helper-simple-access-7.1.0.tgz#65eeb954c8c245beaa4e859da6188f39d71e585c" @@ -207,6 +254,13 @@ dependencies: "@babel/types" "^7.4.0" +"@babel/helper-split-export-declaration@^7.4.4": + version "7.4.4" + resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.4.4.tgz#ff94894a340be78f53f06af038b205c49d993677" + integrity sha512-Ro/XkzLf3JFITkW6b+hNxzZ1n5OQ80NvIUdmHspih1XAhtN3vPTuUFT4eQnela+2MaZ5ulH+iyP513KJrxbN7Q== + dependencies: + "@babel/types" "^7.4.4" + "@babel/helper-wrap-function@^7.1.0": version "7.1.0" resolved "https://registry.yarnpkg.com/@babel/helper-wrap-function/-/helper-wrap-function-7.1.0.tgz#8cf54e9190706067f016af8f75cb3df829cc8c66" @@ -247,6 +301,11 @@ resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.3.tgz#eb3ac80f64aa101c907d4ce5406360fe75b7895b" integrity sha512-gxpEUhTS1sGA63EGQGuA+WESPR/6tz6ng7tSHFCmaTJK/cGK8y37cBTspX+U2xCAue2IQVvF6Z0oigmjwD8YGQ== +"@babel/parser@^7.6.0": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.6.0.tgz#3e05d0647432a8326cb28d0de03895ae5a57f39b" + integrity sha512-+o2q111WEx4srBs7L9eJmcwi655eD8sXniLqMB93TBK9GrNzGrxDWSjiqz2hLU0Ha8MTXFIP0yd9fNdP+m43ZQ== + "@babel/plugin-external-helpers@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/plugin-external-helpers/-/plugin-external-helpers-7.0.0.tgz#61ee7ba5dba27d7cad72a13d46bec23c060b762e" @@ -273,6 +332,14 @@ "@babel/helper-replace-supers" "^7.1.0" "@babel/plugin-syntax-class-properties" "^7.0.0" +"@babel/plugin-proposal-class-properties@^7.5.5": + version "7.5.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.5.5.tgz#a974cfae1e37c3110e71f3c6a2e48b8e71958cd4" + integrity sha512-AF79FsnWFxjlaosgdi421vmYG6/jg79bVD0dpD44QdgobzHKuLZ6S3vl8la9qIeSwGi8i1fS0O1mfuDAAdo1/A== + dependencies: + "@babel/helper-create-class-features-plugin" "^7.5.5" + "@babel/helper-plugin-utils" "^7.0.0" + "@babel/plugin-proposal-export-default-from@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.0.0.tgz#a057bbfd4649facfe39f33a537e18554bdd2b5da" @@ -962,6 +1029,21 @@ globals "^11.1.0" lodash "^4.17.11" +"@babel/traverse@^7.5.5": + version "7.6.0" + resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.6.0.tgz#389391d510f79be7ce2ddd6717be66d3fed4b516" + integrity sha512-93t52SaOBgml/xY74lsmt7xOR4ufYvhb5c5qiM6lu4J/dWGMAfAh6eKw4PjLes6DI6nQgearoxnFJk60YchpvQ== + dependencies: + "@babel/code-frame" "^7.5.5" + "@babel/generator" "^7.6.0" + "@babel/helper-function-name" "^7.1.0" + "@babel/helper-split-export-declaration" "^7.4.4" + "@babel/parser" "^7.6.0" + "@babel/types" "^7.6.0" + debug "^4.1.0" + globals "^11.1.0" + lodash "^4.17.13" + "@babel/types@^7.0.0", "@babel/types@^7.1.2", "@babel/types@^7.1.3", "@babel/types@^7.3.0", "@babel/types@^7.4.0": version "7.4.0" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.4.0.tgz#670724f77d24cce6cc7d8cf64599d511d164894c" @@ -971,6 +1053,15 @@ lodash "^4.17.11" to-fast-properties "^2.0.0" +"@babel/types@^7.4.4", "@babel/types@^7.5.5", "@babel/types@^7.6.0": + version "7.6.1" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.6.1.tgz#53abf3308add3ac2a2884d539151c57c4b3ac648" + integrity sha512-X7gdiuaCmA0uRjCmRtYJNAVCc/q+5xSgsfKJHqMN4iNLILX39677fJE1O40arPMh0TTtS9ItH67yre6c7k6t0g== + dependencies: + esutils "^2.0.2" + lodash "^4.17.13" + to-fast-properties "^2.0.0" + "@cnakazawa/watch@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef" @@ -2033,6 +2124,11 @@ "@types/node" "*" xmlbuilder ">=11.0.1" +"@types/semver@^6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.0.2.tgz#5e8b09f0e4af53034b1d0fb9977a277847836205" + integrity sha512-G1Ggy7/9Nsa1Jt2yiBR2riEuyK2DFNnqow6R7cromXPMNynackRY1vqFTLz/gwnef1LHokbXThcPhqMRjUbkpQ== + "@types/stack-utils@^1.0.1": version "1.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e" @@ -6029,6 +6125,11 @@ lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.1, resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.13.tgz#0bdc3a6adc873d2f4e0c4bac285df91b64fc7b93" integrity sha512-vm3/XWXfWtRua0FkUyEHBZy8kCPjErNBT9fJx8Zvs+U6zjqPbTUOpkaoum3O5uiA8sm+yNMHXfYkTUHFoMxFNA== +lodash@^4.17.13: + version "4.17.15" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" + integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + log-symbols@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-2.2.0.tgz#5740e1c5d6f0dfda4ad9323b5332107ef6b4c40a" @@ -8883,10 +8984,10 @@ typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" -typescript@^3.4.5: - version "3.4.5" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99" - integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw== +typescript@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.2.tgz#105b0f1934119dde543ac8eb71af3a91009efe54" + integrity sha512-lmQ4L+J6mnu3xweP8+rOrUwzmN+MRAj7TgtJtDaXE5PMyX2kCrklhg3rvOsOIfNeAWMQWO2F1GPc1kMD2vLAfw== ua-parser-js@^0.7.18: version "0.7.19" From 31135c4144100b9a8bb4ba6b8f30a695e6089549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 9 Sep 2019 23:42:36 +0200 Subject: [PATCH 2/2] fixup semver.coerce --- packages/cli/src/commands/upgrade/upgrade.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/upgrade/upgrade.ts b/packages/cli/src/commands/upgrade/upgrade.ts index 5abb5110b..0f46df1e1 100644 --- a/packages/cli/src/commands/upgrade/upgrade.ts +++ b/packages/cli/src/commands/upgrade/upgrade.ts @@ -98,9 +98,11 @@ const getVersionToUpgradeTo = async ( currentVersion: string, projectDir: string, ) => { - const newVersion = argv[0] - ? semver.valid(argv[0]) || - (semver.coerce(argv[0]) ? semver.coerce(argv[0])!.version : null) + const argVersion = argv[0]; + const semverCoercedVersion = semver.coerce(argVersion); + const newVersion = argVersion + ? semver.valid(argVersion) || + (semverCoercedVersion ? semverCoercedVersion.version : null) : await getLatestRNVersion(); if (!newVersion) {