@@ -115,14 +115,31 @@ if (FileSystem.exists(dotPnpmFolderPath)) {
115
115
}
116
116
}
117
117
118
+ const pnpmLockBeforePath = path . join ( __dirname , 'workspace/pnpm-lock-git.yaml' ) ;
119
+ const pnpmLockAfterPath = path . join ( __dirname , 'workspace/pnpm-lock.yaml' ) ;
120
+ let pnpmLockBeforeContent = '' ;
121
+
122
+ if ( FileSystem . exists ( pnpmLockBeforePath ) ) {
123
+ pnpmLockBeforeContent = FileSystem . readFile ( pnpmLockBeforePath ) . toString ( ) . replace ( / \s + / g, ' ' ) . trim ( ) ;
124
+ FileSystem . copyFile ( {
125
+ sourcePath : pnpmLockBeforePath ,
126
+ destinationPath : pnpmLockAfterPath ,
127
+ alreadyExistsBehavior : 'overwrite'
128
+ } ) ;
129
+ } else {
130
+ pnpmLockBeforeContent = '' ;
131
+ FileSystem . deleteFile ( pnpmLockAfterPath ) ;
132
+ }
133
+
118
134
const pnpmInstallArgs = [
119
135
'install' ,
120
136
'--store' ,
121
137
rushConfiguration . pnpmOptions . pnpmStorePath ,
122
138
'--strict-peer-dependencies' ,
123
139
'--recursive' ,
124
140
'--link-workspace-packages=false' ,
125
- '--frozen-lockfile=false' // productionMode ? 'true' : 'false'
141
+ // PNPM gets confused by the rewriting performed by our .pnpmfile.cjs afterAllResolved hook
142
+ '--frozen-lockfile=false'
126
143
] ;
127
144
128
145
console . log ( '\nInstalling:' ) ;
@@ -136,6 +153,32 @@ checkSpawnResult(
136
153
'pnpm install'
137
154
) ;
138
155
156
+ // Now compare the before/after
157
+ const pnpmLockAfterContent = FileSystem . readFile ( pnpmLockAfterPath ) . toString ( ) . replace ( / \s + / g, ' ' ) . trim ( ) ;
158
+
159
+ let shrinkwrapUpdatedNotice = false ;
160
+
161
+ if ( pnpmLockBeforeContent !== pnpmLockAfterContent ) {
162
+ if ( productionMode ) {
163
+ console . error ( 'The shrinkwrap file is not up to date:' ) ;
164
+ console . error ( ' Git copy: ' + pnpmLockBeforePath ) ;
165
+ console . error ( ' Current copy: ' + pnpmLockAfterPath ) ;
166
+ console . error ( '\nPlease commit the updated copy to Git\n' ) ;
167
+ process . exitCode = 1 ;
168
+ return ;
169
+ } else {
170
+ // Automatically update the copy
171
+ FileSystem . copyFile ( {
172
+ sourcePath : pnpmLockAfterPath ,
173
+ destinationPath : pnpmLockBeforePath ,
174
+ alreadyExistsBehavior : 'overwrite'
175
+ } ) ;
176
+
177
+ // Show the notice at the very end
178
+ shrinkwrapUpdatedNotice = true ;
179
+ }
180
+ }
181
+
139
182
console . log ( '\n\nInstallation completed successfully.' ) ;
140
183
141
184
console . log ( '\nBuilding projects...\n' ) ;
@@ -148,6 +191,11 @@ checkSpawnResult(
148
191
'pnpm run'
149
192
) ;
150
193
194
+ if ( shrinkwrapUpdatedNotice ) {
195
+ console . error ( '\n==> The shrinkwrap file has been updated. Please commit the changes to Git:' ) ;
196
+ console . error ( ` ${ pnpmLockBeforePath } ` ) ;
197
+ }
198
+
151
199
console . log ( '\n\nFinished build.js' ) ;
152
200
153
201
process . exitCode = 0 ;
0 commit comments