Skip to content

Commit 5ccc2a1

Browse files
authored
Merge pull request #353 from HarperFast/check-versions-fix
Fix check versions to proceed if package hasn't been published yet
2 parents 307dfb7 + 41ec809 commit 5ccc2a1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

scripts/check-versions.mjs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execFileSync } from 'node:child_process';
1+
import { spawnSync } from 'node:child_process';
22
import { readFileSync } from 'node:fs';
33
import { dirname, resolve } from 'node:path';
44
import { fileURLToPath } from 'node:url';
@@ -35,9 +35,19 @@ if (mismatched.length > 0) {
3535
}
3636

3737
// check that the version hasn't already been published to npm
38-
const published = execFileSync('npm', ['view', packageJson.name, 'version']);
39-
if (published.toString().trim() === version) {
40-
console.error(`ERROR: Version ${version} has already been published to npm!`);
38+
const child = spawnSync('npm', ['view', packageJson.name, 'version'], { encoding: 'utf8' });
39+
if (child.status !== 0) {
40+
if (child.stderr.includes('404')) {
41+
console.log(`${packageJson.name} has not been published to npm yet.\n`);
42+
} else {
43+
console.error(`ERROR: Failed to check if ${packageJson.name}@${version} has already been published to npm!`);
44+
console.error(child.stdout);
45+
console.error(child.stderr);
46+
process.exit(1);
47+
}
48+
}
49+
if (child.stdout.trim() === version) {
50+
console.error(`ERROR: ${packageJson.name}@${version} has already been published to npm!`);
4151
process.exit(1);
4252
}
4353

0 commit comments

Comments
 (0)