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
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ flow-typed
[options]
emoji=true

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'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"glob": "^7.1.3",
"jest": "^24.6.0",
"lerna": "^3.13.1",
"metro-memory-fs": "^0.53.1",
"micromatch": "^3.1.10",
"mkdirp": "^0.5.1",
"string-length": "^2.0.0"
Expand Down
10 changes: 1 addition & 9 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@
"connect": "^3.6.5",
"cosmiconfig": "^5.1.0",
"deepmerge": "^3.2.0",
"denodeify": "^1.2.1",
"envinfo": "^7.1.0",
"errorhandler": "^1.5.0",
"escape-string-regexp": "^1.0.5",
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
"glob": "^7.1.1",
"graceful-fs": "^4.1.3",
"inquirer": "^3.0.6",
"joi": "^14.3.1",
"lodash": "^4.17.5",
"logkitty": "^0.4.0",
"metro": "^0.53.1",
"metro-config": "^0.53.1",
"metro-core": "^0.53.1",
"metro-memory-fs": "^0.53.1",
"metro-react-native-babel-transformer": "^0.53.1",
"mime": "^1.3.4",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"morgan": "^1.9.0",
Expand All @@ -57,10 +52,7 @@
"semver": "^5.0.3",
"serve-static": "^1.13.1",
"shell-quote": "1.6.1",
"slash": "^2.0.0",
"ws": "^1.1.0",
"xcode": "^2.0.0",
"xmldoc": "^0.4.0"
"ws": "^1.1.0"
},
"peerDependencies": {
"react-native": "^0.60.0"
Expand Down
8 changes: 0 additions & 8 deletions packages/cli/src/commands/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import {type CommandT} from '../tools/config/types.flow';

import server from './server/server';
import runIOS from './runIOS/runIOS';
import runAndroid from './runAndroid/runAndroid';
import library from './library/library';
import bundle from './bundle/bundle';
import ramBundle from './bundle/ramBundle';
Expand All @@ -14,16 +12,12 @@ import unlink from './link/unlink';
import install from './install/install';
import uninstall from './install/uninstall';
import upgrade from './upgrade/upgrade';
import logAndroid from './logAndroid/logAndroid';
import logIOS from './logIOS/logIOS';
import info from './info/info';
import config from './config/config';
import init from './init';

export default ([
server,
runIOS,
runAndroid,
library,
bundle,
ramBundle,
Expand All @@ -32,8 +26,6 @@ export default ([
install,
uninstall,
upgrade,
logAndroid,
logIOS,
info,
config,
init,
Expand Down
7 changes: 2 additions & 5 deletions packages/cli/src/commands/link/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
*/

import {pick} from 'lodash';
import dedent from 'dedent';

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

import {CLIError} from '../../tools/errors';

import promiseWaterfall from './promiseWaterfall';
import {logger} from '@react-native-community/cli-tools';
import {logger, CLIError} from '@react-native-community/cli-tools';
import commandStub from './commandStub';
import promisify from './promisify';
import getPlatformName from './getPlatformName';
Expand Down Expand Up @@ -61,7 +58,7 @@ function link([rawPackageName]: Array<string>, ctx: ConfigT, opts: FlagsType) {
const packageName = rawPackageName.replace(/^(.+?)(@.+?)$/gi, '$1');

if (!Object.keys(ctx.dependencies).includes(packageName)) {
throw new CLIError(dedent`
throw new CLIError(`
Unknown dependency. Make sure that the package you are trying to link is
already installed in your "node_modules" and present in your "package.json" dependencies.
`);
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/link/linkAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import {uniqBy, flatMap} from 'lodash';
import path from 'path';

import type {ConfigT, PlatformsT} from '../../tools/config/types.flow';
import {CLIError} from '../../tools/errors';
import type {ConfigT} from '../../tools/config/types.flow';

import promiseWaterfall from './promiseWaterfall';
import commandStub from './commandStub';
Expand All @@ -15,6 +14,8 @@ import promisify from './promisify';
import linkAssets from './linkAssets';
import linkDependency from './linkDependency';

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

const dedupeAssets = (assets: Array<string>): Array<string> =>
uniqBy(assets, asset => path.basename(asset));

Expand Down
11 changes: 5 additions & 6 deletions packages/cli/src/commands/link/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import {flatMap, values, difference} from 'lodash';
import type {ConfigT} from '../../tools/config/types.flow';
import dedent from 'dedent';
import {logger} from '@react-native-community/cli-tools';
import {logger, CLIError} from '@react-native-community/cli-tools';
import promiseWaterfall from './promiseWaterfall';
import commandStub from './commandStub';
import promisify from './promisify';
Expand Down Expand Up @@ -83,7 +82,7 @@ function unlink(args: Array<string>, ctx: ConfigT) {
const {[packageName]: dependency, ...otherDependencies} = ctx.dependencies;

if (!dependency) {
throw new Error(dedent`
throw new CLIError(`
Failed to unlink "${packageName}". It appears that the project is not linked yet.
`);
}
Expand Down Expand Up @@ -136,10 +135,10 @@ function unlink(args: Array<string>, ctx: ConfigT) {
);
})
.catch(err => {
logger.error(
`It seems something went wrong while unlinking. Error:\n${err.message}`,
throw new CLIError(
`Something went wrong while unlinking. Reason ${err.message}`,
err,
);
throw err;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,64 +57,29 @@ Array [
]
`;

exports[`should merge project configuration with default values 1`] = `
exports[`should merge project configuration with default values: snapshoting \`react-native-test\` config 1`] = `
Object {
"assets": Array [],
"commands": Array [],
"dependencies": Object {
"react-native": Object {
"assets": Array [],
"hooks": Object {},
"name": "react-native",
"params": Array [],
"platforms": Object {
"android": null,
"ios": null,
},
},
"react-native-test": Object {
"assets": Array [
"foo",
],
"hooks": Object {},
"name": "react-native-test",
"params": Array [],
"platforms": Object {
"android": null,
"ios": Object {
"folder": "<<REPLACED>>/node_modules/react-native-test",
"libraryFolder": "Libraries",
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"sharedLibraries": Array [],
"sourceDir": "./abc",
},
},
},
},
"haste": Object {
"platforms": Array [
"ios",
"android",
],
"providesModuleNodeModules": Array [
"react-native",
],
},
"assets": Array [
"foo",
],
"hooks": Object {},
"name": "react-native-test",
"params": Array [],
"platforms": Object {
"android": Object {},
"ios": Object {},
},
"project": Object {
"android": null,
"ios": null,
"ios": Object {
"folder": "<<REPLACED>>/node_modules/react-native-test",
"libraryFolder": "Libraries",
"pbxprojPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj/project.pbxproj",
"plist": Array [],
"podfile": null,
"podspec": null,
"projectName": "HelloWorld.xcodeproj",
"projectPath": "<<REPLACED>>/node_modules/react-native-test/ios/HelloWorld.xcodeproj",
"sharedLibraries": Array [],
"sourceDir": "./abc",
},
},
"reactNativePath": "<<REPLACED>>",
"root": "<<REPLACED>>",
}
`;

Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/tools/config/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,10 @@ test('should merge project configuration with default values', () => {
}
}`,
});
const config = loadConfig(DIR);
expect(removeString(config, DIR)).toMatchSnapshot();
const {dependencies} = loadConfig(DIR);
expect(removeString(dependencies['react-native-test'], DIR)).toMatchSnapshot(
'snapshoting `react-native-test` config',
);
});

test('should read `rnpm` config from a dependency and transform it to a new format', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
/**
* @flow
*/
import chalk from 'chalk';
import dedent from 'dedent';

/**
* CLIError
*
* Features:
* - uses original stack trace when error object is passed
* - makes an inline string to match current styling inside CLI
*/
export class CLIError extends Error {
constructor(msg: string, error?: Error) {
super(msg.replace(/(\r\n|\n|\r)/gm, ' '));
if (error) {
this.stack = error.stack
.split('\n')
.slice(0, 2)
.join('\n');
} else {
Error.captureStackTrace(this, CLIError);
}
}
}

export class ProcessError extends Error {
constructor(msg: string, processError: string) {
super(`${chalk.red(msg)}\n\n${chalk.gray(processError)}`);
Error.captureStackTrace(this, ProcessError);
}
}
import {CLIError} from '@react-native-community/cli-tools';

type JoiErrorDetails<K, T> = {
message: string,
Expand Down Expand Up @@ -61,7 +32,7 @@ export class JoiError extends CLIError {
switch (error.type) {
case 'object.allowUnknown': {
const value = JSON.stringify(error.context.value);
return dedent`
return `
Unknown option ${name} with value "${value}" was found.
This is either a typing error or a user mistake. Fixing it will remove this message.
`;
Expand All @@ -70,7 +41,7 @@ export class JoiError extends CLIError {
case 'string.base': {
const expectedType = error.type.replace('.base', '');
const actualType = typeof error.context.value;
return dedent`
return `
Option ${name} must be a ${expectedType}, instead got ${actualType}
`;
}
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
// @todo: Move this to React Native in the future
if (dependencyName === 'react-native') {
config.platforms = {ios, android};
config.commands = [...ios.commands, ...android.commands];
}

const isPlatform = Object.keys(config.platforms).length > 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/tools/config/readConfigFromDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
type CommandT,
} from './types.flow';

import {JoiError} from '../errors';
import {JoiError} from './errors';

import * as schema from './schema';

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/tools/config/resolveReactNativePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @flow
*/
import path from 'path';
import dedent from 'dedent';
import {CLIError} from '@react-native-community/cli-tools';

/**
* Finds path to React Native inside `node_modules` or throws
Expand All @@ -17,7 +17,7 @@ export default function resolveReactNativePath(root: string) {
}),
);
} catch (_ignored) {
throw new Error(dedent`
throw new CLIError(`
Unable to find React Native files. Make sure "react-native" module is installed
in your project dependencies.

Expand Down
6 changes: 5 additions & 1 deletion packages/platform-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"version": "2.0.0-alpha.5",
"main": "build/index.js",
"dependencies": {
"@react-native-community/cli-tools": "^2.0.0-alpha.5"
"@react-native-community/cli-tools": "^2.0.0-alpha.5",
"node-fetch": "^2.2.0",
"logkitty": "^0.4.0",
"slash": "^2.0.0",
"xmldoc": "^0.4.0"
}
}
7 changes: 7 additions & 0 deletions packages/platform-android/src/commands/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* @flow
*/
import logAndroid from './logAndroid';
import runAndroid from './runAndroid';

export default [logAndroid, runAndroid];
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
import path from 'path';
import {spawnSync, spawn, execFileSync} from 'child_process';
import fs from 'fs';
import isString from 'lodash/isString';

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

import adb from './adb';
import runOnAllDevices from './runOnAllDevices';
import isPackagerRunning from './isPackagerRunning';
import tryRunAdbReverse from './tryRunAdbReverse';
import tryLaunchAppOnDevice from './tryLaunchAppOnDevice';
import getAdbPath from './getAdbPath';
Expand Down Expand Up @@ -87,7 +86,7 @@ function buildAndRun(args) {

const adbPath = getAdbPath();
if (args.deviceId) {
if (isString(args.deviceId)) {
if (typeof args.deviceId === 'string') {
return runOnSpecificDevice(
args,
cmd,
Expand Down
Loading