Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[expo-cli][xdl] move module version checker to xdl (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsokal authored and fson committed Nov 8, 2018
1 parent 04f9572 commit 4bbfefe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 30 deletions.
2 changes: 0 additions & 2 deletions packages/expo-cli/package.json
Expand Up @@ -75,11 +75,9 @@
"indent-string": "^3.1.0",
"inquirer": "^5.0.1",
"klaw-sync": "^6.0.0",
"latest-version": "^4.0.0",
"lodash": "^4.17.4",
"match-require": "^2.1.0",
"ora": "^1.3.0",
"p-timeout": "^2.0.1",
"progress": "^2.0.0",
"qrcode-terminal": "^0.11.0",
"semver": "^5.0.1",
Expand Down
34 changes: 6 additions & 28 deletions packages/expo-cli/src/update.js
@@ -1,36 +1,14 @@
/**
* @flow
*/
import latestVersionAsync from 'latest-version';
import pTimeout from 'p-timeout';
import semver from 'semver';
import { ModuleVersion } from 'xdl';

import { FsCache } from 'xdl';
import packageJSON from '../package.json';

const UpdateCacher = new FsCache.Cacher(
async () => {
return { latestVersion: await pTimeout(latestVersionAsync(packageJSON.name), 2000) };
},
`${packageJSON.name}-updates.json`,
24 * 60 * 60 * 1000 // one day
const ModuleVersionChecker = ModuleVersion.createModuleVersionChecker(
packageJSON.name,
packageJSON.version
);

async function checkForUpdateAsync(): Promise<{
updateIsAvailable: boolean,
current: string,
latest: string,
}> {
const current = packageJSON.version;

// check for an outdated install based on either a fresh npm query or our cache
const { latestVersion } = await UpdateCacher.getAsync();

return {
updateIsAvailable: semver.gt(latestVersion, current),
latest: latestVersion,
current,
};
async function checkForUpdateAsync() {
return await ModuleVersionChecker.checkAsync();
}

export default {
Expand Down
2 changes: 2 additions & 0 deletions packages/xdl/package.json
Expand Up @@ -62,13 +62,15 @@
"inquirer": "^5.0.1",
"invariant": "^2.2.4",
"joi": "^14.0.4",
"latest-version": "^4.0.0",
"lodash": "^4.14.1",
"md5hex": "^1.0.0",
"minimatch": "^3.0.4",
"mv": "^2.1.1",
"ncp": "^2.0.0",
"node-forge": "^0.7.4",
"opn": "^4.0.2",
"p-timeout": "^2.0.1",
"plist": "^2.1.0",
"prop-types": "^15.5.10",
"querystring": "^0.2.0",
Expand Down
28 changes: 28 additions & 0 deletions packages/xdl/src/tools/ModuleVersion.js
@@ -0,0 +1,28 @@
import latestVersionAsync from 'latest-version';
import pTimeout from 'p-timeout';
import semver from 'semver';

import { Cacher } from './FsCache';

function createModuleVersionChecker(name, currentVersion) {
const UpdateCacher = new Cacher(
async () => {
return { latestVersion: await pTimeout(latestVersionAsync(name), 2000) };
},
`${name}-updates.json`,
24 * 60 * 60 * 1000 // one day
);

async function checkAsync() {
const { latestVersion } = await UpdateCacher.getAsync();
return {
updateIsAvailable: semver.gt(latestVersion, currentVersion),
latest: latestVersion,
current: currentVersion,
};
}

return { checkAsync };
}

export { createModuleVersionChecker };
3 changes: 3 additions & 0 deletions packages/xdl/src/xdl.js
Expand Up @@ -108,6 +108,9 @@ module.exports = {
get LoggerDetach() {
return require('./detach/Logger').default;
},
get ModuleVersion() {
return require('./tools/ModuleVersion');
},
get Modules() {
return require('./modules/Modules');
},
Expand Down

0 comments on commit 4bbfefe

Please sign in to comment.