Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
module.exports = {
extends: '@react-native-community',
extends: ['@react-native-community', 'plugin:import/errors'],
env: {
node: true,
},
rules: {
'prettier/prettier': [2, 'fb'],
},
// @todo: remove once we cover whole codebase with types
plugins: ['eslint-plugin-import'],
settings: {
react: {
version: 'latest',
},
'import/resolver': {
alias: {
map: [['types', './types/index.js']],
},
},
},
overrides: [
{
files: ['**/__mocks__/**', '**/__fixtures__/**', '**/__e2e__/**', 'jest/**'],
files: [
'**/__mocks__/**',
'**/__fixtures__/**',
'**/__e2e__/**',
'jest/**',
],
env: {
jest: true,
},
Expand Down
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ esproposal.export_star_as=enable
esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
module.name_mapper='types' -> '<PROJECT_ROOT>/types/index.js'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
Expand Down
8 changes: 8 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,13 @@ module.exports = {
plugins: [
require.resolve('@babel/plugin-transform-strict-mode'),
[require.resolve('@babel/plugin-transform-modules-commonjs'), {lazy: true}],
[
require.resolve('babel-plugin-module-resolver', {
root: ['.'],
alias: {
types: './types',
},
}),
],
],
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
"@babel/preset-flow": "^7.0.0",
"@react-native-community/eslint-config": "^0.0.3",
"babel-jest": "^24.6.0",
"babel-plugin-module-resolver": "^3.2.0",
"chalk": "^2.4.2",
"eslint": "^5.10.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.17.0",
"execa": "^1.0.0",
"flow-bin": "^0.96.0",
"flow-bin": "^0.97.0",
"flow-typed": "^2.5.1",
"glob": "^7.1.3",
"jest": "^24.6.0",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @flow
*/

// eslint-disable-next-line import/default
import cliEntry from '.';

cliEntry.run();
2 changes: 1 addition & 1 deletion packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import childProcess from 'child_process';
import commander from 'commander';
import path from 'path';

import type {CommandT, ConfigT} from './tools/config/types.flow';
import type {CommandT, ConfigT} from 'types';

import commands from './commands';
import init from './commands/init/initCompat';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/buildBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import outputBundle from 'metro/src/shared/output/bundle';
import path from 'path';
import chalk from 'chalk';
import type {CommandLineArgs} from './bundleCommandLineArgs';
import type {ConfigT} from '../../tools/config/types.flow';
import type {ConfigT} from 'types';
import saveAssets from './saveAssets';
import loadMetroConfig from '../../tools/loadMetroConfig';
import {logger} from '@react-native-community/cli-tools';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/config/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @flow
*/
import {type ConfigT} from '../../tools/config/types.flow';
import {type ConfigT} from 'types';
export default {
name: 'config',
description: 'Print CLI configuration',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @flow
*/
import {type CommandT} from '../tools/config/types.flow';
import {type CommandT} from 'types';

import server from './server/server';
import library from './library/library';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/info/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import envinfo from 'envinfo';
import {logger} from '@react-native-community/cli-tools';
import type {ConfigT} from '../../tools/config/types.flow';
import type {ConfigT} from 'types';

const info = async function getInfo(
argv: Array<string>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @flow
import path from 'path';

export default class DirectoryAlreadyExistsError extends Error {
constructor(directory: string) {
super(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs-extra';
import minimist from 'minimist';
import semver from 'semver';
import type {ConfigT} from '../../tools/config/types.flow';
import type {ConfigT} from 'types';
import {validateProjectName} from './validate';
import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError';
import printRunInstructions from './printRunInstructions';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/install/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {ConfigT} from '../../tools/config/types.flow';
import type {ConfigT} from 'types';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/link';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/install/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {ConfigT} from '../../tools/config/types.flow';
import type {ConfigT} from 'types';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/unlink';
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/link/__tests__/link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('link', () => {
});

it('should register native module when android/ios projects are present', done => {
const prelink = jest.fn().mockImplementation(cb => cb());
const postlink = jest.fn().mockImplementation(cb => cb());
const prelink = jest.fn();
const postlink = jest.fn();
const registerNativeModule = jest.fn();

const config = {
Expand Down
46 changes: 0 additions & 46 deletions packages/cli/src/commands/link/__tests__/promiseWaterfall-test.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/cli/src/commands/link/commandStub.js

This file was deleted.

38 changes: 19 additions & 19 deletions packages/cli/src/commands/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@
*/

import {pick} from 'lodash';

import {type ConfigT} from '../../tools/config/types.flow';

import promiseWaterfall from './promiseWaterfall';
import {logger, CLIError} from '@react-native-community/cli-tools';
import commandStub from './commandStub';
import promisify from './promisify';
import {type ConfigT} from 'types';
import getPlatformName from './getPlatformName';

import linkDependency from './linkDependency';
import linkAssets from './linkAssets';
import linkAll from './linkAll';
Expand All @@ -31,7 +25,11 @@ type FlagsType = {
* @param args If optional argument [packageName] is provided,
* only that package is processed.
*/
function link([rawPackageName]: Array<string>, ctx: ConfigT, opts: FlagsType) {
async function link(
[rawPackageName]: Array<string>,
ctx: ConfigT,
opts: FlagsType,
) {
let platforms = ctx.platforms;
let project = ctx.project;

Expand Down Expand Up @@ -68,19 +66,21 @@ function link([rawPackageName]: Array<string>, ctx: ConfigT, opts: FlagsType) {

logger.debug(`Package to link: ${rawPackageName}`);

const tasks = [
() => promisify(dependency.hooks.prelink || commandStub),
() => linkDependency(platforms, project, dependency),
() => promisify(dependency.hooks.postlink || commandStub),
() => linkAssets(platforms, project, dependency.assets),
];

return promiseWaterfall(tasks).catch(err => {
try {
if (dependency.hooks.prelink) {
await dependency.hooks.prelink();
}
await linkDependency(platforms, project, dependency);
if (dependency.hooks.postlink) {
await dependency.hooks.postlink();
}
await linkAssets(platforms, project, dependency.assets);
} catch (error) {
throw new CLIError(
`Something went wrong while linking. Reason: ${err.message}`,
err,
`Something went wrong while linking. Reason: ${error.message}`,
error,
);
});
}
}

export const func = link;
Expand Down
40 changes: 19 additions & 21 deletions packages/cli/src/commands/link/linkAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
* @flow
*/

import {uniqBy, flatMap} from 'lodash';
import {uniqBy} from 'lodash';
import path from 'path';

import type {ConfigT} from '../../tools/config/types.flow';

import promiseWaterfall from './promiseWaterfall';
import commandStub from './commandStub';
import promisify from './promisify';
import type {ConfigT} from 'types';

import linkAssets from './linkAssets';
import linkDependency from './linkDependency';
Expand All @@ -19,7 +15,7 @@ import {CLIError} from '@react-native-community/cli-tools';
const dedupeAssets = (assets: Array<string>): Array<string> =>
uniqBy(assets, asset => path.basename(asset));

function linkAll(config: ConfigT) {
async function linkAll(config: ConfigT) {
const projectAssets = config.assets;

const assets = dedupeAssets(
Expand All @@ -29,22 +25,24 @@ function linkAll(config: ConfigT) {
),
);

const tasks = flatMap(
config.dependencies,
dependency => [
() => promisify(dependency.hooks.prelink || commandStub),
() => linkDependency(config.platforms, config.project, dependency),
() => promisify(dependency.hooks.postlink || commandStub),
],
() => linkAssets(config.platforms, config.project, assets),
);

return promiseWaterfall(tasks).catch(err => {
try {
Object.keys(config.dependencies).forEach(async key => {
const dependency = config.dependencies[key];
if (dependency.hooks.prelink) {
await dependency.hooks.prelink();
}
await linkDependency(config.platforms, config.project, dependency);
if (dependency.hooks.postlink) {
await dependency.hooks.postlink();
}
});
await linkAssets(config.platforms, config.project, assets);
} catch (error) {
throw new CLIError(
`Something went wrong while linking. Reason: ${err.message}`,
err,
`Something went wrong while linking. Reason: ${error.message}`,
error,
);
});
}
}

export default linkAll;
2 changes: 1 addition & 1 deletion packages/cli/src/commands/link/linkAssets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import {isEmpty} from 'lodash';
import type {PlatformsT, ProjectConfigT} from '../../tools/config/types.flow';
import type {PlatformsT, ProjectConfigT} from 'types';

import {logger} from '@react-native-community/cli-tools';

Expand Down
10 changes: 4 additions & 6 deletions packages/cli/src/commands/link/linkDependency.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// @flow

import type {
DependencyConfigT,
ProjectConfigT,
PlatformsT,
} from '../../tools/config/types.flow';
import type {DependencyConfigT, ProjectConfigT, PlatformsT} from 'types';
import {logger} from '@react-native-community/cli-tools';
import pollParams from './pollParams';
import getPlatformName from './getPlatformName';
Expand Down Expand Up @@ -34,8 +30,10 @@ const linkDependency = async (
}

const isInstalled = linkConfig.isInstalled(
// $FlowFixMe
projectConfig,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't get Flow to understand this (don't say TS gonna fix it, it probably won't). Help appreciated on getting this solved, but I'm also cool with leaving this as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will! Flow has issues understanding whether it's Android/iOS its dealing right now. Run into it in other places too, so good to ignore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, but that has noting to do with platforms, just figuring out alternatives of types. E.g. If we rewritten this code to switch statement with a lot of repetition, Flow would understand the branching logic, but that would be too much

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yeah, I know it has nothing to do with platforms :) Was just an example I used to explain what you said!

name,
// $FlowFixMe
dependencyConfig,
);

Expand All @@ -47,7 +45,7 @@ const linkDependency = async (
}

logger.info(`Linking "${name}" ${getPlatformName(platform)} dependency`);

// $FlowFixMe
linkConfig.register(name, dependencyConfig, params, projectConfig);

logger.info(
Expand Down
Loading