scripts/compute-target-versions.mjs
scripts/compute-target-versions.mjsBrowse 8 files
618 tokens
2,352 bytes
Token encoding: o200k_base
Snapshot 646e806
← Back to SKILL.md
1#!/usr/bin/env node2// Computes the target-train version options for a migration authoring task3// (SKILL.md section 2). Anchored on the npm dist-tags: a prerelease `next`4// above `latest` is an active prerelease train; anything else means the train5// rolled over and the next cut starts a new minor. Requires the repo's6// node_modules to be installed; `semver` resolves from there.7import { execSync } from 'node:child_process';8import semver from 'semver';9 10function bail(reason) {11 console.error(12 `${reason}; compute the options by hand per SKILL.md section 2.`13 );14 process.exit(1);15}16 17let distTags;18try {19 distTags = JSON.parse(20 execSync('npm view nx dist-tags --json', {21 encoding: 'utf-8',22 timeout: 30_000,23 })24 );25} catch (e) {26 bail(`Could not read the nx dist-tags (${String(e.message).split('\n')[0]})`);27}28const { latest, next } = distTags ?? {};29if (!semver.valid(latest) || !semver.valid(next) || semver.prerelease(latest)) {30 bail(`Unexpected nx dist-tags (latest: ${latest}, next: ${next})`);31}32 33const options = [];34if (semver.prerelease(next) && semver.gt(next, latest)) {35 options.push({36 version: semver.inc(next, 'prerelease'),37 reason: `next prerelease on the active train (next is ${next})`,38 recommended: true,39 });40} else {41 // A stable next above latest (mid-promotion) means the rollover already42 // happened; anchor the new minor on it so the result is not backdated.43 const base = semver.gt(next, latest) ? next : latest;44 options.push({45 version: `${semver.inc(base, 'minor')}-beta.0`,46 reason: `first prerelease of the next minor (train rolled over: next is ${next})`,47 recommended: true,48 });49}50if (semver.major(next) <= semver.major(latest)) {51 options.push({52 version: `${semver.inc(latest, 'major')}-beta.0`,53 reason:54 'next major at beta.0, for breaking work aimed at the upcoming major (the branch, not this field, chooses the ship vehicle: merges only after the train switch)',55 recommended: false,56 });57}58 59console.log(`nx dist-tags: latest ${latest}, next ${next}\n`);60for (const { version, reason, recommended } of options) {61 console.log(`${recommended ? '*' : ' '} ${version} ${reason}`);62}63console.log(64 '\n* recommended default for non-interactive runs. Interactive runs present every option plus free text (SKILL.md section 2).'65);66