Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed using wrong package manager in yarn workspace projects #503

Merged
merged 21 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
66864f0
fixed yarn.lock file lookup for monorepo projects
connectdotz Dec 8, 2017
70f61b5
Bump XDL version to 47.2.0.
fson Jan 17, 2018
56beafa
Update CHANGELOG and bump version
fson Jan 17, 2018
4139951
Update to Expo SDK 25 but don't publish yet
brentvatne Jan 19, 2018
9d87aca
Don't run jest with watch mode by default because of #529
brentvatne Jan 19, 2018
fcc9629
Remove jest-expo plugin on eject and use jest-react-native instead (#…
KELiON Jan 19, 2018
efd617c
Add --reason shortcut flag (#498)
cem2ran Jan 19, 2018
c671c7a
Upgrade XDL to v48.0.2
fson Jan 25, 2018
8d7c8ae
1.11.0
fson Jan 25, 2018
dad2003
Add changelog for v1.11.0
fson Jan 25, 2018
fc1ef3c
1.11.1
fson Jan 26, 2018
77764f3
Add new versions and remove unsupported versions
brentvatne Jan 30, 2018
d655a32
Add jest to devDependencies when ejecting (#553)
yacinehmito Feb 16, 2018
d0fba82
Update troubleshooting related to running a VPN (#538)
jagberg Feb 16, 2018
e531d1a
Added backers and sponsors on the README (#569)
monkeywithacupcake Feb 23, 2018
fabade9
fixed yarn.lock file lookup for monorepo projects
connectdotz Dec 8, 2017
d98e3a3
Merge branch 'yarn-lookup-fix' of https://github.com/connectdotz/crea…
connectdotz Mar 3, 2018
086d57b
clean up jest config
connectdotz Mar 3, 2018
1c5f252
fixed yarn.lock file lookup for monorepo projects
connectdotz Dec 8, 2017
2de1d29
clean up jest config
connectdotz Mar 3, 2018
ed1603c
Merge branch 'yarn-lookup-fix' of https://github.com/connectdotz/crea…
connectdotz Mar 6, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.11.1 (January 26, 2018)

Update XDL to version 48.0.2.

## 1.10.0 (January 18, 2018)

Update to Expo SDK 25.

## 1.9.0 (January 17, 2018)

Update XDL to version 47.2.0.

## 1.8.0 (November 27, 2017)

Update for SDK 23.
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Create React Native App
[![npm version](https://badge.fury.io/js/create-react-native-app.svg)](https://badge.fury.io/js/create-react-native-app)
[![Backers on Open Collective](https://opencollective.com/create-react-native-app/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/create-react-native-app/sponsors/badge.svg)](#sponsors) [![npm version](https://badge.fury.io/js/create-react-native-app.svg)](https://badge.fury.io/js/create-react-native-app)

Create React Native apps with no build configuration.

Expand Down Expand Up @@ -123,3 +123,33 @@ If you need to build IPAs and APKs for publishing to the App Store and/or Play S
Contributions will be licensed under the [3-clause BSD license](https://github.com/react-community/create-react-native-app/blob/master/LICENSE). Please fork the repository, perform your work on a feature branch, and submit a pull request to this repository's master branch from your fork's branch.

For details about setting up a development environment and testing your changes, please see [CONTRIBUTING.md](https://github.com/react-community/create-react-native-app/blob/master/CONTRIBUTING.md).

## Contributors

This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
<a href="graphs/contributors"><img src="https://opencollective.com/create-react-native-app/contributors.svg?width=890&button=false" /></a>


## Backers

Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/create-react-native-app#backer)]

<a href="https://opencollective.com/create-react-native-app#backers" target="_blank"><img src="https://opencollective.com/create-react-native-app/backers.svg?width=890"></a>


## Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/create-react-native-app#sponsor)]

<a href="https://opencollective.com/create-react-native-app/sponsor/0/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/1/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/2/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/3/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/4/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/5/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/6/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/7/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/8/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/create-react-native-app/sponsor/9/website" target="_blank"><img src="https://opencollective.com/create-react-native-app/sponsor/9/avatar.svg"></a>


7 changes: 2 additions & 5 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ Each version of these dependencies is only compatible with a narrow version rang

| `react-native` | `react` | `expo` | `sdkVersion` in app.json |
|----------------|-----------------|--------|--------------------------|
| 0.41.x | 15.4.x | 14.x.x | `"14.0.0"` |
| 0.42.x | 15.4.x | 15.x.x | `"15.0.0"` |
| 0.43.x | 16.0.0-alpha.6 | 16.x.x | `"16.0.0"` |
| 0.44.x | 16.0.0-alpha.6 | 17.x.x | `"17.0.0"` |
| 0.45.x | 16.0.0-alpha.12 | 18.x.x | `"18.0.0"` |
| 0.46.x | 16.0.0-alpha.12 | 19.x.x | `"19.0.0"` |
| 0.47.x | 16.0.0-alpha.12 | 20.x.x | `"20.0.0"` |
| 0.48.x | 16.0.0-alpha.12 | 21.x.x | `"21.0.0"` |
| 0.49.x | 16.0.0-beta.5 | 22.x.x | `"22.0.0"` |
| 0.50.x | 16.0.0 | 23.x.x | `"23.0.0"` |
| 0.51.x | 16.0.0 | 24.x.x | `"24.0.0"` |
| 0.52.x | 16.2.0 | 25.x.x | `"25.0.0"` |
5 changes: 4 additions & 1 deletion create-react-native-app/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const argv = minimist(process.argv.slice(2));
* --version - to print current version
* --verbose - to print npm logs during init
* --scripts-version <alternative package>
* --reason - shortcut for: --scripts-version 'reason-react-native-scripts'
* --package-manager <package manager name or path>
* Example of valid values:
* - a specific npm version: "0.22.0-rc1"
Expand All @@ -40,7 +41,9 @@ if (commands.length === 0) {
process.exit(1);
}

createApp(commands[0], !!argv.verbose, argv['scripts-version']).then(() => {});
const scriptsVersion = argv.reason ? 'reason-react-native-scripts' : argv['scripts-version'];

createApp(commands[0], !!argv.verbose, scriptsVersion).then(() => {});

function userHasYarn() {
try {
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"private": true,
"scripts": {
"format": "prettier --single-quote --trailing-comma=es5 --print-width=100 --write '{create-react-native-app,react-native-scripts}/{src,template}/**/*.js'"
"format": "prettier --single-quote --trailing-comma=es5 --print-width=100 --write '{create-react-native-app,react-native-scripts}/{src,template}/**/*.js'",
"test": "jest"
},
"devDependencies": {
"jest": "^21.2.1",
"prettier": "^0.21.0"
},
"jest": {
"testPathIgnorePatterns": [
"node_modules",
"template"
]
}
}
43 changes: 43 additions & 0 deletions react-native-scripts/__mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// based on jest official doc: https://facebook.github.io/jest/docs/en/manual-mocks.html
// __mocks__/fs.js
'use strict';

const path = require('path');

const fs = jest.genMockFromModule('fs');

// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let mockFiles = Object.create(null);
function __setMockFiles(newMockFiles) {
mockFiles = Object.create(null);
for (const file in newMockFiles) {
const dir = path.dirname(file);
if (!mockFiles[dir]) {
mockFiles[dir] = [];
}
mockFiles[dir].push(path.basename(file));
}
}

// A custom version of `readdirSync` that reads from the special mocked out
// file list set via __setMockFiles
function readdirSync(directoryPath) {
return mockFiles[directoryPath] || [];
}

function accessSync(directoryPath) {
const dir = path.dirname(directoryPath);
const children = mockFiles[dir];

if (!children || children.indexOf(path.basename(directoryPath)) < 0) {
throw new TypeError(`no such file/dir: ${directoryPath}`);
}
}

fs.__setMockFiles = __setMockFiles;
fs.readdirSync = readdirSync;
fs.accessSync = accessSync;

module.exports = fs;
4 changes: 2 additions & 2 deletions react-native-scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-scripts",
"version": "1.8.0",
"version": "1.11.1",
"description": "Configuration and scripts for Create React Native App.",
"license": "BSD-3-Clause",
"keywords": [
Expand Down Expand Up @@ -38,7 +38,7 @@
"progress": "^2.0.0",
"qrcode-terminal": "^0.11.0",
"rimraf": "^2.6.1",
"xdl": "46.0.1"
"xdl": "48.0.2"
},
"devDependencies": {
"@taskr/babel": "^1.0.6",
Expand Down
18 changes: 3 additions & 15 deletions react-native-scripts/src/bin/crna-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@ import App from '../../../../App';
import React, { Component } from 'react';
import { View } from 'react-native';

// we don't want this to require transformation
class AwakeInDevApp extends Component {
render() {
return React.createElement(
View,
{
style: {
flex: 1,
},
},
React.createElement(App, this.props),
React.createElement(process.env.NODE_ENV === 'development' ? Expo.KeepAwake : View)
);
}
if (process.env.NODE_ENV === 'development') {
Expo.KeepAwake.activate();
}

Expo.registerRootComponent(AwakeInDevApp);
Expo.registerRootComponent(App);
14 changes: 13 additions & 1 deletion react-native-scripts/src/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import path from 'path';
import rimraf from 'rimraf';
import spawn from 'cross-spawn';
import log from '../util/log';
import { hasYarn } from '../util/pm';

import { detach } from '../util/expo';

Expand Down Expand Up @@ -78,7 +79,7 @@ Ejecting is permanent! Please be careful with your selection.
const { ejectMethod } = await inquirer.prompt(questions);

if (ejectMethod === 'raw') {
const useYarn = await fse.exists(path.resolve('yarn.lock'));
const useYarn = hasYarn(process.cwd());
const npmOrYarn = useYarn ? 'yarn' : 'npm';
const appJson = JSON.parse(await fse.readFile(path.resolve('app.json')));
const pkgJson = JSON.parse(await fse.readFile(path.resolve('package.json')));
Expand Down Expand Up @@ -191,10 +192,21 @@ from \`babel-preset-expo\` to \`babel-preset-react-native-stage-0/decorator-supp
// missing native modules will cause
delete pkgJson.dependencies.expo;
delete pkgJson.devDependencies['react-native-scripts'];
delete pkgJson.devDependencies['jest-expo'];

pkgJson.scripts.start = 'react-native start';
pkgJson.scripts.ios = 'react-native run-ios';
pkgJson.scripts.android = 'react-native run-android';
pkgJson.scripts.test = 'jest';

newDevDependencies.push('jest');

if (pkgJson.jest.preset === 'jest-expo') {
pkgJson.jest.preset = 'react-native';
newDevDependencies.push('jest-react-native');
} else {
log(`${chalk.bold('Warning')}: it looks like you've changed the Jest preset from jest-expo to ${pkgJson.jest.preset}. We recommend you make sure this Jest preset is compatible with ejected apps.`)
}

// no longer relevant to an ejected project (maybe build is?)
delete pkgJson.scripts.eject;
Expand Down
15 changes: 8 additions & 7 deletions react-native-scripts/src/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@ import pathExists from 'path-exists';
import spawn from 'cross-spawn';
import log from '../util/log';
import install from '../util/install';
import { hasYarn } from '../util/pm';

// UPDATE DEPENDENCY VERSIONS HERE
const DEFAULT_DEPENDENCIES = {
expo: '^23.0.4',
react: '16.0.0',
'react-native': '0.50.3',
expo: '^25.0.0',
react: '16.2.0',
'react-native': '0.52.0',
};

// TODO figure out how this interacts with ejection
const DEFAULT_DEV_DEPENDENCIES = {
'jest-expo': '23.0.0',
'react-test-renderer': '16.0.0',
'jest-expo': '25.0.0',
'react-test-renderer': '16.2.0',
};

module.exports = async (appPath: string, appName: string, verbose: boolean, cwd: string = '') => {
const ownPackageName: string = require('../../package.json').name;
const ownPath: string = path.join(appPath, 'node_modules', ownPackageName);
const useYarn: boolean = await pathExists(path.join(appPath, 'yarn.lock'));
const useYarn: boolean = hasYarn(appPath);
const npmOrYarn = useYarn ? 'yarn' : 'npm';

// FIXME(perry) remove when npm 5 is supported
Expand Down Expand Up @@ -70,7 +71,7 @@ https://github.com/npm/npm/issues/16991
eject: 'react-native-scripts eject',
android: 'react-native-scripts android',
ios: 'react-native-scripts ios',
test: 'node node_modules/jest/bin/jest.js --watch',
test: 'node node_modules/jest/bin/jest.js',
};

appPackage.jest = {
Expand Down
3 changes: 2 additions & 1 deletion react-native-scripts/src/scripts/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import path from 'path';
import pathExists from 'path-exists';
import qr from 'qrcode-terminal';
import log from '../util/log';
import { hasYarn } from '../util/pm';

import packager from '../util/packager';

Config.validation.reactNativeVersionWarnings = false;
Config.developerTool = 'crna';
Config.offline = true;

const command: string = pathExists.sync(path.join(process.cwd(), 'yarn.lock')) ? 'yarnpkg' : 'npm';
const command: string = hasYarn(process.cwd()) ? 'yarnpkg' : 'npm';

if (!Simulator.isPlatformSupported()) {
log(
Expand Down
35 changes: 35 additions & 0 deletions react-native-scripts/src/util/__tests__/pm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

jest.mock('fs');

import { hasYarn } from '../pm';

describe('hasYarn', () => {
const MOCK_FILE_INFO = {
'/a/b/yarn.lock': 'fake yarn.lock',
};

beforeEach(() => {
// Set up some mocked out file info before each test
require('fs').__setMockFiles(MOCK_FILE_INFO);
});
test('undefined path will throw exception', () => {
expect(() => hasYarn(undefined, false)).toThrow();
});
test('empty path is ok', () => {
expect(hasYarn('', false)).toEqual(false);
});
test('can find yarn in the given path', () => {
expect(hasYarn('/a/b', false)).toEqual(true);
});
test('can find yarn in the parent path', () => {
expect(hasYarn('/a/b/c/d/e', false)).toEqual(true);
});
test('can NOT find yarn in the children path', () => {
expect(hasYarn('/a', false)).toEqual(false);
});
test('can use cached value 2nd time around', () => {
expect(hasYarn('/a/b/c/d/e', false)).toEqual(true);
expect(hasYarn(undefined, true)).toEqual(true);
});
});
3 changes: 2 additions & 1 deletion react-native-scripts/src/util/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import spawn from 'cross-spawn';
import pathExists from 'path-exists';
import path from 'path';
import log from '../util/log';
import { hasYarn } from './pm';

type InstallResult = {
code: number,
Expand All @@ -17,7 +18,7 @@ export default (async function install(
packageVersion?: string,
options?: any = {}
): Promise<InstallResult> {
const useYarn: boolean = await pathExists(path.join(appPath, 'yarn.lock'));
const useYarn: boolean = hasYarn(appPath);

let command = '';
let args = [];
Expand Down
42 changes: 42 additions & 0 deletions react-native-scripts/src/util/pm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @flow

'use strict';

import path from 'path';
import fs from 'fs';

/**
* check if the current path uses yarn, i.e. looking for yarn.lock in
* the current path and up
*
* @param {*} startingPath a path where we will look for yarn.lock file.
* Will traverse up the filesystem until we either find the file or reach the root
*
* @param {boolean} useCached if true and we have a cached hasYarn result, it will be returned, otherwise go through the
* normal lookup logic described above. mainly for optimization purpose, default is true.
*/
let _hasYarn: ?boolean;
export function hasYarn(startingPath: string, useCached: boolean = true): boolean {
if (_hasYarn != null && useCached) {
return _hasYarn;
}

_hasYarn = false;
let p = path.normalize(startingPath);
while (p.length > 0) {
const yarnLock = path.resolve(p, 'yarn.lock');
try {
const file = path.join(p, 'yarn.lock');
fs.accessSync(file);
_hasYarn = true;
break;
} catch (e) {
const parsed = path.parse(p);
if (parsed.root === parsed.dir) {
break;
}
p = parsed.dir;
}
}
return _hasYarn;
}
2 changes: 1 addition & 1 deletion react-native-scripts/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function (fly) {
}

export async function babel(fly, opts) {
await fly.source(opts.src || paths.source).babel().target(paths.build);
await fly.source(opts.src || paths.source, {ignore: '**/__tests__/**'}).babel().target(paths.build);
}

export async function clean(fly) {
Expand Down