1- import * as assert from 'node:assert' ;
1+ import assert from 'node:assert' ;
22import { readFileSync , writeFileSync } from 'fs' ;
3- import * as path from 'path' ;
3+ import path from 'path' ;
44import { inc , lt } from 'semver' ;
5- import * as yargs from 'yargs' ;
5+ import yargs from 'yargs' ;
66import { hideBin } from 'yargs/helpers' ;
77
88import {
@@ -15,10 +15,17 @@ import {
1515 LernaModule ,
1616} from './prepareRelease' ;
1717
18- function replacePackageScopes ( rootDir : string , lernaModules : LernaModule [ ] , targetScope : string ) : number {
18+ function replacePackageScopes (
19+ rootDir : string ,
20+ lernaModules : LernaModule [ ] ,
21+ targetScope : string ,
22+ ) : number {
1923 let filesChanged = 0 ;
2024 // replace all @bitgo packages & source code with alternate SCOPE
21- const filePaths = [ ...walk ( path . join ( rootDir , 'modules' ) ) , ...walk ( path . join ( rootDir , 'webpack' ) ) ] ;
25+ const filePaths = [
26+ ...walk ( path . join ( rootDir , 'modules' ) ) ,
27+ ...walk ( path . join ( rootDir , 'webpack' ) ) ,
28+ ] ;
2229 const moduleNames = lernaModules . map ( ( { name } ) => name ) ;
2330
2431 filePaths . forEach ( ( file ) => {
@@ -31,9 +38,14 @@ function replacePackageScopes(rootDir: string, lernaModules: LernaModule[], targ
3138// we must manually set one
3239function replaceBitGoPackageScope ( rootDir : string , targetScope : string ) : void {
3340 const cwd = path . join ( rootDir , 'modules' , 'bitgo' ) ;
34- const json = JSON . parse ( readFileSync ( path . join ( cwd , 'package.json' ) , { encoding : 'utf-8' } ) ) ;
41+ const json = JSON . parse (
42+ readFileSync ( path . join ( cwd , 'package.json' ) , { encoding : 'utf-8' } ) ,
43+ ) ;
3544 json . name = `${ targetScope } /bitgo` ;
36- writeFileSync ( path . join ( cwd , 'package.json' ) , JSON . stringify ( json , null , 2 ) + '\n' ) ;
45+ writeFileSync (
46+ path . join ( cwd , 'package.json' ) ,
47+ JSON . stringify ( json , null , 2 ) + '\n' ,
48+ ) ;
3749}
3850
3951/**
@@ -42,7 +54,11 @@ function replaceBitGoPackageScope(rootDir: string, targetScope: string): void {
4254 * @returns The parsed package.json content
4355 */
4456function readModulePackageJson ( module : LernaModule ) : any {
45- return JSON . parse ( readFileSync ( path . join ( module . location , 'package.json' ) , { encoding : 'utf-8' } ) ) ;
57+ return JSON . parse (
58+ readFileSync ( path . join ( module . location , 'package.json' ) , {
59+ encoding : 'utf-8' ,
60+ } ) ,
61+ ) ;
4662}
4763
4864/**
@@ -51,7 +67,10 @@ function readModulePackageJson(module: LernaModule): any {
5167 * @param json The content to write
5268 */
5369function writeModulePackageJson ( module : LernaModule , json : any ) : void {
54- writeFileSync ( path . join ( module . location , 'package.json' ) , JSON . stringify ( json , null , 2 ) + '\n' ) ;
70+ writeFileSync (
71+ path . join ( module . location , 'package.json' ) ,
72+ JSON . stringify ( json , null , 2 ) + '\n' ,
73+ ) ;
5574}
5675
5776/**
@@ -67,7 +86,7 @@ function incrementVersionsForModuleLocation(
6786 preid : string ,
6887 module : LernaModule ,
6988 tags : DistTags | undefined ,
70- allModules : LernaModule [ ]
89+ allModules : LernaModule [ ] ,
7190) : string | undefined {
7291 const json = readModulePackageJson ( module ) ;
7392
@@ -77,15 +96,20 @@ function incrementVersionsForModuleLocation(
7796 if ( tags [ preid ] ) {
7897 const version = tags [ preid ] . split ( '-' ) ;
7998 const latest = tags ?. latest ?. split ( '-' ) ?? [ '0.0.0' ] ;
80- prevTag = lt ( version [ 0 ] , latest [ 0 ] ) ? `${ tags . latest } -${ preid } ` : tags [ preid ] ;
99+ prevTag = lt ( version [ 0 ] , latest [ 0 ] )
100+ ? `${ tags . latest } -${ preid } `
101+ : tags [ preid ] ;
81102 } else {
82103 prevTag = `${ tags . latest } -${ preid } ` ;
83104 }
84105 }
85106
86107 if ( prevTag ) {
87108 const next = inc ( prevTag , 'prerelease' , undefined , preid ) ;
88- assert ( typeof next === 'string' , `Failed to increment version for ${ json . name } prevTag=${ prevTag } ` ) ;
109+ assert (
110+ typeof next === 'string' ,
111+ `Failed to increment version for ${ json . name } prevTag=${ prevTag } ` ,
112+ ) ;
89113 console . log ( `Setting next version for ${ json . name } to ${ next } ` ) ;
90114 json . version = next ;
91115 writeModulePackageJson ( module , json ) ;
@@ -119,15 +143,26 @@ function incrementVersionsForModuleLocation(
119143 * @param {String } preid - The prerelease identifier
120144 * @param {LernaModule[] } lernaModules - The modules to update
121145 */
122- async function incrementVersions ( preid : string , lernaModules : LernaModule [ ] ) : Promise < void > {
146+ async function incrementVersions (
147+ preid : string ,
148+ lernaModules : LernaModule [ ] ,
149+ ) : Promise < void > {
123150 const distTags = await getDistTagsForModules ( lernaModules ) ;
124151
125152 for ( const m of lernaModules ) {
126153 try {
127- incrementVersionsForModuleLocation ( preid , m , distTags . get ( m ) , lernaModules ) ;
154+ incrementVersionsForModuleLocation (
155+ preid ,
156+ m ,
157+ distTags . get ( m ) ,
158+ lernaModules ,
159+ ) ;
128160 } catch ( e ) {
129161 // it's not necessarily a blocking error. Let lerna try and publish anyways
130- console . warn ( `Couldn't set next version for ${ m . name } at ${ m . location } ` , e ) ;
162+ console . warn (
163+ `Couldn't set next version for ${ m . name } at ${ m . location } ` ,
164+ e ,
165+ ) ;
131166 }
132167 }
133168}
@@ -151,7 +186,9 @@ yargs(hideBin(process.argv))
151186 . option ( 'root-dir' , {
152187 type : 'string' ,
153188 description : 'Root directory of the repository' ,
154- default : process . env . BITGO_PREPARE_RELEASE_ROOT_DIR || path . join ( __dirname , '..' ) ,
189+ default :
190+ process . env . BITGO_PREPARE_RELEASE_ROOT_DIR ||
191+ path . join ( __dirname , '..' ) ,
155192 } ) ;
156193 } ,
157194 async ( argv ) => {
@@ -166,7 +203,11 @@ yargs(hideBin(process.argv))
166203 const lernaModules = await getLernaModules ( ) ;
167204
168205 // Replace package scopes
169- const filesChanged = replacePackageScopes ( rootDir , lernaModules , targetScope ) ;
206+ const filesChanged = replacePackageScopes (
207+ rootDir ,
208+ lernaModules ,
209+ targetScope ,
210+ ) ;
170211
171212 // Replace BitGo package scope
172213 replaceBitGoPackageScope ( rootDir , targetScope ) ;
@@ -178,14 +219,16 @@ yargs(hideBin(process.argv))
178219 console . log ( `Successfully re-targeted ${ filesChanged } files.` ) ;
179220 process . exit ( 0 ) ;
180221 } else {
181- console . error ( 'No files were changed, something must have gone wrong.' ) ;
222+ console . error (
223+ 'No files were changed, something must have gone wrong.' ,
224+ ) ;
182225 process . exit ( 1 ) ;
183226 }
184227 } catch ( error ) {
185228 console . error ( 'Error in prepare-release script:' , error ) ;
186229 process . exit ( 1 ) ;
187230 }
188- }
231+ } ,
189232 )
190233 . help ( )
191234 . alias ( 'help' , 'h' )
0 commit comments