Skip to content

Commit b171255

Browse files
authored
Fix check package availability scripts (#6032)
1 parent 143f37c commit b171255

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

release-scripts/checkIfPackageShouldBePublished.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33
* Licensed under the MIT License.
44
*/
55

6-
const execSync = require("child_process").execSync;
7-
8-
function checkVersion(packageName, version) {
9-
// It is expected npm view will fail for packages that are about to be published. 2> dev/null/ is used to suppress the error.
10-
return execSync(`npm view ${packageName}@${version} 2> /dev/null`).toString().trim();
11-
}
12-
6+
const checkPackageAndVersion = require("./checkPackageAndVersion.js");
137
const path = require("path");
148
const libPath = path.join(__dirname, '..', process.argv[2]);
159

1610
const { name, version } = require(`${libPath}/package.json`);
1711

18-
const versionIsPublished = checkVersion(name, version);
12+
const versionIsPublished = checkPackageAndVersion(name, version);
1913

2014
if (versionIsPublished) {
2115
process.exit(0);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
const { execSync } = require("child_process");
7+
8+
const checkPackageAndVersion = (packageName, version) => {
9+
// It is expected npm view will fail for packages that are about to be published. 2> dev/null/ is used to suppress the error.
10+
try {
11+
execSync(`npm view --silent ${packageName}@${version} `).toString().trim();
12+
return true;
13+
} catch (error) {
14+
return false;
15+
}
16+
}
17+
18+
module.exports = checkPackageAndVersion;

release-scripts/checkPackageAvailability.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,21 @@
33
* Licensed under the MIT License.
44
*/
55

6-
const execSync = require("child_process").execSync;
7-
8-
function getPublishedVersion(packageName) {
9-
return execSync(`npm view ${packageName}@${version}`).toString().trim();
10-
}
11-
6+
const checkPackageAndVersion = require("./checkPackageAndVersion.js");
127
const path = require("path");
138
const libPath = path.join(__dirname, '..', process.argv[2]);
149

15-
const packageName = require(`${libPath}/package.json`).name;
16-
const currentVersion = require(`${libPath}/package.json`).version;
10+
const { name, version } = require(`${libPath}/package.json`);
1711

1812
let iteration = 0;
1913
const intervalId = setInterval(() => {
2014
if (iteration > 12) {
2115
clearInterval(intervalId);
22-
throw new Error(`Timed out waiting for ${packageName} version ${currentVersion}`);
16+
throw new Error(`Timed out waiting for ${name} version ${version}`);
2317
}
24-
const publishedVersion = getPublishedVersion(packageName);
25-
if (currentVersion === publishedVersion) {
26-
console.log(`${packageName} successfully published version ${currentVersion}`);
18+
const versionIsPublished = checkPackageAndVersion(name, version);
19+
if (versionIsPublished) {
20+
console.log(`${name} successfully published version ${version}`);
2721
clearInterval(intervalId);
2822
process.exit(0);
2923
}

0 commit comments

Comments
 (0)