@@ -24,8 +24,8 @@ import {
2424 gitRestoreFile ,
2525} from './common/git' ;
2626import { log } from './common/output' ;
27- import { PackageJson , loadPackageJson , npmInstall , savePackageJson } from './common/packageJson' ;
28- import { TrasnactionFn , noop , transaction } from './common/transaction' ;
27+ import { PackageJson , loadPackageJson , npmInstall , npmRun , savePackageJson } from './common/packageJson' ;
28+ import { TrasnactionFn , transaction } from './common/transaction' ;
2929
3030const rootDir = path . join ( __dirname , '..' ) ;
3131
@@ -60,7 +60,15 @@ function updateVersion(
6060}
6161
6262async function main ( ) {
63- const options = [ '--dry-run' , '--no-push' , '--no-commit' , '--no-checkout' , '--no-add' , '--name' ] as const ;
63+ const options = [
64+ '--dry-run' ,
65+ '--no-push' ,
66+ '--no-commit' ,
67+ '--no-checkout' ,
68+ '--no-add' ,
69+ '--no-sync' ,
70+ '--name' ,
71+ ] as const ;
6472
6573 const argv = process . argv . slice ( 2 ) ;
6674 const [ packageJsonPath , versionOrRelease , identifier ] = argv . filter ( ( v ) => ! options . some ( ( o ) => v . startsWith ( o ) ) ) ;
@@ -69,10 +77,6 @@ async function main() {
6977 throw new Error ( 'first argument must be a package.json path' ) ;
7078 }
7179
72- if ( ! versionOrRelease ) {
73- throw new Error ( 'second argument must be a version or release type' ) ;
74- }
75-
7680 const optionValues = options . reduce (
7781 ( val , k ) => {
7882 const opt = argv . find ( ( v ) => v . startsWith ( `${ k } =` ) ) ;
@@ -100,11 +104,15 @@ async function main() {
100104 typeof optionValues [ '--name' ] === 'string'
101105 ? optionValues [ '--name' ]
102106 : packageJson . name . replace ( '@backtrace/' , '' ) ;
103- const updatedPackageJson = updateVersion ( packageJson , versionOrRelease , identifier ) ;
107+ const updatedPackageJson = versionOrRelease
108+ ? updateVersion ( packageJson , versionOrRelease , identifier )
109+ : packageJson ;
104110 const currentBranch = execute ( gitGetCurrentBranch ( ) ) ;
105111 const branchName = `${ packageName } /${ updatedPackageJson . version } ` ;
106112
107- log ( `updating version from ${ packageJson . version } to ${ updatedPackageJson . version } ` ) ;
113+ if ( packageJson . version !== updatedPackageJson . version ) {
114+ log ( `updating version from ${ packageJson . version } to ${ updatedPackageJson . version } ` ) ;
115+ }
108116
109117 const exit : TrasnactionFn = [
110118 'exit' ,
@@ -114,29 +122,32 @@ async function main() {
114122 } ,
115123 ] ;
116124
125+ const filesToAdd : string [ ] = [
126+ packageJsonPath ,
127+ packageLockPath ,
128+ path . join ( path . dirname ( packageJsonPath ) , 'CHANGELOG.md' ) ,
129+ ] ;
130+ if ( ! dryRun ) {
131+ await savePackageJson ( packageJsonPath , updatedPackageJson ) ;
132+ }
133+
134+ if ( ! optionValues [ '--no-sync' ] ) {
135+ const execute = executor ( ) ;
136+ const args = dryRun ? [ '--dry-run' ] : [ ] ;
137+ const syncedPackages = execute ( npmRun ( 'syncVersions' , { args } ) )
138+ . trim ( )
139+ . split ( '\n' )
140+ . filter ( ( f ) => ! ! f ) ;
141+ for ( const path of syncedPackages ) {
142+ filesToAdd . push ( path ) ;
143+ }
144+ }
145+
117146 const run = transaction (
118- dryRun
119- ? noop
120- : [
121- 'save package json' ,
122- ( ) => savePackageJson ( packageJsonPath , updatedPackageJson ) ,
123- ( ) => savePackageJson ( packageJsonPath , packageJson ) ,
124- ] ,
125147 [ 'npm install' , ( ) => execute ( npmInstall ( ) ) , ( ) => execute ( gitRestoreFile ( packageLockPath ) ) ] ,
126148 optionValues [ '--no-add' ]
127149 ? exit
128- : [
129- 'add package.json to git' ,
130- ( ) => execute ( gitAdd ( packageJsonPath ) ) ,
131- ( ) => execute ( gitReset ( packageJsonPath ) ) ,
132- ] ,
133- optionValues [ '--no-add' ]
134- ? exit
135- : [
136- 'add package-lock.json to git' ,
137- ( ) => execute ( gitAdd ( packageLockPath ) ) ,
138- ( ) => execute ( gitReset ( packageLockPath ) ) ,
139- ] ,
150+ : [ 'add files to git' , ( ) => execute ( gitAdd ( ...filesToAdd ) ) , ( ) => execute ( gitReset ( ...filesToAdd ) ) ] ,
140151 optionValues [ '--no-checkout' ]
141152 ? exit
142153 : [ 'create branch' , ( ) => execute ( gitCreateBranch ( branchName ) ) , ( ) => execute ( gitDeleteBranch ( branchName ) ) ] ,
0 commit comments