mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-09-16 09:41:38 +08:00
add timeout for version query
This commit is contained in:
6
bun.lock
6
bun.lock
@@ -41,6 +41,8 @@
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/tcp-ping": "^0.1.6",
|
||||
"@types/update-notifier": "^6.0.8",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
"@types/yazl": "^2.4.6",
|
||||
"typescript": "^5.7.2",
|
||||
},
|
||||
},
|
||||
@@ -174,6 +176,10 @@
|
||||
|
||||
"@types/update-notifier": ["@types/update-notifier@6.0.8", "", { "dependencies": { "@types/configstore": "*", "boxen": "^7.1.1" } }, "sha512-IlDFnfSVfYQD+cKIg63DEXn3RFmd7W1iYtKQsJodcHK9R1yr8aKbKaPKfBxzPpcHCq2DU8zUq4PIPmy19Thjfg=="],
|
||||
|
||||
"@types/yauzl": ["@types/yauzl@2.10.3", "", { "dependencies": { "@types/node": "*" } }, "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q=="],
|
||||
|
||||
"@types/yazl": ["@types/yazl@2.4.6", "", { "dependencies": { "@types/node": "*" } }, "sha512-/ifFjQtcKaoZOjl5NNCQRR0fAKafB3Foxd7J/WvFPTMea46zekapcR30uzkwIkKAAuq5T6d0dkwz754RFH27hg=="],
|
||||
|
||||
"@xhmikosr/archive-type": ["@xhmikosr/archive-type@7.0.0", "", { "dependencies": { "file-type": "^19.0.0" } }, "sha512-sIm84ZneCOJuiy3PpWR5bxkx3HaNt1pqaN+vncUBZIlPZCq8ASZH+hBVdu5H8znR7qYC6sKwx+ie2Q7qztJTxA=="],
|
||||
|
||||
"@xhmikosr/bin-check": ["@xhmikosr/bin-check@7.0.3", "", { "dependencies": { "execa": "^5.1.1", "isexe": "^2.0.0" } }, "sha512-4UnCLCs8DB+itHJVkqFp9Zjg+w/205/J2j2wNBsCEAm/BuBmtua2hhUOdAMQE47b1c7P9Xmddj0p+X1XVsfHsA=="],
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update-cli",
|
||||
"version": "1.41.0-beta.1",
|
||||
"version": "1.41.0",
|
||||
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -76,7 +76,8 @@
|
||||
"@types/semver": "^7.5.8",
|
||||
"@types/tcp-ping": "^0.1.6",
|
||||
"@types/update-notifier": "^6.0.8",
|
||||
"@types/yauzl": "^2.10.3",
|
||||
"@types/yazl": "^2.4.6",
|
||||
"typescript": "^5.7.2"
|
||||
},
|
||||
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ export async function question(query: string, password?: boolean) {
|
||||
}
|
||||
|
||||
export function translateOptions(options: Record<string, string>) {
|
||||
const ret = {};
|
||||
const ret: Record<string, string> = {};
|
||||
for (const key in options) {
|
||||
const v = options[key];
|
||||
if (typeof v === 'string') {
|
||||
@@ -40,19 +40,21 @@ export function translateOptions(options: Record<string, string>) {
|
||||
|
||||
export function getRNVersion() {
|
||||
const version = JSON.parse(
|
||||
fs.readFileSync(
|
||||
require.resolve('react-native/package.json', {
|
||||
paths: [process.cwd()],
|
||||
}),
|
||||
),
|
||||
fs
|
||||
.readFileSync(
|
||||
require.resolve('react-native/package.json', {
|
||||
paths: [process.cwd()],
|
||||
}),
|
||||
)
|
||||
.toString(),
|
||||
).version;
|
||||
|
||||
// We only care about major and minor version.
|
||||
const match = /^(\d+)\.(\d+)\./.exec(version);
|
||||
const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
|
||||
|
||||
return {
|
||||
version,
|
||||
major: match[1] | 0,
|
||||
minor: match[2] | 0,
|
||||
major: Number(major),
|
||||
minor: Number(minor),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -173,17 +175,22 @@ export function saveToLocal(originPath: string, destName: string) {
|
||||
// fs.copyFileSync(originPath, destPath);
|
||||
}
|
||||
|
||||
async function getLatestVersion(pkgName: string) {
|
||||
return Promise.race([
|
||||
latestVersion(pkgName)
|
||||
.then((p) => p.latest)
|
||||
.catch(() => ''),
|
||||
new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
|
||||
]);
|
||||
async function getLatestVersion(pkgNames: string[]) {
|
||||
return latestVersion(pkgNames, {
|
||||
useCache: true,
|
||||
requestOptions: {
|
||||
timeout: 2000,
|
||||
},
|
||||
})
|
||||
.then((pkgs) => pkgs.map((pkg) => pkg.latest))
|
||||
.catch(() => []);
|
||||
}
|
||||
|
||||
export async function printVersionCommand() {
|
||||
let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
|
||||
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
|
||||
'react-native-update-cli',
|
||||
'react-native-update',
|
||||
]);
|
||||
latestPushyCliVersion = latestPushyCliVersion
|
||||
? ` (最新:${chalk.green(latestPushyCliVersion)})`
|
||||
: '';
|
||||
@@ -199,7 +206,6 @@ export async function printVersionCommand() {
|
||||
},
|
||||
);
|
||||
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
||||
let latestPushyVersion = await getLatestVersion('react-native-update');
|
||||
latestPushyVersion = latestPushyVersion
|
||||
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||
: '';
|
||||
@@ -226,6 +232,4 @@ export async function printVersionCommand() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export { checkPlugins };
|
||||
|
Reference in New Issue
Block a user