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/semver": "^7.5.8",
|
||||||
"@types/tcp-ping": "^0.1.6",
|
"@types/tcp-ping": "^0.1.6",
|
||||||
"@types/update-notifier": "^6.0.8",
|
"@types/update-notifier": "^6.0.8",
|
||||||
|
"@types/yauzl": "^2.10.3",
|
||||||
|
"@types/yazl": "^2.4.6",
|
||||||
"typescript": "^5.7.2",
|
"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/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/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=="],
|
"@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",
|
"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.",
|
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -76,7 +76,8 @@
|
|||||||
"@types/semver": "^7.5.8",
|
"@types/semver": "^7.5.8",
|
||||||
"@types/tcp-ping": "^0.1.6",
|
"@types/tcp-ping": "^0.1.6",
|
||||||
"@types/update-notifier": "^6.0.8",
|
"@types/update-notifier": "^6.0.8",
|
||||||
|
"@types/yauzl": "^2.10.3",
|
||||||
|
"@types/yazl": "^2.4.6",
|
||||||
"typescript": "^5.7.2"
|
"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>) {
|
export function translateOptions(options: Record<string, string>) {
|
||||||
const ret = {};
|
const ret: Record<string, string> = {};
|
||||||
for (const key in options) {
|
for (const key in options) {
|
||||||
const v = options[key];
|
const v = options[key];
|
||||||
if (typeof v === 'string') {
|
if (typeof v === 'string') {
|
||||||
@@ -40,19 +40,21 @@ export function translateOptions(options: Record<string, string>) {
|
|||||||
|
|
||||||
export function getRNVersion() {
|
export function getRNVersion() {
|
||||||
const version = JSON.parse(
|
const version = JSON.parse(
|
||||||
fs.readFileSync(
|
fs
|
||||||
require.resolve('react-native/package.json', {
|
.readFileSync(
|
||||||
paths: [process.cwd()],
|
require.resolve('react-native/package.json', {
|
||||||
}),
|
paths: [process.cwd()],
|
||||||
),
|
}),
|
||||||
|
)
|
||||||
|
.toString(),
|
||||||
).version;
|
).version;
|
||||||
|
|
||||||
// We only care about major and minor version.
|
const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
|
||||||
const match = /^(\d+)\.(\d+)\./.exec(version);
|
|
||||||
return {
|
return {
|
||||||
version,
|
version,
|
||||||
major: match[1] | 0,
|
major: Number(major),
|
||||||
minor: match[2] | 0,
|
minor: Number(minor),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,17 +175,22 @@ export function saveToLocal(originPath: string, destName: string) {
|
|||||||
// fs.copyFileSync(originPath, destPath);
|
// fs.copyFileSync(originPath, destPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLatestVersion(pkgName: string) {
|
async function getLatestVersion(pkgNames: string[]) {
|
||||||
return Promise.race([
|
return latestVersion(pkgNames, {
|
||||||
latestVersion(pkgName)
|
useCache: true,
|
||||||
.then((p) => p.latest)
|
requestOptions: {
|
||||||
.catch(() => ''),
|
timeout: 2000,
|
||||||
new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
|
},
|
||||||
]);
|
})
|
||||||
|
.then((pkgs) => pkgs.map((pkg) => pkg.latest))
|
||||||
|
.catch(() => []);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function printVersionCommand() {
|
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
|
latestPushyCliVersion = latestPushyCliVersion
|
||||||
? ` (最新:${chalk.green(latestPushyCliVersion)})`
|
? ` (最新:${chalk.green(latestPushyCliVersion)})`
|
||||||
: '';
|
: '';
|
||||||
@@ -199,7 +206,6 @@ export async function printVersionCommand() {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
||||||
let latestPushyVersion = await getLatestVersion('react-native-update');
|
|
||||||
latestPushyVersion = latestPushyVersion
|
latestPushyVersion = latestPushyVersion
|
||||||
? ` (最新:${chalk.green(latestPushyVersion)})`
|
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||||
: '';
|
: '';
|
||||||
@@ -226,6 +232,4 @@ export async function printVersionCommand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export { checkPlugins };
|
export { checkPlugins };
|
||||||
|
Reference in New Issue
Block a user