Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into Esemesek/remove-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Esemesek committed Jan 23, 2019
2 parents e35a80b + 861b0c3 commit 359e12f
Show file tree
Hide file tree
Showing 265 changed files with 220 additions and 67 deletions.
11 changes: 6 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/node_modules/**
**/debugger-ui/**
**/templates/**
**/global-cli/**
**/flow-typed/**
node_modules/
debugger-ui/
templates/
global-cli/
flow-typed/
build/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.idea
package-lock.json
npm-debug.log
build/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ All work on React Native CLI happens directly on GitHub. Contributors send pull

Repository is splitted into two packages:

* `local-cli` - Historically, it was included in `react-native` package. Contains all the commands code.
* `cli` - Historically, it was included in `react-native` package. Contains all the commands code.
* `global-cli` - Historically, it was a `react-native-cli` package and the only reason this package existed was to initialize an empty project.

## Testing your changes

You can test your changes by calling `cli.js` directly from the cloned repository. You need to make sure the version of React Native matches the one present in devDependencies of the CLI. Otherwise, you may get unexpected errors.

```sh
node /path/to/cloned/project/packages/local-cli/cli.js
node /path/to/cloned/project/packages/cli/index.js
```

## Typechecking, linting and testing
Expand Down
3 changes: 1 addition & 2 deletions packages/local-cli/.babelrc.js → packages/cli/.babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ module.exports = {
[
require.resolve('@babel/preset-env'),
{
targets: { node: '8' },
targets: { node: 8 },
useBuiltIns: 'entry',
},
],
require.resolve('@babel/preset-flow'),
],
plugins: [require.resolve('@babel/plugin-transform-strict-mode')],
only: [new RegExp(`^${escapeRegExp(__dirname)}`)],
};
2 changes: 2 additions & 0 deletions packages/local-cli/.npmignore → packages/cli/.npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__fixtures__
__tests__
__mocks__
src
20 changes: 12 additions & 8 deletions packages/local-cli/package.json → packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.1",
"description": "React Native CLI",
"license": "MIT",
"main": "cli.js",
"main": "build/index.js",
"bin": {
"react-native": "bin.js"
"react-native": "build/bin.js"
},
"engineStrict": true,
"engines": {
Expand All @@ -15,8 +15,12 @@
"type": "git",
"url": "https://github.com/react-native-community/react-native-cli.git"
},
"scripts": {
"prepublish": "yarn build",
"build": "rm -rf build; babel src --copy-files --out-dir build --ignore '**/__tests__/**','**/__mocks__/**','**/__fixtures__/**'"
},
"jest": {
"displayName": "local",
"displayName": "cli",
"testPathIgnorePatterns": [
"/node_modules/",
"/templates/"
Expand All @@ -27,11 +31,6 @@
"testEnvironment": "node"
},
"dependencies": {
"@babel/core": "^7.1.5",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-flow": "^7.0.0",
"@babel/register": "^7.0.0",
"chalk": "^1.1.1",
"commander": "^2.9.0",
"compression": "^1.7.1",
Expand Down Expand Up @@ -67,6 +66,11 @@
"xmldoc": "^0.4.0"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.1.5",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-flow": "^7.0.0",
"flow-bin": "0.87.0",
"react-native": "^0.57.0"
},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/local-cli/bin.js → packages/cli/src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ if (isInstalledGlobally()) {
);
process.exit(1);
} else {
require('./cli').run();
require('.').run();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const getCommands = require('./core/getCommands');
const getLegacyConfig = require('./core/getLegacyConfig');
const init = require('./init/init');
const assertRequiredOptions = require('./util/assertRequiredOptions');
const pkg = require('./package.json');
const pkg = require('../package.json');

commander.version(pkg.version);

Expand Down Expand Up @@ -130,8 +130,8 @@ const addCommand = (command: CommandT, ctx: ContextT) => {

async function run() {
const setupEnvScript = /^win/.test(process.platform)
? 'setup_env.bat'
: 'setup_env.sh';
? path.join('..', 'setup_env.bat')
: path.join('..', 'setup_env.sh');

childProcess.execFileSync(path.join(__dirname, setupEnvScript));

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ const path = require('path');
const findPlugins = require('../findPlugins');

const ROOT = path.join(__dirname, '..', '..');
const pjsonPath = path.join(ROOT, 'package.json');
const pjsonPath = path.join(ROOT, './package.json');

describe('findPlugins', () => {
beforeEach(() => {
jest.resetModules();
});

it('returns an array of dependencies', () => {
jest.mock(pjsonPath, () => ({
dependencies: { 'rnpm-plugin-test': '*' },
}));
jest.doMock(
pjsonPath,
() => ({
dependencies: { 'rnpm-plugin-test': '*' },
}),
{ virtual: true }
);

expect(findPlugins(ROOT)).toHaveProperty('commands');
expect(findPlugins(ROOT)).toHaveProperty('platforms');
Expand All @@ -32,7 +36,7 @@ describe('findPlugins', () => {
});

it('returns an empty array if there are no plugins in this folder', () => {
jest.mock(pjsonPath, () => ({}));
jest.doMock(pjsonPath, () => ({}), { virtual: true });
expect(findPlugins(ROOT)).toHaveProperty('commands');
expect(findPlugins(ROOT)).toHaveProperty('platforms');
expect(findPlugins(ROOT).commands).toHaveLength(0);
Expand All @@ -47,33 +51,45 @@ describe('findPlugins', () => {
});

it('returns plugins from both dependencies and dev dependencies', () => {
jest.mock(pjsonPath, () => ({
dependencies: { 'rnpm-plugin-test': '*' },
devDependencies: { 'rnpm-plugin-test-2': '*' },
}));
jest.doMock(
pjsonPath,
() => ({
dependencies: { 'rnpm-plugin-test': '*' },
devDependencies: { 'rnpm-plugin-test-2': '*' },
}),
{ virtual: true }
);
expect(findPlugins(ROOT)).toHaveProperty('commands');
expect(findPlugins(ROOT)).toHaveProperty('platforms');
expect(findPlugins(ROOT).commands).toHaveLength(2);
expect(findPlugins(ROOT).platforms).toHaveLength(0);
});

it('returns unique list of plugins', () => {
jest.mock(pjsonPath, () => ({
dependencies: { 'rnpm-plugin-test': '*' },
devDependencies: { 'rnpm-plugin-test': '*' },
}));
jest.doMock(
pjsonPath,
() => ({
dependencies: { 'rnpm-plugin-test': '*' },
devDependencies: { 'rnpm-plugin-test': '*' },
}),
{ virtual: true }
);
expect(findPlugins(ROOT).commands).toHaveLength(1);
});

it('returns plugins in scoped modules', () => {
jest.mock(pjsonPath, () => ({
dependencies: {
'@org/rnpm-plugin-test': '*',
'@org/react-native-test': '*',
'@react-native/test': '*',
'@react-native-org/test': '*',
},
}));
jest.doMock(
pjsonPath,
() => ({
dependencies: {
'@org/rnpm-plugin-test': '*',
'@org/react-native-test': '*',
'@react-native/test': '*',
'@react-native-org/test': '*',
},
}),
{ virtual: true }
);

expect(findPlugins(ROOT)).toHaveProperty('commands');
expect(findPlugins(ROOT)).toHaveProperty('platforms');
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function eject() {
path.resolve(
'node_modules',
'react-native',
'local-cli',
'@react-native-community',
'cli',
'templates',
'HelloWorld',
'ios'
Expand All @@ -91,7 +92,8 @@ function eject() {
path.resolve(
'node_modules',
'react-native',
'local-cli',
'@react-native-community',
'cli',
'templates',
'HelloWorld',
'android'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const walk = require('../util/walk');
* Util for creating a new React Native project.
* Copy the project from a template and use the correct project name in
* all files.
* @param srcPath e.g. '/Users/martin/AwesomeApp/node_modules/react-native/local-cli/templates/HelloWorld'
* @param srcPath e.g. '/Users/martin/AwesomeApp/node_modules/react-native/template'
* @param destPath e.g. '/Users/martin/AwesomeApp'
* @param newProjectName e.g. 'AwesomeApp'
* @param options e.g. {
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions packages/local-cli/cli.js → packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
// gracefulify() has to be called before anything else runs
require('graceful-fs').gracefulify(require('fs'));

// Transpile the source code
const babelConfig = require('./.babelrc');

require('@babel/register')(babelConfig);

const cli = require('./cliEntry');

if (require.main === module) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ describe('getProjectDependencies', () => {
jest.resetModules();
});
it('should return an array of project dependencies', () => {
jest.setMock(path.join(CWD, './package.json'), {
dependencies: {
lodash: '^6.0.0',
'react-native': '^16.0.0',
'react-native-local-cli': '*',
},
});
jest.doMock(
path.join(CWD, './package.json'),
() => ({
dependencies: {
lodash: '^6.0.0',
'react-native': '^16.0.0',
'@react-native-community/cli': '*',
},
}),
{ virtual: true }
);

expect(getProjectDependencies(CWD)).toEqual(['lodash']);
});

it('should return an empty array when no dependencies set', () => {
jest.setMock(path.join(CWD, './package.json'), {});
jest.doMock(path.join(CWD, './package.json'), () => ({}), {
virtual: true,
});
expect(getProjectDependencies(CWD)).toEqual([]);
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const path = require('path');
*/
const EXCLUDED_PROJECTS = [
'react-native',
'react-native-local-cli',
'@react-native-community/cli',
'react-native-local-cli-preview',
];

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/global-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// The only job of react-native-cli is to init the repository and then
// forward all the commands to the local version of react-native.
//
// If you need to add a new command, please add it to local-cli/.
// If you need to add a new command, please add it to @react-native-community/cli.
//
// The only reason to modify this file is to add more warnings and
// troubleshooting information for the `react-native init` command.
Expand Down
2 changes: 1 addition & 1 deletion packages/global-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
"semver": "^5.0.3"
},
"jest": {
"displayName": "global"
"displayName": "global-cli"
}
}
Loading

0 comments on commit 359e12f

Please sign in to comment.