GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — BitGoJS/scripts/prepare-release.ts at master · BitGo/BitGoJS Expand file tree/ Copy pathprepare-release.tsMore file actions 258 lines (235 loc) · 7.5 KB / Copy pathprepare-release.tsFile metadata and controls258 lines (235 loc) · 7.5 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 /** * Prepare packages for beta/alpha release under an alternate npm scope. * * This script transforms the entire monorepo: * 1. Re-scopes all `@bitgo/*` packages to `@bitgo-beta/*` (or the target scope) * 2. Fetches npm dist-tags and computes next prerelease versions * 3. Pins all inter-module dependency versions to exact values (removes ranges) * * See docs/beta-release.md for detailed documentation. * * Usage: npx tsx scripts/prepare-release.ts [preid] --scope [scope] --root-dir [dir] */ import assert from 'node:assert'; import { existsSync, readFileSync, writeFileSync } from 'fs'; import path from 'path'; import { inc, lt } from 'semver'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { walk, getDistTagsForModules, getLernaModules, changeScopeInFile, setDependencyVersion, findFirstUnpublishedVersion, getDistTagsCache, DistTags, LernaModule, } from './prepareRelease'; function replacePackageScopes( rootDir: string, lernaModules: LernaModule[], targetScope: string, ): number { let filesChanged = 0; // replace all @bitgo packages & source code with alternate SCOPE const filePaths = [ ...walk(path.join(rootDir, 'modules')), ...walk(path.join(rootDir, 'webpack')), ]; const moduleNames = lernaModules.map(({ name }) => name); filePaths.forEach((file) => { filesChanged += changeScopeInFile(file, moduleNames, targetScope); }); return filesChanged; } // modules/bitgo is the only package we publish without an `@bitgo` prefix, so // we must manually set one function replaceBitGoPackageScope(rootDir: string, targetScope: string): void { const cwd = path.join(rootDir, 'modules', 'bitgo'); const json = JSON.parse( readFileSync(path.join(cwd, 'package.json'), { encoding: 'utf-8' }), ); json.name = `${targetScope}/bitgo`; writeFileSync( path.join(cwd, 'package.json'), JSON.stringify(json, null, 2) + '\n', ); } /** * Read package.json for a module * @param module The module to read package.json from * @returns The parsed package.json content */ function readModulePackageJson(module: LernaModule): any { return JSON.parse( readFileSync(path.join(module.location, 'package.json'), { encoding: 'utf-8', }), ); } /** * Write package.json for a module * @param module The module to write package.json to * @param json The content to write */ function writeModulePackageJson(module: LernaModule, json: any): void { writeFileSync( path.join(module.location, 'package.json'), JSON.stringify(json, null, 2) + '\n', ); } /** * Increment the version for a single module based on the preid. * * @param {String} preid - The prerelease identifier * @param {LernaModule} module - The module to update * @param {DistTags|undefined} tags - The dist tags for the module * @param {LernaModule[]} allModules - All modules for dependency updates * @returns {String|undefined} - The new version if set, undefined otherwise */ async function incrementVersionsForModuleLocation( preid: string, module: LernaModule, tags: DistTags | undefined, allModules: LernaModule[], probeRegistry: boolean, ): Promise<string | undefined> { const json = readModulePackageJson(module); let prevTag: string | undefined = undefined; if (tags) { if (tags[preid]) { const version = tags[preid].split('-'); const latest = tags?.latest?.split('-') ?? ['0.0.0']; prevTag = lt(version[0], latest[0]) ? `${tags.latest}-${preid}` : tags[preid]; } else if (tags.latest) { prevTag = `${tags.latest}-${preid}`; } } if (prevTag || (tags && Object.keys(tags).length === 0)) { const initialCandidate = prevTag ? inc(prevTag, 'prerelease', undefined, preid) : json.version; assert( typeof initialCandidate === 'string', `Failed to increment version for ${json.name} prevTag=${prevTag}`, ); const next = probeRegistry ? await findFirstUnpublishedVersion(json.name, initialCandidate, preid) : initialCandidate; console.log(`Setting next version for ${json.name} to ${next}`); json.version = next; writeModulePackageJson(module, json); // since we're manually setting new versions, we must also reconcile all other lerna packages to use the 'next' version for this module allModules.forEach((otherModule) => { // skip it for the current version if (otherModule.location === module.location) { return; } // Use readModulePackageJson here instead of direct readFileSync const otherJson = readModulePackageJson(otherModule); // Check if this module depends on the one we're updating const otherJsonString = JSON.stringify(otherJson); if (otherJsonString.includes(json.name)) { setDependencyVersion(otherJson, json.name, next); writeModulePackageJson(otherModule, otherJson); } }); return next; } return undefined; } /** * increment the version based on the preid. * * @param {String} preid - The prerelease identifier * @param {LernaModule[]} lernaModules - The modules to update */ async function incrementVersions( preid: string, lernaModules: LernaModule[], ): Promise<void> { const cachePath = getDistTagsCache(); const probeRegistry = !(cachePath && existsSync(cachePath)); const distTags = await getDistTagsForModules(lernaModules); for (const m of lernaModules) { try { await incrementVersionsForModuleLocation( preid, m, distTags.get(m), lernaModules, probeRegistry, ); } catch (e) { console.error( `Couldn't set next version for ${m.name} at ${m.location}`, e, ); throw e; } } } yargs(hideBin(process.argv)) .command( '$0 [preid]', 'Prepare packages for release with a new scope and incremented versions', (yargs) => { return yargs .positional('preid', { type: 'string', describe: 'Prerelease identifier', default: 'beta', }) .option('scope', { type: 'string', description: 'Target scope for packages', default: '@bitgo-beta', }) .option('root-dir', { type: 'string', description: 'Root directory of the repository', default: process.env.BITGO_PREPARE_RELEASE_ROOT_DIR || path.join(__dirname, '..'), }); }, async (argv) => { const { preid, scope: targetScope, rootDir } = argv; console.log(`Preparing to re-target to ${targetScope}`); console.log(`Using root directory: ${rootDir}`); console.log(`Using prerelease identifier: ${preid}`); try { // Get lerna modules directly const lernaModules = await getLernaModules(); // Replace package scopes const filesChanged = replacePackageScopes( rootDir, lernaModules, targetScope, ); // Replace BitGo package scope replaceBitGoPackageScope(rootDir, targetScope); // Increment versions await incrementVersions(preid, lernaModules); if (filesChanged) { console.log(`Successfully re-targeted ${filesChanged} files.`); process.exit(0); } else { console.error( 'No files were changed, something must have gone wrong.', ); process.exit(1); } } catch (error) { console.error('Error in prepare-release script:', error); process.exit(1); } }, ) .help() .alias('help', 'h') .parse(); |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |