|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { fileURLToPath } from "node:url"; |
| 4 | +import { dirname, join } from "node:path"; |
| 5 | +import { readFileSync } from "node:fs"; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | + |
| 10 | +const packageJsonPath = join(__dirname, "../../package.json"); |
| 11 | +const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")); |
| 12 | +const version = packageJson.version; |
| 13 | + |
| 14 | +// Check if this is an alpha version |
| 15 | +const isAlpha = version.includes("alpha") || version.includes("-alpha."); |
| 16 | + |
| 17 | +if (isAlpha) { |
| 18 | + // For alpha versions, require --tag=alpha |
| 19 | + const npmTag = process.env.npm_config_tag; |
| 20 | + |
| 21 | + if (!npmTag || npmTag === "latest") { |
| 22 | + console.error( |
| 23 | + `❌ Alpha version ${version} cannot be published to "latest" tag`, |
| 24 | + ); |
| 25 | + console.error("Use: npm publish --tag=alpha"); |
| 26 | + process.exit(1); |
| 27 | + } |
| 28 | + |
| 29 | + if (npmTag !== "alpha") { |
| 30 | + console.error( |
| 31 | + `❌ Alpha version ${version} should use --tag=alpha, not --tag=${npmTag}`, |
| 32 | + ); |
| 33 | + console.error("Use: npm publish --tag=alpha"); |
| 34 | + process.exit(1); |
| 35 | + } |
| 36 | + |
| 37 | + console.log(`✅ Publishing alpha version ${version} with --tag=alpha`); |
| 38 | +} else { |
| 39 | + // For stable versions, warn if not using latest |
| 40 | + const npmTag = process.env.npm_config_tag; |
| 41 | + if (npmTag && npmTag !== "latest") { |
| 42 | + console.warn( |
| 43 | + `⚠️ Publishing stable version ${version} with --tag=${npmTag}`, |
| 44 | + ); |
| 45 | + console.warn("Did you mean to use --tag=latest or no tag?"); |
| 46 | + } else { |
| 47 | + console.log(`✅ Publishing stable version ${version}`); |
| 48 | + } |
| 49 | +} |
0 commit comments