Skip to content

Commit 5f7dba3

Browse files
grabbouthymikee
authored andcommitted
feat: extract iOS and Android specific linking files out of the core (react-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.
1 parent 0d8f2e4 commit 5f7dba3

File tree

215 files changed

+1260
-815
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+1260
-815
lines changed

.circleci/config.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
keys:
1717
- v2-dependencies-{{ checksum "package.json" }}
1818
- v2-dependencies-
19-
- run: yarn install
19+
- run: yarn --frozen-lockfile
2020
- save_cache:
2121
key: v2-dependencies-{{ checksum "package.json" }}
2222
paths:
@@ -25,32 +25,48 @@ jobs:
2525
root: .
2626
paths:
2727
- .
28-
lint-and-flow:
28+
lint:
2929
<<: *defaults
3030
steps:
3131
- attach_workspace:
3232
at: ~/react-native-cli
33-
- run: |
34-
yarn lint
35-
yarn flow-check
36-
tests:
33+
- run: yarn lint
34+
typecheck:
3735
<<: *defaults
3836
steps:
3937
- attach_workspace:
4038
at: ~/react-native-cli
41-
- run: yarn test:ci
39+
- run: yarn flow-check
40+
unit-tests:
41+
<<: *defaults
42+
steps:
43+
- attach_workspace:
44+
at: ~/react-native-cli
45+
- run: yarn test:ci:unit
4246
- store_artifacts:
4347
path: coverage
4448
destination: coverage
49+
e2e-tests:
50+
<<: *defaults
51+
steps:
52+
- attach_workspace:
53+
at: ~/react-native-cli
54+
- run: yarn test:ci:e2e
4555

4656
workflows:
4757
version: 2
4858
build-and-test:
4959
jobs:
5060
- install-dependencies
51-
- lint-and-flow:
61+
- lint:
62+
requires:
63+
- install-dependencies
64+
- typecheck:
65+
requires:
66+
- install-dependencies
67+
- unit-tests:
5268
requires:
5369
- install-dependencies
54-
- tests:
70+
- e2e-tests:
5571
requires:
5672
- install-dependencies

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
},
1414
overrides: [
1515
{
16-
files: ['**/__mocks__/**', '**/__fixtures__/**', 'testSetup.js'],
16+
files: ['**/__mocks__/**', '**/__fixtures__/**', '**/__e2e__/**', 'jest/**'],
1717
env: {
1818
jest: true,
1919
},

e2e/__tests__/init.test.js renamed to __e2e__/init.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22
import fs from 'fs';
33
import path from 'path';
4-
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
4+
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
55

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

@@ -14,11 +14,11 @@ afterEach(() => {
1414
});
1515

1616
test('init --template fails without package name', () => {
17-
const {stderr} = run(DIR, [
18-
'init',
19-
'--template',
20-
'react-native-new-template',
21-
]);
17+
const {stderr} = run(
18+
DIR,
19+
['init', '--template', 'react-native-new-template'],
20+
{expectedFailure: true},
21+
);
2222
expect(stderr).toContain('missing required argument');
2323
});
2424

e2e/__tests__/install.test.js renamed to __e2e__/install.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import path from 'path';
3-
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
3+
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
44

55
const DIR = getTempDirectory('command-install-test');
66
const pkg = 'react-native-config';

e2e/__tests__/legacyInit.test.js renamed to __e2e__/legacyInit.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'fs';
33
import path from 'path';
44
import execa from 'execa';
5-
import {getTempDirectory, cleanup, writeFiles} from '../helpers';
5+
import {getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
66

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

e2e/__tests__/uninstall.test.js renamed to __e2e__/uninstall.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import {run, getTempDirectory, cleanup, writeFiles} from '../helpers';
2+
import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';
33

44
const DIR = getTempDirectory('command-uninstall-test');
55
const pkg = 'react-native-config';
File renamed without changes.
File renamed without changes.

e2e/jest.config.js

-5
This file was deleted.

jest.config.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1+
const common = {testEnvironment: 'node'};
2+
13
module.exports = {
2-
testEnvironment: 'node',
3-
projects: ['<rootDir>/packages/*', '<rootDir>/e2e'],
4+
projects: [
5+
{
6+
...common,
7+
displayName: 'e2e',
8+
setupFiles: ['<rootDir>/jest/setupE2eTests.js'],
9+
testMatch: ['<rootDir>/**/__e2e__/*{.,-}test.js'],
10+
},
11+
{
12+
...common,
13+
displayName: 'unit',
14+
setupFiles: ['<rootDir>/jest/setupUnitTests.js'],
15+
testMatch: ['<rootDir>/**/__tests__/*{.,-}test.js'],
16+
},
17+
],
418
};
File renamed without changes.
File renamed without changes.

jest/setupUnitTests.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @flow
3+
*/
4+
5+
jest.mock('@react-native-community/cli-tools', () => ({
6+
...jest.requireActual('@react-native-community/cli-tools'),
7+
logger: {
8+
success: jest.fn(),
9+
info: jest.fn(),
10+
warn: jest.fn(),
11+
error: jest.fn(),
12+
debug: jest.fn(),
13+
log: jest.fn(),
14+
setVerbose: jest.fn(),
15+
isVerbose: jest.fn(),
16+
},
17+
}));
18+
19+
jest.setTimeout(20000);

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"lerna": "3.10.6",
3-
"version": "independent",
3+
"version": "2.0.0-alpha.3",
44
"npmClient": "yarn",
55
"useWorkspaces": true
66
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build-clean": "rm -rf ./packages/*/build",
99
"watch": "node ./scripts/watch.js",
1010
"test": "jest",
11-
"test:ci": "jest -i",
11+
"test:ci:unit": "jest packages --ci --coverage",
12+
"test:ci:e2e": "jest e2e --ci -i",
1213
"lint": "eslint . --cache --report-unused-disable-directives",
1314
"flow-check": "flow check",
1415
"postinstall": "yarn build-clean && yarn build",

packages/cli/jest.config.js

-4
This file was deleted.

packages/cli/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"testEnvironment": "node"
2020
},
2121
"dependencies": {
22+
"@react-native-community/cli-platform-ios": "2.0.0-alpha.3",
23+
"@react-native-community/cli-platform-android": "2.0.0-alpha.3",
24+
"@react-native-community/cli-tools": "2.0.0-alpha.3",
2225
"chalk": "^1.1.1",
2326
"commander": "^2.19.0",
2427
"compression": "^1.7.1",

packages/cli/src/cliEntry.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import type {CommandT, ContextT} from './tools/types.flow';
1717
import {getCommands} from './commands';
1818
import init from './commands/init/initCompat';
1919
import assertRequiredOptions from './tools/assertRequiredOptions';
20-
import logger from './tools/logger';
20+
import {logger} from '@react-native-community/cli-tools';
2121
import {setProjectDir} from './tools/packageManager';
2222
import pkgJson from '../package.json';
2323
import loadConfig from './tools/config';

packages/cli/src/commands/bundle/buildBundle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {CommandLineArgs} from './bundleCommandLineArgs';
1616
import type {ContextT} from '../../tools/types.flow';
1717
import saveAssets from './saveAssets';
1818
import loadMetroConfig from '../../tools/loadMetroConfig';
19-
import logger from '../../tools/logger';
19+
import {logger} from '@react-native-community/cli-tools';
2020

2121
async function buildBundle(
2222
args: CommandLineArgs,

packages/cli/src/commands/bundle/saveAssets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import fs from 'fs';
1414
import filterPlatformAssetScales from './filterPlatformAssetScales';
1515
import getAssetDestPathAndroid from './getAssetDestPathAndroid';
1616
import getAssetDestPathIOS from './getAssetDestPathIOS';
17-
import logger from '../../tools/logger';
17+
import {logger} from '@react-native-community/cli-tools';
1818

1919
function saveAssets(assets, platform, assetsDest) {
2020
if (!assetsDest) {

packages/cli/src/commands/info/__tests__/info.test.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// @flow
22
import info from '../info';
3-
import logger from '../../../tools/logger';
3+
import {logger} from '@react-native-community/cli-tools';
44
import loadConfig from '../../../tools/config';
55

6-
jest.mock('../../../tools/logger', () => ({
7-
info: jest.fn(),
8-
error: jest.fn(),
9-
log: jest.fn(),
6+
jest.mock('@react-native-community/cli-tools', () => ({
7+
logger: {
8+
info: jest.fn(),
9+
error: jest.fn(),
10+
log: jest.fn(),
11+
},
1012
}));
1113

1214
jest.mock('../../../tools/config');

packages/cli/src/commands/info/info.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

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

1414
const info = async function getInfo(

packages/cli/src/commands/init/editTemplate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'fs-extra';
33
import path from 'path';
44
import walk from '../../tools/walk';
5-
import logger from '../../tools/logger';
5+
import {logger} from '@react-native-community/cli-tools';
66

77
function replaceNameInUTF8File(
88
filePath: string,

packages/cli/src/commands/init/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {ContextT} from '../../tools/types.flow';
66
import {validateProjectName} from './validate';
77
import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError';
88
import printRunInstructions from './printRunInstructions';
9-
import logger from '../../tools/logger';
9+
import {logger} from '@react-native-community/cli-tools';
1010
import {
1111
installTemplatePackage,
1212
getTemplateConfig,

packages/cli/src/commands/init/initCompat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import process from 'process';
1414
import printRunInstructions from './printRunInstructions';
1515
import {createProjectFromTemplate} from '../../tools/generator/templates';
1616
import * as PackageManager from '../../tools/packageManager';
17-
import logger from '../../tools/logger';
17+
import {logger} from '@react-native-community/cli-tools';
1818

1919
/**
2020
* Creates the template for a React Native project given the provided

packages/cli/src/commands/init/printRunInstructions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import path from 'path';
1212
import chalk from 'chalk';
13-
import logger from '../../tools/logger';
13+
import {logger} from '@react-native-community/cli-tools';
1414

1515
function printRunInstructions(projectDir: string, projectName: string) {
1616
const absoluteProjectDir = path.resolve(projectDir);

packages/cli/src/commands/init/template.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import execa from 'execa';
44
import path from 'path';
55
import * as PackageManager from '../../tools/packageManager';
6-
import logger from '../../tools/logger';
6+
import {logger} from '@react-native-community/cli-tools';
77
import copyFiles from '../../tools/copyFiles';
88

99
export type TemplateConfig = {

packages/cli/src/commands/install/install.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type {ContextT} from '../../tools/types.flow';
11-
import logger from '../../tools/logger';
11+
import {logger} from '@react-native-community/cli-tools';
1212
import * as PackageManager from '../../tools/packageManager';
1313
import link from '../link/link';
1414
import loadConfig from '../../tools/config';

packages/cli/src/commands/install/uninstall.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

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

packages/cli/src/commands/library/library.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import path from 'path';
1212
import copyAndReplace from '../../tools/copyAndReplace';
1313
import isValidPackageName from '../../tools/isValidPackageName';
1414
import walk from '../../tools/walk';
15-
import logger from '../../tools/logger';
15+
import {logger} from '@react-native-community/cli-tools';
1616

1717
/**
1818
* Creates a new native library with the given name

0 commit comments

Comments
 (0)