Skip to content

Commit 94c06e9

Browse files
committed
add timeout for version query
1 parent ac1a000 commit 94c06e9

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

bun.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"@types/semver": "^7.5.8",
4242
"@types/tcp-ping": "^0.1.6",
4343
"@types/update-notifier": "^6.0.8",
44+
"@types/yauzl": "^2.10.3",
45+
"@types/yazl": "^2.4.6",
4446
"typescript": "^5.7.2",
4547
},
4648
},
@@ -174,6 +176,10 @@
174176

175177
"@types/update-notifier": ["@types/[email protected]", "", { "dependencies": { "@types/configstore": "*", "boxen": "^7.1.1" } }, "sha512-IlDFnfSVfYQD+cKIg63DEXn3RFmd7W1iYtKQsJodcHK9R1yr8aKbKaPKfBxzPpcHCq2DU8zUq4PIPmy19Thjfg=="],
176178

179+
"@types/yauzl": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q=="],
180+
181+
"@types/yazl": ["@types/[email protected]", "", { "dependencies": { "@types/node": "*" } }, "sha512-/ifFjQtcKaoZOjl5NNCQRR0fAKafB3Foxd7J/WvFPTMea46zekapcR30uzkwIkKAAuq5T6d0dkwz754RFH27hg=="],
182+
177183
"@xhmikosr/archive-type": ["@xhmikosr/[email protected]", "", { "dependencies": { "file-type": "^19.0.0" } }, "sha512-sIm84ZneCOJuiy3PpWR5bxkx3HaNt1pqaN+vncUBZIlPZCq8ASZH+hBVdu5H8znR7qYC6sKwx+ie2Q7qztJTxA=="],
178184

179185
"@xhmikosr/bin-check": ["@xhmikosr/[email protected]", "", { "dependencies": { "execa": "^5.1.1", "isexe": "^2.0.0" } }, "sha512-4UnCLCs8DB+itHJVkqFp9Zjg+w/205/J2j2wNBsCEAm/BuBmtua2hhUOdAMQE47b1c7P9Xmddj0p+X1XVsfHsA=="],

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update-cli",
3-
"version": "1.41.0-beta.1",
3+
"version": "1.41.0",
44
"description": "Command tools for javaScript updater with `pushy` service for react native apps.",
55
"main": "index.js",
66
"bin": {
@@ -76,7 +76,8 @@
7676
"@types/semver": "^7.5.8",
7777
"@types/tcp-ping": "^0.1.6",
7878
"@types/update-notifier": "^6.0.8",
79+
"@types/yauzl": "^2.10.3",
80+
"@types/yazl": "^2.4.6",
7981
"typescript": "^5.7.2"
80-
},
81-
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
82+
}
8283
}

src/utils/index.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function question(query: string, password?: boolean) {
2323
}
2424

2525
export function translateOptions(options: Record<string, string>) {
26-
const ret = {};
26+
const ret: Record<string, string> = {};
2727
for (const key in options) {
2828
const v = options[key];
2929
if (typeof v === 'string') {
@@ -40,19 +40,21 @@ export function translateOptions(options: Record<string, string>) {
4040

4141
export function getRNVersion() {
4242
const version = JSON.parse(
43-
fs.readFileSync(
44-
require.resolve('react-native/package.json', {
45-
paths: [process.cwd()],
46-
}),
47-
),
43+
fs
44+
.readFileSync(
45+
require.resolve('react-native/package.json', {
46+
paths: [process.cwd()],
47+
}),
48+
)
49+
.toString(),
4850
).version;
4951

50-
// We only care about major and minor version.
51-
const match = /^(\d+)\.(\d+)\./.exec(version);
52+
const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
53+
5254
return {
5355
version,
54-
major: match[1] | 0,
55-
minor: match[2] | 0,
56+
major: Number(major),
57+
minor: Number(minor),
5658
};
5759
}
5860

@@ -173,17 +175,22 @@ export function saveToLocal(originPath: string, destName: string) {
173175
// fs.copyFileSync(originPath, destPath);
174176
}
175177

176-
async function getLatestVersion(pkgName: string) {
177-
return Promise.race([
178-
latestVersion(pkgName)
179-
.then((p) => p.latest)
180-
.catch(() => ''),
181-
new Promise((resolve) => setTimeout(() => resolve(''), 2000)),
182-
]);
178+
async function getLatestVersion(pkgNames: string[]) {
179+
return latestVersion(pkgNames, {
180+
useCache: true,
181+
requestOptions: {
182+
timeout: 2000,
183+
},
184+
})
185+
.then((pkgs) => pkgs.map((pkg) => pkg.latest))
186+
.catch(() => []);
183187
}
184188

185189
export async function printVersionCommand() {
186-
let latestPushyCliVersion = await getLatestVersion('react-native-update-cli');
190+
let [latestPushyCliVersion, latestPushyVersion] = await getLatestVersion([
191+
'react-native-update-cli',
192+
'react-native-update',
193+
]);
187194
latestPushyCliVersion = latestPushyCliVersion
188195
? ` (最新:${chalk.green(latestPushyCliVersion)})`
189196
: '';
@@ -199,7 +206,6 @@ export async function printVersionCommand() {
199206
},
200207
);
201208
pushyVersion = require(PACKAGE_JSON_PATH).version;
202-
let latestPushyVersion = await getLatestVersion('react-native-update');
203209
latestPushyVersion = latestPushyVersion
204210
? ` (最新:${chalk.green(latestPushyVersion)})`
205211
: '';
@@ -226,6 +232,4 @@ export async function printVersionCommand() {
226232
}
227233
}
228234

229-
230-
231235
export { checkPlugins };

0 commit comments

Comments
 (0)