@@ -10,11 +10,9 @@ const execAsync = promisify(exec);
1010
1111// Helper function to load JSON
1212const loadJsonFile = ( filePath ) => {
13- const file = readFileSync ( filePath , { encoding : 'utf8' } ) ;
14- return ( file ) ? JSON . parse ( file ) : { } ;
13+ return JSON . parse ( readFileSync ( filePath , { encoding : 'utf8' } ) ) ;
1514} ;
1615
17-
1816// Get the current version from npm
1917const getCurrentVersionFromNpm = async ( packageName ) => {
2018 try {
@@ -26,29 +24,6 @@ const getCurrentVersionFromNpm = async (packageName) => {
2624 process . exit ( 1 ) ;
2725 }
2826} ;
29- // Load the main package.json to determine the version to set
30- const mainPackageJsonPath = join ( process . cwd ( ) , 'package.json' ) ;
31- const mainPackageJson = loadJsonFile ( mainPackageJsonPath ) ;
32- const versionArg = process . argv [ 2 ] ;
33- const dryRun = process . argv . includes ( '--dry-run' ) ;
34- const ciOverride = process . argv . includes ( '--ci' ) ;
35-
36- let npmVersion = await getCurrentVersionFromNpm ( mainPackageJson . name ) ;
37- let newVersion = mainPackageJson . version ;
38-
39- const updatedFiles = [ ] ;
40-
41-
42- // Update the version in the main package.json if a new version is set
43- mainPackageJson . version = newVersion ;
44- updateDependencyVersions ( mainPackageJson , newVersion ) ; // Update dependency versions
45- if ( ! dryRun ) {
46- writeFileSync ( mainPackageJsonPath , JSON . stringify ( mainPackageJson , null , 2 ) + '\n' ) ;
47- }
48- console . log ( `Updated main package version to ${ newVersion } ` ) ;
49- updatedFiles . push ( mainPackageJsonPath ) ;
50-
51-
5227
5328// determine if this dependency should have its version number updated
5429const isUpdateableDep = function ( dep ) {
@@ -132,6 +107,29 @@ async function updatePackageVersion(dir) {
132107 }
133108}
134109
110+ // Load the main package.json to determine the version to set
111+ const mainPackageJsonPath = join ( process . cwd ( ) , 'package.json' ) ;
112+ const mainPackageJson = loadJsonFile ( mainPackageJsonPath ) ;
113+ const versionArg = process . argv [ 2 ] ;
114+ const dryRun = process . argv . includes ( '--dry-run' ) ;
115+ const ciOverride = process . argv . includes ( '--ci' ) ;
116+
117+ let npmVersion = await getCurrentVersionFromNpm ( mainPackageJson . name ) ;
118+ let newVersion = mainPackageJson . version ;
119+
120+ const updatedFiles = [ ] ;
121+
122+ // Update the version in the main package.json if a new version is set
123+ mainPackageJson . version = newVersion ;
124+ updateDependencyVersions ( mainPackageJson , newVersion ) ; // Update dependency versions
125+ if ( ! dryRun ) {
126+ writeFileSync ( mainPackageJsonPath , JSON . stringify ( mainPackageJson , null , 2 ) + '\n' ) ;
127+ }
128+ console . log ( `Updated main package version to ${ newVersion } ` ) ;
129+ updatedFiles . push ( mainPackageJsonPath ) ;
130+
131+
132+
135133// Read workspaces to publish from main package
136134// ignoring internal packages
137135const workspaceGlobs = mainPackageJson . workspaces . filter ( val => ! val . includes ( 'internal-packages' ) ) ;
0 commit comments