Skip to content

Commit

Permalink
feat: extract iOS and Android specific linking files out of the core (r…
Browse files Browse the repository at this point in the history
…eact-native-community#290)

Summary:
---------

Historically, Android and iOS platform were hardcoded inside CLI and provided by default. Then, other packages could export additional platforms on top of it.

React Native as a platform was hardcoded in Metro configuration (default platforms, default extensions) and inside link. That means all new features were always developed with these platforms in mind, leaving others behind. We often used private APIs, which made things more complicated for 3rd party platform developers.

From this PR on, there's no longer concept of an out-of-tree platform inside of the CLI. In a follow up PR to React Native, I am going to configure iOS and Android platforms inside React Native, just like React Native Windows exposes Windows platform.

This will open room for improvements and should make it even easier for the CLI to welcome other platforms.
  • Loading branch information
grabbou authored and thymikee committed Apr 5, 2019
1 parent 0d8f2e4 commit 5f7dba3
Show file tree
Hide file tree
Showing 215 changed files with 1,260 additions and 815 deletions.
34 changes: 25 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
keys:
- v2-dependencies-{{ checksum "package.json" }}
- v2-dependencies-
- run: yarn install
- run: yarn --frozen-lockfile
- save_cache:
key: v2-dependencies-{{ checksum "package.json" }}
paths:
Expand All @@ -25,32 +25,48 @@ jobs:
root: .
paths:
- .
lint-and-flow:
lint:
<<: *defaults
steps:
- attach_workspace:
at: ~/react-native-cli
- run: |
yarn lint
yarn flow-check
tests:
- run: yarn lint
typecheck:
<<: *defaults
steps:
- attach_workspace:
at: ~/react-native-cli
- run: yarn test:ci
- run: yarn flow-check
unit-tests:
<<: *defaults
steps:
- attach_workspace:
at: ~/react-native-cli
- run: yarn test:ci:unit
- store_artifacts:
path: coverage
destination: coverage
e2e-tests:
<<: *defaults
steps:
- attach_workspace:
at: ~/react-native-cli
- run: yarn test:ci:e2e

workflows:
version: 2
build-and-test:
jobs:
- install-dependencies
- lint-and-flow:
- lint:
requires:
- install-dependencies
- typecheck:
requires:
- install-dependencies
- unit-tests:
requires:
- install-dependencies
- tests:
- e2e-tests:
requires:
- install-dependencies
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
},
overrides: [
{
files: ['**/__mocks__/**', '**/__fixtures__/**', 'testSetup.js'],
files: ['**/__mocks__/**', '**/__fixtures__/**', '**/__e2e__/**', 'jest/**'],
env: {
jest: true,
},
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions e2e/__tests__/init.test.js → __e2e__/init.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import fs from 'fs';
import path from 'path';
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-init');

Expand All @@ -14,11 +14,11 @@ afterEach(() => {
});

test('init --template fails without package name', () => {
const {stderr} = run(DIR, [
'init',
'--template',
'react-native-new-template',
]);
const {stderr} = run(
DIR,
['init', '--template', 'react-native-new-template'],
{expectedFailure: true},
);
expect(stderr).toContain('missing required argument');
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/install.test.js → __e2e__/install.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import path from 'path';
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-install-test');
const pkg = 'react-native-config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs';
import path from 'path';
import execa from 'execa';
import {getTempDirectory, cleanup, writeFiles} from '../helpers';
import {getTempDirectory, cleanup, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-legacy-init');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @flow
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-uninstall-test');
const pkg = 'react-native-config';
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions e2e/jest.config.js

This file was deleted.

18 changes: 16 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
const common = {testEnvironment: 'node'};

module.exports = {
testEnvironment: 'node',
projects: ['<rootDir>/packages/*', '<rootDir>/e2e'],
projects: [
{
...common,
displayName: 'e2e',
setupFiles: ['<rootDir>/jest/setupE2eTests.js'],
testMatch: ['<rootDir>/**/__e2e__/*{.,-}test.js'],
},
{
...common,
displayName: 'unit',
setupFiles: ['<rootDir>/jest/setupUnitTests.js'],
testMatch: ['<rootDir>/**/__tests__/*{.,-}test.js'],
},
],
};
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions jest/setupUnitTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @flow
*/

jest.mock('@react-native-community/cli-tools', () => ({
...jest.requireActual('@react-native-community/cli-tools'),
logger: {
success: jest.fn(),
info: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
debug: jest.fn(),
log: jest.fn(),
setVerbose: jest.fn(),
isVerbose: jest.fn(),
},
}));

jest.setTimeout(20000);
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "3.10.6",
"version": "independent",
"version": "2.0.0-alpha.3",
"npmClient": "yarn",
"useWorkspaces": true
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"build-clean": "rm -rf ./packages/*/build",
"watch": "node ./scripts/watch.js",
"test": "jest",
"test:ci": "jest -i",
"test:ci:unit": "jest packages --ci --coverage",
"test:ci:e2e": "jest e2e --ci -i",
"lint": "eslint . --cache --report-unused-disable-directives",
"flow-check": "flow check",
"postinstall": "yarn build-clean && yarn build",
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/jest.config.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"testEnvironment": "node"
},
"dependencies": {
"@react-native-community/cli-platform-ios": "2.0.0-alpha.3",
"@react-native-community/cli-platform-android": "2.0.0-alpha.3",
"@react-native-community/cli-tools": "2.0.0-alpha.3",
"chalk": "^1.1.1",
"commander": "^2.19.0",
"compression": "^1.7.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {CommandT, ContextT} from './tools/types.flow';
import {getCommands} from './commands';
import init from './commands/init/initCompat';
import assertRequiredOptions from './tools/assertRequiredOptions';
import logger from './tools/logger';
import {logger} from '@react-native-community/cli-tools';
import {setProjectDir} from './tools/packageManager';
import pkgJson from '../package.json';
import loadConfig from './tools/config';
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 @@ -16,7 +16,7 @@ import type {CommandLineArgs} from './bundleCommandLineArgs';
import type {ContextT} from '../../tools/types.flow';
import saveAssets from './saveAssets';
import loadMetroConfig from '../../tools/loadMetroConfig';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';

async function buildBundle(
args: CommandLineArgs,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/bundle/saveAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import fs from 'fs';
import filterPlatformAssetScales from './filterPlatformAssetScales';
import getAssetDestPathAndroid from './getAssetDestPathAndroid';
import getAssetDestPathIOS from './getAssetDestPathIOS';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';

function saveAssets(assets, platform, assetsDest) {
if (!assetsDest) {
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/src/commands/info/__tests__/info.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// @flow
import info from '../info';
import logger from '../../../tools/logger';
import {logger} from '@react-native-community/cli-tools';
import loadConfig from '../../../tools/config';

jest.mock('../../../tools/logger', () => ({
info: jest.fn(),
error: jest.fn(),
log: jest.fn(),
jest.mock('@react-native-community/cli-tools', () => ({
logger: {
info: jest.fn(),
error: jest.fn(),
log: jest.fn(),
},
}));

jest.mock('../../../tools/config');
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 @@ -8,7 +8,7 @@
*/

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

const info = async function getInfo(
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/editTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import fs from 'fs-extra';
import path from 'path';
import walk from '../../tools/walk';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';

function replaceNameInUTF8File(
filePath: string,
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 @@ -6,7 +6,7 @@ import type {ContextT} from '../../tools/types.flow';
import {validateProjectName} from './validate';
import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError';
import printRunInstructions from './printRunInstructions';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';
import {
installTemplatePackage,
getTemplateConfig,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/initCompat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import process from 'process';
import printRunInstructions from './printRunInstructions';
import {createProjectFromTemplate} from '../../tools/generator/templates';
import * as PackageManager from '../../tools/packageManager';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';

/**
* Creates the template for a React Native project given the provided
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/printRunInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

function printRunInstructions(projectDir: string, projectName: string) {
const absoluteProjectDir = path.resolve(projectDir);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/init/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import execa from 'execa';
import path from 'path';
import * as PackageManager from '../../tools/packageManager';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';
import copyFiles from '../../tools/copyFiles';

export type TemplateConfig = {
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 @@ -8,7 +8,7 @@
*/

import type {ContextT} from '../../tools/types.flow';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/link';
import loadConfig from '../../tools/config';
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 @@ -8,7 +8,7 @@
*/

import type {ContextT} from '../../tools/types.flow';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../../tools/packageManager';
import link from '../link/unlink';

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/library/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import path from 'path';
import copyAndReplace from '../../tools/copyAndReplace';
import isValidPackageName from '../../tools/isValidPackageName';
import walk from '../../tools/walk';
import logger from '../../tools/logger';
import {logger} from '@react-native-community/cli-tools';

/**
* Creates a new native library with the given name
Expand Down
Loading

0 comments on commit 5f7dba3

Please sign in to comment.