diff --git a/packages/cli-types/src/index.ts b/packages/cli-types/src/index.ts index 89dc7f0da..4b79d27c0 100644 --- a/packages/cli-types/src/index.ts +++ b/packages/cli-types/src/index.ts @@ -86,6 +86,8 @@ export interface Dependency { hooks: { prelink?: string; postlink?: string; + preunlink?: string; + postunlink?: string; }; params: InquirerPrompt[]; } diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 8fedc63f0..64dce9ebc 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -2,20 +2,15 @@ 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 import/namespace, import/default -// @ts-ignore - JS file -import unlink from './link/unlink'; // eslint-disable-line import/namespace, import/default +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'; -// @ts-ignore - JS file import init from './init'; // @ts-ignore - JS file import doctor from './doctor'; diff --git a/packages/cli/src/commands/install/install.ts b/packages/cli/src/commands/install/install.ts index 3405af990..fcf95ab69 100644 --- a/packages/cli/src/commands/install/install.ts +++ b/packages/cli/src/commands/install/install.ts @@ -7,8 +7,7 @@ */ import {logger} from '@react-native-community/cli-tools'; import * as PackageManager from '../../tools/packageManager'; -// @ts-ignore FIXME after converting link/link -import link from '../link/link'; // eslint-disable-line import/namespace, import/default +import link from '../link/link'; // @ts-ignore FIXME after converting tools/config import loadConfig from '../../tools/config'; // eslint-disable-line import/namespace, import/default diff --git a/packages/cli/src/commands/install/uninstall.ts b/packages/cli/src/commands/install/uninstall.ts index 61da179ef..a82e6c71a 100644 --- a/packages/cli/src/commands/install/uninstall.ts +++ b/packages/cli/src/commands/install/uninstall.ts @@ -8,8 +8,7 @@ import {Config} from '@react-native-community/cli-types'; import {logger} from '@react-native-community/cli-tools'; import * as PackageManager from '../../tools/packageManager'; -// @ts-ignore FIXME after converting link/unlink -import unlink from '../link/unlink'; // eslint-disable-line import/namespace, import/default +import unlink from '../link/unlink'; async function uninstall(args: Array, ctx: Config): Promise { const name = args[0]; diff --git a/packages/cli/src/commands/link/__tests__/link-test.js b/packages/cli/src/commands/link/__tests__/link-test.ts similarity index 97% rename from packages/cli/src/commands/link/__tests__/link-test.js rename to packages/cli/src/commands/link/__tests__/link-test.ts index 3487b09ec..fd4974f69 100644 --- a/packages/cli/src/commands/link/__tests__/link-test.js +++ b/packages/cli/src/commands/link/__tests__/link-test.ts @@ -1,7 +1,6 @@ import {func as link} from '../link'; -import loadConfig from '../../../tools/config'; +import loadConfig from '../../../tools/config'; // eslint-disable-line import/namespace, import/default import makeHook from '../makeHook'; - jest.mock('chalk', () => ({grey: str => str, bold: str => str})); jest.mock('../../../tools/config'); jest.mock('../makeHook', () => { @@ -94,7 +93,7 @@ describe('link', () => { await link(['react-native-blur'], config, {}); expect(registerNativeModule.mock.calls).toHaveLength(2); - expect(makeHook.mock.calls).toEqual([[prelink], [postlink]]); + expect((makeHook as jest.Mock).mock.calls).toEqual([[prelink], [postlink]]); }); it('should copy assets only from the specific dependency that we are linking', done => { diff --git a/packages/cli/src/commands/link/__tests__/makeHook-test.js b/packages/cli/src/commands/link/__tests__/makeHook-test.ts similarity index 77% rename from packages/cli/src/commands/link/__tests__/makeHook-test.js rename to packages/cli/src/commands/link/__tests__/makeHook-test.ts index 6114c1b71..70982f359 100644 --- a/packages/cli/src/commands/link/__tests__/makeHook-test.js +++ b/packages/cli/src/commands/link/__tests__/makeHook-test.ts @@ -1,6 +1,3 @@ -/** - * @flow - */ import makeHook from '../makeHook'; afterAll(() => { @@ -10,14 +7,12 @@ afterAll(() => { describe('makeHook', () => { it('invokes the command', async () => { const hook = makeHook('echo'); - // $FlowFixMe - execa weird Promise-like return value const result = await hook(); expect(result.cmd).toBe('echo'); }); it('invokes the command with multiple arguments', async () => { const hook = makeHook('node -p "1;"'); - // $FlowFixMe - execa weird Promise-like return value const result = await hook(); expect(result.cmd).toBe('node -p "1;"'); }); diff --git a/packages/cli/src/commands/link/getPlatformName.js b/packages/cli/src/commands/link/getPlatformName.js deleted file mode 100644 index 455d9c06c..000000000 --- a/packages/cli/src/commands/link/getPlatformName.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * @flow - */ - -const names = { - ios: 'iOS', - android: 'Android', -}; - -export default function getPlatformName(name: string) { - return names[name] || name; -} diff --git a/packages/cli/src/commands/link/getPlatformName.ts b/packages/cli/src/commands/link/getPlatformName.ts new file mode 100644 index 000000000..f926cec61 --- /dev/null +++ b/packages/cli/src/commands/link/getPlatformName.ts @@ -0,0 +1,8 @@ +const names: {[key: string]: string} = { + ios: 'iOS', + android: 'Android', +}; + +export default function getPlatformName(name: string): string { + return names[name] || name; +} diff --git a/packages/cli/src/commands/link/link.js b/packages/cli/src/commands/link/link.ts similarity index 95% rename from packages/cli/src/commands/link/link.js rename to packages/cli/src/commands/link/link.ts index d7e458e82..a23d04340 100644 --- a/packages/cli/src/commands/link/link.js +++ b/packages/cli/src/commands/link/link.ts @@ -4,13 +4,12 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ import chalk from 'chalk'; import {pick} from 'lodash'; import {logger, CLIError} from '@react-native-community/cli-tools'; -import {type ConfigT} from 'types'; +import {Config} from '@react-native-community/cli-types'; import getPlatformName from './getPlatformName'; import linkDependency from './linkDependency'; import linkAssets from './linkAssets'; @@ -18,8 +17,8 @@ import linkAll from './linkAll'; import makeHook from './makeHook'; type FlagsType = { - platforms?: Array, - all?: boolean, + platforms?: Array; + all?: boolean; }; /** @@ -30,13 +29,14 @@ type FlagsType = { */ async function link( [rawPackageName]: Array, - ctx: ConfigT, + ctx: Config, opts: FlagsType, ) { let platforms = ctx.platforms; let project = ctx.project; if (opts.platforms) { + // @ts-ignore platforms = pick(platforms, opts.platforms); logger.debug('Skipping selected platforms'); } diff --git a/packages/cli/src/commands/link/linkAll.js b/packages/cli/src/commands/link/linkAll.ts similarity index 88% rename from packages/cli/src/commands/link/linkAll.js rename to packages/cli/src/commands/link/linkAll.ts index 97ce27ade..48610253a 100644 --- a/packages/cli/src/commands/link/linkAll.js +++ b/packages/cli/src/commands/link/linkAll.ts @@ -1,12 +1,8 @@ -/** - * @flow - */ - import {uniqBy} from 'lodash'; -import path from 'path'; +import * as path from 'path'; import chalk from 'chalk'; import {CLIError, logger} from '@react-native-community/cli-tools'; -import type {ConfigT} from 'types'; +import {Config} from '@react-native-community/cli-types'; import linkAssets from './linkAssets'; import linkDependency from './linkDependency'; import makeHook from './makeHook'; @@ -15,11 +11,11 @@ const dedupeAssets = (assets: Array): Array => uniqBy(assets, asset => path.basename(asset)); type Options = { - linkDeps?: boolean, - linkAssets?: boolean, + linkDeps?: boolean; + linkAssets?: boolean; }; -async function linkAll(config: ConfigT, options: Options) { +async function linkAll(config: Config, options: Options) { if (options.linkDeps) { logger.debug('Linking all dependencies'); logger.info( @@ -60,7 +56,7 @@ async function linkAll(config: ConfigT, options: Options) { ), ); try { - await linkAssets(config.platforms, config.project, assets); + linkAssets(config.platforms, config.project, assets); } catch (error) { throw new CLIError('Linking assets failed.', error); } diff --git a/packages/cli/src/commands/link/linkAssets.js b/packages/cli/src/commands/link/linkAssets.ts similarity index 72% rename from packages/cli/src/commands/link/linkAssets.js rename to packages/cli/src/commands/link/linkAssets.ts index 700893724..ad6c7e7e3 100644 --- a/packages/cli/src/commands/link/linkAssets.js +++ b/packages/cli/src/commands/link/linkAssets.ts @@ -1,15 +1,12 @@ -// @flow - import {isEmpty} from 'lodash'; -import type {PlatformsT, ProjectConfigT} from 'types'; - +import {Config} from '@react-native-community/cli-types'; import {logger} from '@react-native-community/cli-tools'; -const linkAssets = ( - platforms: PlatformsT, - project: ProjectConfigT, +export default function linkAssets( + platforms: Config['platforms'], + project: Config['project'], assets: Array, -) => { +) { if (isEmpty(assets)) { return; } @@ -25,11 +22,9 @@ const linkAssets = ( } logger.info(`Linking assets to ${platform} project`); - // $FlowFixMe: We check for existence of project[platform] + linkConfig.copyAssets(assets, project[platform]); }); logger.success('Assets have been successfully linked to your project'); -}; - -export default linkAssets; +} diff --git a/packages/cli/src/commands/link/linkDependency.js b/packages/cli/src/commands/link/linkDependency.ts similarity index 70% rename from packages/cli/src/commands/link/linkDependency.js rename to packages/cli/src/commands/link/linkDependency.ts index a893076a8..e23d4f9ee 100644 --- a/packages/cli/src/commands/link/linkDependency.js +++ b/packages/cli/src/commands/link/linkDependency.ts @@ -1,20 +1,28 @@ -// @flow import chalk from 'chalk'; -import type {DependencyConfigT, ProjectConfigT, PlatformsT} from 'types'; +import { + Config, + Dependency, + AndroidDependencyConfig, + AndroidProjectConfig, + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; import {logger} from '@react-native-community/cli-tools'; import pollParams from './pollParams'; import getPlatformName from './getPlatformName'; -const linkDependency = async ( - platforms: PlatformsT, - project: ProjectConfigT, - dependency: DependencyConfigT, -) => { +export default async function linkDependency( + platforms: Config['platforms'], + project: Config['project'], + dependency: Dependency, +) { const params = await pollParams(dependency.params); Object.keys(platforms || {}).forEach(platform => { - const projectConfig = project[platform]; - const dependencyConfig = dependency.platforms[platform]; + const projectConfig: AndroidProjectConfig | IOSProjectConfig = + project[platform]; + const dependencyConfig: AndroidDependencyConfig | IOSDependencyConfig = + dependency.platforms[platform]; if (!projectConfig || !dependencyConfig) { return; @@ -30,10 +38,8 @@ const linkDependency = async ( } const isInstalled = linkConfig.isInstalled( - // $FlowFixMe projectConfig, name, - // $FlowFixMe dependencyConfig, ); @@ -49,7 +55,7 @@ const linkDependency = async ( logger.info( `Linking "${chalk.bold(name)}" ${getPlatformName(platform)} dependency`, ); - // $FlowFixMe + linkConfig.register(name, dependencyConfig, params, projectConfig); logger.info( @@ -58,6 +64,4 @@ const linkDependency = async ( )}" has been successfully linked`, ); }); -}; - -export default linkDependency; +} diff --git a/packages/cli/src/commands/link/makeHook.js b/packages/cli/src/commands/link/makeHook.ts similarity index 79% rename from packages/cli/src/commands/link/makeHook.js rename to packages/cli/src/commands/link/makeHook.ts index 29b23489c..1cb435965 100644 --- a/packages/cli/src/commands/link/makeHook.js +++ b/packages/cli/src/commands/link/makeHook.ts @@ -1,13 +1,9 @@ -/** - * @flow - */ - import execa from 'execa'; export default function makeHook(command: string) { return () => { const args = command.split(' '); - const cmd = args.shift(); + const cmd = args.shift() as string; return execa(cmd, args, {stdio: 'inherit'}); }; diff --git a/packages/cli/src/commands/link/pollParams.js b/packages/cli/src/commands/link/pollParams.ts similarity index 51% rename from packages/cli/src/commands/link/pollParams.js rename to packages/cli/src/commands/link/pollParams.ts index ed93ac813..9e381d1c3 100644 --- a/packages/cli/src/commands/link/pollParams.js +++ b/packages/cli/src/commands/link/pollParams.ts @@ -3,20 +3,17 @@ * * 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 inquirer from 'inquirer'; -import type {InquirerPromptT} from 'types'; +// @ts-ignore untyped +import {prompt, QuestionCollection, Answers} from 'inquirer'; -export default (questions: InquirerPromptT) => - new Promise((resolve, reject) => { +export default (questions: QuestionCollection) => + new Promise((resolve, reject) => { if (!questions) { resolve({}); return; } - inquirer.prompt(questions).then(resolve, reject); + prompt(questions).then(resolve, reject); }); diff --git a/packages/cli/src/commands/link/unlink.js b/packages/cli/src/commands/link/unlink.ts similarity index 83% rename from packages/cli/src/commands/link/unlink.js rename to packages/cli/src/commands/link/unlink.ts index d19d5321a..59759d905 100644 --- a/packages/cli/src/commands/link/unlink.js +++ b/packages/cli/src/commands/link/unlink.ts @@ -3,30 +3,37 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ import {flatMap, values, difference, pick} from 'lodash'; import {logger, CLIError} from '@react-native-community/cli-tools'; -import type {ConfigT} from 'types'; +import { + Config, + Dependency, + AndroidDependencyConfig, + AndroidProjectConfig, + IOSDependencyConfig, + IOSProjectConfig, +} from '@react-native-community/cli-types'; import getPlatformName from './getPlatformName'; import makeHook from './makeHook'; type Flags = { - platforms?: Array, + platforms?: Array; }; const unlinkDependency = ( - platforms, - project, - dependency, - packageName, - otherDependencies, + platforms: Config['platforms'], + project: Config['project'], + dependency: Dependency, + packageName: string, + otherDependencies: Array, ) => { Object.keys(platforms || {}).forEach(platform => { - const projectConfig = project[platform]; - const dependencyConfig = dependency.platforms[platform]; + const projectConfig: AndroidProjectConfig | IOSProjectConfig = + project[platform]; + const dependencyConfig: AndroidDependencyConfig | IOSDependencyConfig = + dependency.platforms[platform]; if (!projectConfig || !dependencyConfig) { return; } @@ -41,10 +48,8 @@ const unlinkDependency = ( } const isInstalled = linkConfig.isInstalled( - // $FlowFixMe projectConfig, packageName, - // $FlowFixMe dependencyConfig, ); @@ -61,9 +66,7 @@ const unlinkDependency = ( linkConfig.unregister( packageName, - // $FlowFixMe dependencyConfig, - // $FlowFixMe projectConfig, otherDependencies, ); @@ -82,11 +85,12 @@ const unlinkDependency = ( * If optional argument [packageName] is provided, it's the only one * that's checked */ -async function unlink(args: Array, ctx: ConfigT, opts: Flags) { +async function unlink(args: Array, ctx: Config, opts: Flags) { const packageName = args[0]; let platforms = ctx.platforms; if (opts.platforms) { + // @ts-ignore platforms = pick(platforms, opts.platforms); logger.debug('Skipping selected platforms'); } @@ -107,8 +111,8 @@ async function unlink(args: Array, ctx: ConfigT, opts: Flags) { const dependencies = values(otherDependencies); try { - if (dependency.hooks.preulink) { - await makeHook(dependency.hooks.preulink)(); + if (dependency.hooks.preunlink) { + await makeHook(dependency.hooks.preunlink)(); } unlinkDependency( platforms, @@ -149,7 +153,7 @@ async function unlink(args: Array, ctx: ConfigT, opts: Flags) { } logger.info(`Unlinking assets from ${platform} project`); - // $FlowFixMe + linkConfig.unlinkAssets(assets, projectConfig); });