This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[expo-cli][xdl] move module version checker to xdl (#169)
- Loading branch information
Showing
5 changed files
with
39 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters