Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit 31cd5e1

Browse files
Check if the package is published on the correct tag
1 parent f702d2b commit 31cd5e1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

build-scripts/publish.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,27 @@ const path = require('path');
2929
const runCommand = require('./run-command');
3030

3131
const packagesDirPath = path.resolve(__dirname, '../packages');
32+
const isNightlyVersion = process.env.COMPILER_NIGHTLY === 'true';
3233

3334
async function isPackageVersionPublished(packageName, version) {
34-
return fetch(`https://registry.npmjs.org/${encodeURI(packageName)}/${version}`)
35+
const isPublished = await fetch(`https://registry.npmjs.org/${encodeURI(packageName)}/${version}`)
3536
.then((res) => res.ok);
37+
38+
if (!isPublished) {
39+
return false;
40+
}
41+
42+
const packageInfoResponse = await fetch(`https://registry.npmjs.org/${encodeURI(packageName)}`);
43+
if (!packageInfoResponse.ok) {
44+
return false;
45+
}
46+
47+
const packageDetail = await packageInfoResponse.json();
48+
console.log(packageDetail['dist-tags']);
49+
if (isNightlyVersion) {
50+
return packageDetail['dist-tags'].nightly === version;
51+
}
52+
return packageDetail['dist-tags'].latest === version;
3653
}
3754

3855
async function isValidPackagePath(packageDir) {
@@ -55,15 +72,14 @@ async function getPackageInfo(packageDir) {
5572

5673
async function publishPackagesIfNeeded(packageInfo) {
5774
const pkgJson = packageInfo.pkg;
58-
console.log('Is nightly version:', Boolean(process.env.COMPILER_NIGHTLY), process.env.COMPILER_NIGHTLY);
5975
const isAlreadyPublished = await isPackageVersionPublished(pkgJson.name, pkgJson.version);
6076
if (isAlreadyPublished) {
6177
console.log('Already published', pkgJson.name, pkgJson.version);
6278
return;
6379
}
6480
console.log('Publishing', pkgJson.name, pkgJson.version);
6581
const publishArgs = ['-w', pkgJson.name, 'publish'];
66-
if (process.env.COMPILER_NIGHTLY) {
82+
if (isNightlyVersion) {
6783
publishArgs.push('--tag', 'nightly');
6884
}
6985
await runCommand('npm', publishArgs);

0 commit comments

Comments
 (0)