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
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
"@react-native-community/cli-platform-ios": "^3.0.0-alpha.2",
"@react-native-community/cli-tools": "^2.8.3",
"@react-native-community/cli-types": "^3.0.0-alpha.2",
"@types/mkdirp": "^0.5.2",
"@types/semver": "^6.0.2",
"chalk": "^2.4.2",
"command-exists": "^1.2.8",
"commander": "^2.19.0",
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/info/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import envinfo from 'envinfo';
import {logger} from '@react-native-community/cli-tools';
import {Config} from '@react-native-community/cli-types';
// @ts-ignore - JS file
import releaseChecker from '../../tools/releaseChecker';

const info = async function getInfo(_argv: Array<string>, ctx: Config) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/init/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as PackageManager from '../../tools/packageManager';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import copyFiles from '../../tools/copyFiles';
// $FlowFixMe - converted to TS
import replacePathSepForRegex from '../../tools/replacePathSepForRegex';

export type TemplateConfig = {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/server/runServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import messageSocket from './messageSocket';
import webSocketProxy from './webSocketProxy';
import MiddlewareManager from './middleware/MiddlewareManager';
import loadMetroConfig from '../../tools/loadMetroConfig';
// $FlowFixMe - converted to TS
import releaseChecker from '../../tools/releaseChecker';

export type Args = {|
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/__tests__/copyFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import path from 'path';
import copyFiles from '../copyFiles';
import {cleanup, getTempDirectory} from '../../../../../jest/helpers';
// $FlowFixMe - converted to TS
import replacePathSepForRegex from '../replacePathSepForRegex';

const DIR = getTempDirectory('copyFiles-test');
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/__tests__/packageManager-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
jest.mock('execa', () => jest.fn());
import execa from 'execa';
// $FlowFixMe - converted to TS
import * as yarn from '../yarn';
import {logger} from '@react-native-community/cli-tools';
import * as PackageManager from '../packageManager';
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/tools/packageManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import execa from 'execa';
import {logger} from '@react-native-community/cli-tools';
// $FlowFixMe - converted to TS
import {getYarnVersionIfAvailable, isProjectUsingYarn} from './yarn';

type Options = {|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
/**
* @flow
*/
import semver from 'semver';
import {logger} from '@react-native-community/cli-tools';
import cacheManager from './releaseCacheManager';
import {fetch} from '@react-native-community/cli-tools';
import {fetch, logger} from '@react-native-community/cli-tools';

export type Release = {
version: string,
changelogUrl: string,
diffUrl: string,
version: string;
changelogUrl: string;
diffUrl: string;
};

/**
Expand All @@ -22,7 +18,7 @@ export type Release = {
export default async function getLatestRelease(
name: string,
currentVersion: string,
) {
): Promise<Release | void> {
logger.debug('Checking for a newer version of React Native');
try {
logger.debug(`Current version: ${currentVersion}`);
Expand All @@ -36,7 +32,7 @@ export default async function getLatestRelease(
const aWeek = 7 * 24 * 60 * 60 * 1000;
const lastChecked = cacheManager.get(name, 'lastChecked');
const now = new Date();
if (lastChecked && now - new Date(lastChecked) < aWeek) {
if (lastChecked && Number(now) - Number(new Date(lastChecked)) < aWeek) {
logger.debug('Cached release is still recent, skipping remote check');
return;
}
Expand Down Expand Up @@ -75,10 +71,13 @@ function buildDiffUrl(version: string) {
/**
* Returns the most recent React Native version available to upgrade to.
*/
async function getLatestRnDiffPurgeVersion(name: string, eTag: ?string) {
async function getLatestRnDiffPurgeVersion(
name: string,
eTag?: string,
): Promise<string> {
const options = {
// https://developer.github.com/v3/#user-agent-required
headers: ({'User-Agent': 'React-Native-CLI'}: Headers),
headers: {'User-Agent': 'React-Native-CLI'} as Headers,
};

if (eTag) {
Expand All @@ -94,11 +93,10 @@ async function getLatestRnDiffPurgeVersion(name: string, eTag: ?string) {
if (status === 200) {
const body: Array<any> = data;
const latestVersion = body[0].name.substring(8);
const eTagHeader = headers.get('eTag');

// Update cache only if newer release is stable.
if (!semver.prerelease(latestVersion)) {
const eTagHeader = headers.get('eTag');

if (!semver.prerelease(latestVersion) && eTagHeader) {
logger.debug(`Saving ${eTagHeader} to cache`);
cacheManager.set(name, 'eTag', eTagHeader);
cacheManager.set(name, 'latestVersion', latestVersion);
Expand All @@ -120,6 +118,6 @@ async function getLatestRnDiffPurgeVersion(name: string, eTag: ?string) {
}

type Headers = {
'User-Agent': mixed,
[header: string]: mixed,
'User-Agent': string;
[header: string]: string;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import path from 'path';
import {logger} from '@react-native-community/cli-tools';
// @ts-ignore - JS file
import resolveNodeModuleDir from '../config/resolveNodeModuleDir';
import getLatestRelease from './getLatestRelease';
import printNewRelease from './printNewRelease';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/**
* @flow
*/
import chalk from 'chalk';
import {logger} from '@react-native-community/cli-tools';
import type {Release} from './getLatestRelease';
import {Release} from './getLatestRelease';
import cacheManager from './releaseCacheManager';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* @flow
*/
import path from 'path';
import fs from 'fs';
import os from 'os';
import mkdirp from 'mkdirp';
import {logger} from '@react-native-community/cli-tools';

type ReleaseCacheKey = 'eTag' | 'lastChecked' | 'latestVersion';
type Cache = {[key: ReleaseCacheKey]: string};
type Cache = {[key in ReleaseCacheKey]?: string};

function loadCache(name: string): ?Cache {
function loadCache(name: string): Cache | undefined {
try {
const cacheRaw = fs.readFileSync(
path.resolve(getCacheRootPath(), name),
Expand All @@ -24,6 +21,7 @@ function loadCache(name: string): ?Cache {
saveCache(name, {});
}
logger.debug('No release cache found');
return undefined;
}
}

Expand All @@ -42,17 +40,18 @@ function saveCache(name: string, cache: Cache) {
function getCacheRootPath() {
const cachePath = path.resolve(os.homedir(), '.react-native-cli', 'cache');
if (!fs.existsSync(cachePath)) {
mkdirp(cachePath);
mkdirp.sync(cachePath);
}

return cachePath;
}

function get(name: string, key: ReleaseCacheKey): ?string {
function get(name: string, key: ReleaseCacheKey): string | undefined {
const cache = loadCache(name);
if (cache) {
return cache[key];
}
return undefined;
}

function set(name: string, key: ReleaseCacheKey, value: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import path from 'path';

export default function replacePathSepForRegex(string: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

import {execSync} from 'child_process';
Expand Down Expand Up @@ -48,6 +47,6 @@ export function getYarnVersionIfAvailable() {
* Let's be safe and not mix yarn and npm in a single project.
* @param projectDir e.g. /Users/martin/AwesomeApp
*/
export function isProjectUsingYarn(projectDir) {
export function isProjectUsingYarn(projectDir: string) {
return fs.existsSync(path.join(projectDir, 'yarn.lock'));
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,13 @@
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA==

"@types/mkdirp@^0.5.2":
version "0.5.2"
resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.2.tgz#503aacfe5cc2703d5484326b1b27efa67a339c1f"
integrity sha512-U5icWpv7YnZYGsN4/cmh3WD2onMY0aJIiTE6+51TwJCttdHvtCYmkBNOobHlXwrJRL0nkH9jH4kD+1FAdMN4Tg==
dependencies:
"@types/node" "*"

"@types/node-fetch@^2.3.3":
version "2.3.3"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.3.3.tgz#eb9c2a0ce8e9424ebe0c0cbe6f1e8ea7576c1310"
Expand Down